Skip to content

Commit 63fbdab

Browse files
jibaronfweisbec
authored andcommitted
tracing: Add DECLARE_TRACE_WITH_CALLBACK() macro
Introduce a new 'DECLARE_TRACE_WITH_CALLBACK()' macro, so that tracepoints can associate an external register/unregister function. This prepares for the syscalls tracer conversion to trace events. We will need to perform arch level operations once a syscall event is turned on/off, such as TIF flags setting, hence the need of such specific callbacks. Signed-off-by: Jason Baron <jbaron@redhat.com> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Jiaying Zhang <jiayingz@google.com> Cc: Martin Bligh <mbligh@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Masami Hiramatsu <mhiramat@redhat.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
1 parent 066e037 commit 63fbdab

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

include/linux/tracepoint.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ struct tracepoint {
6060
* Make sure the alignment of the structure in the __tracepoints section will
6161
* not add unwanted padding between the beginning of the section and the
6262
* structure. Force alignment to the same alignment as the section start.
63+
* An optional set of (un)registration functions can be passed to perform any
64+
* additional (un)registration work.
6365
*/
64-
#define DECLARE_TRACE(name, proto, args) \
66+
#define DECLARE_TRACE_WITH_CALLBACK(name, proto, args, reg, unreg) \
6567
extern struct tracepoint __tracepoint_##name; \
6668
static inline void trace_##name(proto) \
6769
{ \
@@ -71,13 +73,30 @@ struct tracepoint {
7173
} \
7274
static inline int register_trace_##name(void (*probe)(proto)) \
7375
{ \
74-
return tracepoint_probe_register(#name, (void *)probe); \
76+
int ret; \
77+
void (*func)(void) = reg; \
78+
\
79+
ret = tracepoint_probe_register(#name, (void *)probe); \
80+
if (func && !ret) \
81+
func(); \
82+
return ret; \
7583
} \
7684
static inline int unregister_trace_##name(void (*probe)(proto)) \
7785
{ \
78-
return tracepoint_probe_unregister(#name, (void *)probe);\
86+
int ret; \
87+
void (*func)(void) = unreg; \
88+
\
89+
ret = tracepoint_probe_unregister(#name, (void *)probe);\
90+
if (func && !ret) \
91+
func(); \
92+
return ret; \
7993
}
8094

95+
96+
#define DECLARE_TRACE(name, proto, args) \
97+
DECLARE_TRACE_WITH_CALLBACK(name, TP_PROTO(proto), TP_ARGS(args),\
98+
NULL, NULL);
99+
81100
#define DEFINE_TRACE(name) \
82101
static const char __tpstrtab_##name[] \
83102
__attribute__((section("__tracepoints_strings"))) = #name; \
@@ -94,7 +113,7 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
94113
struct tracepoint *end);
95114

96115
#else /* !CONFIG_TRACEPOINTS */
97-
#define DECLARE_TRACE(name, proto, args) \
116+
#define DECLARE_TRACE_WITH_CALLBACK(name, proto, args, reg, unreg) \
98117
static inline void _do_trace_##name(struct tracepoint *tp, proto) \
99118
{ } \
100119
static inline void trace_##name(proto) \
@@ -108,6 +127,10 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
108127
return -ENOSYS; \
109128
}
110129

130+
#define DECLARE_TRACE(name, proto, args) \
131+
DECLARE_TRACE_WITH_CALLBACK(name, TP_PROTO(proto), TP_ARGS(args),\
132+
NULL, NULL);
133+
111134
#define DEFINE_TRACE(name)
112135
#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
113136
#define EXPORT_TRACEPOINT_SYMBOL(name)

0 commit comments

Comments
 (0)