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