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.34.x. Keeping kABI compatibility.
10 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 include/linux/tracepoint.h | 149 ++++++++++++++++++++++++++++++++++-----------
14 kernel/tracepoint.c | 144 +++++++++++++++++++++++++++++++------------
15 2 files changed, 219 insertions(+), 74 deletions(-)
17 Index: linux/include/linux/tracepoint.h
18 ===================================================================
19 --- linux.orig/include/linux/tracepoint.h
20 +++ linux/include/linux/tracepoint.h
25 +#define HAVE_KABI_2635_TRACEPOINT
27 +struct tracepoint_func {
34 const char *name; /* Tracepoint name */
35 int state; /* State. */
36 void (*regfunc)(void);
37 void (*unregfunc)(void);
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 {
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.
48 -#define __DO_TRACE(tp, proto, args) \
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".
58 +#define __DO_TRACE(tp, data_proto, data_args, proto, args) \
60 + struct tracepoint_func *it_func_ptr; \
63 + rcu_read_lock_sched_notrace(); \
64 + it_func_ptr = rcu_dereference_sched((tp)->funcs); \
65 + if (it_func_ptr) { \
67 + if (it_func_ptr->kabi_2635) { \
70 - rcu_read_lock_sched_notrace(); \
71 - it_func = rcu_dereference_sched((tp)->funcs); \
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); \
80 + it_func = (it_func_ptr)->func; \
81 + ((void(*)(proto))(it_func))(args); \
83 + } while ((++it_func_ptr)->func); \
85 rcu_read_unlock_sched_notrace(); \
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.
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) \
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), \
104 - static inline int register_trace_##name(void (*probe)(proto)) \
106 + static inline int \
107 + register_trace_##name(void (*probe)(proto)) \
109 return tracepoint_probe_register(#name, (void *)probe); \
111 - static inline int unregister_trace_##name(void (*probe)(proto)) \
113 - return tracepoint_probe_unregister(#name, (void *)probe);\
116 + static inline int \
117 + unregister_trace_##name(void (*probe)(proto)) \
119 + return tracepoint_probe_unregister(#name, (void *)probe); \
121 + static inline int \
122 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
124 + return kabi_2635_tracepoint_probe_register(#name, (void *)probe, \
127 + static inline int \
128 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
130 + return kabi_2635_tracepoint_probe_unregister(#name, (void *)probe, \
135 #define DEFINE_TRACE_FN(name, reg, unreg) \
136 @@ -100,19 +141,29 @@ extern void tracepoint_update_probe_rang
137 struct tracepoint *end);
139 #else /* !CONFIG_TRACEPOINTS */
140 -#define DECLARE_TRACE(name, proto, args) \
141 - static inline void _do_trace_##name(struct tracepoint *tp, proto) \
143 - static inline void trace_##name(proto) \
145 - static inline int register_trace_##name(void (*probe)(proto)) \
149 - static inline int unregister_trace_##name(void (*probe)(proto)) \
153 +#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
154 + static inline void trace_##name(proto) \
156 + static inline int \
157 + register_trace_##name(void (*probe)(proto)) \
161 + static inline int \
162 + unregister_trace_##name(void (*probe)(proto)) \
166 + static inline int \
167 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
171 + static inline int \
172 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
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)
182 #endif /* CONFIG_TRACEPOINTS */
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.
192 + * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
193 + * and "void *__data" as the callback prototype.
195 + * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
196 + * "void *__data, proto" as the callback prototype.
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))
205 #endif /* DECLARE_TRACE */
208 @@ -130,15 +203,23 @@ static inline void tracepoint_update_pro
209 * Internal API, should not be used directly.
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);
215 * Disconnect a probe from a tracepoint.
216 * Internal API, should not be used directly.
218 -extern int tracepoint_probe_unregister(const char *name, void *probe);
220 +tracepoint_probe_unregister(const char *name, void *probe);
222 +kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data);
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,
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,
230 extern void tracepoint_probe_update_all(void);
232 struct tracepoint_iter {
233 Index: 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
239 struct tracepoint_entry {
240 struct hlist_node hlist;
242 + struct tracepoint_func *funcs;
243 int refcount; /* Number of times armed. 0 if disarmed. */
246 @@ -64,12 +64,12 @@ struct tp_probes {
248 struct list_head list;
251 + struct tracepoint_func probes[0];
254 static inline void *allocate_probes(int count)
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;
261 @@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct r
262 kfree(container_of(head, struct tp_probes, u.rcu));
265 -static inline void release_probes(void *old)
266 +static inline void release_probes(struct tracepoint_func *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)
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);
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)
288 + struct tracepoint_func *old, *new;
292 @@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracep
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);
303 /* + 2 : one for new probe, one for NULL func */
304 @@ -120,9 +122,11 @@ tracepoint_entry_add_probe(struct tracep
306 return ERR_PTR(-ENOMEM);
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;
318 debug_print_probes(entry);
319 @@ -130,10 +134,11 @@ tracepoint_entry_add_probe(struct tracep
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)
327 int nr_probes = 0, nr_del = 0, i;
329 + struct tracepoint_func *old, *new;
333 @@ -142,8 +147,10 @@ tracepoint_entry_remove_probe(struct tra
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++) {
341 + (old[nr_probes].func == probe &&
342 + old[nr_probes].data == data))
346 @@ -160,10 +167,11 @@ tracepoint_entry_remove_probe(struct tra
347 new = allocate_probes(nr_probes - nr_del + 1);
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++)
354 + (old[i].func != probe || old[i].data != data))
356 - new[nr_probes - nr_del] = NULL;
357 + new[nr_probes - nr_del].func = NULL;
358 entry->refcount = nr_probes - nr_del;
361 @@ -315,18 +323,19 @@ static void tracepoint_update_probes(voi
362 module_update_tracepoints();
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)
369 struct tracepoint_entry *entry;
371 + struct tracepoint_func *old;
373 entry = get_tracepoint(name);
375 entry = add_tracepoint(name);
378 + return (struct tracepoint_func *)entry;
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);
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.
389 -int tracepoint_probe_register(const char *name, void *probe)
391 +int ___tracepoint_probe_register(const char *name, void *probe, void *data,
395 + struct tracepoint_func *old;
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);
403 @@ -354,17 +365,30 @@ int tracepoint_probe_register(const char
408 +int kabi_2635_tracepoint_probe_register(const char *name, void *probe, void *data)
410 + return ___tracepoint_probe_register(name, probe, data, 1);
412 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register);
415 +int tracepoint_probe_register(const char *name, void *probe)
417 + return ___tracepoint_probe_register(name, probe, NULL, 0);
419 EXPORT_SYMBOL_GPL(tracepoint_probe_register);
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)
425 struct tracepoint_entry *entry;
427 + struct tracepoint_func *old;
429 entry = get_tracepoint(name);
431 return ERR_PTR(-ENOENT);
432 - old = tracepoint_entry_remove_probe(entry, probe);
433 + old = tracepoint_entry_remove_probe(entry, probe, data);
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
441 -int tracepoint_probe_unregister(const char *name, void *probe)
443 +int ___tracepoint_probe_unregister(const char *name, void *probe, void *data)
446 + struct tracepoint_func *old;
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);
454 @@ -396,6 +421,17 @@ int tracepoint_probe_unregister(const ch
459 +int kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data)
461 + return ___tracepoint_probe_unregister(name, probe, data);
463 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister);
465 +int tracepoint_probe_unregister(const char *name, void *probe)
467 + return ___tracepoint_probe_unregister(name, probe, NULL);
469 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
471 static LIST_HEAD(old_probes);
472 @@ -418,12 +454,14 @@ static void tracepoint_add_old_probes(vo
474 * caller must call tracepoint_probe_update_all()
476 -int tracepoint_probe_register_noupdate(const char *name, void *probe)
478 +int ___tracepoint_probe_register_noupdate(const char *name, void *probe,
479 + void *data, bool kabi_2635)
482 + struct tracepoint_func *old;
484 mutex_lock(&tracepoints_mutex);
485 - old = tracepoint_add_probe(name, probe);
486 + old = tracepoint_add_probe(name, probe, data, kabi_2635);
488 mutex_unlock(&tracepoints_mutex);
490 @@ -432,6 +470,18 @@ int tracepoint_probe_register_noupdate(c
491 mutex_unlock(&tracepoints_mutex);
495 +int kabi_2635_tracepoint_probe_register_noupdate(const char *name, void *probe,
498 + return ___tracepoint_probe_register_noupdate(name, probe, data, 1);
500 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register_noupdate);
502 +int tracepoint_probe_register_noupdate(const char *name, void *probe)
504 + return ___tracepoint_probe_register_noupdate(name, probe, NULL, 0);
506 EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
509 @@ -441,12 +491,14 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_regis
511 * caller must call tracepoint_probe_update_all()
513 -int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
515 +int ___tracepoint_probe_unregister_noupdate(const char *name, void *probe,
519 + struct tracepoint_func *old;
521 mutex_lock(&tracepoints_mutex);
522 - old = tracepoint_remove_probe(name, probe);
523 + old = tracepoint_remove_probe(name, probe, data);
525 mutex_unlock(&tracepoints_mutex);
527 @@ -455,6 +507,18 @@ int tracepoint_probe_unregister_noupdate
528 mutex_unlock(&tracepoints_mutex);
532 +int kabi_2635_tracepoint_probe_unregister_noupdate(const char *name, void *probe,
535 + return ___tracepoint_probe_unregister_noupdate(name, probe, data);
537 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister_noupdate);
539 +int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
541 + return ___tracepoint_probe_unregister_noupdate(name, probe, NULL);
543 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate);