How to register a function on a tracepoint

register_trace_##name宏中

In this function, tracepoint_probe_register can hang multiple processing functions on the same cp,

View function: trace_block_rq_issue defines the hook function of this tracepoint and tracepoint

Trace_block_rq_issue(q, rq) is input to you in the tracepoint; where q is request_queue, rq is struct request, these two things are provided to you by tracepoint, all functions can be obtained, what is the execution process of this function? Yes, there must be a void function in the hook function. Each ftrace has registered its own function, including perf, which has also registered its own function in the function. Let's see what function is registered by ftrace, it must be in ftrace is to register its own specific function

There are many hook functions in kernel/trace/trace_events.c

ftrace_enable_fops

ftrace_event_format_fops

__ftrace_event_enable_disable

Using the awesome systemtap, you can easily get what the hook in the function is: call->class->reg(call, TRACE_REG_UNREGISTER, file);

The address to get the hook is: trace_event_reg

Then what is the hook function, it is found to be the function trace_event_raw_event_block_rq_issue

How did this function come about?

are generated in the header file

./include/trace/events/f2fs.h

DECLARE_EVENT_CLASS will expand the function trace_event_raw_event_block_rq_issue function in this macro

In the declare_event_class function of f2fs

122 DECLARE_EVENT_CLASS(f2fs__inode,
 123
 124     TP_PROTO(struct inode *inode),
 125
 126     TP_ARGS(inode),
 127
 128     TP_STRUCT__entry(
 129         __field(dev_t,  dev)
 130         __field(ino_t,  ino)
 131         __field(ino_t,  pino)
 132         __field(umode_t, mode)
 133         __field(loff_t, size)
 134         __field(unsigned int, nlink)
 135         __field(blkcnt_t, blocks)
 136         __field(__u8,   advise)
 137     ),
 138
 139     TP_fast_assign(
 140         __entry->dev    = inode->i_sb->s_dev;
 141         __entry->ino    = inode->i_ino;
 142         __entry->pino   = F2FS_I(inode)->i_pino;
 143         __entry->mode   = inode->i_mode;
 144         __entry->nlink  = inode->i_nlink;
 145         __entry->size   = inode->i_size;
 146         __entry->blocks = inode->i_blocks;
 147         __entry->advise = F2FS_I(inode)->i_advise;
 148     ),
 149
 150     TP_printk("dev = (%d,%d), ino = %lu, pino = %lu, i_mode = 0x%hx, "
 151         "i_size = %lld, i_nlink = %u, i_blocks = %llu, i_advise = 0x%x",
 152         show_dev_ino(__entry),
 153         (unsigned long)__entry->pino,
 154         __entry->mode,
 155         __entry->size,
 156         (unsigned int)__entry->nlink,
 157         (unsigned long long)__entry->blocks,
 158         (unsigned char)__entry->advise)
 159 );

 In the function:

./include/trace/trace_events.h

664 static notrace void                         \
665 trace_event_raw_event_##call(void *__data, proto)           \
666 {                                   \
667     struct trace_event_file *trace_file = __data;           \
668     struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
669     struct trace_event_buffer fbuffer;              \
670     struct trace_event_raw_##call *entry;               \
671     int __data_size;                        \
672                                     \
673     if (trace_trigger_soft_disabled(trace_file))            \
674         return;                         \
675                                     \   
676     __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
677                                     \
678     entry = trace_event_buffer_reserve(&fbuffer, trace_file,    \
679                  sizeof(*entry) + __data_size);     \
680                                     \
681     if (!entry)                         \
682         return;                         \
683                                     \   
684     tstruct                             \
685                                     \   
686     { assign; }                         \
687                                     \   
688     trace_event_buffer_commit(&fbuffer);                \
689 }   

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325929867&siteId=291194637