* [PATCH v6] dma-buf: add some tracepoints to debug.
@ 2025-12-16 6:39 Xiang Gao
2025-12-16 8:43 ` Christian König
0 siblings, 1 reply; 4+ messages in thread
From: Xiang Gao @ 2025-12-16 6:39 UTC (permalink / raw)
To: sumit.semwal, christian.koenig, rostedt, mhiramat
Cc: linux-media, dri-devel, linux-kernel, mathieu.desnoyers, dhowells,
kuba, brauner, akpm, linux-trace-kernel, gaoxiang17
From: gaoxiang17 <gaoxiang17@xiaomi.com>
Since we can only inspect dmabuf by iterating over process FDs or the
dmabuf_list, we need to add our own tracepoints to track its status in
real time in production.
For example:
binder:3016_1-3102 [006] ...1. 255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
binder:3016_1-3102 [006] ...1. 255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
binder:3016_1-3102 [006] ...1. 255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
kworker/6:1-86 [006] ...1. 255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
RenderThread-9293 [006] ...1. 316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
RenderThread-9293 [006] ...1. 316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
RenderThread-9293 [006] ...1. 318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
---
drivers/dma-buf/dma-buf.c | 42 ++++++++-
include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
2 files changed, 195 insertions(+), 1 deletion(-)
create mode 100644 include/trace/events/dma_buf.h
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 2bcf9ceca997..831973de76c4 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -35,6 +35,25 @@
#include "dma-buf-sysfs-stats.h"
+#define CREATE_TRACE_POINTS
+#include <trace/events/dma_buf.h>
+
+/*
+ * dmabuf->name must be accessed with holding dmabuf->name_lock.
+ * we need to take the lock around the tracepoint call itself where
+ * it is called in the code.
+ *
+ * Note: FUNC##_enabled() is a static branch that will only
+ * be set when the trace event is enabled.
+ */
+#define DMA_BUF_TRACE(FUNC, ...) \
+ do { \
+ if (FUNC##_enabled()) { \
+ guard(spinlock)(&dmabuf->name_lock); \
+ FUNC(__VA_ARGS__); \
+ } \
+ } while (0)
+
static inline int is_dma_buf_file(struct file *);
static DEFINE_MUTEX(dmabuf_list_mutex);
@@ -220,6 +239,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
dmabuf->size >> PAGE_SHIFT)
return -EINVAL;
+ DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
+
return dmabuf->ops->mmap(dmabuf, vma);
}
@@ -745,6 +766,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
__dma_buf_list_add(dmabuf);
+ DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
+
return dmabuf;
err_dmabuf:
@@ -779,6 +802,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
fd_install(fd, dmabuf->file);
+ DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
+
return fd;
}
EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
@@ -794,6 +819,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
struct dma_buf *dma_buf_get(int fd)
{
struct file *file;
+ struct dma_buf *dmabuf;
file = fget(fd);
@@ -805,7 +831,11 @@ struct dma_buf *dma_buf_get(int fd)
return ERR_PTR(-EINVAL);
}
- return file->private_data;
+ dmabuf = file->private_data;
+
+ DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
+
+ return dmabuf;
}
EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
@@ -825,6 +855,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
return;
fput(dmabuf->file);
+
+ DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
}
EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
@@ -979,6 +1011,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
list_add(&attach->node, &dmabuf->attachments);
dma_resv_unlock(dmabuf->resv);
+ DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
+ dma_buf_attachment_is_dynamic(attach), dev);
+
return attach;
err_attach:
@@ -1023,6 +1058,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
if (dmabuf->ops->detach)
dmabuf->ops->detach(dmabuf, attach);
+ DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
+ dma_buf_attachment_is_dynamic(attach), attach->dev);
+
kfree(attach);
}
EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
@@ -1488,6 +1526,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
vma_set_file(vma, dmabuf->file);
vma->vm_pgoff = pgoff;
+ DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
+
return dmabuf->ops->mmap(dmabuf, vma);
}
EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
diff --git a/include/trace/events/dma_buf.h b/include/trace/events/dma_buf.h
new file mode 100644
index 000000000000..81ee4d05979c
--- /dev/null
+++ b/include/trace/events/dma_buf.h
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM dma_buf
+
+#if !defined(_TRACE_DMA_BUF_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_DMA_BUF_H
+
+#include <linux/dma-buf.h>
+#include <linux/tracepoint.h>
+
+DECLARE_EVENT_CLASS(dma_buf,
+
+ TP_PROTO(struct dma_buf *dmabuf),
+
+ TP_ARGS(dmabuf),
+
+ TP_STRUCT__entry(
+ __string(exp_name, dmabuf->exp_name)
+ __field(size_t, size)
+ __field(ino_t, ino)
+ ),
+
+ TP_fast_assign(
+ __assign_str(exp_name);
+ __entry->size = dmabuf->size;
+ __entry->ino = dmabuf->file->f_inode->i_ino;
+ ),
+
+ TP_printk("exp_name=%s size=%zu ino=%lu",
+ __get_str(exp_name),
+ __entry->size,
+ __entry->ino)
+);
+
+DECLARE_EVENT_CLASS(dma_buf_attach_dev,
+
+ TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
+
+ TP_ARGS(dmabuf, attach, is_dynamic, dev),
+
+ TP_STRUCT__entry(
+ __string(dev_name, dev_name(dev))
+ __string(exp_name, dmabuf->exp_name)
+ __field(size_t, size)
+ __field(ino_t, ino)
+ __field(struct dma_buf_attachment *, attach)
+ __field(bool, is_dynamic)
+ ),
+
+ TP_fast_assign(
+ __assign_str(dev_name);
+ __assign_str(exp_name);
+ __entry->size = dmabuf->size;
+ __entry->ino = dmabuf->file->f_inode->i_ino;
+ __entry->is_dynamic = is_dynamic;
+ __entry->attach = attach;
+ ),
+
+ TP_printk("exp_name=%s size=%zu ino=%lu attachment:%p is_dynamic=%d dev_name=%s",
+ __get_str(exp_name),
+ __entry->size,
+ __entry->ino,
+ __entry->attach,
+ __entry->is_dynamic,
+ __get_str(dev_name))
+);
+
+DECLARE_EVENT_CLASS(dma_buf_fd,
+
+ TP_PROTO(struct dma_buf *dmabuf, int fd),
+
+ TP_ARGS(dmabuf, fd),
+
+ TP_STRUCT__entry(
+ __string(exp_name, dmabuf->exp_name)
+ __field(size_t, size)
+ __field(ino_t, ino)
+ __field(int, fd)
+ ),
+
+ TP_fast_assign(
+ __assign_str(exp_name);
+ __entry->size = dmabuf->size;
+ __entry->ino = dmabuf->file->f_inode->i_ino;
+ __entry->fd = fd;
+ ),
+
+ TP_printk("exp_name=%s size=%zu ino=%lu fd=%d",
+ __get_str(exp_name),
+ __entry->size,
+ __entry->ino,
+ __entry->fd)
+);
+
+DEFINE_EVENT(dma_buf, dma_buf_export,
+
+ TP_PROTO(struct dma_buf *dmabuf),
+
+ TP_ARGS(dmabuf)
+);
+
+DEFINE_EVENT(dma_buf, dma_buf_mmap_internal,
+
+ TP_PROTO(struct dma_buf *dmabuf),
+
+ TP_ARGS(dmabuf)
+);
+
+DEFINE_EVENT(dma_buf, dma_buf_mmap,
+
+ TP_PROTO(struct dma_buf *dmabuf),
+
+ TP_ARGS(dmabuf)
+);
+
+DEFINE_EVENT(dma_buf, dma_buf_put,
+
+ TP_PROTO(struct dma_buf *dmabuf),
+
+ TP_ARGS(dmabuf)
+);
+
+DEFINE_EVENT(dma_buf_attach_dev, dma_buf_dynamic_attach,
+
+ TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
+
+ TP_ARGS(dmabuf, attach, is_dynamic, dev)
+);
+
+DEFINE_EVENT(dma_buf_attach_dev, dma_buf_detach,
+
+ TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
+
+ TP_ARGS(dmabuf, attach, is_dynamic, dev)
+);
+
+DEFINE_EVENT(dma_buf_fd, dma_buf_fd,
+
+ TP_PROTO(struct dma_buf *dmabuf, int fd),
+
+ TP_ARGS(dmabuf, fd)
+);
+
+DEFINE_EVENT(dma_buf_fd, dma_buf_get,
+
+ TP_PROTO(struct dma_buf *dmabuf, int fd),
+
+ TP_ARGS(dmabuf, fd)
+);
+
+#endif /* _TRACE_DMA_BUF_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v6] dma-buf: add some tracepoints to debug.
2025-12-16 6:39 [PATCH v6] dma-buf: add some tracepoints to debug Xiang Gao
@ 2025-12-16 8:43 ` Christian König
2025-12-16 9:05 ` Barry Song
[not found] ` <b0e5daa85079423480fdbb82c09dc707@xiaomi.com>
0 siblings, 2 replies; 4+ messages in thread
From: Christian König @ 2025-12-16 8:43 UTC (permalink / raw)
To: Xiang Gao, sumit.semwal, rostedt, mhiramat
Cc: linux-media, dri-devel, linux-kernel, mathieu.desnoyers, dhowells,
kuba, brauner, akpm, linux-trace-kernel, gaoxiang17
On 12/16/25 07:39, Xiang Gao wrote:
> From: gaoxiang17 <gaoxiang17@xiaomi.com>
>
> Since we can only inspect dmabuf by iterating over process FDs or the
> dmabuf_list, we need to add our own tracepoints to track its status in
> real time in production.
>
> For example:
> binder:3016_1-3102 [006] ...1. 255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
> binder:3016_1-3102 [006] ...1. 255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
> binder:3016_1-3102 [006] ...1. 255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
> kworker/6:1-86 [006] ...1. 255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
> RenderThread-9293 [006] ...1. 316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
> RenderThread-9293 [006] ...1. 316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
> RenderThread-9293 [006] ...1. 318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
>
> Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Going to push this to drm-misc-next today unless somebody has some last minute objections.
Regards,
Christian.
> ---
> drivers/dma-buf/dma-buf.c | 42 ++++++++-
> include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
> 2 files changed, 195 insertions(+), 1 deletion(-)
> create mode 100644 include/trace/events/dma_buf.h
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 2bcf9ceca997..831973de76c4 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -35,6 +35,25 @@
>
> #include "dma-buf-sysfs-stats.h"
>
> +#define CREATE_TRACE_POINTS
> +#include <trace/events/dma_buf.h>
> +
> +/*
> + * dmabuf->name must be accessed with holding dmabuf->name_lock.
> + * we need to take the lock around the tracepoint call itself where
> + * it is called in the code.
> + *
> + * Note: FUNC##_enabled() is a static branch that will only
> + * be set when the trace event is enabled.
> + */
> +#define DMA_BUF_TRACE(FUNC, ...) \
> + do { \
> + if (FUNC##_enabled()) { \
> + guard(spinlock)(&dmabuf->name_lock); \
> + FUNC(__VA_ARGS__); \
> + } \
> + } while (0)
> +
> static inline int is_dma_buf_file(struct file *);
>
> static DEFINE_MUTEX(dmabuf_list_mutex);
> @@ -220,6 +239,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
> dmabuf->size >> PAGE_SHIFT)
> return -EINVAL;
>
> + DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
> +
> return dmabuf->ops->mmap(dmabuf, vma);
> }
>
> @@ -745,6 +766,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>
> __dma_buf_list_add(dmabuf);
>
> + DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
> +
> return dmabuf;
>
> err_dmabuf:
> @@ -779,6 +802,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
>
> fd_install(fd, dmabuf->file);
>
> + DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
> +
> return fd;
> }
> EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
> @@ -794,6 +819,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
> struct dma_buf *dma_buf_get(int fd)
> {
> struct file *file;
> + struct dma_buf *dmabuf;
>
> file = fget(fd);
>
> @@ -805,7 +831,11 @@ struct dma_buf *dma_buf_get(int fd)
> return ERR_PTR(-EINVAL);
> }
>
> - return file->private_data;
> + dmabuf = file->private_data;
> +
> + DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
> +
> + return dmabuf;
> }
> EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
>
> @@ -825,6 +855,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
> return;
>
> fput(dmabuf->file);
> +
> + DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
> }
> EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
>
> @@ -979,6 +1011,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
> list_add(&attach->node, &dmabuf->attachments);
> dma_resv_unlock(dmabuf->resv);
>
> + DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
> + dma_buf_attachment_is_dynamic(attach), dev);
> +
> return attach;
>
> err_attach:
> @@ -1023,6 +1058,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
> if (dmabuf->ops->detach)
> dmabuf->ops->detach(dmabuf, attach);
>
> + DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
> + dma_buf_attachment_is_dynamic(attach), attach->dev);
> +
> kfree(attach);
> }
> EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
> @@ -1488,6 +1526,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
> vma_set_file(vma, dmabuf->file);
> vma->vm_pgoff = pgoff;
>
> + DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
> +
> return dmabuf->ops->mmap(dmabuf, vma);
> }
> EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
> diff --git a/include/trace/events/dma_buf.h b/include/trace/events/dma_buf.h
> new file mode 100644
> index 000000000000..81ee4d05979c
> --- /dev/null
> +++ b/include/trace/events/dma_buf.h
> @@ -0,0 +1,154 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM dma_buf
> +
> +#if !defined(_TRACE_DMA_BUF_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_DMA_BUF_H
> +
> +#include <linux/dma-buf.h>
> +#include <linux/tracepoint.h>
> +
> +DECLARE_EVENT_CLASS(dma_buf,
> +
> + TP_PROTO(struct dma_buf *dmabuf),
> +
> + TP_ARGS(dmabuf),
> +
> + TP_STRUCT__entry(
> + __string(exp_name, dmabuf->exp_name)
> + __field(size_t, size)
> + __field(ino_t, ino)
> + ),
> +
> + TP_fast_assign(
> + __assign_str(exp_name);
> + __entry->size = dmabuf->size;
> + __entry->ino = dmabuf->file->f_inode->i_ino;
> + ),
> +
> + TP_printk("exp_name=%s size=%zu ino=%lu",
> + __get_str(exp_name),
> + __entry->size,
> + __entry->ino)
> +);
> +
> +DECLARE_EVENT_CLASS(dma_buf_attach_dev,
> +
> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
> +
> + TP_ARGS(dmabuf, attach, is_dynamic, dev),
> +
> + TP_STRUCT__entry(
> + __string(dev_name, dev_name(dev))
> + __string(exp_name, dmabuf->exp_name)
> + __field(size_t, size)
> + __field(ino_t, ino)
> + __field(struct dma_buf_attachment *, attach)
> + __field(bool, is_dynamic)
> + ),
> +
> + TP_fast_assign(
> + __assign_str(dev_name);
> + __assign_str(exp_name);
> + __entry->size = dmabuf->size;
> + __entry->ino = dmabuf->file->f_inode->i_ino;
> + __entry->is_dynamic = is_dynamic;
> + __entry->attach = attach;
> + ),
> +
> + TP_printk("exp_name=%s size=%zu ino=%lu attachment:%p is_dynamic=%d dev_name=%s",
> + __get_str(exp_name),
> + __entry->size,
> + __entry->ino,
> + __entry->attach,
> + __entry->is_dynamic,
> + __get_str(dev_name))
> +);
> +
> +DECLARE_EVENT_CLASS(dma_buf_fd,
> +
> + TP_PROTO(struct dma_buf *dmabuf, int fd),
> +
> + TP_ARGS(dmabuf, fd),
> +
> + TP_STRUCT__entry(
> + __string(exp_name, dmabuf->exp_name)
> + __field(size_t, size)
> + __field(ino_t, ino)
> + __field(int, fd)
> + ),
> +
> + TP_fast_assign(
> + __assign_str(exp_name);
> + __entry->size = dmabuf->size;
> + __entry->ino = dmabuf->file->f_inode->i_ino;
> + __entry->fd = fd;
> + ),
> +
> + TP_printk("exp_name=%s size=%zu ino=%lu fd=%d",
> + __get_str(exp_name),
> + __entry->size,
> + __entry->ino,
> + __entry->fd)
> +);
> +
> +DEFINE_EVENT(dma_buf, dma_buf_export,
> +
> + TP_PROTO(struct dma_buf *dmabuf),
> +
> + TP_ARGS(dmabuf)
> +);
> +
> +DEFINE_EVENT(dma_buf, dma_buf_mmap_internal,
> +
> + TP_PROTO(struct dma_buf *dmabuf),
> +
> + TP_ARGS(dmabuf)
> +);
> +
> +DEFINE_EVENT(dma_buf, dma_buf_mmap,
> +
> + TP_PROTO(struct dma_buf *dmabuf),
> +
> + TP_ARGS(dmabuf)
> +);
> +
> +DEFINE_EVENT(dma_buf, dma_buf_put,
> +
> + TP_PROTO(struct dma_buf *dmabuf),
> +
> + TP_ARGS(dmabuf)
> +);
> +
> +DEFINE_EVENT(dma_buf_attach_dev, dma_buf_dynamic_attach,
> +
> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
> +
> + TP_ARGS(dmabuf, attach, is_dynamic, dev)
> +);
> +
> +DEFINE_EVENT(dma_buf_attach_dev, dma_buf_detach,
> +
> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
> +
> + TP_ARGS(dmabuf, attach, is_dynamic, dev)
> +);
> +
> +DEFINE_EVENT(dma_buf_fd, dma_buf_fd,
> +
> + TP_PROTO(struct dma_buf *dmabuf, int fd),
> +
> + TP_ARGS(dmabuf, fd)
> +);
> +
> +DEFINE_EVENT(dma_buf_fd, dma_buf_get,
> +
> + TP_PROTO(struct dma_buf *dmabuf, int fd),
> +
> + TP_ARGS(dmabuf, fd)
> +);
> +
> +#endif /* _TRACE_DMA_BUF_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v6] dma-buf: add some tracepoints to debug.
2025-12-16 8:43 ` Christian König
@ 2025-12-16 9:05 ` Barry Song
[not found] ` <b0e5daa85079423480fdbb82c09dc707@xiaomi.com>
1 sibling, 0 replies; 4+ messages in thread
From: Barry Song @ 2025-12-16 9:05 UTC (permalink / raw)
To: Christian König
Cc: Xiang Gao, sumit.semwal, rostedt, mhiramat, linux-media,
dri-devel, linux-kernel, mathieu.desnoyers, dhowells, kuba,
brauner, akpm, linux-trace-kernel, gaoxiang17
On Tue, Dec 16, 2025 at 4:44 PM Christian König
<christian.koenig@amd.com> wrote:
>
> On 12/16/25 07:39, Xiang Gao wrote:
> > From: gaoxiang17 <gaoxiang17@xiaomi.com>
> >
> > Since we can only inspect dmabuf by iterating over process FDs or the
> > dmabuf_list, we need to add our own tracepoints to track its status in
> > real time in production.
> >
> > For example:
> > binder:3016_1-3102 [006] ...1. 255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
> > binder:3016_1-3102 [006] ...1. 255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
> > binder:3016_1-3102 [006] ...1. 255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
> > kworker/6:1-86 [006] ...1. 255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
> > RenderThread-9293 [006] ...1. 316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
> > RenderThread-9293 [006] ...1. 316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
> > RenderThread-9293 [006] ...1. 318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
> >
> > Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> Going to push this to drm-misc-next today unless somebody has some last minute objections.
No objection, but I would strongly suggest Xiang include a
diff description next time, after the changelog for each new
version.
I recall clearly commenting on both changelog refinement and
the DMA_BUF_TRACE() macro [1]. It would be better to mention
similar things for each new version next time :-)
[1] https://lore.kernel.org/lkml/CAGsJ_4y0zc_nh2q=w4uR04vtveCf6L7+hgafznHuL8ByWbyNOQ@mail.gmail.com/
Thanks
Barry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 答复: [External Mail]Re: [PATCH v6] dma-buf: add some tracepoints to debug.
[not found] ` <b0e5daa85079423480fdbb82c09dc707@xiaomi.com>
@ 2025-12-16 16:15 ` Christian König
0 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2025-12-16 16:15 UTC (permalink / raw)
To: 高翔, Xiang Gao, sumit.semwal@linaro.org,
rostedt@goodmis.org, mhiramat@kernel.org
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com,
dhowells@redhat.com, kuba@kernel.org, brauner@kernel.org,
akpm@linux-foundation.org, linux-trace-kernel@vger.kernel.org
I have to take that back, the automated checkers have nit picks on this patch:
/home/ckoenig/Downloads/[PATCH v6] dma-buf: add some tracepoints to debug. - Xiang Gao <gxxa03070307@gmail.com> - 2025-12-16 0739.eml:308: trailing whitespace.
/* SPDX-License-Identifier: GPL-2.0 */
/home/ckoenig/Downloads/[PATCH v6] dma-buf: add some tracepoints to debug. - Xiang Gao <gxxa03070307@gmail.com> - 2025-12-16 0739.eml:309: trailing whitespace.
#undef TRACE_SYSTEM
/home/ckoenig/Downloads/[PATCH v6] dma-buf: add some tracepoints to debug. - Xiang Gao <gxxa03070307@gmail.com> - 2025-12-16 0739.eml:310: trailing whitespace.
#define TRACE_SYSTEM dma_buf
/home/ckoenig/Downloads/[PATCH v6] dma-buf: add some tracepoints to debug. - Xiang Gao <gxxa03070307@gmail.com> - 2025-12-16 0739.eml:311: trailing whitespace.
/home/ckoenig/Downloads/[PATCH v6] dma-buf: add some tracepoints to debug. - Xiang Gao <gxxa03070307@gmail.com> - 2025-12-16 0739.eml:312: trailing whitespace.
#if !defined(_TRACE_DMA_BUF_H) || defined(TRACE_HEADER_MULTI_READ)
Additional to that the patch doesn't seems to be based against drm-misc-next:
error: patch failed: drivers/dma-buf/dma-buf.c:35
error: drivers/dma-buf/dma-buf.c: patch does not apply
So please fix the whitespace issues, rebase and send out again. I should be able to apply it tomorrow then.
Regards,
Christian.
On 12/16/25 14:12, 高翔 wrote:
> thanks.
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *发件人:* Christian König <christian.koenig@amd.com>
> *发送时间:* 2025年12月16日 16:43:26
> *收件人:* Xiang Gao; sumit.semwal@linaro.org; rostedt@goodmis.org; mhiramat@kernel.org
> *抄送:* linux-media@vger.kernel.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; mathieu.desnoyers@efficios.com; dhowells@redhat.com; kuba@kernel.org; brauner@kernel.org; akpm@linux-foundation.org; linux-trace-kernel@vger.kernel.org; 高翔
> *主题:* [External Mail]Re: [PATCH v6] dma-buf: add some tracepoints to debug.
>
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
>
> On 12/16/25 07:39, Xiang Gao wrote:
>> From: gaoxiang17 <gaoxiang17@xiaomi.com>
>>
>> Since we can only inspect dmabuf by iterating over process FDs or the
>> dmabuf_list, we need to add our own tracepoints to track its status in
>> real time in production.
>>
>> For example:
>> binder:3016_1-3102 [006] ...1. 255.126521: dma_buf_export: exp_name=qcom,system size=12685312 ino=2738
>> binder:3016_1-3102 [006] ...1. 255.126528: dma_buf_fd: exp_name=qcom,system size=12685312 ino=2738 fd=8
>> binder:3016_1-3102 [006] ...1. 255.126642: dma_buf_mmap_internal: exp_name=qcom,system size=28672 ino=2739
>> kworker/6:1-86 [006] ...1. 255.127194: dma_buf_put: exp_name=qcom,system size=12685312 ino=2738
>> RenderThread-9293 [006] ...1. 316.618179: dma_buf_get: exp_name=qcom,system size=12771328 ino=2762 fd=176
>> RenderThread-9293 [006] ...1. 316.618195: dma_buf_dynamic_attach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
>> RenderThread-9293 [006] ...1. 318.878220: dma_buf_detach: exp_name=qcom,system size=12771328 ino=2762 attachment:ffffff880a18dd00 is_dynamic=0 dev_name=kgsl-3d0
>>
>> Signed-off-by: Xiang Gao <gaoxiang17@xiaomi.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
>
> Going to push this to drm-misc-next today unless somebody has some last minute objections.
>
> Regards,
> Christian.
>
>> ---
>> drivers/dma-buf/dma-buf.c | 42 ++++++++-
>> include/trace/events/dma_buf.h | 154 +++++++++++++++++++++++++++++++++
>> 2 files changed, 195 insertions(+), 1 deletion(-)
>> create mode 100644 include/trace/events/dma_buf.h
>>
>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
>> index 2bcf9ceca997..831973de76c4 100644
>> --- a/drivers/dma-buf/dma-buf.c
>> +++ b/drivers/dma-buf/dma-buf.c
>> @@ -35,6 +35,25 @@
>>
>> #include "dma-buf-sysfs-stats.h"
>>
>> +#define CREATE_TRACE_POINTS
>> +#include <trace/events/dma_buf.h>
>> +
>> +/*
>> + * dmabuf->name must be accessed with holding dmabuf->name_lock.
>> + * we need to take the lock around the tracepoint call itself where
>> + * it is called in the code.
>> + *
>> + * Note: FUNC##_enabled() is a static branch that will only
>> + * be set when the trace event is enabled.
>> + */
>> +#define DMA_BUF_TRACE(FUNC, ...) \
>> + do { \
>> + if (FUNC##_enabled()) { \
>> + guard(spinlock)(&dmabuf->name_lock); \
>> + FUNC(__VA_ARGS__); \
>> + } \
>> + } while (0)
>> +
>> static inline int is_dma_buf_file(struct file *);
>>
>> static DEFINE_MUTEX(dmabuf_list_mutex);
>> @@ -220,6 +239,8 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
>> dmabuf->size >> PAGE_SHIFT)
>> return -EINVAL;
>>
>> + DMA_BUF_TRACE(trace_dma_buf_mmap_internal, dmabuf);
>> +
>> return dmabuf->ops->mmap(dmabuf, vma);
>> }
>>
>> @@ -745,6 +766,8 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
>>
>> __dma_buf_list_add(dmabuf);
>>
>> + DMA_BUF_TRACE(trace_dma_buf_export, dmabuf);
>> +
>> return dmabuf;
>>
>> err_dmabuf:
>> @@ -779,6 +802,8 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
>>
>> fd_install(fd, dmabuf->file);
>>
>> + DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
>> +
>> return fd;
>> }
>> EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
>> @@ -794,6 +819,7 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
>> struct dma_buf *dma_buf_get(int fd)
>> {
>> struct file *file;
>> + struct dma_buf *dmabuf;
>>
>> file = fget(fd);
>>
>> @@ -805,7 +831,11 @@ struct dma_buf *dma_buf_get(int fd)
>> return ERR_PTR(-EINVAL);
>> }
>>
>> - return file->private_data;
>> + dmabuf = file->private_data;
>> +
>> + DMA_BUF_TRACE(trace_dma_buf_get, dmabuf, fd);
>> +
>> + return dmabuf;
>> }
>> EXPORT_SYMBOL_NS_GPL(dma_buf_get, "DMA_BUF");
>>
>> @@ -825,6 +855,8 @@ void dma_buf_put(struct dma_buf *dmabuf)
>> return;
>>
>> fput(dmabuf->file);
>> +
>> + DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);
>> }
>> EXPORT_SYMBOL_NS_GPL(dma_buf_put, "DMA_BUF");
>>
>> @@ -979,6 +1011,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
>> list_add(&attach->node, &dmabuf->attachments);
>> dma_resv_unlock(dmabuf->resv);
>>
>> + DMA_BUF_TRACE(trace_dma_buf_dynamic_attach, dmabuf, attach,
>> + dma_buf_attachment_is_dynamic(attach), dev);
>> +
>> return attach;
>>
>> err_attach:
>> @@ -1023,6 +1058,9 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
>> if (dmabuf->ops->detach)
>> dmabuf->ops->detach(dmabuf, attach);
>>
>> + DMA_BUF_TRACE(trace_dma_buf_detach, dmabuf, attach,
>> + dma_buf_attachment_is_dynamic(attach), attach->dev);
>> +
>> kfree(attach);
>> }
>> EXPORT_SYMBOL_NS_GPL(dma_buf_detach, "DMA_BUF");
>> @@ -1488,6 +1526,8 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
>> vma_set_file(vma, dmabuf->file);
>> vma->vm_pgoff = pgoff;
>>
>> + DMA_BUF_TRACE(trace_dma_buf_mmap, dmabuf);
>> +
>> return dmabuf->ops->mmap(dmabuf, vma);
>> }
>> EXPORT_SYMBOL_NS_GPL(dma_buf_mmap, "DMA_BUF");
>> diff --git a/include/trace/events/dma_buf.h b/include/trace/events/dma_buf.h
>> new file mode 100644
>> index 000000000000..81ee4d05979c
>> --- /dev/null
>> +++ b/include/trace/events/dma_buf.h
>> @@ -0,0 +1,154 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +#undef TRACE_SYSTEM
>> +#define TRACE_SYSTEM dma_buf
>> +
>> +#if !defined(_TRACE_DMA_BUF_H) || defined(TRACE_HEADER_MULTI_READ)
>> +#define _TRACE_DMA_BUF_H
>> +
>> +#include <linux/dma-buf.h>
>> +#include <linux/tracepoint.h>
>> +
>> +DECLARE_EVENT_CLASS(dma_buf,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf),
>> +
>> + TP_ARGS(dmabuf),
>> +
>> + TP_STRUCT__entry(
>> + __string(exp_name, dmabuf->exp_name)
>> + __field(size_t, size)
>> + __field(ino_t, ino)
>> + ),
>> +
>> + TP_fast_assign(
>> + __assign_str(exp_name);
>> + __entry->size = dmabuf->size;
>> + __entry->ino = dmabuf->file->f_inode->i_ino;
>> + ),
>> +
>> + TP_printk("exp_name=%s size=%zu ino=%lu",
>> + __get_str(exp_name),
>> + __entry->size,
>> + __entry->ino)
>> +);
>> +
>> +DECLARE_EVENT_CLASS(dma_buf_attach_dev,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
>> +
>> + TP_ARGS(dmabuf, attach, is_dynamic, dev),
>> +
>> + TP_STRUCT__entry(
>> + __string(dev_name, dev_name(dev))
>> + __string(exp_name, dmabuf->exp_name)
>> + __field(size_t, size)
>> + __field(ino_t, ino)
>> + __field(struct dma_buf_attachment *, attach)
>> + __field(bool, is_dynamic)
>> + ),
>> +
>> + TP_fast_assign(
>> + __assign_str(dev_name);
>> + __assign_str(exp_name);
>> + __entry->size = dmabuf->size;
>> + __entry->ino = dmabuf->file->f_inode->i_ino;
>> + __entry->is_dynamic = is_dynamic;
>> + __entry->attach = attach;
>> + ),
>> +
>> + TP_printk("exp_name=%s size=%zu ino=%lu attachment:%p is_dynamic=%d dev_name=%s",
>> + __get_str(exp_name),
>> + __entry->size,
>> + __entry->ino,
>> + __entry->attach,
>> + __entry->is_dynamic,
>> + __get_str(dev_name))
>> +);
>> +
>> +DECLARE_EVENT_CLASS(dma_buf_fd,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, int fd),
>> +
>> + TP_ARGS(dmabuf, fd),
>> +
>> + TP_STRUCT__entry(
>> + __string(exp_name, dmabuf->exp_name)
>> + __field(size_t, size)
>> + __field(ino_t, ino)
>> + __field(int, fd)
>> + ),
>> +
>> + TP_fast_assign(
>> + __assign_str(exp_name);
>> + __entry->size = dmabuf->size;
>> + __entry->ino = dmabuf->file->f_inode->i_ino;
>> + __entry->fd = fd;
>> + ),
>> +
>> + TP_printk("exp_name=%s size=%zu ino=%lu fd=%d",
>> + __get_str(exp_name),
>> + __entry->size,
>> + __entry->ino,
>> + __entry->fd)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf, dma_buf_export,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf),
>> +
>> + TP_ARGS(dmabuf)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf, dma_buf_mmap_internal,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf),
>> +
>> + TP_ARGS(dmabuf)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf, dma_buf_mmap,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf),
>> +
>> + TP_ARGS(dmabuf)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf, dma_buf_put,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf),
>> +
>> + TP_ARGS(dmabuf)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf_attach_dev, dma_buf_dynamic_attach,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
>> +
>> + TP_ARGS(dmabuf, attach, is_dynamic, dev)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf_attach_dev, dma_buf_detach,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, struct dma_buf_attachment *attach, bool is_dynamic, struct device *dev),
>> +
>> + TP_ARGS(dmabuf, attach, is_dynamic, dev)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf_fd, dma_buf_fd,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, int fd),
>> +
>> + TP_ARGS(dmabuf, fd)
>> +);
>> +
>> +DEFINE_EVENT(dma_buf_fd, dma_buf_get,
>> +
>> + TP_PROTO(struct dma_buf *dmabuf, int fd),
>> +
>> + TP_ARGS(dmabuf, fd)
>> +);
>> +
>> +#endif /* _TRACE_DMA_BUF_H */
>> +
>> +/* This part must be outside protection */
>> +#include <trace/define_trace.h>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-16 16:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-16 6:39 [PATCH v6] dma-buf: add some tracepoints to debug Xiang Gao
2025-12-16 8:43 ` Christian König
2025-12-16 9:05 ` Barry Song
[not found] ` <b0e5daa85079423480fdbb82c09dc707@xiaomi.com>
2025-12-16 16:15 ` 答复: [External Mail]Re: " Christian König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox