diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-04-20 17:04:50 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-05-14 09:50:34 -0400 |
commit | 38516ab59fbc5b3bb278cf5e1fe2867c70cff32e (patch) | |
tree | 904476d7780a27001281b9cb93c7959128f9a1d7 /samples | |
parent | 53da59aa6dd881fd0bbdd058a8a299d90ce9dd1d (diff) |
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>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/tracepoints/tp-samples-trace.h | 4 | ||||
-rw-r--r-- | samples/tracepoints/tracepoint-probe-sample.c | 13 | ||||
-rw-r--r-- | samples/tracepoints/tracepoint-probe-sample2.c | 7 |
3 files changed, 12 insertions, 12 deletions
diff --git a/samples/tracepoints/tp-samples-trace.h b/samples/tracepoints/tp-samples-trace.h index dffdc49878af..4d46be965961 100644 --- a/samples/tracepoints/tp-samples-trace.h +++ b/samples/tracepoints/tp-samples-trace.h | |||
@@ -7,7 +7,5 @@ | |||
7 | DECLARE_TRACE(subsys_event, | 7 | DECLARE_TRACE(subsys_event, |
8 | TP_PROTO(struct inode *inode, struct file *file), | 8 | TP_PROTO(struct inode *inode, struct file *file), |
9 | TP_ARGS(inode, file)); | 9 | TP_ARGS(inode, file)); |
10 | DECLARE_TRACE(subsys_eventb, | 10 | DECLARE_TRACE_NOARGS(subsys_eventb); |
11 | TP_PROTO(void), | ||
12 | TP_ARGS()); | ||
13 | #endif | 11 | #endif |
diff --git a/samples/tracepoints/tracepoint-probe-sample.c b/samples/tracepoints/tracepoint-probe-sample.c index 9e60eb6ca2d8..744c0b9652a7 100644 --- a/samples/tracepoints/tracepoint-probe-sample.c +++ b/samples/tracepoints/tracepoint-probe-sample.c | |||
@@ -13,7 +13,8 @@ | |||
13 | * Here the caller only guarantees locking for struct file and struct inode. | 13 | * Here the caller only guarantees locking for struct file and struct inode. |
14 | * Locking must therefore be done in the probe to use the dentry. | 14 | * Locking must therefore be done in the probe to use the dentry. |
15 | */ | 15 | */ |
16 | static void probe_subsys_event(struct inode *inode, struct file *file) | 16 | static void probe_subsys_event(void *ignore, |
17 | struct inode *inode, struct file *file) | ||
17 | { | 18 | { |
18 | path_get(&file->f_path); | 19 | path_get(&file->f_path); |
19 | dget(file->f_path.dentry); | 20 | dget(file->f_path.dentry); |
@@ -23,7 +24,7 @@ static void probe_subsys_event(struct inode *inode, struct file *file) | |||
23 | path_put(&file->f_path); | 24 | path_put(&file->f_path); |
24 | } | 25 | } |
25 | 26 | ||
26 | static void probe_subsys_eventb(void) | 27 | static void probe_subsys_eventb(void *ignore) |
27 | { | 28 | { |
28 | printk(KERN_INFO "Event B is encountered\n"); | 29 | printk(KERN_INFO "Event B is encountered\n"); |
29 | } | 30 | } |
@@ -32,9 +33,9 @@ static int __init tp_sample_trace_init(void) | |||
32 | { | 33 | { |
33 | int ret; | 34 | int ret; |
34 | 35 | ||
35 | ret = register_trace_subsys_event(probe_subsys_event); | 36 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
36 | WARN_ON(ret); | 37 | WARN_ON(ret); |
37 | ret = register_trace_subsys_eventb(probe_subsys_eventb); | 38 | ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL); |
38 | WARN_ON(ret); | 39 | WARN_ON(ret); |
39 | 40 | ||
40 | return 0; | 41 | return 0; |
@@ -44,8 +45,8 @@ module_init(tp_sample_trace_init); | |||
44 | 45 | ||
45 | static void __exit tp_sample_trace_exit(void) | 46 | static void __exit tp_sample_trace_exit(void) |
46 | { | 47 | { |
47 | unregister_trace_subsys_eventb(probe_subsys_eventb); | 48 | unregister_trace_subsys_eventb(probe_subsys_eventb, NULL); |
48 | unregister_trace_subsys_event(probe_subsys_event); | 49 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
49 | tracepoint_synchronize_unregister(); | 50 | tracepoint_synchronize_unregister(); |
50 | } | 51 | } |
51 | 52 | ||
diff --git a/samples/tracepoints/tracepoint-probe-sample2.c b/samples/tracepoints/tracepoint-probe-sample2.c index be2a960573f1..9fcf990e5d4b 100644 --- a/samples/tracepoints/tracepoint-probe-sample2.c +++ b/samples/tracepoints/tracepoint-probe-sample2.c | |||
@@ -12,7 +12,8 @@ | |||
12 | * Here the caller only guarantees locking for struct file and struct inode. | 12 | * Here the caller only guarantees locking for struct file and struct inode. |
13 | * Locking must therefore be done in the probe to use the dentry. | 13 | * Locking must therefore be done in the probe to use the dentry. |
14 | */ | 14 | */ |
15 | static void probe_subsys_event(struct inode *inode, struct file *file) | 15 | static void probe_subsys_event(void *ignore, |
16 | struct inode *inode, struct file *file) | ||
16 | { | 17 | { |
17 | printk(KERN_INFO "Event is encountered with inode number %lu\n", | 18 | printk(KERN_INFO "Event is encountered with inode number %lu\n", |
18 | inode->i_ino); | 19 | inode->i_ino); |
@@ -22,7 +23,7 @@ static int __init tp_sample_trace_init(void) | |||
22 | { | 23 | { |
23 | int ret; | 24 | int ret; |
24 | 25 | ||
25 | ret = register_trace_subsys_event(probe_subsys_event); | 26 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
26 | WARN_ON(ret); | 27 | WARN_ON(ret); |
27 | 28 | ||
28 | return 0; | 29 | return 0; |
@@ -32,7 +33,7 @@ module_init(tp_sample_trace_init); | |||
32 | 33 | ||
33 | static void __exit tp_sample_trace_exit(void) | 34 | static void __exit tp_sample_trace_exit(void) |
34 | { | 35 | { |
35 | unregister_trace_subsys_event(probe_subsys_event); | 36 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
36 | tracepoint_synchronize_unregister(); | 37 | tracepoint_synchronize_unregister(); |
37 | } | 38 | } |
38 | 39 | ||