ok, thanks.

________________________________
发件人: Steven Rostedt <[email protected]>
发送时间: 2025年12月24日 0:44:24
收件人: 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 v9] dma-buf: add some tracepoints to debug.

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

On Tue, 23 Dec 2025 11:27:49 +0800
Xiang Gao <[email protected]> wrote:

>
> +#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__);                                      
>         \
> +             } else if (IS_ENABLED(CONFIG_LOCKDEP)) {        \
> +                     /* Expose this lock when lockdep is enabled */  \
> +                     guard(spinlock)(&dmabuf->name_lock);    \
> +             }                                                               
>                         \
> +     } while (0)
> +

I hate to make another comment here, but I was just thinking that this can
be made to look a little nicer. Basically, we want to make sure that when
LOCKDEP is active, we always take the lock. But we also need to take the
lock when tracing is enabled. The tracepoint itself is a static branch,
which means it is a nop when not active, so there's no real problem with
calling it. Thus, this could look better as:

#define DMA_BUF_TRACE(FUNC, ...)                                        \
        do {                                                            \
                /* Always expose lock if lockdep is enabled */          \
                if (IS_ENABLED(CONFIG_LOCKDEP) || FUNC##_enabled()) {   \
                        guard(spinlock)(&dmabuf->name_lock);            \
                        FUNC(__VA_ARGS__);                              \
                }                                                       \
        } while (0)


-- Steve

Reply via email to