Skip to content

Commit de7b297

Browse files
compudjrostedt
authored andcommitted
tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints
Register/unregister tracepoint probes with struct tracepoint pointer rather than tracepoint name. This change, which vastly simplifies tracepoint.c, has been proposed by Steven Rostedt. It also removes 8.8kB (mostly of text) to the vmlinux size. From this point on, the tracers need to pass a struct tracepoint pointer to probe register/unregister. A probe can now only be connected to a tracepoint that exists. Moreover, tracers are responsible for unregistering the probe before the module containing its associated tracepoint is unloaded. text data bss dec hex filename 10443444 4282528 10391552 25117524 17f4354 vmlinux.orig 10434930 4282848 10391552 25109330 17f2352 vmlinux Link: http://lkml.kernel.org/r/1396992381-23785-2-git-send-email-mathieu.desnoyers@efficios.com CC: Ingo Molnar <mingo@kernel.org> CC: Frederic Weisbecker <fweisbec@gmail.com> CC: Andrew Morton <akpm@linux-foundation.org> CC: Frank Ch. Eigler <fche@redhat.com> CC: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> [ SDR - fixed return val in void func in tracepoint_module_going() ] Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 68114e5 commit de7b297

File tree

9 files changed

+331
-352
lines changed

9 files changed

+331
-352
lines changed

include/linux/ftrace_event.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/percpu.h>
88
#include <linux/hardirq.h>
99
#include <linux/perf_event.h>
10+
#include <linux/tracepoint.h>
1011

1112
struct trace_array;
1213
struct trace_buffer;
@@ -232,6 +233,7 @@ enum {
232233
TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
233234
TRACE_EVENT_FL_WAS_ENABLED_BIT,
234235
TRACE_EVENT_FL_USE_CALL_FILTER_BIT,
236+
TRACE_EVENT_FL_TRACEPOINT_BIT,
235237
};
236238

