]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.25/patches.trace/tracepoints-samples.patch
Updated xen patches taken from suse.
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.trace / tracepoints-samples.patch
1 From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
2 Subject: Tracepoints Samples
3
4 Tracepoint example code under samples/.
5
6 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
7 Acked-by: 'Peter Zijlstra' <peterz@infradead.org>
8 CC: Masami Hiramatsu <mhiramat@redhat.com>
9 CC: "Frank Ch. Eigler" <fche@redhat.com>
10 CC: 'Ingo Molnar' <mingo@elte.hu>
11 CC: 'Hideo AOKI' <haoki@redhat.com>
12 CC: Takashi Nishiie <t-nishiie@np.css.fujitsu.com>
13 CC: 'Steven Rostedt' <rostedt@goodmis.org>
14 CC: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
15 Acked-by: Jan Blunck <jblunck@suse.de>
16 ---
17 samples/Kconfig | 6 ++
18 samples/Makefile | 2
19 samples/tracepoints/Makefile | 6 ++
20 samples/tracepoints/tp-samples-trace.h | 13 +++++
21 samples/tracepoints/tracepoint-probe-sample.c | 55 +++++++++++++++++++++++++
22 samples/tracepoints/tracepoint-probe-sample2.c | 42 +++++++++++++++++++
23 samples/tracepoints/tracepoint-sample.c | 53 ++++++++++++++++++++++++
24 7 files changed, 176 insertions(+), 1 deletion(-)
25
26 Index: linux-2.6-lttng/samples/Kconfig
27 ===================================================================
28 --- linux-2.6-lttng.orig/samples/Kconfig 2008-07-07 09:59:25.000000000 -0400
29 +++ linux-2.6-lttng/samples/Kconfig 2008-07-07 10:00:07.000000000 -0400
30 @@ -13,6 +13,12 @@ config SAMPLE_MARKERS
31 help
32 This build markers example modules.
33
34 +config SAMPLE_TRACEPOINTS
35 + tristate "Build tracepoints examples -- loadable modules only"
36 + depends on TRACEPOINTS && m
37 + help
38 + This build tracepoints example modules.
39 +
40 config SAMPLE_KOBJECT
41 tristate "Build kobject examples"
42 help
43 Index: linux-2.6-lttng/samples/tracepoints/Makefile
44 ===================================================================
45 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
46 +++ linux-2.6-lttng/samples/tracepoints/Makefile 2008-07-07 10:53:09.000000000 -0400
47 @@ -0,0 +1,6 @@
48 +# builds the tracepoint example kernel modules;
49 +# then to use one (as root): insmod <module_name.ko>
50 +
51 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-sample.o
52 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample.o
53 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample2.o
54 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample.c
55 ===================================================================
56 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
57 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample.c 2008-07-07 10:50:26.000000000 -0400
58 @@ -0,0 +1,55 @@
59 +/*
60 + * tracepoint-probe-sample.c
61 + *
62 + * sample tracepoint probes.
63 + */
64 +
65 +#include <linux/module.h>
66 +#include <linux/file.h>
67 +#include <linux/dcache.h>
68 +#include "tp-samples-trace.h"
69 +
70 +/*
71 + * Here the caller only guarantees locking for struct file and struct inode.
72 + * Locking must therefore be done in the probe to use the dentry.
73 + */
74 +static void probe_subsys_event(struct inode *inode, struct file *file)
75 +{
76 + path_get(&file->f_path);
77 + dget(file->f_path.dentry);
78 + printk(KERN_INFO "Event is encountered with filename %s\n",
79 + file->f_path.dentry->d_name.name);
80 + dput(file->f_path.dentry);
81 + path_put(&file->f_path);
82 +}
83 +
84 +static void probe_subsys_eventb(void)
85 +{
86 + printk(KERN_INFO "Event B is encountered\n");
87 +}
88 +
89 +int __init tp_sample_trace_init(void)
90 +{
91 + int ret;
92 +
93 + ret = register_trace_subsys_event(probe_subsys_event);
94 + WARN_ON(ret);
95 + ret = register_trace_subsys_eventb(probe_subsys_eventb);
96 + WARN_ON(ret);
97 +
98 + return 0;
99 +}
100 +
101 +module_init(tp_sample_trace_init);
102 +
103 +void __exit tp_sample_trace_exit(void)
104 +{
105 + unregister_trace_subsys_eventb(probe_subsys_eventb);
106 + unregister_trace_subsys_event(probe_subsys_event);
107 +}
108 +
109 +module_exit(tp_sample_trace_exit);
110 +
111 +MODULE_LICENSE("GPL");
112 +MODULE_AUTHOR("Mathieu Desnoyers");
113 +MODULE_DESCRIPTION("Tracepoint Probes Samples");
114 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-sample.c
115 ===================================================================
116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
117 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-sample.c 2008-07-07 10:04:16.000000000 -0400
118 @@ -0,0 +1,53 @@
119 +/* tracepoint-sample.c
120 + *
121 + * Executes a tracepoint when /proc/tracepoint-example is opened.
122 + *
123 + * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
124 + *
125 + * This file is released under the GPLv2.
126 + * See the file COPYING for more details.
127 + */
128 +
129 +#include <linux/module.h>
130 +#include <linux/sched.h>
131 +#include <linux/proc_fs.h>
132 +#include "tp-samples-trace.h"
133 +
134 +struct proc_dir_entry *pentry_example;
135 +
136 +static int my_open(struct inode *inode, struct file *file)
137 +{
138 + int i;
139 +
140 + trace_subsys_event(inode, file);
141 + for (i = 0; i < 10; i++)
142 + trace_subsys_eventb();
143 + return -EPERM;
144 +}
145 +
146 +static struct file_operations mark_ops = {
147 + .open = my_open,
148 +};
149 +
150 +static int example_init(void)
151 +{
152 + printk(KERN_ALERT "example init\n");
153 + pentry_example = proc_create("tracepoint-example", 0444, NULL,
154 + &mark_ops);
155 + if (!pentry_example)
156 + return -EPERM;
157 + return 0;
158 +}
159 +
160 +static void example_exit(void)
161 +{
162 + printk(KERN_ALERT "example exit\n");
163 + remove_proc_entry("tracepoint-example", NULL);
164 +}
165 +
166 +module_init(example_init)
167 +module_exit(example_exit)
168 +
169 +MODULE_LICENSE("GPL");
170 +MODULE_AUTHOR("Mathieu Desnoyers");
171 +MODULE_DESCRIPTION("Tracepoint example");
172 Index: linux-2.6-lttng/samples/tracepoints/tp-samples-trace.h
173 ===================================================================
174 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
175 +++ linux-2.6-lttng/samples/tracepoints/tp-samples-trace.h 2008-07-07 10:06:26.000000000 -0400
176 @@ -0,0 +1,13 @@
177 +#ifndef _TP_SAMPLES_TRACE_H
178 +#define _TP_SAMPLES_TRACE_H
179 +
180 +#include <linux/proc_fs.h> /* for struct inode and struct file */
181 +#include <linux/tracepoint.h>
182 +
183 +DEFINE_TRACE(subsys_event,
184 + TPPROTO(struct inode *inode, struct file *file),
185 + TPARGS(inode, file));
186 +DEFINE_TRACE(subsys_eventb,
187 + TPPROTO(void),
188 + TPARGS());
189 +#endif
190 Index: linux-2.6-lttng/samples/Makefile
191 ===================================================================
192 --- linux-2.6-lttng.orig/samples/Makefile 2008-07-07 10:44:50.000000000 -0400
193 +++ linux-2.6-lttng/samples/Makefile 2008-07-07 10:44:59.000000000 -0400
194 @@ -1,3 +1,3 @@
195 # Makefile for Linux samples code
196
197 -obj-$(CONFIG_SAMPLES) += markers/ kobject/ kprobes/
198 +obj-$(CONFIG_SAMPLES) += markers/ kobject/ kprobes/ tracepoints/
199 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample2.c
200 ===================================================================
201 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
202 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample2.c 2008-07-07 10:56:09.000000000 -0400
203 @@ -0,0 +1,42 @@
204 +/*
205 + * tracepoint-probe-sample2.c
206 + *
207 + * 2nd sample tracepoint probes.
208 + */
209 +
210 +#include <linux/module.h>
211 +#include <linux/fs.h>
212 +#include "tp-samples-trace.h"
213 +
214 +/*
215 + * Here the caller only guarantees locking for struct file and struct inode.
216 + * Locking must therefore be done in the probe to use the dentry.
217 + */
218 +static void probe_subsys_event(struct inode *inode, struct file *file)
219 +{
220 + printk(KERN_INFO "Event is encountered with inode number %lu\n",
221 + inode->i_ino);
222 +}
223 +
224 +int __init tp_sample_trace_init(void)
225 +{
226 + int ret;
227 +
228 + ret = register_trace_subsys_event(probe_subsys_event);
229 + WARN_ON(ret);
230 +
231 + return 0;
232 +}
233 +
234 +module_init(tp_sample_trace_init);
235 +
236 +void __exit tp_sample_trace_exit(void)
237 +{
238 + unregister_trace_subsys_event(probe_subsys_event);
239 +}
240 +
241 +module_exit(tp_sample_trace_exit);
242 +
243 +MODULE_LICENSE("GPL");
244 +MODULE_AUTHOR("Mathieu Desnoyers");
245 +MODULE_DESCRIPTION("Tracepoint Probes Samples");