Commit [38516a]  Maximize  Restore  History

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));



/* 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);
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:


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.

#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 <>
Acked-by: Masami Hiramatsu <>
Acked-by: Frederic Weisbecker <>
Cc: Neil Horman <>
Cc: David S. Miller <>
Signed-off-by: Steven Rostedt <>

Steven Rostedt Steven Rostedt 2010-04-20

Steven Rostedt Steven Rostedt 2010-05-14

changed include/linux/tracepoint.h
changed include/trace/ftrace.h
changed kernel/trace/blktrace.c
changed kernel/trace/ftrace.c
changed kernel/trace/kmemtrace.c
changed kernel/trace/trace_sched_switch.c
changed kernel/trace/trace_sched_wakeup.c
changed kernel/trace/trace_syscalls.c
changed kernel/trace/trace_workqueue.c
changed kernel/tracepoint.c
changed net/core/drop_monitor.c
changed samples/tracepoints/tp-samples-trace.h
changed samples/tracepoints/tracepoint-probe-sample.c
changed samples/tracepoints/tracepoint-probe-sample2.c
include/linux/tracepoint.h Diff Switch to side-by-side view
include/trace/ftrace.h Diff Switch to side-by-side view
kernel/trace/blktrace.c Diff Switch to side-by-side view
kernel/trace/ftrace.c Diff Switch to side-by-side view
kernel/trace/kmemtrace.c Diff Switch to side-by-side view
kernel/trace/trace_sched_switch.c Diff Switch to side-by-side view
kernel/trace/trace_sched_wakeup.c Diff Switch to side-by-side view
kernel/trace/trace_syscalls.c Diff Switch to side-by-side view
kernel/trace/trace_workqueue.c Diff Switch to side-by-side view
kernel/tracepoint.c Diff Switch to side-by-side view
net/core/drop_monitor.c Diff Switch to side-by-side view
samples/tracepoints/tp-samples-trace.h Diff Switch to side-by-side view
samples/tracepoints/tracepoint-probe-sample.c Diff Switch to side-by-side view
samples/tracepoints/tracepoint-probe-sample2.c Diff Switch to side-by-side view

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks