转自:
在kernel中经常会看到trace_XX形式的函数,但是又找不到它的定义。这个其实是kernel的tracepoint,定义在include/linux/tracepoint.h中。#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \extern struct tracepoint __tracepoint_##name;\static inline void trace_##name(proto)\{ \if (static_key_false(&__tracepoint_##name.key))\__DO_TRACE(&__tracepoint_##name,\TP_PROTO(data_proto),\TP_ARGS(data_args),\TP_CONDITION(cond),,);\} \__DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args),\PARAMS(cond), PARAMS(data_proto), PARAMS(data_args))\static inline int\register_trace_##name(void (*probe)(data_proto), void *data)\{ \return tracepoint_probe_register(#name, (void *)probe,\data); \} \static inline int\unregister_trace_##name(void (*probe)(data_proto), void *data)\{ \return tracepoint_probe_unregister(#name, (void *)probe, \ data); \} \static inline void\check_trace_callback_type_##name(void (*cb)(data_proto))\{ \} \static inline bool\trace_##name##_enabled(void)\{ \return static_key_false(&__tracepoint_##name.key);\}这些trace_开头的函数是由上面这个宏来定义的。trace_要想起作用,需要调用register_trace_##name,给他关联一个probe函数,当调用trace_时就执行probe函数,否则这个trace_不会起实际作用。