Linux 内核中的函数:trace_io_uring_submit_sqe 在哪里?

Where is the function: trace_io_uring_submit_sqe in Linux kernel?

最近,我正在跟踪 Linux 内核中的 io_uring。我发现在 io_uring.c. Through searching symbol on Github mirror repository or on elixir.bootlin 中调用了一个函数 trace_io_uring_submit_sqe,我找不到它的定义。有没有其他方法可以找到它,或者它根本不存在?

此符号是使用宏动态创建的,这就是您无法在源代码中找到它的原因。

文件trace/events/io_uring.h is included on line 84, and it contains this宏的用法TRACE_EVENT:

TRACE_EVENT(io_uring_submit_sqe, //(...more code)

TRACE_EVENT 宏在 linux/tracepoint.h using another macro, DECLARE_TRACE. DECLARE_TRACE is defined in the same file on line 418 and uses __DECLARE_TRACE which is defined in the same file again, on line 241 or 341 depending on the value of the macro TRACEPOINTS_ENABLED on line 162 中定义。

__DECLARE_TRACE 宏开始于:

#define __DECLARE_TRACE(name, proto, args, cond, data_proto)        \
    extern int __traceiter_##name(data_proto);          \
    DECLARE_STATIC_CALL(tp_func_##name, __traceiter_##name);    \
    extern struct tracepoint __tracepoint_##name;           \
    static inline void trace_##name(proto)              \
    //(... more code)

这一行具体来说:

static inline void trace_##name(proto)

扩展为 static inline void 函数的声明,该函数的名称是从 TRACE_EVENT 传递下来的 name,并在其前面加上前缀 trace_## 用于宏中的字符串连接),在您的情况下会导致名称 trace_io_uring_submit_sqe.

Here 您可能会找到跟踪文档。

如何识别使用宏生成动态代码?

如果您查看整个 io_uring.c 文件,您会发现一些函数的名称遵循 trace_ + some_function 的公式。同时,在源码中可以找到其中none个。这通常意味着这些符号是使用宏生成的。在这种情况下,您可以尝试查找公共前缀而不是整个符号。如果您在 github 上搜索 trace_,您会找到 multiple similar macros,这可以让您了解正在发生的事情。