Bump minimum kernel version to 3.0
[lttng-modules.git] / linux-patches / backport-tracepoint-data-2.6.32-33.patch
CommitLineData
3a523f5b
MD
1commit 2c2a566b64b4254c530fb0c2222b30e8a739bac9
2Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3Date: Sat Sep 1 17:45:09 2012 -0700
4
5 tracing: Let tracepoints have data passed to tracepoint callbacks (backport)
6
7 Backport of commit 38516ab59fbc5b3bb278cf5e1fe2867c70cff32e for
8 2.6.32.x and 2.6.33.x. Keeping kABI compatibility.
9
10 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11
12---
83788d81
AG
13 include/linux/tracepoint.h | 141 +++++++++++++++++++++++++-------
14 kernel/tracepoint.c | 144 ++++++++++++++++++++++++---------
15 samples/tracepoints/tp-samples-trace.h | 4 +-
16 3 files changed, 216 insertions(+), 73 deletions(-)
3a523f5b
MD
17
18Index: linux/include/linux/tracepoint.h
19===================================================================
20--- linux.orig/include/linux/tracepoint.h
21+++ linux/include/linux/tracepoint.h
22@@ -20,12 +20,20 @@
23 struct module;
24 struct tracepoint;
25
26+#define HAVE_KABI_2635_TRACEPOINT
27+
28+struct tracepoint_func {
29+ void *func;
30+ void *data;
31+ bool kabi_2635;
32+};
33+
34 struct tracepoint {
35 const char *name; /* Tracepoint name */
36 int state; /* State. */
37 void (*regfunc)(void);
38 void (*unregfunc)(void);
39- void **funcs;
40+ struct tracepoint_func *funcs;
41 } __attribute__((aligned(32))); /*
42 * Aligned on 32 bytes because it is
43 * globally visible and gcc happily
44@@ -43,17 +51,33 @@ struct tracepoint {
45 /*
46 * it_func[0] is never NULL because there is at least one element in the array
47 * when the array itself is non NULL.
48+ *
49+ * Note, the proto and args passed in includes "__data" as the first parameter.
50+ * The reason for this is to handle the "void" prototype. If a tracepoint
51+ * has a "void" prototype, then it is invalid to declare a function
52+ * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
53+ * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
54 */
55-#define __DO_TRACE(tp, proto, args) \
56+#define __DO_TRACE(tp, data_proto, data_args, proto, args) \
57 do { \
58- void **it_func; \
59+ struct tracepoint_func *it_func_ptr; \
60+ void *it_func; \
61 \
62 rcu_read_lock_sched_notrace(); \
63- it_func = rcu_dereference((tp)->funcs); \
64- if (it_func) { \
65+ it_func_ptr = rcu_dereference((tp)->funcs); \
66+ if (it_func_ptr) { \
67 do { \
68- ((void(*)(proto))(*it_func))(args); \
69- } while (*(++it_func)); \
70+ if (it_func_ptr->kabi_2635) { \
71+ void *__data; \
72+ \
73+ it_func = (it_func_ptr)->func; \
74+ __data = (it_func_ptr)->data; \
75+ ((void(*)(data_proto))(it_func))(data_args); \
76+ } else { \
77+ it_func = (it_func_ptr)->func; \
78+ ((void(*)(proto))(it_func))(args); \
79+ } \
80+ } while ((++it_func_ptr)->func); \
81 } \
82 rcu_read_unlock_sched_notrace(); \
83 } while (0)
84@@ -63,22 +87,39 @@ struct tracepoint {
85 * not add unwanted padding between the beginning of the section and the
86 * structure. Force alignment to the same alignment as the section start.
87 */
88-#define DECLARE_TRACE(name, proto, args) \
89+#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
90 extern struct tracepoint __tracepoint_##name; \
91 static inline void trace_##name(proto) \
92 { \
93 if (unlikely(__tracepoint_##name.state)) \
94 __DO_TRACE(&__tracepoint_##name, \
95- TP_PROTO(proto), TP_ARGS(args)); \
96+ TP_PROTO(data_proto), \
97+ TP_ARGS(data_args), \
98+ TP_PROTO(proto), \
99+ TP_ARGS(args)); \
100 } \
101- static inline int register_trace_##name(void (*probe)(proto)) \
102- { \
103+ static inline int \
104+ register_trace_##name(void (*probe)(proto)) \
105+ { \
106 return tracepoint_probe_register(#name, (void *)probe); \
107- } \
108- static inline int unregister_trace_##name(void (*probe)(proto)) \
109- { \
110- return tracepoint_probe_unregister(#name, (void *)probe);\
111- }
112+ } \
113+ static inline int \
114+ unregister_trace_##name(void (*probe)(proto)) \
115+ { \
116+ return tracepoint_probe_unregister(#name, (void *)probe); \
117+ } \
118+ static inline int \
119+ kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
120+ { \
121+ return kabi_2635_tracepoint_probe_register(#name, (void *)probe, \
122+ data); \
123+ } \
124+ static inline int \
125+ kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
126+ { \
127+ return kabi_2635_tracepoint_probe_unregister(#name, (void *)probe, \
128+ data); \
129+ }
130
131
132 #define DEFINE_TRACE_FN(name, reg, unreg) \
133@@ -100,19 +141,29 @@ extern void tracepoint_update_probe_rang
134 struct tracepoint *end);
135
136 #else /* !CONFIG_TRACEPOINTS */
137-#define DECLARE_TRACE(name, proto, args) \
138- static inline void _do_trace_##name(struct tracepoint *tp, proto) \
139- { } \
140- static inline void trace_##name(proto) \
141- { } \
142- static inline int register_trace_##name(void (*probe)(proto)) \
143- { \
144- return -ENOSYS; \
145- } \
146- static inline int unregister_trace_##name(void (*probe)(proto)) \
147- { \
148- return -ENOSYS; \
149- }
150+#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
151+ static inline void trace_##name(proto) \
152+ { } \
153+ static inline int \
154+ register_trace_##name(void (*probe)(proto)) \
155+ { \
156+ return -ENOSYS; \
157+ } \
158+ static inline int \
159+ unregister_trace_##name(void (*probe)(proto)) \
160+ { \
161+ return -ENOSYS; \
162+ } \
163+ static inline int \
164+ kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
165+ { \
166+ return -ENOSYS; \
167+ } \
168+ static inline int \
169+ kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
170+ { \
171+ return -ENOSYS; \
172+ }
173
174 #define DEFINE_TRACE_FN(name, reg, unreg)
175 #define DEFINE_TRACE(name)
176@@ -123,6 +174,28 @@ static inline void tracepoint_update_pro
177 struct tracepoint *end)
178 { }
179 #endif /* CONFIG_TRACEPOINTS */
180+
181+/*
182+ * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
183+ * (void). "void" is a special value in a function prototype and can
184+ * not be combined with other arguments. Since the DECLARE_TRACE()
185+ * macro adds a data element at the beginning of the prototype,
186+ * we need a way to differentiate "(void *data, proto)" from
187+ * "(void *data, void)". The second prototype is invalid.
188+ *
189+ * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
190+ * and "void *__data" as the callback prototype.
191+ *
192+ * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
193+ * "void *__data, proto" as the callback prototype.
194+ */
195+#define DECLARE_TRACE_NOARGS(name) \
196+ __DECLARE_TRACE(name, void, , void *__data, __data)
197+#define DECLARE_TRACE(name, proto, args) \
198+ __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
199+ PARAMS(void *__data, proto), \
200+ PARAMS(__data, args))
201+
202 #endif /* DECLARE_TRACE */
203
204 /*
205@@ -130,15 +203,23 @@ static inline void tracepoint_update_pro
206 * Internal API, should not be used directly.
207 */
208 extern int tracepoint_probe_register(const char *name, void *probe);
209+extern int kabi_2635_tracepoint_probe_register(const char *name, void *probe, void *data);
210
211 /*
212 * Disconnect a probe from a tracepoint.
213 * Internal API, should not be used directly.
214 */
215-extern int tracepoint_probe_unregister(const char *name, void *probe);
216+extern int
217+tracepoint_probe_unregister(const char *name, void *probe);
218+extern int
219+kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data);
220
221 extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
222+extern int kabi_2635_tracepoint_probe_register_noupdate(const char *name, void *probe,
223+ void *data);
224 extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
225+extern int kabi_2635_tracepoint_probe_unregister_noupdate(const char *name, void *probe,
226+ void *data);
227 extern void tracepoint_probe_update_all(void);
228
229 struct tracepoint_iter {
230Index: linux/kernel/tracepoint.c
231===================================================================
232--- linux.orig/kernel/tracepoint.c
233+++ linux/kernel/tracepoint.c
234@@ -54,7 +54,7 @@ static struct hlist_head tracepoint_tabl
235 */
236 struct tracepoint_entry {
237 struct hlist_node hlist;
238- void **funcs;
239+ struct tracepoint_func *funcs;
240 int refcount; /* Number of times armed. 0 if disarmed. */
241 char name[0];
242 };
243@@ -64,12 +64,12 @@ struct tp_probes {
244 struct rcu_head rcu;
245 struct list_head list;
246 } u;
247- void *probes[0];
248+ struct tracepoint_func probes[0];
249 };
250
251 static inline void *allocate_probes(int count)
252 {
253- struct tp_probes *p = kmalloc(count * sizeof(void *)
254+ struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func)
255 + sizeof(struct tp_probes), GFP_KERNEL);
256 return p == NULL ? NULL : p->probes;
257 }
258@@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct r
259 kfree(container_of(head, struct tp_probes, u.rcu));
260 }
261
262-static inline void release_probes(void *old)
263+static inline void release_probes(struct tracepoint_func *old)
264 {
265 if (old) {
266 struct tp_probes *tp_probes = container_of(old,
267@@ -95,15 +95,16 @@ static void debug_print_probes(struct tr
268 if (!tracepoint_debug || !entry->funcs)
269 return;
270
271- for (i = 0; entry->funcs[i]; i++)
272- printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i]);
273+ for (i = 0; entry->funcs[i].func; i++)
274+ printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i].func);
275 }
276
277-static void *
278-tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe)
279+static struct tracepoint_func *
280+tracepoint_entry_add_probe(struct tracepoint_entry *entry,
281+ void *probe, void *data, bool kabi_2635)
282 {
283 int nr_probes = 0;
284- void **old, **new;
285+ struct tracepoint_func *old, *new;
286
287 WARN_ON(!probe);
288
289@@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracep
290 old = entry->funcs;
291 if (old) {
292 /* (N -> N+1), (N != 0, 1) probes */
293- for (nr_probes = 0; old[nr_probes]; nr_probes++)
294- if (old[nr_probes] == probe)
295+ for (nr_probes = 0; old[nr_probes].func; nr_probes++)
296+ if (old[nr_probes].func == probe &&
297+ old[nr_probes].data == data)
298 return ERR_PTR(-EEXIST);
299 }
300 /* + 2 : one for new probe, one for NULL func */
301@@ -120,9 +122,11 @@ tracepoint_entry_add_probe(struct tracep
302 if (new == NULL)
303 return ERR_PTR(-ENOMEM);
304 if (old)
305- memcpy(new, old, nr_probes * sizeof(void *));
306- new[nr_probes] = probe;
307- new[nr_probes + 1] = NULL;
308+ memcpy(new, old, nr_probes * sizeof(struct tracepoint_func));
309+ new[nr_probes].func = probe;
310+ new[nr_probes].data = data;
311+ new[nr_probes].kabi_2635 = kabi_2635;
312+ new[nr_probes + 1].func = NULL;
313 entry->refcount = nr_probes + 1;
314 entry->funcs = new;
315 debug_print_probes(entry);
316@@ -130,10 +134,11 @@ tracepoint_entry_add_probe(struct tracep
317 }
318
319 static void *
320-tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe)
321+tracepoint_entry_remove_probe(struct tracepoint_entry *entry,
322+ void *probe, void *data)
323 {
324 int nr_probes = 0, nr_del = 0, i;
325- void **old, **new;
326+ struct tracepoint_func *old, *new;
327
328 old = entry->funcs;
329
330@@ -142,8 +147,10 @@ tracepoint_entry_remove_probe(struct tra
331
332 debug_print_probes(entry);
333 /* (N -> M), (N > 1, M >= 0) probes */
334- for (nr_probes = 0; old[nr_probes]; nr_probes++) {
335- if ((!probe || old[nr_probes] == probe))
336+ for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
337+ if (!probe ||
338+ (old[nr_probes].func == probe &&
339+ old[nr_probes].data == data))
340 nr_del++;
341 }
342
343@@ -160,10 +167,11 @@ tracepoint_entry_remove_probe(struct tra
344 new = allocate_probes(nr_probes - nr_del + 1);
345 if (new == NULL)
346 return ERR_PTR(-ENOMEM);
347- for (i = 0; old[i]; i++)
348- if ((probe && old[i] != probe))
349+ for (i = 0; old[i].func; i++)
350+ if (probe &&
351+ (old[i].func != probe || old[i].data != data))
352 new[j++] = old[i];
353- new[nr_probes - nr_del] = NULL;
354+ new[nr_probes - nr_del].func = NULL;
355 entry->refcount = nr_probes - nr_del;
356 entry->funcs = new;
357 }
358@@ -315,18 +323,19 @@ static void tracepoint_update_probes(voi
359 module_update_tracepoints();
360 }
361
362-static void *tracepoint_add_probe(const char *name, void *probe)
363+static struct tracepoint_func *
364+tracepoint_add_probe(const char *name, void *probe, void *data, bool kabi_2635)
365 {
366 struct tracepoint_entry *entry;
367- void *old;
368+ struct tracepoint_func *old;
369
370 entry = get_tracepoint(name);
371 if (!entry) {
372 entry = add_tracepoint(name);
373 if (IS_ERR(entry))
374- return entry;
375+ return (struct tracepoint_func *)entry;
376 }
377- old = tracepoint_entry_add_probe(entry, probe);
378+ old = tracepoint_entry_add_probe(entry, probe, data, kabi_2635);
379 if (IS_ERR(old) && !entry->refcount)
380 remove_tracepoint(entry);
381 return old;
382@@ -340,12 +349,14 @@ static void *tracepoint_add_probe(const
383 * Returns 0 if ok, error value on error.
384 * The probe address must at least be aligned on the architecture pointer size.
385 */
386-int tracepoint_probe_register(const char *name, void *probe)
387+static
388+int ___tracepoint_probe_register(const char *name, void *probe, void *data,
389+ bool kabi_2635)
390 {
391- void *old;
392+ struct tracepoint_func *old;
393
394 mutex_lock(&tracepoints_mutex);
395- old = tracepoint_add_probe(name, probe);
396+ old = tracepoint_add_probe(name, probe, data, kabi_2635);
397 mutex_unlock(&tracepoints_mutex);
398 if (IS_ERR(old))
399 return PTR_ERR(old);
400@@ -354,17 +365,30 @@ int tracepoint_probe_register(const char
401 release_probes(old);
402 return 0;
403 }
404+
405+int kabi_2635_tracepoint_probe_register(const char *name, void *probe, void *data)
406+{
407+ return ___tracepoint_probe_register(name, probe, data, 1);
408+}
409+EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register);
410+
411+
412+int tracepoint_probe_register(const char *name, void *probe)
413+{
414+ return ___tracepoint_probe_register(name, probe, NULL, 0);
415+}
416 EXPORT_SYMBOL_GPL(tracepoint_probe_register);
417
418-static void *tracepoint_remove_probe(const char *name, void *probe)
419+static struct tracepoint_func *
420+tracepoint_remove_probe(const char *name, void *probe, void *data)
421 {
422 struct tracepoint_entry *entry;
423- void *old;
424+ struct tracepoint_func *old;
425
426 entry = get_tracepoint(name);
427 if (!entry)
428 return ERR_PTR(-ENOENT);
429- old = tracepoint_entry_remove_probe(entry, probe);
430+ old = tracepoint_entry_remove_probe(entry, probe, data);
431 if (IS_ERR(old))
432 return old;
433 if (!entry->refcount)
434@@ -382,12 +406,13 @@ static void *tracepoint_remove_probe(con
435 * itself uses stop_machine(), which insures that every preempt disabled section
436 * have finished.
437 */
438-int tracepoint_probe_unregister(const char *name, void *probe)
439+static
440+int ___tracepoint_probe_unregister(const char *name, void *probe, void *data)
441 {
442- void *old;
443+ struct tracepoint_func *old;
444
445 mutex_lock(&tracepoints_mutex);
446- old = tracepoint_remove_probe(name, probe);
447+ old = tracepoint_remove_probe(name, probe, data);
448 mutex_unlock(&tracepoints_mutex);
449 if (IS_ERR(old))
450 return PTR_ERR(old);
451@@ -396,6 +421,17 @@ int tracepoint_probe_unregister(const ch
452 release_probes(old);
453 return 0;
454 }
455+
456+int kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data)
457+{
458+ return ___tracepoint_probe_unregister(name, probe, data);
459+}
460+EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister);
461+
462+int tracepoint_probe_unregister(const char *name, void *probe)
463+{
464+ return ___tracepoint_probe_unregister(name, probe, NULL);
465+}
466 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
467
468 static LIST_HEAD(old_probes);
469@@ -418,12 +454,14 @@ static void tracepoint_add_old_probes(vo
470 *
471 * caller must call tracepoint_probe_update_all()
472 */
473-int tracepoint_probe_register_noupdate(const char *name, void *probe)
474+static
475+int ___tracepoint_probe_register_noupdate(const char *name, void *probe,
476+ void *data, bool kabi_2635)
477 {
478- void *old;
479+ struct tracepoint_func *old;
480
481 mutex_lock(&tracepoints_mutex);
482- old = tracepoint_add_probe(name, probe);
483+ old = tracepoint_add_probe(name, probe, data, kabi_2635);
484 if (IS_ERR(old)) {
485 mutex_unlock(&tracepoints_mutex);
486 return PTR_ERR(old);
487@@ -432,6 +470,18 @@ int tracepoint_probe_register_noupdate(c
488 mutex_unlock(&tracepoints_mutex);
489 return 0;
490 }
491+
492+int kabi_2635_tracepoint_probe_register_noupdate(const char *name, void *probe,
493+ void *data)
494+{
495+ return ___tracepoint_probe_register_noupdate(name, probe, data, 1);
496+}
497+EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register_noupdate);
498+
499+int tracepoint_probe_register_noupdate(const char *name, void *probe)
500+{
501+ return ___tracepoint_probe_register_noupdate(name, probe, NULL, 0);
502+}
503 EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
504
505 /**
506@@ -441,12 +491,14 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_regis
507 *
508 * caller must call tracepoint_probe_update_all()
509 */
510-int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
511+static
512+int ___tracepoint_probe_unregister_noupdate(const char *name, void *probe,
513+ void *data)
514 {
515- void *old;
516+ struct tracepoint_func *old;
517
518 mutex_lock(&tracepoints_mutex);
519- old = tracepoint_remove_probe(name, probe);
520+ old = tracepoint_remove_probe(name, probe, data);
521 if (IS_ERR(old)) {
522 mutex_unlock(&tracepoints_mutex);
523 return PTR_ERR(old);
524@@ -455,6 +507,18 @@ int tracepoint_probe_unregister_noupdate
525 mutex_unlock(&tracepoints_mutex);
526 return 0;
527 }
528+
529+int kabi_2635_tracepoint_probe_unregister_noupdate(const char *name, void *probe,
530+ void *data)
531+{
532+ return ___tracepoint_probe_unregister_noupdate(name, probe, data);
533+}
534+EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister_noupdate);
535+
536+int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
537+{
538+ return ___tracepoint_probe_unregister_noupdate(name, probe, NULL);
539+}
540 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate);
541
542 /**
83788d81
AG
543Index: linux/samples/tracepoints/tp-samples-trace.h
544===================================================================
545--- linux.orig/samples/tracepoints/tp-samples-trace.h
546+++ linux/samples/tracepoints/tp-samples-trace.h
547@@ -7,7 +7,5 @@
548 DECLARE_TRACE(subsys_event,
549 TP_PROTO(struct inode *inode, struct file *file),
550 TP_ARGS(inode, file));
551-DECLARE_TRACE(subsys_eventb,
552- TP_PROTO(void),
553- TP_ARGS());
554+DECLARE_TRACE_NOARGS(subsys_eventb);
555 #endif
This page took 0.048941 seconds and 4 git commands to generate.