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