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