Skip to content

Commit 38516ab

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Let tracepoints have data passed to tracepoint callbacks
This patch adds data to be passed to tracepoint callbacks. The created functions from DECLARE_TRACE() now need a mandatory data parameter. For example: DECLARE_TRACE(mytracepoint, int value, value) Will create the register function: int register_trace_mytracepoint((void(*)(void *data, int value))probe, void *data); As the first argument, all callbacks (probes) must take a (void *data) parameter. So a callback for the above tracepoint will look like: void myprobe(void *data, int value) { } The callback may choose to ignore the data parameter. This change allows callbacks to register a private data pointer along with the function probe. void mycallback(void *data, int value); register_trace_mytracepoint(mycallback, mydata); Then the mycallback() will receive the "mydata" as the first parameter before the args. A more detailed example: DECLARE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status)); /* In the C file */ DEFINE_TRACE(mytracepoint, TP_PROTO(int status), TP_ARGS(status)); [...] trace_mytracepoint(status); /* In a file registering this tracepoint */ int my_callback(void *data, int status) { struct my_struct my_data = data; [...] } [...] my_data = kmalloc(sizeof(*my_data), GFP_KERNEL); init_my_data(my_data); register_trace_mytracepoint(my_callback, my_data); The same callback can also be registered to the same tracepoint as long as the data registered is different. Note, the data must also be used to unregister the callback: unregister_trace_mytracepoint(my_callback, my_data); Because of the data parameter, tracepoints declared this way can not have no args. That is: DECLARE_TRACE(mytracepoint, TP_PROTO(void), TP_ARGS()); will cause an error. If no arguments are needed, a new macro can be used instead: DECLARE_TRACE_NOARGS(mytracepoint); Since there are no arguments, the proto and args fields are left out. This is part of a series to make the tracepoint footprint smaller: text data bss dec hex filename 4913961 1088356 861512 6863829 68bbd5 vmlinux.orig 4914025 1088868 861512 6864405 68be15 vmlinux.class 4918492 1084612 861512 6864616 68bee8 vmlinux.tracepoint Again, this patch also increases the size of the kernel, but lays the ground work for decreasing it. v5: Fixed net/core/drop_monitor.c to handle these updates. v4: Moved the DECLARE_TRACE() DECLARE_TRACE_NOARGS out of the #ifdef CONFIG_TRACE_POINTS, since the two are the same in both cases. The __DECLARE_TRACE() is what changes. Thanks to Frederic Weisbecker for pointing this out. v3: Made all register_* functions require data to be passed and all callbacks to take a void * parameter as its first argument. This makes the calling functions comply with C standards. Also added more comments to the modifications of DECLARE_TRACE(). v2: Made the DECLARE_TRACE() have the ability to pass arguments and added a new DECLARE_TRACE_NOARGS() for tracepoints that do not need any arguments. Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: Masami Hiramatsu <mhiramat@redhat.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 53da59a commit 38516ab

14 files changed

Lines changed: 298 additions & 210 deletions

‎include/linux/tracepoint.h‎

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
struct module;
2121
struct tracepoint;
2222

23+
struct tracepoint_func {
24+
void *func;
25+
void *data;
26+
};
27+
2328
struct tracepoint {
2429
const char *name; /* Tracepoint name */
2530
int state; /* State. */
2631
void (*regfunc)(void);
2732
void (*unregfunc)(void);
28-
void **funcs;
33+
struct tracepoint_func *funcs;
2934
} __attribute__((aligned(32))); /*
3035
* Aligned on 32 bytes because it is
3136
* globally visible and gcc happily
@@ -37,16 +42,19 @@ struct tracepoint {
3742
* Connect a probe to a tracepoint.
3843
* Internal API, should not be used directly.
3944
*/
40-
extern int tracepoint_probe_register(const char *name, void *probe);
45+
extern int tracepoint_probe_register(const char *name, void *probe, void *data);
4146

