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 2 files changed, 215 insertions(+), 70 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 + * 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".
54 -#define __DO_TRACE(tp, proto, args) \
55 +#define __DO_TRACE(tp, data_proto, data_args, proto, args) \
58 + struct tracepoint_func *it_func_ptr; \
61 rcu_read_lock_sched_notrace(); \
62 - it_func = rcu_dereference((tp)->funcs); \
64 + it_func_ptr = rcu_dereference((tp)->funcs); \
65 + if (it_func_ptr) { \
67 - ((void(*)(proto))(*it_func))(args); \
68 - } while (*(++it_func)); \
69 + if (it_func_ptr->kabi_2635) { \
72 + it_func = (it_func_ptr)->func; \
73 + __data = (it_func_ptr)->data; \
74 + ((void(*)(data_proto))(it_func))(data_args); \
76 + it_func = (it_func_ptr)->func; \
77 + ((void(*)(proto))(it_func))(args); \
79 + } while ((++it_func_ptr)->func); \
81 rcu_read_unlock_sched_notrace(); \
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.
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) \
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), \
100 - static inline int register_trace_##name(void (*probe)(proto)) \
102 + static inline int \
103 + register_trace_##name(void (*probe)(proto)) \
105 return tracepoint_probe_register(#name, (void *)probe); \
107 - static inline int unregister_trace_##name(void (*probe)(proto)) \
109 - return tracepoint_probe_unregister(#name, (void *)probe);\
112 + static inline int \
113 + unregister_trace_##name(void (*probe)(proto)) \
115 + return tracepoint_probe_unregister(#name, (void *)probe); \
117 + static inline int \
118 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
120 + return kabi_2635_tracepoint_probe_register(#name, (void *)probe, \
123 + static inline int \
124 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
126 + return kabi_2635_tracepoint_probe_unregister(#name, (void *)probe, \
131 #define DEFINE_TRACE_FN(name, reg, unreg) \
132 @@ -100,19 +141,29 @@ extern void tracepoint_update_probe_rang
133 struct tracepoint *end);
135 #else /* !CONFIG_TRACEPOINTS */
136 -#define DECLARE_TRACE(name, proto, args) \
137 - static inline void _do_trace_##name(struct tracepoint *tp, proto) \
139 - static inline void trace_##name(proto) \
141 - static inline int register_trace_##name(void (*probe)(proto)) \
145 - static inline int unregister_trace_##name(void (*probe)(proto)) \
149 +#define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
150 + static inline void trace_##name(proto) \
152 + static inline int \
153 + register_trace_##name(void (*probe)(proto)) \
157 + static inline int \
158 + unregister_trace_##name(void (*probe)(proto)) \
162 + static inline int \
163 + kabi_2635_register_trace_##name(void (*probe)(data_proto), void *data) \
167 + static inline int \
168 + kabi_2635_unregister_trace_##name(void (*probe)(data_proto), void *data) \
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)
178 #endif /* CONFIG_TRACEPOINTS */
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.
188 + * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
189 + * and "void *__data" as the callback prototype.
191 + * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
192 + * "void *__data, proto" as the callback prototype.
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))
201 #endif /* DECLARE_TRACE */
204 @@ -130,15 +203,23 @@ static inline void tracepoint_update_pro
205 * Internal API, should not be used directly.
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);
211 * Disconnect a probe from a tracepoint.
212 * Internal API, should not be used directly.
214 -extern int tracepoint_probe_unregister(const char *name, void *probe);
216 +tracepoint_probe_unregister(const char *name, void *probe);
218 +kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data);
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,
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,
226 extern void tracepoint_probe_update_all(void);
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
235 struct tracepoint_entry {
236 struct hlist_node hlist;
238 + struct tracepoint_func *funcs;
239 int refcount; /* Number of times armed. 0 if disarmed. */
242 @@ -64,12 +64,12 @@ struct tp_probes {
244 struct list_head list;
247 + struct tracepoint_func probes[0];
250 static inline void *allocate_probes(int count)
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;
257 @@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct r
258 kfree(container_of(head, struct tp_probes, u.rcu));
261 -static inline void release_probes(void *old)
262 +static inline void release_probes(struct tracepoint_func *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)
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);
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)
284 + struct tracepoint_func *old, *new;
288 @@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracep
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);
299 /* + 2 : one for new probe, one for NULL func */
300 @@ -120,9 +122,11 @@ tracepoint_entry_add_probe(struct tracep
302 return ERR_PTR(-ENOMEM);
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;
314 debug_print_probes(entry);
315 @@ -130,10 +134,11 @@ tracepoint_entry_add_probe(struct tracep
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)
323 int nr_probes = 0, nr_del = 0, i;
325 + struct tracepoint_func *old, *new;
329 @@ -142,8 +147,10 @@ tracepoint_entry_remove_probe(struct tra
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++) {
337 + (old[nr_probes].func == probe &&
338 + old[nr_probes].data == data))
342 @@ -160,10 +167,11 @@ tracepoint_entry_remove_probe(struct tra
343 new = allocate_probes(nr_probes - nr_del + 1);
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++)
350 + (old[i].func != probe || old[i].data != data))
352 - new[nr_probes - nr_del] = NULL;
353 + new[nr_probes - nr_del].func = NULL;
354 entry->refcount = nr_probes - nr_del;
357 @@ -315,18 +323,19 @@ static void tracepoint_update_probes(voi
358 module_update_tracepoints();
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)
365 struct tracepoint_entry *entry;
367 + struct tracepoint_func *old;
369 entry = get_tracepoint(name);
371 entry = add_tracepoint(name);
374 + return (struct tracepoint_func *)entry;
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);
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.
385 -int tracepoint_probe_register(const char *name, void *probe)
387 +int ___tracepoint_probe_register(const char *name, void *probe, void *data,
391 + struct tracepoint_func *old;
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);
399 @@ -354,17 +365,30 @@ int tracepoint_probe_register(const char
404 +int kabi_2635_tracepoint_probe_register(const char *name, void *probe, void *data)
406 + return ___tracepoint_probe_register(name, probe, data, 1);
408 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register);
411 +int tracepoint_probe_register(const char *name, void *probe)
413 + return ___tracepoint_probe_register(name, probe, NULL, 0);
415 EXPORT_SYMBOL_GPL(tracepoint_probe_register);
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)
421 struct tracepoint_entry *entry;
423 + struct tracepoint_func *old;
425 entry = get_tracepoint(name);
427 return ERR_PTR(-ENOENT);
428 - old = tracepoint_entry_remove_probe(entry, probe);
429 + old = tracepoint_entry_remove_probe(entry, probe, data);
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
437 -int tracepoint_probe_unregister(const char *name, void *probe)
439 +int ___tracepoint_probe_unregister(const char *name, void *probe, void *data)
442 + struct tracepoint_func *old;
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);
450 @@ -396,6 +421,17 @@ int tracepoint_probe_unregister(const ch
455 +int kabi_2635_tracepoint_probe_unregister(const char *name, void *probe, void *data)
457 + return ___tracepoint_probe_unregister(name, probe, data);
459 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister);
461 +int tracepoint_probe_unregister(const char *name, void *probe)
463 + return ___tracepoint_probe_unregister(name, probe, NULL);
465 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
467 static LIST_HEAD(old_probes);
468 @@ -418,12 +454,14 @@ static void tracepoint_add_old_probes(vo
470 * caller must call tracepoint_probe_update_all()
472 -int tracepoint_probe_register_noupdate(const char *name, void *probe)
474 +int ___tracepoint_probe_register_noupdate(const char *name, void *probe,
475 + void *data, bool kabi_2635)
478 + struct tracepoint_func *old;
480 mutex_lock(&tracepoints_mutex);
481 - old = tracepoint_add_probe(name, probe);
482 + old = tracepoint_add_probe(name, probe, data, kabi_2635);
484 mutex_unlock(&tracepoints_mutex);
486 @@ -432,6 +470,18 @@ int tracepoint_probe_register_noupdate(c
487 mutex_unlock(&tracepoints_mutex);
491 +int kabi_2635_tracepoint_probe_register_noupdate(const char *name, void *probe,
494 + return ___tracepoint_probe_register_noupdate(name, probe, data, 1);
496 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_register_noupdate);
498 +int tracepoint_probe_register_noupdate(const char *name, void *probe)
500 + return ___tracepoint_probe_register_noupdate(name, probe, NULL, 0);
502 EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
505 @@ -441,12 +491,14 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_regis
507 * caller must call tracepoint_probe_update_all()
509 -int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
511 +int ___tracepoint_probe_unregister_noupdate(const char *name, void *probe,
515 + struct tracepoint_func *old;
517 mutex_lock(&tracepoints_mutex);
518 - old = tracepoint_remove_probe(name, probe);
519 + old = tracepoint_remove_probe(name, probe, data);
521 mutex_unlock(&tracepoints_mutex);
523 @@ -455,6 +507,18 @@ int tracepoint_probe_unregister_noupdate
524 mutex_unlock(&tracepoints_mutex);
528 +int kabi_2635_tracepoint_probe_unregister_noupdate(const char *name, void *probe,
531 + return ___tracepoint_probe_unregister_noupdate(name, probe, data);
533 +EXPORT_SYMBOL_GPL(kabi_2635_tracepoint_probe_unregister_noupdate);
535 +int tracepoint_probe_unregister_noupdate(const char *name, void *probe)
537 + return ___tracepoint_probe_unregister_noupdate(name, probe, NULL);
539 EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate);