1 commit 2c2a566b64b4254c530fb0c2222b30e8a739bac9
2 Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 Date: Sat Sep 1 17:45:09 2012 -0700
5 tracing: Let tracepoints have data passed to tracepoint callbacks (backport)
7 Backport of commit 38516ab59fbc5b3bb278cf5e1fe2867c70cff32e for
8 2.6.32.x and 2.6.33.x. Keeping kABI compatibility.
10 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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(-)
18 Index: linux/include/linux/tracepoint.h
19 ===================================================================
20 --- linux.orig/include/linux/tracepoint.h
21 +++ linux/include/linux/tracepoint.h
26 +#define HAVE_KABI_2635_TRACEPOINT
28 +struct tracepoint_func {
35 const char *name; /* Tracepoint name */
36 int state; /* State. */
37 void (*regfunc)(void);
38 void (*unregfunc)(void);
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 {
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.
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".
55 -#define __DO_TRACE(tp, proto, args) \
56 +#define __DO_TRACE(tp, data_proto, data_args, proto, args) \
59 + struct tracepoint_func *it_func_ptr; \
62 rcu_read_lock_sched_notrace(); \
63 - it_func = rcu_dereference((tp)->funcs); \
65 + it_func_ptr = rcu_dereference((tp)->funcs); \
66 + if (it_func_ptr) { \
68 - ((void(*)(proto))(*it_func))(args); \
69 - } while (*(++it_func)); \
70 + if (it_func_ptr->kabi_2635) { \
73 + it_func = (it_func_ptr)->func; \
74 + __data = (it_func_ptr)->data; \
75 + ((void(*)(data_proto))(it_func))(data_args); \
77 + it_func = (it_func_ptr)->func; \
78 + ((void(*)(proto))(it_func))(args); \
80 + } while ((++it_func_ptr)->func); \
82 rcu_read_unlock_sched_notrace(); \
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.
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) \
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), \
101 - static inline int register_trace_##name(void (*probe)(proto)) \
103 + static inline int \
104 + register_trace_##name(void (*probe)(proto)) \
106 return tracepoint_probe_register(#name, (void *)probe); \
108 - static inline int unregister_trace_##name(void (*probe)(proto)) \
110 - return tracepoint_probe_unregister(#name, (void *)probe);\
113 + static inline int \
114 + unregister_trace_##name(void (*probe)(proto)) \
116 + return tracepoint_probe_unregister(#name, (void *)probe); \
118 + static inline int \
119 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
121 + return kabi_2635_tracepoint_probe_register(#name, (void *)probe, \
124 + static inline int \
125 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
127 + return kabi_2635_tracepoint_probe_unregister(#name, (void *)probe, \
132 #define DEFINE_TRACE_FN(name, reg, unreg) \
133 @@ -100,19 +141,29 @@ extern void tracepoint_update_probe_rang
134 struct tracepoint *end);
136 #else /* !CONFIG_TRACEPOINTS */
137 -#define DECLARE_TRACE(name, proto, args) \
138 - static inline void _do_trace_##name(struct tracepoint *tp, proto) \
140 - static inline void trace_##name(proto) \
142 - static inline int register_trace_##name(void (*probe)(proto)) \
146 - static inline int unregister_trace_##name(void (*probe)(proto)) \
150 +#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
151 + static inline void trace_##name(proto) \
153 + static inline int \
154 + register_trace_##name(void (*probe)(proto)) \
158 + static inline int \
159 + unregister_trace_##name(void (*probe)(proto)) \
163 + static inline int \
164 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
168 + static inline int \
169 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
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)
179 #endif /* CONFIG_TRACEPOINTS */
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.
189 + * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
190 + * and "void *__data" as the callback prototype.
192 + * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
193 + * "void *__data, proto" as the callback prototype.
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))
202 #endif /* DECLARE_TRACE */
205 @@ -130,15 +203,23 @@ static inline void tracepoint_update_pro
206 * Internal API, should not be used directly.
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);
212 * Disconnect a probe from a tracepoint.
213 * Internal API, should not be used directly.
215 -extern int tracepoint_probe_unregister(const char *name, void *probe);
217 +tracepoint_probe_unregister(const char *name, void *probe);
219 +kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data);
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,
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,
227 extern void tracepoint_probe_update_all(void);
229 struct tracepoint_iter {
230 Index: 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
236 struct tracepoint_entry {
237 struct hlist_node hlist;
239 + struct tracepoint_func *funcs;
240 int refcount; /* Number of times armed. 0 if disarmed. */
243 @@ -64,12 +64,12 @@ struct tp_probes {
245 struct list_head list;
248 + struct tracepoint_func probes[0];
251 static inline void *allocate_probes(int count)
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;
258 @@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct r
259 kfree(container_of(head, struct tp_probes, u.rcu));
262 -static inline void release_probes(void *old)
263 +static inline void release_probes(struct tracepoint_func *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)
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);
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)
285 + struct tracepoint_func *old, *new;
289 @@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracep
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);
300 /* + 2 : one for new probe, one for NULL func */
301 @@ -120,9 +122,11 @@ tracepoint_entry_add_probe(struct tracep
303 return ERR_PTR(-ENOMEM);
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;
315 debug_print_probes(entry);
316 @@ -130,10 +134,11 @@ tracepoint_entry_add_probe(struct tracep
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)
324 int nr_probes = 0, nr_del = 0, i;
326 + struct tracepoint_func *old, *new;
330 @@ -142,8 +147,10 @@ tracepoint_entry_remove_probe(struct tra
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++) {
338 + (old[nr_probes].func == probe &&
339 + old[nr_probes].data == data))
343 @@ -160,10 +167,11 @@ tracepoint_entry_remove_probe(struct tra
344 new = allocate_probes(nr_probes - nr_del + 1);
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++)
351 + (old[i].func != probe || old[i].data != data))
353 - new[nr_probes - nr_del] = NULL;
354 + new[nr_probes - nr_del].func = NULL;
355 entry->refcount = nr_probes - nr_del;
358 @@ -315,18 +323,19 @@ static void tracepoint_update_probes(voi
359 module_update_tracepoints();
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)
366 struct tracepoint_entry *entry;
368 + struct tracepoint_func *old;
370 entry = get_tracepoint(name);
372 entry = add_tracepoint(name);
375 + return (struct tracepoint_func *)entry;
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);
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.
386 -int tracepoint_probe_register(const char *name, void *probe)
388 +int ___tracepoint_probe_register(const char *name, void *probe, void *data,
392 + struct tracepoint_func *old;
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);
400 @@ -354,17 +365,30 @@ int tracepoint_probe_register(const char
405 +int kabi_2635_tracepoint_probe_register(const char *name, void *probe, void *data)
407 + return ___tracepoint_probe_register(name, probe, data, 1);
409 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register);
412 +int tracepoint_probe_register(const char *name, void *probe)
414 + return ___tracepoint_probe_register(name, probe, NULL, 0);
416 EXPORT_SYMBOL_GPL(tracepoint_probe_register);
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)
422 struct tracepoint_entry *entry;
424 + struct tracepoint_func *old;
426 entry = get_tracepoint(name);
428 return ERR_PTR(-ENOENT);
429 - old = tracepoint_entry_remove_probe(entry, probe);
430 + old = tracepoint_entry_remove_probe(entry, probe, data);
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
438 -int tracepoint_probe_unregister(const char *name, void *probe)
440 +int ___tracepoint_probe_unregister(const char *name, void *probe, void *data)
443 + struct tracepoint_func *old;
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);
451 @@ -396,6 +421,17 @@ int tracepoint_probe_unregister(const ch
456 +int kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data)
458 + return ___tracepoint_probe_unregister(name, probe, data);
460 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister);
462 +int tracepoint_probe_unregister(const char *name, void *probe)
464 + return ___tracepoint_probe_unregister(name, probe, NULL);
466 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
468 static LIST_HEAD(old_probes);
469 @@ -418,12 +454,14 @@ static void tracepoint_add_old_probes(vo
471 * caller must call tracepoint_probe_update_all()
473 -int tracepoint_probe_register_noupdate(const char *name, void *probe)
475 +int ___tracepoint_probe_register_noupdate(const char *name, void *probe,
476 + void *data, bool kabi_2635)
479 + struct tracepoint_func *old;
481 mutex_lock(&tracepoints_mutex);
482 - old = tracepoint_add_probe(name, probe);
483 + old = tracepoint_add_probe(name, probe, data, kabi_2635);
485 mutex_unlock(&tracepoints_mutex);
487 @@ -432,6 +470,18 @@ int tracepoint_probe_register_noupdate(c
488 mutex_unlock(&tracepoints_mutex);
492 +int kabi_2635_tracepoint_probe_register_noupdate(const char *name, void *probe,
495 + return ___tracepoint_probe_register_noupdate(name, probe, data, 1);
497 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register_noupdate);
499 +int tracepoint_probe_register_noupdate(const char *name, void *probe)
501 + return ___tracepoint_probe_register_noupdate(name, probe, NULL, 0);
503 EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
506 @@ -441,12 +491,14 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_regis
508 * caller must call tracepoint_probe_update_all()
510 -int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
512 +int ___tracepoint_probe_unregister_noupdate(const char *name, void *probe,
516 + struct tracepoint_func *old;
518 mutex_lock(&tracepoints_mutex);
519 - old = tracepoint_remove_probe(name, probe);
520 + old = tracepoint_remove_probe(name, probe, data);
522 mutex_unlock(&tracepoints_mutex);
524 @@ -455,6 +507,18 @@ int tracepoint_probe_unregister_noupdate
525 mutex_unlock(&tracepoints_mutex);
529 +int kabi_2635_tracepoint_probe_unregister_noupdate(const char *name, void *probe,
532 + return ___tracepoint_probe_unregister_noupdate(name, probe, data);
534 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister_noupdate);
536 +int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
538 + return ___tracepoint_probe_unregister_noupdate(name, probe, NULL);
540 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate);
543 Index: 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
548 DECLARE_TRACE(subsys_event,
549 TP_PROTO(struct inode *inode, struct file *file),
550 TP_ARGS(inode, file));
551 -DECLARE_TRACE(subsys_eventb,
554 +DECLARE_TRACE_NOARGS(subsys_eventb);