4247
/*
4348
* Disconnect a probe from a tracepoint.
4449
* Internal API, should not be used directly.
4550
*/
46-
extern int tracepoint_probe_unregister(const char *name, void *probe);
51+
extern int
52+
tracepoint_probe_unregister(const char *name, void *probe, void *data);
4753

48-
extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
49-
extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
54+
extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
55+
void *data);
56+
extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
57+
void *data);
5058
extern void tracepoint_probe_update_all(void);
5159

5260
struct tracepoint_iter {
@@ -102,17 +110,27 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
102110
/*
103111
* it_func[0] is never NULL because there is at least one element in the array
104112
* when the array itself is non NULL.
113+
*
114+
* Note, the proto and args passed in includes "__data" as the first parameter.
115+
* The reason for this is to handle the "void" prototype. If a tracepoint
116+
* has a "void" prototype, then it is invalid to declare a function
117+
* as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
118+
* "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
105119
*/
106120
#define __DO_TRACE(tp, proto, args) \
107121
do { \
108-
void **it_func; \
122+
struct tracepoint_func *it_func_ptr; \
123+
void *it_func; \
124+
void *__data; \
109125
\
110126
rcu_read_lock_sched_notrace(); \
111-
it_func = rcu_dereference_sched((tp)->funcs); \
112-
if (it_func) { \
127+
it_func_ptr = rcu_dereference_sched((tp)->funcs); \
128+
if (it_func_ptr) { \
113129
do { \
114-
((void(*)(proto))(*it_func))(args); \
115-
} while (*(++it_func)); \
130+
it_func = (it_func_ptr)->func; \
131+
__data = (it_func_ptr)->data; \
132+
((void(*)(proto))(it_func))(args); \
133+
} while ((++it_func_ptr)->func); \
116134
} \
117135
rcu_read_unlock_sched_notrace(); \
118136
} while (0)
@@ -122,23 +140,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
122140
* not add unwanted padding between the beginning of the section and the
123141
* structure. Force alignment to the same alignment as the section start.
124142
*/
125-
#define DECLARE_TRACE(name, proto, args) \
143+
#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
126144
extern struct tracepoint __tracepoint_##name; \
127145
static inline void trace_##name(proto) \
128146
{ \
129147
if (unlikely(__tracepoint_##name.state)) \
130148
__DO_TRACE(&__tracepoint_##name, \
131-
TP_PROTO(proto), TP_ARGS(args)); \
149+
TP_PROTO(data_proto), \
150+
TP_ARGS(data_args)); \
132151
} \
133-
static inline int register_trace_##name(void (*probe)(proto)) \
152+
static inline int \
153+
register_trace_##name(void (*probe)(data_proto), void *data) \
134154
{ \
135-
return tracepoint_probe_register(#name, (void *)probe); \
155+
return tracepoint_probe_register(#name, (void *)probe, \
156+
data); \
136157
} \
137-
static inline int unregister_trace_##name(void (*probe)(proto)) \
158+
static inline int \
159+
unregister_trace_##name(void (*probe)(data_proto), void *data) \
138160
{ \
139-
return tracepoint_probe_unregister(#name, (void *)probe);\
161+
return tracepoint_probe_unregister(#name, (void *)probe, \
162+
data); \
140163
} \
141-
static inline void check_trace_callback_type_##name(void (*cb)(proto)) \
164+
static inline void \
165+
check_trace_callback_type_##name(void (*cb)(data_proto)) \
142166
{ \
143167
}
144168

@@ -158,20 +182,22 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
158182
EXPORT_SYMBOL(__tracepoint_##name)
159183

160184
#else /* !CONFIG_TRACEPOINTS */
161-
#define DECLARE_TRACE(name, proto, args) \
162-
static inline void _do_trace_##name(struct tracepoint *tp, proto) \
163-
{ } \
185+
#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
164186
static inline void trace_##name(proto) \
165187
{ } \
166-
static inline int register_trace_##name(void (*probe)(proto)) \
188+
static inline int \
189+
register_trace_##name(void (*probe)(data_proto), \
190+
void *data) \
167191
{ \
168192
return -ENOSYS; \
169193
} \
170-
static inline int unregister_trace_##name(void (*probe)(proto)) \
194+
static inline int \
195+
unregister_trace_##name(void (*probe)(data_proto), \
196+
void *data) \
171197
{ \
172198
return -ENOSYS; \
173199
} \
174-
static inline void check_trace_callback_type_##name(void (*cb)(proto)) \
200+
static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
175201
{ \
176202
}
177203

@@ -181,6 +207,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
181207
#define EXPORT_TRACEPOINT_SYMBOL(name)
182208

183209
#endif /* CONFIG_TRACEPOINTS */
210+
211+
/*
212+
* The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
213+
* (void). "void" is a special value in a function prototype and can
214+
* not be combined with other arguments. Since the DECLARE_TRACE()
215+
* macro adds a data element at the beginning of the prototype,
216+
* we need a way to differentiate "(void *data, proto)" from
217+
* "(void *data, void)". The second prototype is invalid.
218+
*
219+
* DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
220+
* and "void *__data" as the callback prototype.
221+
*
222+
* DECLARE_TRACE() passes "proto" as the tracepoint protoype and
223+
* "void *__data, proto" as the callback prototype.
224+
*/
225+
#define DECLARE_TRACE_NOARGS(name) \
226+
__DECLARE_TRACE(name, void, , void *__data, __data)
227+
228+
#define DECLARE_TRACE(name, proto, args) \
229+
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
230+
PARAMS(void *__data, proto), \
231+
PARAMS(__data, args))
232+
184233
#endif /* DECLARE_TRACE */
185234

186235
#ifndef TRACE_EVENT

‎include/trace/ftrace.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,18 @@ static inline notrace int ftrace_get_offsets_##call( \
406406
#undef DEFINE_EVENT
407407
#define DEFINE_EVENT(template, name, proto, args) \
408408
\
409-
static void perf_trace_##name(proto); \
409+
static void perf_trace_##name(void *, proto); \
410410
\
411411
static notrace int \
412412
perf_trace_enable_##name(struct ftrace_event_call *unused) \
413413
{ \
414-
return register_trace_##name(perf_trace_##name); \
414+
return register_trace_##name(perf_trace_##name, NULL); \
415415
} \
416416
\
417417
static notrace void \
418418
perf_trace_disable_##name(struct ftrace_event_call *unused) \
419419
{ \
420-
unregister_trace_##name(perf_trace_##name); \
420+
unregister_trace_##name(perf_trace_##name, NULL); \
421421
}
422422

423423
#undef DEFINE_EVENT_PRINT
@@ -578,21 +578,21 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
578578
#undef DEFINE_EVENT
579579
#define DEFINE_EVENT(template, call, proto, args) \
580580
\
581-
static notrace void ftrace_raw_event_##call(proto) \
581+
static notrace void ftrace_raw_event_##call(void *__ignore, proto) \
582582
{ \
583583
ftrace_raw_event_id_##template(&event_##call, args); \
584584
} \
585585
\
586586
static notrace int \
587587
ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \
588588
{ \
589-
return register_trace_##call(ftrace_raw_event_##call); \
589+
return register_trace_##call(ftrace_raw_event_##call, NULL); \
590590
} \
591591
\
592592
static notrace void \
593593
ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \
594594
{ \
595-
unregister_trace_##call(ftrace_raw_event_##call); \
595+
unregister_trace_##call(ftrace_raw_event_##call, NULL); \
596596
} \
597597
\
598598
static struct trace_event ftrace_event_type_##call = { \
@@ -793,7 +793,7 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \
793793

794794
#undef DEFINE_EVENT
795795
#define DEFINE_EVENT(template, call, proto, args) \
796-
static notrace void perf_trace_##call(proto) \
796+
static notrace void perf_trace_##call(void *__ignore, proto) \
797797
{ \
798798
struct ftrace_event_call *event_call = &event_##call; \
799799
\

0 commit comments

Comments
 (0)