dma-buf: add some tracepoints to debug.
Subsystems (3)
PATCH v4 1/1 dma-buf: add some tracepoints to debug.
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or dmabuf_list.
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750
binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8
binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751
kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751
RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087
RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0
RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.h
drivers/dma-buf/dma-buf.c +47 -1
@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);
@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }
@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +return dmabuf; err_dmabuf:
@@ -779,6 +792,11 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)fd_install (fd, dmabuf->file); +if (trace_dma_buf_fd_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_fd (dmabuf, fd); + } +return fd; }EXPORT_SYMBOL_NS_GPL (dma_buf_fd,"DMA_BUF" );
@@ -794,6 +812,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 +824,14 @@ struct dma_buf *dma_buf_get(int fd)return ERR_PTR (-EINVAL ); } -return file->private_data; + dmabuf = file->private_data; + +if (trace_dma_buf_get_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_get (dmabuf, fd); + } + +return dmabuf; }EXPORT_SYMBOL_NS_GPL (dma_buf_get,"DMA_BUF" );
@@ -825,6 +851,11 @@ void dma_buf_put(struct dma_buf *dmabuf)return ;fput (dmabuf->file); + +if (trace_dma_buf_put_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_put (dmabuf); + } }EXPORT_SYMBOL_NS_GPL (dma_buf_put,"DMA_BUF" );
@@ -979,6 +1010,11 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,list_add (&attach->node, &dmabuf->attachments);dma_resv_unlock (dmabuf->resv); +if (trace_dma_buf_dynamic_attach_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_dynamic_attach (dmabuf,dma_buf_attachment_is_dynamic (attach), dev); + } +return attach; err_attach:
@@ -1023,6 +1059,11 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)if (dmabuf->ops->detach) dmabuf->ops->detach (dmabuf, attach); +if (trace_dma_buf_detach_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_detach (dmabuf,dma_buf_attachment_is_dynamic (attach), attach->dev); + } +kfree (attach); }EXPORT_SYMBOL_NS_GPL (dma_buf_detach,"DMA_BUF" );
@@ -1488,6 +1529,11 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,vma_set_file (vma, dmabuf->file); vma->vm_pgoff = pgoff; +if (trace_dma_buf_mmap_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }EXPORT_SYMBOL_NS_GPL (dma_buf_mmap,"DMA_BUF" );
include/trace/events/dma_buf.h new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.
might be:
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.
Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }
drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +
perhaps a macro similar to the one below
#define DMA_BUF_TRACE(FUNC, ...) \
do { \
if (FUNC##_enabled()) { \
guard(spinlock)(&dmabuf->name_lock); \
FUNC(__VA_ARGS__); \
} \
} while (0)This would help us avoid duplicating a lot of code.
could be:DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);
?
Christian König
maintainerQuoted 77 lines · Barry Song
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.might be:
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.Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +perhaps a macro similar to the one below
#define DMA_BUF_TRACE(FUNC, ...) \ do { \ if (FUNC##_enabled()) { \ guard(spinlock)(&dmabuf->name_lock); \ FUNC(__VA_ARGS__); \ } \ } while (0)
Quoted 7 lines
This would help us avoid duplicating a lot of code.
could be:
DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);?
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
Regards,
Christian.
Quoted 2 lines
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
Many threads use dmabuf "qcom,system". If there is a userspace name, we can immediately find the dmabuf I'm using. It might indeed not be necessary in other scenarios.
Quoted 1 line
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
This requires some thought.
________________________________
发件人: Christian König <[email protected]>
发送时间: 2025年11月28日 17:39:31
收件人: Barry Song; Xiang Gao
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈
Quoted 77 lines · Barry Song
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.might be:
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.Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +perhaps a macro similar to the one below
#define DMA_BUF_TRACE(FUNC, ...) \ do { \ if (FUNC##_enabled()) { \ guard(spinlock)(&dmabuf->name_lock); \ FUNC(__VA_ARGS__); \ } \ } while (0)
Quoted 7 lines
This would help us avoid duplicating a lot of code.
could be:
DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);?
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
Regards,
Christian.
Quoted 1 line
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
At present, from the perspective of processes, trace still makes sense.
________________________________
发件人: 高翔
发送时间: 2025年11月28日 21:14:14
收件人: Christian König; Barry Song; Xiang Gao
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] 主题: 答复: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
Quoted 2 lines
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
Many threads use dmabuf "qcom,system". If there is a userspace name, we can immediately find the dmabuf I'm using. It might indeed not be necessary in other scenarios.
Quoted 1 line
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
This requires some thought.
________________________________
发件人: Christian König <[email protected]>
发送时间: 2025年11月28日 17:39:31
收件人: Barry Song; Xiang Gao
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈
Quoted 77 lines · Barry Song
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.might be:
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.Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +perhaps a macro similar to the one below
#define DMA_BUF_TRACE(FUNC, ...) \ do { \ if (FUNC##_enabled()) { \ guard(spinlock)(&dmabuf->name_lock); \ FUNC(__VA_ARGS__); \ } \ } while (0)
Quoted 7 lines
This would help us avoid duplicating a lot of code.
could be:
DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);?
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
Regards,
Christian.
Christian König
maintainerQuoted 2 lines · 高翔
Quoted 1 line
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
At present, from the perspective of processes, trace still makes sense.
Yeah, it probably do in most use cases. I just want to cover all use cases.
Maybe just use %p to print the attachment pointer until we have something better.
Quoted 9 lines
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*发件人:* 高翔
*发送时间:* 2025年11月28日 21:14:14
*收件人:* Christian König; Barry Song; Xiang Gao
*抄送:* [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] *主题:* 答复: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
Quoted 4 lines
Quoted 2 lines
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.Many threads use dmabuf "qcom,system". If there is a userspace name, we can immediately find the dmabuf I'm using. It might indeed not be necessary in other scenarios.
The DMA-buf "name" is an userspace assigned name and *not* useable for what you suggest here.
E.g. it is usually something like "texture", "shader", "dummy", "global"....
Could be that you have a driver or use case where it is something more specific and we can keep it where it makes sense for you, but I strongly suggest to always print the ino first since that one is guaranteed to be unique.
Regards,
Christian.
Quoted 110 lines
Quoted 3 lines
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
This requires some thought.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*发件人:* Christian König <[email protected]>
*发送时间:* 2025年11月28日 17:39:31
*收件人:* Barry Song; Xiang Gao
*抄送:* [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 *主题:* [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈Quoted 77 lines · Barry Song
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.might be:
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.Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275:dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284:dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399:dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193:dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994:dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004:dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802:dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>---
drivers/dma-buf/dma-buf.c | 48 +++++++++-include/trace/events/dma_buf.h| 160 +++++++++++++++++++++++++++++++++2 files changed, 207 insertions(+), 1 deletion(-)create mode 100644
include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@ #include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> + static inline int is_dma_buf_file(struct file *); static DEFINE_MUTEX(dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT) return -EINVAL; + if (trace_dma_buf_mmap_internal_enabled()) { + guard(spinlock)(&dmabuf->name_lock); + trace_dma_buf_mmap_internal(dmabuf); + } + return dmabuf->ops->mmap(dmabuf, vma); }drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) __dma_buf_list_add(dmabuf); + if (trace_dma_buf_export_enabled()) { + guard(spinlock)(&dmabuf->name_lock); + trace_dma_buf_export(dmabuf); + } +perhaps a macro similar to the one below
#define
DMA_BUF_TRACE(FUNC, ...)\
do { \
if (FUNC##_enabled()) { \
guard(spinlock)(&dmabuf->name_lock); \
FUNC(__VA_ARGS__); \
} \
} while (0)Quoted 7 lines
This would help us avoid duplicating a lot of code.
could be:
DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);?
Thinking more about it I was wondering if we really need the userspace assigned name in the tracepoint in the first place.
The ino should be sufficient to uniquely identify each dma-buf, tracing the name should only be printed if it's changing or otherwise we spam the tracelog quite a bit with it.
BTW We don't have any identification for an attachment, so when multiple devices attach to the same DMA-buf the trace would be quite meaningless. We should probably fix that.
Regards,
Christian.
so nice, thanks.
________________________________
发件人: Barry Song <[email protected]>
发送时间: 2025年11月28日 17:31:46
收件人: Xiang Gao
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; 高翔 主题: [External Mail]Re: [PATCH v4] dma-buf: add some tracepoints to debug.
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈
Quoted 5 lines · Xiang Gao
From: gaoxiang17 <[email protected]>
I want to track the status of dmabuf in real time in the production environment. But now we can only check it by traversing the fd in the process or
dmabuf_list.
might be:
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.
Quoted 44 lines
For example:
binder:3031_4-18348 [005] ...1. 545.568275: dma_buf_export: exp_name=qcom,system name=(null) size=217088 ino=2750 binder:3031_4-18348 [005] ...1. 545.568284: dma_buf_fd: exp_name=qcom,system name=(null) size=217088 ino=2750 fd=8 binder:3031_4-18348 [005] ...1. 545.568399: dma_buf_mmap_internal: exp_name=qcom,system name=qcom,system size=28672 ino=2751 kworker/5:1-130 [005] ...1. 545.570193: dma_buf_put: exp_name=qcom,system name=ab size=28672 ino=2751 RenderThread-18891 [005] ...1. 545.602994: dma_buf_get: exp_name=qcom,system name=ab size=217088 ino=2750 fd=1087 RenderThread-9409 [000] .n.1. 545.745004: dma_buf_dynamic_attach: exp_name=qcom,system name=ab size=217088 ino=2750 is_dynamic=0 dev_name=kgsl-3d0 RenderThread-9409 [005] ...1. 545.747802: dma_buf_detach: exp_name=qcom,system name=bq size=12771328 ino=2764 is_dynamic=0 dev_name=kgsl-3d0Signed-off-by Xiang Gao <[email protected]>--- drivers/dma-buf/dma-buf.c | 48 +++++++++- include/trace/events/dma_buf.h | 160 +++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/dma_buf.hdrivers/dma-buf/dma-buf.c +8
-0@@ -35,6 +35,9 @@#include "dma-buf-sysfs-stats.h" +#define CREATE_TRACE_POINTS +#include <trace/events/dma_buf.h> +static inline int is_dma_buf_file (struct file *);static DEFINE_MUTEX (dmabuf_list_mutex);@@ -220,6 +223,11 @@ static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) dmabuf->size >> PAGE_SHIFT)return -EINVAL ; +if (trace_dma_buf_mmap_internal_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_mmap_internal (dmabuf); + } +return dmabuf->ops->mmap (dmabuf, vma); }
drivers/dma-buf/dma-buf.c struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) · line 760
Quoted 8 lines
drivers/dma-buf/dma-buf.c +5
-0@@ -745,6 +753,11 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)__dma_buf_list_add (dmabuf); +if (trace_dma_buf_export_enabled ()) { +guard (spinlock)(&dmabuf->name_lock); +trace_dma_buf_export (dmabuf); + } +
perhaps a macro similar to the one below
#define DMA_BUF_TRACE(FUNC, ...) \
do { \
if (FUNC##_enabled()) { \
guard(spinlock)(&dmabuf->name_lock); \
FUNC(__VA_ARGS__); \
} \
} while (0)This would help us avoid duplicating a lot of code.
could be:DMA_BUF_TRACE(trace_dma_buf_put, dmabuf);DMA_BUF_TRACE(trace_dma_buf_attach, dmabuf, dev);
?