2

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?

Steven
  • 811
  • 4
  • 23

1 Answers1

3

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.

msaw328
  • 1,459
  • 10
  • 18
  • Thanks for your answer, let me check one thing. Can I claim that `trace_io_uring_submit_sqe` do the things between [line:246~256](https://elixir.bootlin.com/linux/v5.14-rc6/source/include/linux/tracepoint.h#L246)? – Steven Aug 21 '21 at 02:13
  • Comment at [here](https://elixir.bootlin.com/linux/v5.14-rc6/source/include/trace/events/io_uring.h#L334) seems to imply that `io_uring_submit_sqe` not only dump information. – Steven Aug 21 '21 at 02:43
  • Yes, lines 246 to 256 define the body of the function which is being declared by the macro, so this is what the function will do once called. – msaw328 Aug 24 '21 at 20:28