Skip to content

Commit

Permalink
tracepoint: Use struct pointer instead of name hash for reg/unreg tra…
Browse files Browse the repository at this point in the history
…cepoints

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>
  • Loading branch information
Mathieu Desnoyers authored and Steven Rostedt committed Apr 9, 2014
1 parent 68114e5 commit de7b297
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 352 deletions.
22 changes: 20 additions & 2 deletions include/linux/ftrace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/percpu.h>
#include <linux/hardirq.h>
#include <linux/perf_event.h>
#include <linux/tracepoint.h>

struct trace_array;
struct trace_buffer;
Expand Down Expand Up @@ -232,6 +233,7 @@ enum {
TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
TRACE_EVENT_FL_WAS_ENABLED_BIT,
TRACE_EVENT_FL_USE_CALL_FILTER_BIT,
TRACE_EVENT_FL_TRACEPOINT_BIT,
};

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

struct ftrace_event_call {
struct list_head list;
struct ftrace_event_class *class;
char *name;
union {
char *name;
/* Set TRACE_EVENT_FL_TRACEPOINT flag when using "tp" */
struct tracepoint *tp;
};
struct trace_event event;
const char *print_fmt;
struct event_filter *filter;
Expand All @@ -271,6 +279,7 @@ struct ftrace_event_call {
* bit 3: ftrace internal event (do not enable)
* bit 4: Event was enabled by module
* bit 5: use call filter rather than file filter
* bit 6: Event is a tracepoint
*/
int flags; /* static flags of different events */

Expand All @@ -283,6 +292,15 @@ struct ftrace_event_call {
#endif
};

static inline const char *
ftrace_event_name(struct ftrace_event_call *call)
{
if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
return call->tp ? call->tp->name : NULL;
else
return call->name;
}

struct trace_array;
struct ftrace_subsystem_dir;

Expand Down Expand Up @@ -353,7 +371,7 @@ struct ftrace_event_file {
#define __TRACE_EVENT_FLAGS(name, value) \
static int __init trace_init_flags_##name(void) \
{ \
event_##name.flags = value; \
event_##name.flags |= value; \
return 0; \
} \
early_initcall(trace_init_flags_##name);
Expand Down
41 changes: 25 additions & 16 deletions include/linux/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* See Documentation/trace/tracepoints.txt.
*
* (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
* Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* Heavily inspired from the Linux Kernel Markers.
*
Expand All @@ -21,6 +21,7 @@

struct module;
struct tracepoint;
struct notifier_block;

struct tracepoint_func {
void *func;
Expand All @@ -35,31 +36,39 @@ struct tracepoint {
struct tracepoint_func __rcu *funcs;
};

/*
* Connect a probe to a tracepoint.
* Internal API, should not be used directly.
*/
extern int tracepoint_probe_register(const char *name, void *probe, void *data);

/*
* Disconnect a probe from a tracepoint.
* Internal API, should not be used directly.
*/
extern int
tracepoint_probe_unregister(const char *name, void *probe, void *data);
tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
extern int
tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
extern void
for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
void *priv);

#ifdef CONFIG_MODULES
struct tp_module {
struct list_head list;
unsigned int num_tracepoints;
struct tracepoint * const *tracepoints_ptrs;
};

bool trace_module_has_bad_taint(struct module *mod);
extern int register_tracepoint_module_notifier(struct notifier_block *nb);
extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
#else
static inline bool trace_module_has_bad_taint(struct module *mod)
{
return false;
}
static inline
int register_tracepoint_module_notifier(struct notifier_block *nb)
{
return 0;
}
static inline
int unregister_tracepoint_module_notifier(struct notifier_block *nb)
{
return 0;
}
#endif /* CONFIG_MODULES */

/*
Expand Down Expand Up @@ -160,14 +169,14 @@ static inline void tracepoint_synchronize_unregister(void)
static inline int \
register_trace_##name(void (*probe)(data_proto), void *data) \
{ \
return tracepoint_probe_register(#name, (void *)probe, \
data); \
return tracepoint_probe_register(&__tracepoint_##name, \
(void *)probe, data); \
} \
static inline int \
unregister_trace_##name(void (*probe)(data_proto), void *data) \
{ \
return tracepoint_probe_unregister(#name, (void *)probe, \
data); \
return tracepoint_probe_unregister(&__tracepoint_##name,\
(void *)probe, data); \
} \
static inline void \
check_trace_callback_type_##name(void (*cb)(data_proto)) \
Expand Down
9 changes: 6 additions & 3 deletions include/trace/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,11 @@ static inline notrace int ftrace_get_offsets_##call( \
* };
*
* static struct ftrace_event_call event_<call> = {
* .name = "<call>",
* .tp = &__tracepoint_<call>,
* .class = event_class_<template>,
* .event = &ftrace_event_type_<call>,
* .print_fmt = print_fmt_<call>,
* .flags = TRACE_EVENT_FL_TRACEPOINT,
* };
* // its only safe to use pointers when doing linker tricks to
* // create an array.
Expand Down Expand Up @@ -605,10 +606,11 @@ static struct ftrace_event_class __used __refdata event_class_##call = { \
#define DEFINE_EVENT(template, call, proto, args) \
\
static struct ftrace_event_call __used event_##call = { \
.name = #call, \
.tp = &__tracepoint_##call, \
.class = &event_class_##template, \
.event.funcs = &ftrace_event_type_funcs_##template, \
.print_fmt = print_fmt_##template, \
.flags = TRACE_EVENT_FL_TRACEPOINT, \
}; \
static struct ftrace_event_call __used \
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
Expand All @@ -619,10 +621,11 @@ __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
static const char print_fmt_##call[] = print; \
\
static struct ftrace_event_call __used event_##call = { \
.name = #call, \
.tp = &__tracepoint_##call, \
.class = &event_class_##template, \
.event.funcs = &ftrace_event_type_funcs_##call, \
.print_fmt = print_fmt_##call, \
.flags = TRACE_EVENT_FL_TRACEPOINT, \
}; \
static struct ftrace_event_call __used \
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
Expand Down
Loading

0 comments on commit de7b297

Please sign in to comment.