Tracepoint: register/unregister struct tracepoint
Mathieu Desnoyers
reviewerRFC PATCH v2 1/1 Tracepoint: register/unregister struct tracepoint
Register/unregister tracepoint probes with struct tracepoint pointer rather than tracepoint name.
This change, which vastly simplifies tracepoint.c, has been proposed by Steven Rostedt.
Quoted 1 line
From this point on, the tracers need to pass a struct tracepoint pointer
to probe register/unregister. A probe can now only be connected to a tracepoint that exists. Moreover, tracers are responsible for unregistering the probe before the module containing its associated tracepoint is unloaded.
since v1:
- Adapt ftrace/perf callers,
- Update tracepoint.h macro,
- Build tested.
Still needs testing.
This patch applies on top of 1b39437c61f562f82d6a4e3218470339a44620f7, after applying:
- "Tracepoint cleanup: remove unused API functions"
- "Tracepoint API doc update: data argument"
--- include/linux/ftrace_event.h | 1 + include/linux/tracepoint.h | 15 +- include/trace/ftrace.h | 2 + kernel/trace/trace_events.c | 8 +- kernel/tracepoint.c | 440 +++++++++++------------------------------- 5 files changed, 127 insertions(+), 339 deletions(-)
include/linux/ftrace_event.h +1 -0
@@ -230,6 +230,7 @@ struct ftrace_event_call {struct list_head list;struct ftrace_event_class *class;char *name; +struct tracepoint *tp;struct trace_event event;const char *print_fmt;struct event_filter *filter;
include/linux/tracepoint.h +8 -7
@@ -39,14 +39,15 @@ struct tracepoint {* Connect a probe to a tracepoint. * Internal API, should not be used directly. */ -extern int tracepoint_probe_register (const char *name,void *probe,void *data); +extern int tracepoint_probe_register (struct tracepoint *tp,void *probe, +void *data);/* * Disconnect a probe from a tracepoint. * Internal API, should not be used directly. */ -extern int -tracepoint_probe_unregister (const char *name,void *probe,void *data); +extern int tracepoint_probe_unregister (struct tracepoint *tp,void *probe, +void *data);#ifdef CONFIG_MODULES struct tp_module {
@@ -160,14 +161,14 @@ static inline void tracepoint_synchronize_unregister(void) static inline int \ register_trace_##name(void (*probe)(data_proto), void *data) \ { \ - return tracepoint_probe_register(#name, (void *)probe, \ - data); \ + return tracepoint_probe_register(&__tracepoint_##name, \ + (void *)probe, data); \ } \ static inline int \ unregister_trace_##name(void (*probe)(data_proto), void *data) \ { \ - return tracepoint_probe_unregister(#name, (void *)probe, \ - data); \ + return tracepoint_probe_unregister(&__tracepoint_##name,\ + (void *)probe, data); \ } \ static inline void \ check_trace_callback_type_##name(void (*cb)(data_proto)) \
include/trace/ftrace.h +2 -0
@@ -625,6 +625,7 @@ static struct ftrace_event_class __used __refdata event_class_##call = { \ \ static struct ftrace_event_call __used event_##call = { \ .name = #call, \ + .tp = &__tracepoint_##call, \ .class = &event_class_##template, \ .event.funcs = &ftrace_event_type_funcs_##template, \ .print_fmt = print_fmt_##template, \
@@ -639,6 +640,7 @@ static const char print_fmt_##call[] = print; \ \ static struct ftrace_event_call __used event_##call = { \ .name = #call, \ + .tp = &__tracepoint_##call, \ .class = &event_class_##template, \ .event.funcs = &ftrace_event_type_funcs_##call, \ .print_fmt = print_fmt_##call, \
kernel/trace/trace_events.c +4 -4
@@ -201,22 +201,22 @@ int ftrace_event_reg(struct ftrace_event_call *call,switch (type) {case TRACE_REG_REGISTER : -return tracepoint_probe_register (call->name, +return tracepoint_probe_register (call->tp, call->class->probe, file);case TRACE_REG_UNREGISTER : -tracepoint_probe_unregister (call->name, +tracepoint_probe_unregister (call->tp, call->class->probe, file);return 0 ;#ifdef CONFIG_PERF_EVENTS case TRACE_REG_PERF_REGISTER : -return tracepoint_probe_register (call->name, +return tracepoint_probe_register (call->tp, call->class->perf_probe, call);case TRACE_REG_PERF_UNREGISTER : -tracepoint_probe_unregister (call->name, +tracepoint_probe_unregister (call->tp, call->class->perf_probe, call);return 0 ;
kernel/tracepoint.c +112 -328
594 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Hi -
Quoted 2 lines · Mathieu Desnoyers
[...] Moreover, tracers are responsible for unregistering the probe before the module containing its associated tracepoint is unloaded.
Could you spell out please how a tracer is supposed to know early enough that the module is going to be unloaded?
- FChE
Mathieu Desnoyers
reviewer----- Original Message -----
Quoted 10 lines
From: "Frank Ch. Eigler" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: "Steven Rostedt" <[email protected]>, [email protected], "Ingo Molnar" <[email protected]>, "Frederic Weisbecker" <[email protected]>, "Andrew Morton" <[email protected]>, "Johannes Berg" <[email protected]>
Sent: Thursday, March 13, 2014 12:35:31 PM
Subject: Re: [RFC PATCH v2] Tracepoint: register/unregister struct tracepointHi -
Quoted 7 lines
Quoted 2 lines · Mathieu Desnoyers
[...] Moreover, tracers are responsible for unregistering the probe before the module containing its associated tracepoint is unloaded.
Could you spell out please how a tracer is supposed to know early enough that the module is going to be unloaded?
There are two ways this can be done.
One use-case is when the probe and the callsite are within the same module, or if the module containing the probe has a symbol dependency on the callsite. In this case the probe normally unregisters itself from a module exit function before the module unloads.
The other use-case is if the tracer has a module coming/going notifier tracking the module's tracepoint callsites. The going notifier should be run before the tracepoint.c going notifier. A notifier with negative priority should have this effect, since the tracepoint.c notifier has priority 0.
Thoughts ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Steven Rostedt
maintainerQuoted 6 lines · Mathieu Desnoyers
The other use-case is if the tracer has a module coming/going notifier tracking the module's tracepoint callsites. The going notifier should be run before the
tracepoint.cgoing notifier. A notifier with negative priority should have this effect, since thetracepoint.cnotifier has priority 0.
The tracepoint should change to have two different notifiers that represent one for coming and one for going (as ftrace does). The coming one should have a priority of 0 (or INT_MIN (all other notifiers dependent on this should have > 0)
The going notifier should have a INT_MAX to run after all other tracepoint notifiers. (see kernel/trace/ftrace.c ftrace_module_enter_nb and ftrace_module_exit_nb)
-- Steve
Mathieu Desnoyers
reviewer----- Original Message -----
Quoted 17 lines
From: "Steven Rostedt" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: "Frank Ch. Eigler" <[email protected]>, [email protected], "Ingo Molnar" <[email protected]>, "Frederic Weisbecker" <[email protected]>, "Andrew Morton" <[email protected]>, "Johannes Berg" <[email protected]>
Sent: Thursday, March 13, 2014 2:17:53 PM
Subject: Re: [RFC PATCH v2] Tracepoint: register/unregister struct tracepointQuoted 6 lines · Mathieu Desnoyers
The other use-case is if the tracer has a module coming/going notifier tracking the module's tracepoint callsites. The going notifier should be run before the
tracepoint.cgoing notifier. A notifier with negative priority should have this effect, since thetracepoint.cnotifier has priority 0.
Quoted 8 lines
The tracepoint should change to have two different notifiers that represent one for coming and one for going (as ftrace does). The coming one should have a priority of 0 (or
INT_MIN(all other notifiers dependent on this should have > 0)The going notifier should have a
INT_MAXto run after all other tracepoint notifiers. (seekernel/trace/ftrace.cftrace_module_enter_nbandftrace_module_exit_nb)
OK, I'll spin a v4 with this change.
Thanks!
Mathieu
Quoted 5 lines
-- Steve
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com