linux-kernelio-uring

Where is the function: trace_io_uring_submit_sqe in Linux kernel?


Recently, I'm tracing the io_uring in Linux kernel. I found a function trace_io_uring_submit_sqe was called in io_uring.c. Through searching symbol on Github mirror repository or on elixir.bootlin, I can't found the definition of its. Are there any other way to find it or it just doesn't exist?


Solution

  • This symbol is created dynamically using a macro, that's why you can't find it in the sources.

    The file trace/events/io_uring.h is included on line 84, and it contains this usage of macro TRACE_EVENT:

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

    The TRACE_EVENT macro is defined in 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.

    The __DECLARE_TRACE macro begins with:

    #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)
    

    This line specifically:

    static inline void trace_##name(proto)
    

    expands into a declaration of a static inline void function whose name is the name passed down from TRACE_EVENT with a prefix trace_ prepended to it (## is used for string concatenation in macros), which in your case results in a name of trace_io_uring_submit_sqe.

    Here you may find documentation of tracing.

    How to recognize dynamic code generation using macros?

    If you look throughout the io_uring.c file you will find a few functions with names following the formula of trace_ + some_function. At the same time, none of them can be found in the source code. This often means these symbols are generated using a macro. In such cases you could try looking for the common prefix instead of the whole symbol. If you search for trace_ on github you will find multiple similar macros which could have given you an idea of what is happening.