237239
/*
@@ -244,6 +246,7 @@ enum {
244246
* (used for module unloading, if a module event is enabled,
245247
* it is best to clear the buffers that used it).
246248
* USE_CALL_FILTER - For ftrace internal events, don't use file filter
249+
* TRACEPOINT - Event is a tracepoint
247250
*/
248251
enum {
249252
TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
@@ -252,12 +255,17 @@ enum {
252255
TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
253256
TRACE_EVENT_FL_WAS_ENABLED = (1 << TRACE_EVENT_FL_WAS_ENABLED_BIT),
254257
TRACE_EVENT_FL_USE_CALL_FILTER = (1 << TRACE_EVENT_FL_USE_CALL_FILTER_BIT),
258+
TRACE_EVENT_FL_TRACEPOINT = (1 << TRACE_EVENT_FL_TRACEPOINT_BIT),
255259
};
256260

257261
struct ftrace_event_call {
258262
struct list_head list;
259263
struct ftrace_event_class *class;
260-
char *name;
264+
union {
265+
char *name;
266+
/* Set TRACE_EVENT_FL_TRACEPOINT flag when using "tp" */
267+
struct tracepoint *tp;
268+
};
261269
struct trace_event event;
262270
const char *print_fmt;
263271
struct event_filter *filter;
@@ -271,6 +279,7 @@ struct ftrace_event_call {
271279
* bit 3: ftrace internal event (do not enable)
272280
* bit 4: Event was enabled by module
273281
* bit 5: use call filter rather than file filter
282+
* bit 6: Event is a tracepoint
274283
*/
275284
int flags; /* static flags of different events */
276285

@@ -283,6 +292,15 @@ struct ftrace_event_call {
283292
#endif
284293
};
285294

295+
static inline const char *
296+
ftrace_event_name(struct ftrace_event_call *call)
297+
{
298+
if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
299+
return call->tp ? call->tp->name : NULL;
300+
else
301+
return call->name;
302+
}
303+
286304
struct trace_array;
287305
struct ftrace_subsystem_dir;
288306

@@ -353,7 +371,7 @@ struct ftrace_event_file {
353371
#define __TRACE_EVENT_FLAGS(name, value) \
354372
static int __init trace_init_flags_##name(void) \
355373
{ \
356-
event_##name.flags = value; \
374+
event_##name.flags |= value; \
357375
return 0; \
358376
} \
359377
early_initcall(trace_init_flags_##name);

include/linux/tracepoint.h

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* See Documentation/trace/tracepoints.txt.
88
*
9-
* (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
9+
* Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1010
*
1111
* Heavily inspired from the Linux Kernel Markers.
1212
*
@@ -21,6 +21,7 @@
2121

2222
struct module;
2323
struct tracepoint;
24+
struct notifier_block;
2425

2526
struct tracepoint_func {
2627
void *func;
@@ -35,31 +36,39 @@ struct tracepoint {
3536
struct tracepoint_func __rcu *funcs;
3637
};
3738

38-
/*
39-
* Connect a probe to a tracepoint.
40-
* Internal API, should not be used directly.
41-
*/
42-
extern int tracepoint_probe_register(const char *name, void *probe, void *data);
43-
44-
/*
45-
* Disconnect a probe from a tracepoint.
46-
* Internal API, should not be used directly.
47-
*/
4839
extern int
49-
tracepoint_probe_unregister(const char *name, void *probe, void *data);
40+
tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
41+
extern int
42+
tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
43+
extern void
44+
for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
45+
void *priv);
5046

5147
#ifdef CONFIG_MODULES
5248
struct tp_module {
5349
struct list_head list;
5450
unsigned int num_tracepoints;
5551
struct tracepoint * const *tracepoints_ptrs;
5652
};
53+
5754
bool trace_module_has_bad_taint(struct module *mod);
55+
extern int register_tracepoint_module_notifier(struct notifier_block *nb);
56+
extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
5857
#else
5958
static inline bool trace_module_has_bad_taint(struct module *mod)
6059
{
6160
return false;
6261
}
62+
static inline
63+
int register_tracepoint_module_notifier(struct notifier_block *nb)
64+
{
65+
return 0;
66+
}
67+
static inline
68+
int unregister_tracepoint_module_notifier(struct notifier_block *nb)
69+
{
70+
return 0;
71+
}
6372
#endif /* CONFIG_MODULES */
6473

6574
/*
@@ -160,14 +169,14 @@ static inline void tracepoint_synchronize_unregister(void)
160169
static inline int \
161170
register_trace_##name(void (*probe)(data_proto), void *data) \
162171
{ \
163-
return tracepoint_probe_register(#name, (void *)probe, \
164-
data); \
172+
return tracepoint_probe_register(&__tracepoint_##name, \
173+
(void *)probe, data); \
165174
} \
166175
static inline int \
167176
unregister_trace_##name(void (*probe)(data_proto), void *data) \
168177
{ \
169-
return tracepoint_probe_unregister(#name, (void *)probe, \
170-
data); \
178+
return tracepoint_probe_unregister(&__tracepoint_##name,\
179+
(void *)probe, data); \
171180
} \
172181
static inline void \
173182
check_trace_callback_type_##name(void (*cb)(data_proto)) \

include/trace/ftrace.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ static inline notrace int ftrace_get_offsets_##call( \
470470
* };
471471
*
472472
* static struct ftrace_event_call event_<call> = {
473-
* .name = "<call>",
473+
* .tp = &__tracepoint_<call>,
474474
* .class = event_class_<template>,
475475
* .event = &ftrace_event_type_<call>,
476476
* .print_fmt = print_fmt_<call>,
477+
* .flags = TRACE_EVENT_FL_TRACEPOINT,
477478
* };
478479
* // its only safe to use pointers when doing linker tricks to
479480
* // create an array.
@@ -605,10 +606,11 @@ static struct ftrace_event_class __used __refdata event_class_##call = { \
605606
#define DEFINE_EVENT(template, call, proto, args) \
606607
\
607608
static struct ftrace_event_call __used event_##call = { \
608-
.name = #call, \
609+
.tp = &__tracepoint_##call, \
609610
.class = &event_class_##template, \
610611
.event.funcs = &ftrace_event_type_funcs_##template, \
611612
.print_fmt = print_fmt_##template, \
613+
.flags = TRACE_EVENT_FL_TRACEPOINT, \
612614
}; \
613615
static struct ftrace_event_call __used \
614616
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
@@ -619,10 +621,11 @@ __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
619621
static const char print_fmt_##call[] = print; \
620622
\
621623
static struct ftrace_event_call __used event_##call = { \
622-
.name = #call, \
624+
.tp = &__tracepoint_##call, \
623625
.class = &event_class_##template, \
624626
.event.funcs = &ftrace_event_type_funcs_##call, \
625627
.print_fmt = print_fmt_##call, \
628+
.flags = TRACE_EVENT_FL_TRACEPOINT, \
626629
}; \
627630
static struct ftrace_event_call __used \
628631
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call

0 commit comments

Comments
 (0)