Skip to content

Commit 3b3ddaf

Browse files
gaoxiang17ChristianKoenigAMD
authored andcommitted
dma-buf: add some tracepoints to debug.
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: Steven Rostedt (Google) <rostedt@goodmis.org> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Christian König <christian.koenig@amd.com> Link: https://lore.kernel.org/r/20260109115411.115270-1-gxxa03070307@gmail.com
1 parent d51e390 commit 3b3ddaf

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

drivers/dma-buf/dma-buf.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@
4646
*/
4747
#define DMA_BUF_TRACE(FUNC, ...) \
4848
do { \
49-
if (FUNC##_enabled()) { \
49+
/* Always expose lock if lockdep is enabled */ \
50+
if (IS_ENABLED(CONFIG_LOCKDEP) || FUNC##_enabled()) { \
5051
guard(spinlock)(&dmabuf->name_lock); \
5152
FUNC(__VA_ARGS__); \
52-
} else if (IS_ENABLED(CONFIG_LOCKDEP)) { \
53-
/* Expose this lock when lockdep is enabled */ \
54-
guard(spinlock)(&dmabuf->name_lock); \
5553
} \
5654
} while (0)
5755

@@ -795,8 +793,7 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
795793
return -EINVAL;
796794

797795
fd = FD_ADD(flags, dmabuf->file);
798-
if (fd >= 0)
799-
DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
796+
DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
800797

801798
return fd;
802799
}

include/trace/events/dma_buf.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ DECLARE_EVENT_CLASS(dma_buf,
1515
TP_ARGS(dmabuf),
1616

1717
TP_STRUCT__entry(
18-
__string(exp_name, dmabuf->exp_name)
19-
__field(size_t, size)
20-
__field(ino_t, ino)
18+
__string( exp_name, dmabuf->exp_name)
19+
__field( size_t, size)
20+
__field( ino_t, ino)
2121
),
2222

2323
TP_fast_assign(
2424
__assign_str(exp_name);
25-
__entry->size = dmabuf->size;
26-
__entry->ino = dmabuf->file->f_inode->i_ino;
25+
__entry->size = dmabuf->size;
26+
__entry->ino = dmabuf->file->f_inode->i_ino;
2727
),
2828

2929
TP_printk("exp_name=%s size=%zu ino=%lu",
@@ -40,21 +40,21 @@ DECLARE_EVENT_CLASS(dma_buf_attach_dev,
4040
TP_ARGS(dmabuf, attach, is_dynamic, dev),
4141

4242
TP_STRUCT__entry(
43-
__string(dev_name, dev_name(dev))
44-
__string(exp_name, dmabuf->exp_name)
45-
__field(size_t, size)
46-
__field(ino_t, ino)
47-
__field(struct dma_buf_attachment *, attach)
48-
__field(bool, is_dynamic)
43+
__string( dev_name, dev_name(dev))
44+
__string( exp_name, dmabuf->exp_name)
45+
__field( size_t, size)
46+
__field( ino_t, ino)
47+
__field( struct dma_buf_attachment *, attach)
48+
__field( bool, is_dynamic)
4949
),
5050

5151
TP_fast_assign(
5252
__assign_str(dev_name);
5353
__assign_str(exp_name);
54-
__entry->size = dmabuf->size;
55-
__entry->ino = dmabuf->file->f_inode->i_ino;
56-
__entry->is_dynamic = is_dynamic;
57-
__entry->attach = attach;
54+
__entry->size = dmabuf->size;
55+
__entry->ino = dmabuf->file->f_inode->i_ino;
56+
__entry->is_dynamic = is_dynamic;
57+
__entry->attach = attach;
5858
),
5959

6060
TP_printk("exp_name=%s size=%zu ino=%lu attachment:%p is_dynamic=%d dev_name=%s",
@@ -73,17 +73,17 @@ DECLARE_EVENT_CLASS(dma_buf_fd,
7373
TP_ARGS(dmabuf, fd),
7474

7575
TP_STRUCT__entry(
76-
__string(exp_name, dmabuf->exp_name)
77-
__field(size_t, size)
78-
__field(ino_t, ino)
79-
__field(int, fd)
76+
__string( exp_name, dmabuf->exp_name)
77+
__field( size_t, size)
78+
__field( ino_t, ino)
79+
__field( int, fd)
8080
),
8181

8282
TP_fast_assign(
8383
__assign_str(exp_name);
84-
__entry->size = dmabuf->size;
85-
__entry->ino = dmabuf->file->f_inode->i_ino;
86-
__entry->fd = fd;
84+
__entry->size = dmabuf->size;
85+
__entry->ino = dmabuf->file->f_inode->i_ino;
86+
__entry->fd = fd;
8787
),
8888

8989
TP_printk("exp_name=%s size=%zu ino=%lu fd=%d",
@@ -137,11 +137,13 @@ DEFINE_EVENT(dma_buf_attach_dev, dma_buf_detach,
137137
TP_ARGS(dmabuf, attach, is_dynamic, dev)
138138
);
139139

140-
DEFINE_EVENT(dma_buf_fd, dma_buf_fd,
140+
DEFINE_EVENT_CONDITION(dma_buf_fd, dma_buf_fd,
141141

142142
TP_PROTO(struct dma_buf *dmabuf, int fd),
143143

144-
TP_ARGS(dmabuf, fd)
144+
TP_ARGS(dmabuf, fd),
145+
146+
TP_CONDITION(fd >= 0)
145147
);
146148

147149
DEFINE_EVENT(dma_buf_fd, dma_buf_get,

0 commit comments

Comments
 (0)