Skip to contentSkip to conversation

Tracepoint API simplification, text size shrink

PATCH Superseded Mathieu Desnoyers 2 participants 4 messages Mar 28, 2014 – Apr 1, 2014

Subsystems (2)

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

v8 cover Tracepoint API simplification, text size shrink

Here is v8 of the tracepoint register/unregister API simplification, submitted for 3.15.

This removes 8.8kB to the size of vmlinux (mostly text).

Changes since v1:
- Adapt ftrace/perf callers,
- Update tracepoint.h macro,
- Build tested.

Changes since v2:
- Introduce for_each_tracepoint() iterator to allow listing the currently loaded tracepoints, for modules using coming/going notifiers to track tracepoints.

Changes since v3:
- Introduce module coming and going notifiers each with their own priority to ensure that other coming notifiers are called after, and coming notifiers are called before the tracepoint notifiers.
- Fix: move for_each_tracepoint() outside of the CONFIG_MODULE ifdef.

Changes since v4:
- Split tracepoints_mutex into two locks: tp_modlist_mutex, which protects the tracepoint list of modules, and a tracepoint_mutex, which protects the tracepoints per se. tracepoint_mutex nests inside tp_modlist_mutex.
- Introduce a tracepoint module notifier, to ensure consistency between iteration on tracepoints with for_each_tracepoint() and module coming and going notifications. This consistency is ensured by holding tp_modlist_mutex when calling the notifier and when iterating on the tracepoint module list.

Changes since v5:
- Remove tracepoint_add_old_probes within "Tracepoint cleanup: remove unused API functions" rather than in later patch.
- Remove struct tp_probes "old probes" list within "Tracepoint cleanup:
remove unused API functions", as it is not needed anymore.
- Within "Tracepoint cleanup: remove unused API functions", simply add the new module to tail of list, since there is no need to keep it ordered anymore.

Changes since v6:
- Remove unused struct list_head list from struct tp_probes in patch "Tracepoint: register/unregister struct tracepoint",
- Rename for_each_tracepoint() to for_each_kernel_tracepoint(). Only iterate on kernel tracepoints,
- Registered tracepoint module notifiers now receive struct tp_module pointer rather than struct module pointer,
- register_tracepoint_module_notifier and unregister_tracepoint_module_notifier now iterate on all modules and call coming/going notifiers. This ensures notifier registration and listing of already loaded modules are done atomically (protected by tp_modlist_mutex).

Changes since v7:
- Coding style updates,
- Shrink size of ftrace/perf struct ftrace_event_call,
- Put back the original tracepoints_mutex name, keep an original comment layout that goes beyond 80 columns, put back original tracepoint_module_list name, and rename tp_modlist_mutex to tracepoint_module_list_mutex, so this patch does not introduce cosmetic changes to pre-existing code.

Thanks!

Mathieu

Mathieu Desnoyers (1):
Tracepoint: register/unregister struct tracepoint

 include/linux/ftrace_event.h        |   20 +-
 include/linux/tracepoint.h          |   41 +--
 include/trace/ftrace.h              |    9 +-
 kernel/trace/trace_events.c         |   51 ++--
 kernel/trace/trace_events_trigger.c |    2 +-
 kernel/trace/trace_export.c         |    2 +-
 kernel/trace/trace_kprobe.c         |   29 +-
 kernel/trace/trace_output.c         |    2 +-
 kernel/trace/trace_uprobe.c         |   28 +-
 kernel/tracepoint.c                 |  509 +++++++++++++++--------------------
 10 files changed, 336 insertions(+), 357 deletions(-)
Signature · 1 line
1.7.10.4
author reviewer
#1 lore raw

PATCH v8 1/1 Tracepoint: register/unregister struct tracepoint

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.

Quoted 1 line

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.

CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
CC Frank Ch. Eigler <[email protected]>
CC Johannes Berg <[email protected]>
---
 include/linux/ftrace_event.h        |   20 +-
 include/linux/tracepoint.h          |   41 +--
 include/trace/ftrace.h              |    9 +-
 kernel/trace/trace_events.c         |   51 ++--
 kernel/trace/trace_events_trigger.c |    2 +-
 kernel/trace/trace_export.c         |    2 +-
 kernel/trace/trace_kprobe.c         |   29 +-
 kernel/trace/trace_output.c         |    2 +-
 kernel/trace/trace_uprobe.c         |   28 +-
 kernel/tracepoint.c                 |  509 +++++++++++++++--------------------
 10 files changed, 336 insertions(+), 357 deletions(-)
include/linux/ftrace_event.h +19 -1
index cdc3011..766a14b 100644
@@ -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;
@@ -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,
 };
 
 /*
@@ -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),
@@ -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;
+	} u;
 	struct trace_event	event;
 	const char		*print_fmt;
 	struct event_filter	*filter;
@@ -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 */
 
@@ -283,6 +292,15 @@ struct ftrace_event_call {
 #endif
 };
 
+static inline const char *
+ftrace_event_get_name(struct ftrace_event_call *call)
+{
+	if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
+		return call->u.tp->name;
+	else
+		return call->u.name;
+}
+
 struct trace_array;
 struct ftrace_subsystem_dir;
 
include/linux/tracepoint.h +25 -16

82 lines not on this page · raw message

include/trace/ftrace.h +6 -3
index 8765126..ef86df1 100644
@@ -470,10 +470,11 @@ static inline notrace int ftrace_get_offsets_##call(			\
  * };
  *
  * static struct ftrace_event_call event_<call> = {
- *	.name			= "<call>",
+ *	.u.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.
@@ -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,				\
+	.u.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
@@ -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,				\
+	.u.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
kernel/trace/trace_events.c +30 -21

186 lines not on this page · raw message

kernel/trace/trace_events_trigger.c +1 -1
index 8efbb69..66876df 100644
@@ -1095,7 +1095,7 @@ event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
 	seq_printf(m, "%s:%s:%s",
 		   enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
 		   enable_data->file->event_call->class->system,
-		   enable_data->file->event_call->name);
+		   ftrace_event_get_name(enable_data->file->event_call));
 
 	if (data->count == -1)
 		seq_puts(m, ":unlimited");
kernel/trace/trace_export.c +1 -1
index ee0a509..554d33e 100644
@@ -173,7 +173,7 @@ struct ftrace_event_class __refdata event_class_ftrace_##call = {	\
 };									\
 									\
 struct ftrace_event_call __used event_##call = {			\
-	.name			= #call,				\
+	.u.name			= #call,				\
 	.event.type		= etype,				\
 	.class			= &event_class_ftrace_##call,		\
 	.print_fmt		= print,				\
kernel/trace/trace_kprobe.c +17 -12
index d021d21..e9b805a 100644
@@ -299,8 +299,8 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
 	}
 
 	tk->tp.call.class = &tk->tp.class;
-	tk->tp.call.name = kstrdup(event, GFP_KERNEL);
-	if (!tk->tp.call.name)
+	tk->tp.call.u.name = kstrdup(event, GFP_KERNEL);
+	if (!tk->tp.call.u.name)
 		goto error;
 
 	if (!group || !is_good_name(group)) {
@@ -316,7 +316,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
 	INIT_LIST_HEAD(&tk->tp.files);
 	return tk;
 error:
-	kfree(tk->tp.call.name);
+	kfree(tk->tp.call.u.name);
 	kfree(tk->symbol);
 	kfree(tk);
 	return ERR_PTR(ret);
@@ -330,7 +330,7 @@ static void free_trace_kprobe(struct trace_kprobe *tk)
 		traceprobe_free_probe_arg(&tk->tp.args[i]);
 
 	kfree(tk->tp.call.class->system);
-	kfree(tk->tp.call.name);
+	kfree(tk->tp.call.u.name);
 	kfree(tk->symbol);
 	kfree(tk);
 }
@@ -341,7 +341,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 	struct trace_kprobe *tk;
 
 	list_for_each_entry(tk, &probe_list, list)
-		if (strcmp(tk->tp.call.name, event) == 0 &&
+		if (strcmp(ftrace_event_get_name(&tk->tp.call), event) == 0 &&
 		    strcmp(tk->tp.call.class->system, group) == 0)
 			return tk;
 	return NULL;
@@ -516,7 +516,8 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
 	mutex_lock(&probe_lock);
 
 	/* Delete old (same name) event if exist */
-	old_tk = find_trace_kprobe(tk->tp.call.name, tk->tp.call.class->system);
+	old_tk = find_trace_kprobe(ftrace_event_get_name(&tk->tp.call),
+			tk->tp.call.class->system);
 	if (old_tk) {
 		ret = unregister_trace_kprobe(old_tk);
 		if (ret < 0)
@@ -564,7 +565,8 @@ static int trace_kprobe_module_callback(struct notifier_block *nb,
 			if (ret)
 				pr_warning("Failed to re-register probe %s on"
 					   "%s: %d\n",
-					   tk->tp.call.name, mod->name, ret);
+					   ftrace_event_get_name(&tk->tp.call),
+					   mod->name, ret);
 		}
 	}
 	mutex_unlock(&probe_lock);
@@ -818,7 +820,8 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	int i;
 
 	seq_printf(m, "%c", trace_kprobe_is_return(tk) ? 'r' : 'p');
-	seq_printf(m, ":%s/%s", tk->tp.call.class->system, tk->tp.call.name);
+	seq_printf(m, ":%s/%s", tk->tp.call.class->system,
+			ftrace_event_get_name(&tk->tp.call));
 
 	if (!tk->symbol)
 		seq_printf(m, " 0x%p", tk->rp.kp.addr);
@@ -876,7 +879,8 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
 {
 	struct trace_kprobe *tk = v;
 
-	seq_printf(m, "  %-44s %15lu %15lu\n", tk->tp.call.name, tk->nhit,
+	seq_printf(m, "  %-44s %15lu %15lu\n",
+		   ftrace_event_get_name(&tk->tp.call), tk->nhit,
 		   tk->rp.kp.nmissed);
 
 	return 0;
@@ -1011,7 +1015,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
 	field = (struct kprobe_trace_entry_head *)iter->ent;
 	tp = container_of(event, struct trace_probe, call.event);
 
-	if (!trace_seq_printf(s, "%s: (", tp->call.name))
+	if (!trace_seq_printf(s, "%s: (", ftrace_event_get_name(&tp->call)))
 		goto partial;
 
 	if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET))
@@ -1047,7 +1051,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
 	field = (struct kretprobe_trace_entry_head *)iter->ent;
 	tp = container_of(event, struct trace_probe, call.event);
 
-	if (!trace_seq_printf(s, "%s: (", tp->call.name))
+	if (!trace_seq_printf(s, "%s: (", ftrace_event_get_name(&tp->call)))
 		goto partial;
 
 	if (!seq_print_ip_sym(s, field->ret_ip, flags | TRACE_ITER_SYM_OFFSET))
@@ -1286,7 +1290,8 @@ static int register_kprobe_event(struct trace_kprobe *tk)
 	call->data = tk;
 	ret = trace_add_event_call(call);
 	if (ret) {
-		pr_info("Failed to register kprobe event: %s\n", call->name);
+		pr_info("Failed to register kprobe event: %s\n",
+			ftrace_event_get_name(call));
 		kfree(call->print_fmt);
 		unregister_ftrace_event(&call->event);
 	}
kernel/trace/trace_output.c +1 -1
index ca0e79e2..79c5569 100644
@@ -431,7 +431,7 @@ int ftrace_raw_output_prep(struct trace_iterator *iter,
 	}
 
 	trace_seq_init(p);
-	ret = trace_seq_printf(s, "%s: ", event->name);
+	ret = trace_seq_printf(s, "%s: ", ftrace_event_get_name(event));
 	if (!ret)
 		return TRACE_TYPE_PARTIAL_LINE;
 
kernel/trace/trace_uprobe.c +17 -11
index e447336..9fd4071 100644
@@ -251,8 +251,8 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
 		return ERR_PTR(-ENOMEM);
 
 	tu->tp.call.class = &tu->tp.class;
-	tu->tp.call.name = kstrdup(event, GFP_KERNEL);
-	if (!tu->tp.call.name)
+	tu->tp.call.u.name = kstrdup(event, GFP_KERNEL);
+	if (!tu->tp.call.u.name)
 		goto error;
 
 	tu->tp.class.system = kstrdup(group, GFP_KERNEL);
@@ -269,7 +269,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
 	return tu;
 
 error:
-	kfree(tu->tp.call.name);
+	kfree(tu->tp.call.u.name);
 	kfree(tu);
 
 	return ERR_PTR(-ENOMEM);
@@ -284,7 +284,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
 
 	iput(tu->inode);
 	kfree(tu->tp.call.class->system);
-	kfree(tu->tp.call.name);
+	kfree(tu->tp.call.u.name);
 	kfree(tu->filename);
 	kfree(tu);
 }
@@ -294,7 +294,7 @@ static struct trace_uprobe *find_probe_event(const char *event, const char *grou
 	struct trace_uprobe *tu;
 
 	list_for_each_entry(tu, &uprobe_list, list)
-		if (strcmp(tu->tp.call.name, event) == 0 &&
+		if (strcmp(ftrace_event_get_name(&tu->tp.call), event) == 0 &&
 		    strcmp(tu->tp.call.class->system, group) == 0)
 			return tu;
 
@@ -324,7 +324,8 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
 	mutex_lock(&uprobe_lock);
 
 	/* register as an event */
-	old_tu = find_probe_event(tu->tp.call.name, tu->tp.call.class->system);
+	old_tu = find_probe_event(ftrace_event_get_name(&tu->tp.call),
+			tu->tp.call.class->system);
 	if (old_tu) {
 		/* delete old event */
 		ret = unregister_trace_uprobe(old_tu);
@@ -599,7 +600,8 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	char c = is_ret_probe(tu) ? 'r' : 'p';
 	int i;
 
-	seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system, tu->tp.call.name);
+	seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
+			ftrace_event_get_name(&tu->tp.call));
 	seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset);
 
 	for (i = 0; i < tu->tp.nr_args; i++)
@@ -649,7 +651,8 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
 {
 	struct trace_uprobe *tu = v;
 
-	seq_printf(m, "  %s %-44s %15lu\n", tu->filename, tu->tp.call.name, tu->nhit);
+	seq_printf(m, "  %s %-44s %15lu\n", tu->filename,
+			ftrace_event_get_name(&tu->tp.call), tu->nhit);
 	return 0;
 }
 
@@ -844,12 +847,14 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
 	tu = container_of(event, struct trace_uprobe, tp.call.event);
 
 	if (is_ret_probe(tu)) {
-		if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->tp.call.name,
+		if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)",
+					ftrace_event_get_name(&tu->tp.call),
 					entry->vaddr[1], entry->vaddr[0]))
 			goto partial;
 		data = DATAOF_TRACE_ENTRY(entry, true);
 	} else {
-		if (!trace_seq_printf(s, "%s: (0x%lx)", tu->tp.call.name,
+		if (!trace_seq_printf(s, "%s: (0x%lx)",
+					ftrace_event_get_name(&tu->tp.call),
 					entry->vaddr[0]))
 			goto partial;
 		data = DATAOF_TRACE_ENTRY(entry, false);
@@ -1275,7 +1280,8 @@ static int register_uprobe_event(struct trace_uprobe *tu)
 	ret = trace_add_event_call(call);
 
 	if (ret) {
-		pr_info("Failed to register uprobe event: %s\n", call->name);
+		pr_info("Failed to register uprobe event: %s\n",
+			ftrace_event_get_name(call));
 		kfree(call->print_fmt);
 		unregister_ftrace_event(&call->event);
 	}
kernel/tracepoint.c +219 -290

699 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#2 lore raw

Re: [PATCH v8 1/1] Tracepoint: register/unregister struct tracepoint

Quoted 54 lines · On Fri, 28 Mar 2014 15:09:58 -0700 Mathieu Desnoyers…
CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
CC Frank Ch. Eigler <[email protected]>
CC Johannes Berg <[email protected]>
---
 include/linux/ftrace_event.h        |   20 +-
 include/linux/tracepoint.h          |   41 +--
 include/trace/ftrace.h              |    9 +-
 kernel/trace/trace_events.c         |   51 ++--
 kernel/trace/trace_events_trigger.c |    2 +-
 kernel/trace/trace_export.c         |    2 +-
 kernel/trace/trace_kprobe.c         |   29 +-
 kernel/trace/trace_output.c         |    2 +-
 kernel/trace/trace_uprobe.c         |   28 +-
 kernel/tracepoint.c                 |  509 +++++++++++++++--------------------
 10 files changed, 336 insertions(+), 357 deletions(-)
include/linux/ftrace_event.h +4 -0
index cdc3011..766a14b 100644
@@ -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;
@@ -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,
 };
 
 /*
@@ -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),
@@ -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),
 };

include/linux/ftrace_event.h enum { · line 268

Quoted 10 lines
include/linux/ftrace_event.h +5 -1
 
 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;
+	} u;

Get rid of the "u". Unnamed unions are supported and encouraged.

Quoted 12 lines
include/linux/ftrace_event.h +1 -0
 	struct trace_event	event;
 	const char		*print_fmt;
 	struct event_filter	*filter;
@@ -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 */
 

include/linux/ftrace_event.h struct ftrace_event_call { · line 299

Quoted 8 lines
include/linux/ftrace_event.h +5 -0
@@ -283,6 +292,15 @@ struct ftrace_event_call {
 #endif
 };
 
+static inline const char *
+ftrace_event_get_name(struct ftrace_event_call *call)
+{
+	if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
+		return call->u.tp->name;

call->tp->name;

include/linux/ftrace_event.h struct ftrace_event_call { · line 301

Quoted 2 lines
include/linux/ftrace_event.h +2 -0
+	else
+		return call->u.name;

call->name;

Quoted 101 lines
include/linux/ftrace_event.h +2 -0
+}
+
 struct trace_array;
 struct ftrace_subsystem_dir;
 
include/linux/tracepoint.h +25 -16
index 812b255..08150e2 100644
@@ -6,7 +6,7 @@
  *
  * See Documentation/trace/tracepoints.txt.
  *
- * (C) Copyright 2008 Mathieu Desnoyers <[email protected]>
+ * Copyright (C) 2008-2014 Mathieu Desnoyers <[email protected]>
  *
  * Heavily inspired from the Linux Kernel Markers.
  *
@@ -21,6 +21,7 @@
 
 struct module;
 struct tracepoint;
+struct notifier_block;
 
 struct tracepoint_func {
 	void *func;
@@ -35,18 +36,13 @@ 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 {
@@ -54,12 +50,25 @@ struct tp_module {
 	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 */
 
 /*
@@ -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))	\
include/trace/ftrace.h +0 -0
index 8765126..ef86df1 100644

include/trace/ftrace.h static inline notrace int ftrace_get_offsets_##call( \ · line 473

Quoted 5 lines
include/trace/ftrace.h +1 -1
@@ -470,10 +470,11 @@ static inline notrace int ftrace_get_offsets_##call(			\
  * };
  *
  * static struct ftrace_event_call event_<call> = {
- *	.name			= "<call>",
+ *	.u.tp			= &__tracepoint_<call>,

.tp

Quoted 21 lines
include/trace/ftrace.h +3 -1
  *	.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.
@@ -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,				\
+	.u.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

include/trace/ftrace.h __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call · line 624

Quoted 5 lines
include/trace/ftrace.h +1 -1
@@ -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,				\
+	.u.tp			= &__tracepoint_##call,			\

.tp

Quoted 28 lines
include/trace/ftrace.h +1 -0
 	.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
kernel/trace/trace_events.c +3 -2
index 83a4378..5bdc34f 100644
@@ -223,24 +223,25 @@ int ftrace_event_reg(struct ftrace_event_call *call,
 {
 	struct ftrace_event_file *file = data;
 
+	WARN_ON(!(call->flags & TRACE_EVENT_FL_TRACEPOINT));
 	switch (type) {
 	case TRACE_REG_REGISTER:
-		return tracepoint_probe_register(call->name,
+		return tracepoint_probe_register(call->u.tp,
 						 call->class->probe,
 						 file);
 	case TRACE_REG_UNREGISTER:
-		tracepoint_probe_unregister(call->name,
+		tracepoint_probe_unregister(call->u.tp,
 					    call->class->probe,
 					    file);
 		return 0;

kernel/trace/trace_events.c int ftrace_event_reg(struct ftrace_event_call *call, · line 244

Quoted 10 lines
kernel/trace/trace_events.c +2 -2
 
 #ifdef CONFIG_PERF_EVENTS
 	case TRACE_REG_PERF_REGISTER:
-		return tracepoint_probe_register(call->name,
+		return tracepoint_probe_register(call->u.tp,
 						 call->class->perf_probe,
 						 call);
 	case TRACE_REG_PERF_UNREGISTER:
-		tracepoint_probe_unregister(call->name,
+		tracepoint_probe_unregister(call->u.tp,

all above, call->tp

Quoted 13 lines
kernel/trace/trace_events.c +1 -1
 					    call->class->perf_probe,
 					    call);
 		return 0;
@@ -352,7 +353,7 @@ static int __ftrace_event_enable_disable(struct ftrace_event_file *file,
 			if (ret) {
 				tracing_stop_cmdline_record();
 				pr_info("event trace: Could not enable event "
-					"%s\n", call->name);
+					"%s\n", ftrace_event_get_name(call));
 				break;
 			}
 			set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags);

kernel/trace/trace_events.c __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, · line 491

Quoted 10 lines
kernel/trace/trace_events.c +2 -0
@@ -481,27 +482,29 @@ __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match,
 {
 	struct ftrace_event_file *file;
 	struct ftrace_event_call *call;
+	const char *name;
 	int ret = -EINVAL;
 
 	list_for_each_entry(file, &tr->events, list) {
 
 		call = file->event_call;
+		name = ftrace_event_get_name(call);

If tp is null, then the above will crash. Move the above line to below. the continues. If it's a tracepoint call->name will still be not null.

kernel/trace/trace_events.c __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, · line 497

Quoted 7 lines
kernel/trace/trace_events.c +1 -1
-		if (!call->name || !call->class || !call->class->reg)
+		if (!name || !call->class || !call->class->reg)
 			continue;
 
 		if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
 			continue;

Place the "name = ftrace_event_get_name(call);" here.

Quoted 25 lines
kernel/trace/trace_events.c +3 -3
 		if (match &&
-		    strcmp(match, call->name) != 0 &&
+		    strcmp(match, name) != 0 &&
 		    strcmp(match, call->class->system) != 0)
 			continue;
 
 		if (sub && strcmp(sub, call->class->system) != 0)
 			continue;
 
-		if (event && strcmp(event, call->name) != 0)
+		if (event && strcmp(event, name) != 0)
 			continue;
 
 		ftrace_event_enable_disable(file, set);
@@ -699,7 +702,7 @@ static int t_show(struct seq_file *m, void *v)
 
 	if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
 		seq_printf(m, "%s:", call->class->system);
-	seq_printf(m, "%s\n", call->name);
+	seq_printf(m, "%s\n", ftrace_event_get_name(call));
 
 	return 0;
 }

kernel/trace/trace_events.c system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, · line 798

Quoted 5 lines
kernel/trace/trace_events.c +1 -1
@@ -792,7 +795,7 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
 	mutex_lock(&event_mutex);
 	list_for_each_entry(file, &tr->events, list) {
 		call = file->event_call;
-		if (!call->name || !call->class || !call->class->reg)
+		if (!ftrace_event_get_name(call) || !call->class || !call->class->reg)

Again, we need to test if tp is null. Remove the above change.

Quoted 44 lines
kernel/trace/trace_events.c +6 -4
 			continue;
 
 		if (system && strcmp(call->class->system, system->name) != 0)
@@ -907,7 +910,7 @@ static int f_show(struct seq_file *m, void *v)
 
 	switch ((unsigned long)v) {
 	case FORMAT_HEADER:
-		seq_printf(m, "name: %s\n", call->name);
+		seq_printf(m, "name: %s\n", ftrace_event_get_name(call));
 		seq_printf(m, "ID: %d\n", call->event.type);
 		seq_printf(m, "format:\n");
 		return 0;
@@ -1527,6 +1530,7 @@ event_create_dir(struct dentry *parent, struct ftrace_event_file *file)
 	struct trace_array *tr = file->tr;
 	struct list_head *head;
 	struct dentry *d_events;
+	const char *name;
 	int ret;
 
 	/*
@@ -1540,10 +1544,11 @@ event_create_dir(struct dentry *parent, struct ftrace_event_file *file)
 	} else
 		d_events = parent;
 
-	file->dir = debugfs_create_dir(call->name, d_events);
+	name = ftrace_event_get_name(call);
+	file->dir = debugfs_create_dir(name, d_events);
 	if (!file->dir) {
 		pr_warning("Could not create debugfs '%s' directory\n",
-			   call->name);
+			   name);
 		return -1;
 	}
 
@@ -1567,7 +1572,7 @@ event_create_dir(struct dentry *parent, struct ftrace_event_file *file)
 		ret = call->class->define_fields(call);
 		if (ret < 0) {
 			pr_warning("Could not initialize trace point"
-				   " events/%s\n", call->name);
+				   " events/%s\n", name);
 			return -1;
 		}
 	}

kernel/trace/trace_events.c static void event_remove(struct ftrace_event_call *call) · line 1642

Quoted 8 lines
kernel/trace/trace_events.c +3 -1
@@ -1631,15 +1636,17 @@ static void event_remove(struct ftrace_event_call *call)
 static int event_init(struct ftrace_event_call *call)
 {
 	int ret = 0;
+	const char *name;
 
-	if (WARN_ON(!call->name))
+	name = ftrace_event_get_name(call);
+	if (WARN_ON(!name))

Again, remove the above change. We care if call->name or call->tp is NULL.

You can add another check if it is a tp to make sure tp has a name as well.

Quoted 24 lines
kernel/trace/trace_events.c +2 -2
 		return -EINVAL;
 
 	if (call->class->raw_init) {
 		ret = call->class->raw_init(call);
 		if (ret < 0 && ret != -ENOSYS)
 			pr_warn("Could not initialize trace events/%s\n",
-				call->name);
+				name);
 	}
 
 	return ret;
@@ -1885,7 +1892,7 @@ __trace_add_event_dirs(struct trace_array *tr)
 		ret = __trace_add_new_event(call, tr);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
-				   call->name);
+				   ftrace_event_get_name(call));
 	}
 }
 
@@ -1894,18 +1901,20 @@ find_event_file(struct trace_array *tr, const char *system,  const char *event)
 {
 	struct ftrace_event_file *file;
 	struct ftrace_event_call *call;

kernel/trace/trace_events.c find_event_file(struct trace_array *tr, const char *system, const char *event) · line 1912

Quoted 10 lines
kernel/trace/trace_events.c +3 -1
+	const char *name;
 
 	list_for_each_entry(file, &tr->events, list) {
 
 		call = file->event_call;
+		name = ftrace_event_get_name(call);
 
-		if (!call->name || !call->class || !call->class->reg)
+		if (!name || !call->class || !call->class->reg)
 			continue;

Same here. We should be still testing !call->name, and move the assignment of the name down, before the strcmp.

Quoted 45 lines
kernel/trace/trace_events.c +3 -3
 		if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
 			continue;
 
-		if (strcmp(event, call->name) == 0 &&
+		if (strcmp(event, name) == 0 &&
 		    strcmp(system, call->class->system) == 0)
 			return file;
 	}
@@ -2193,7 +2202,7 @@ __trace_early_add_event_dirs(struct trace_array *tr)
 		ret = event_create_dir(tr->event_dir, file);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
-				   file->event_call->name);
+				   ftrace_event_get_name(file->event_call));
 	}
 }
 
@@ -2217,7 +2226,7 @@ __trace_early_add_events(struct trace_array *tr)
 		ret = __trace_early_add_new_event(call, tr);
 		if (ret < 0)
 			pr_warning("Could not create early event %s\n",
-				   call->name);
+				   ftrace_event_get_name(call));
 	}
 }
 
kernel/trace/trace_events_trigger.c +1 -1
index 8efbb69..66876df 100644
@@ -1095,7 +1095,7 @@ event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops,
 	seq_printf(m, "%s:%s:%s",
 		   enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
 		   enable_data->file->event_call->class->system,
-		   enable_data->file->event_call->name);
+		   ftrace_event_get_name(enable_data->file->event_call));
 
 	if (data->count == -1)
 		seq_puts(m, ":unlimited");
kernel/trace/trace_export.c +0 -0
index ee0a509..554d33e 100644

kernel/trace/trace_export.c struct ftrace_event_class __refdata event_class_ftrace_##call = { \ · line 176

Quoted 5 lines
kernel/trace/trace_export.c +1 -1
@@ -173,7 +173,7 @@ struct ftrace_event_class __refdata event_class_ftrace_##call = {	\
 };									\
 									\
 struct ftrace_event_call __used event_##call = {			\
-	.name			= #call,				\
+	.u.name			= #call,				\

No need for the .u, remove this change.

Quoted 8 lines
kernel/trace/trace_export.c +0 -0
 	.event.type		= etype,				\
 	.class			= &event_class_ftrace_##call,		\
 	.print_fmt		= print,				\
kernel/trace/trace_kprobe.c +0 -0
index d021d21..e9b805a 100644

kernel/trace/trace_kprobe.c static struct trace_kprobe *alloc_trace_kprobe(const char *group, · line 303

Quoted 7 lines
kernel/trace/trace_kprobe.c +2 -2
@@ -299,8 +299,8 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
 	}
 
 	tk->tp.call.class = &tk->tp.class;
-	tk->tp.call.name = kstrdup(event, GFP_KERNEL);
-	if (!tk->tp.call.name)
+	tk->tp.call.u.name = kstrdup(event, GFP_KERNEL);
+	if (!tk->tp.call.u.name)

Same here.

Quoted 13 lines
kernel/trace/trace_kprobe.c +1 -1
 		goto error;
 
 	if (!group || !is_good_name(group)) {
@@ -316,7 +316,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
 	INIT_LIST_HEAD(&tk->tp.files);
 	return tk;
 error:
-	kfree(tk->tp.call.name);
+	kfree(tk->tp.call.u.name);
 	kfree(tk->symbol);
 	kfree(tk);
 	return ERR_PTR(ret);

kernel/trace/trace_kprobe.c static void free_trace_kprobe(struct trace_kprobe *tk) · line 333

Quoted 5 lines
kernel/trace/trace_kprobe.c +1 -1
@@ -330,7 +330,7 @@ static void free_trace_kprobe(struct trace_kprobe *tk)
 		traceprobe_free_probe_arg(&tk->tp.args[i]);
 
 	kfree(tk->tp.call.class->system);
-	kfree(tk->tp.call.name);
+	kfree(tk->tp.call.u.name);

and these.

Quoted 98 lines
kernel/trace/trace_kprobe.c +13 -8
 	kfree(tk->symbol);
 	kfree(tk);
 }
@@ -341,7 +341,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 	struct trace_kprobe *tk;
 
 	list_for_each_entry(tk, &probe_list, list)
-		if (strcmp(tk->tp.call.name, event) == 0 &&
+		if (strcmp(ftrace_event_get_name(&tk->tp.call), event) == 0 &&
 		    strcmp(tk->tp.call.class->system, group) == 0)
 			return tk;
 	return NULL;
@@ -516,7 +516,8 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
 	mutex_lock(&probe_lock);
 
 	/* Delete old (same name) event if exist */
-	old_tk = find_trace_kprobe(tk->tp.call.name, tk->tp.call.class->system);
+	old_tk = find_trace_kprobe(ftrace_event_get_name(&tk->tp.call),
+			tk->tp.call.class->system);
 	if (old_tk) {
 		ret = unregister_trace_kprobe(old_tk);
 		if (ret < 0)
@@ -564,7 +565,8 @@ static int trace_kprobe_module_callback(struct notifier_block *nb,
 			if (ret)
 				pr_warning("Failed to re-register probe %s on"
 					   "%s: %d\n",
-					   tk->tp.call.name, mod->name, ret);
+					   ftrace_event_get_name(&tk->tp.call),
+					   mod->name, ret);
 		}
 	}
 	mutex_unlock(&probe_lock);
@@ -818,7 +820,8 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	int i;
 
 	seq_printf(m, "%c", trace_kprobe_is_return(tk) ? 'r' : 'p');
-	seq_printf(m, ":%s/%s", tk->tp.call.class->system, tk->tp.call.name);
+	seq_printf(m, ":%s/%s", tk->tp.call.class->system,
+			ftrace_event_get_name(&tk->tp.call));
 
 	if (!tk->symbol)
 		seq_printf(m, " 0x%p", tk->rp.kp.addr);
@@ -876,7 +879,8 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
 {
 	struct trace_kprobe *tk = v;
 
-	seq_printf(m, "  %-44s %15lu %15lu\n", tk->tp.call.name, tk->nhit,
+	seq_printf(m, "  %-44s %15lu %15lu\n",
+		   ftrace_event_get_name(&tk->tp.call), tk->nhit,
 		   tk->rp.kp.nmissed);
 
 	return 0;
@@ -1011,7 +1015,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
 	field = (struct kprobe_trace_entry_head *)iter->ent;
 	tp = container_of(event, struct trace_probe, call.event);
 
-	if (!trace_seq_printf(s, "%s: (", tp->call.name))
+	if (!trace_seq_printf(s, "%s: (", ftrace_event_get_name(&tp->call)))
 		goto partial;
 
 	if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET))
@@ -1047,7 +1051,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
 	field = (struct kretprobe_trace_entry_head *)iter->ent;
 	tp = container_of(event, struct trace_probe, call.event);
 
-	if (!trace_seq_printf(s, "%s: (", tp->call.name))
+	if (!trace_seq_printf(s, "%s: (", ftrace_event_get_name(&tp->call)))
 		goto partial;
 
 	if (!seq_print_ip_sym(s, field->ret_ip, flags | TRACE_ITER_SYM_OFFSET))
@@ -1286,7 +1290,8 @@ static int register_kprobe_event(struct trace_kprobe *tk)
 	call->data = tk;
 	ret = trace_add_event_call(call);
 	if (ret) {
-		pr_info("Failed to register kprobe event: %s\n", call->name);
+		pr_info("Failed to register kprobe event: %s\n",
+			ftrace_event_get_name(call));
 		kfree(call->print_fmt);
 		unregister_ftrace_event(&call->event);
 	}
kernel/trace/trace_output.c +1 -1
index ca0e79e2..79c5569 100644
@@ -431,7 +431,7 @@ int ftrace_raw_output_prep(struct trace_iterator *iter,
 	}
 
 	trace_seq_init(p);
-	ret = trace_seq_printf(s, "%s: ", event->name);
+	ret = trace_seq_printf(s, "%s: ", ftrace_event_get_name(event));
 	if (!ret)
 		return TRACE_TYPE_PARTIAL_LINE;
 
kernel/trace/trace_uprobe.c +0 -0
index e447336..9fd4071 100644

kernel/trace/trace_uprobe.c alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret) · line 254

Quoted 6 lines
kernel/trace/trace_uprobe.c +1 -2
@@ -251,8 +251,8 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
 		return ERR_PTR(-ENOMEM);
 
 	tu->tp.call.class = &tu->tp.class;
-	tu->tp.call.name = kstrdup(event, GFP_KERNEL);
-	if (!tu->tp.call.name)
+	tu->tp.call.u.name = kstrdup(event, GFP_KERNEL);

Remove the .u.

Quoted 14 lines
kernel/trace/trace_uprobe.c +2 -1
+	if (!tu->tp.call.u.name)
 		goto error;
 
 	tu->tp.class.system = kstrdup(group, GFP_KERNEL);
@@ -269,7 +269,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
 	return tu;
 
 error:
-	kfree(tu->tp.call.name);
+	kfree(tu->tp.call.u.name);
 	kfree(tu);
 
 	return ERR_PTR(-ENOMEM);

kernel/trace/trace_uprobe.c static void free_trace_uprobe(struct trace_uprobe *tu) · line 287

Quoted 5 lines
kernel/trace/trace_uprobe.c +1 -1
@@ -284,7 +284,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
 
 	iput(tu->inode);
 	kfree(tu->tp.call.class->system);
-	kfree(tu->tp.call.name);
+	kfree(tu->tp.call.u.name);

Here too.

kernel/tracepoint.c

Quoted 73 lines
kernel/trace/trace_uprobe.c +13 -7
 	kfree(tu->filename);
 	kfree(tu);
 }
@@ -294,7 +294,7 @@ static struct trace_uprobe *find_probe_event(const char *event, const char *grou
 	struct trace_uprobe *tu;
 
 	list_for_each_entry(tu, &uprobe_list, list)
-		if (strcmp(tu->tp.call.name, event) == 0 &&
+		if (strcmp(ftrace_event_get_name(&tu->tp.call), event) == 0 &&
 		    strcmp(tu->tp.call.class->system, group) == 0)
 			return tu;
 
@@ -324,7 +324,8 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
 	mutex_lock(&uprobe_lock);
 
 	/* register as an event */
-	old_tu = find_probe_event(tu->tp.call.name, tu->tp.call.class->system);
+	old_tu = find_probe_event(ftrace_event_get_name(&tu->tp.call),
+			tu->tp.call.class->system);
 	if (old_tu) {
 		/* delete old event */
 		ret = unregister_trace_uprobe(old_tu);
@@ -599,7 +600,8 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	char c = is_ret_probe(tu) ? 'r' : 'p';
 	int i;
 
-	seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system, tu->tp.call.name);
+	seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
+			ftrace_event_get_name(&tu->tp.call));
 	seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset);
 
 	for (i = 0; i < tu->tp.nr_args; i++)
@@ -649,7 +651,8 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
 {
 	struct trace_uprobe *tu = v;
 
-	seq_printf(m, "  %s %-44s %15lu\n", tu->filename, tu->tp.call.name, tu->nhit);
+	seq_printf(m, "  %s %-44s %15lu\n", tu->filename,
+			ftrace_event_get_name(&tu->tp.call), tu->nhit);
 	return 0;
 }
 
@@ -844,12 +847,14 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
 	tu = container_of(event, struct trace_uprobe, tp.call.event);
 
 	if (is_ret_probe(tu)) {
-		if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->tp.call.name,
+		if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)",
+					ftrace_event_get_name(&tu->tp.call),
 					entry->vaddr[1], entry->vaddr[0]))
 			goto partial;
 		data = DATAOF_TRACE_ENTRY(entry, true);
 	} else {
-		if (!trace_seq_printf(s, "%s: (0x%lx)", tu->tp.call.name,
+		if (!trace_seq_printf(s, "%s: (0x%lx)",
+					ftrace_event_get_name(&tu->tp.call),
 					entry->vaddr[0]))
 			goto partial;
 		data = DATAOF_TRACE_ENTRY(entry, false);
@@ -1275,7 +1280,8 @@ static int register_uprobe_event(struct trace_uprobe *tu)
 	ret = trace_add_event_call(call);
 
 	if (ret) {
-		pr_info("Failed to register uprobe event: %s\n", call->name);
+		pr_info("Failed to register uprobe event: %s\n",
+			ftrace_event_get_name(call));
 		kfree(call->print_fmt);
 		unregister_ftrace_event(&call->event);
 	}
kernel/tracepoint.c +0 -0
index 50f8329..8c4f2f4 100644

I'll look at this file now. But might as well send a v9 of this patch, with the updates. Adding the '.u' is fine for finding all the locations you need to look at. But the final patch should strip it out, as it's just a distraction.

-- Steve

author reviewer
#3 lore raw

Re: [PATCH v8 1/1] Tracepoint: register/unregister struct tracepoint

----- Original Message -----

Quoted 70 lines

From: "Steven Rostedt" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: [email protected], "Ingo Molnar" <[email protected]>, "Frederic Weisbecker" <[email protected]>, "Andrew Morton" <[email protected]>, "Frank Ch. Eigler" <[email protected]>, "Johannes Berg" <[email protected]>
Sent: Tuesday, April 1, 2014 11:02:41 AM
Subject: Re: [PATCH v8 1/1] Tracepoint: register/unregister struct tracepoint

Quoted 58 lines · On Fri, 28 Mar 2014 15:09:58 -0700 Mathieu Desnoyers…
CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
CC Frank Ch. Eigler <[email protected]>
CC Johannes Berg <[email protected]>
---
 include/linux/ftrace_event.h        |   20 +-
 include/linux/tracepoint.h          |   41 +--
 include/trace/ftrace.h              |    9 +-
 kernel/trace/trace_events.c         |   51 ++--
 kernel/trace/trace_events_trigger.c |    2 +-
 kernel/trace/trace_export.c         |    2 +-
 kernel/trace/trace_kprobe.c         |   29 +-
 kernel/trace/trace_output.c         |    2 +-
 kernel/trace/trace_uprobe.c         |   28 +-
 kernel/tracepoint.c                 |  509
 +++++++++++++++--------------------
 10 files changed, 336 insertions(+), 357 deletions(-)
include/linux/ftrace_event.h +3 -0
index cdc3011..766a14b 100644
@@ -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;
@@ -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,
 };
 
 /*
@@ -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 {
include/linux/ftrace_event.h +1 -0
 	TRACE_EVENT_FL_FILTERED		= (1 << TRACE_EVENT_FL_FILTERED_BIT),
@@ -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),
 };
 
Quoted 11 lines

include/linux/ftrace_event.h enum { · line 268

Quoted 9 lines
include/linux/ftrace_event.h +5 -1
 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;
+	} u;

Get rid of the "u". Unnamed unions are supported and encouraged.

OK, will do.

[...]

Quoted 4 lines
Quoted 4 lines
kernel/trace/trace_events.c +0 -0
index 83a4378..5bdc34f 100644

[...]

Quoted 8 lines
Quoted 8 lines
kernel/trace/trace_events.c +1 -0
@@ -481,27 +482,29 @@ __ftrace_set_clr_event_nolock(struct trace_array *tr,
 const char *match,
 {
 	struct ftrace_event_file *file;
 	struct ftrace_event_call *call;
+	const char *name;
 	int ret = -EINVAL;
 
Quoted 7 lines

kernel/trace/trace_events.c __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, · line 491

Quoted 4 lines
kernel/trace/trace_events.c +1 -0
 	list_for_each_entry(file, &tr->events, list) {
 
 		call = file->event_call;
+		name = ftrace_event_get_name(call);

If tp is null, then the above will crash. Move the above line to below. the continues. If it's a tracepoint call->name will still be not null.

Hrm, but then we'd be changing the code structure a lot, since we're testing "name" for NULL as a condition for the continue you refer to.

I recommend that we modify ftrace_event_get_name() instead, and check for NULL call->tp in there (and return NULL in that case).

Quoted 11 lines

kernel/trace/trace_events.c __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, · line 497

Quoted 8 lines
kernel/trace/trace_events.c +1 -1
-		if (!call->name || !call->class || !call->class->reg)
+		if (!name || !call->class || !call->class->reg)
 			continue;
 
 		if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
 			continue;

Place the "name = ftrace_event_get_name(call);" here.

Will change ftrace_event_get_name() to test for NULL call->tp instead (see above).

Quoted 22 lines
Quoted 22 lines
kernel/trace/trace_events.c +3 -3
 		if (match &&
-		    strcmp(match, call->name) != 0 &&
+		    strcmp(match, name) != 0 &&
 		    strcmp(match, call->class->system) != 0)
 			continue;
 
 		if (sub && strcmp(sub, call->class->system) != 0)
 			continue;
 
-		if (event && strcmp(event, call->name) != 0)
+		if (event && strcmp(event, name) != 0)
 			continue;
 
 		ftrace_event_enable_disable(file, set);
@@ -699,7 +702,7 @@ static int t_show(struct seq_file *m, void *v)
 
 	if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
 		seq_printf(m, "%s:", call->class->system);
-	seq_printf(m, "%s\n", call->name);
+	seq_printf(m, "%s\n", ftrace_event_get_name(call));
 
Quoted 11 lines

kernel/trace/trace_events.c system_enable_read(struct file *filp, char __user · line 799

Quoted 9 lines
kernel/trace/trace_events.c +1 -1
 	return 0;
 }
@@ -792,7 +795,7 @@ system_enable_read(struct file *filp, char __user
 *ubuf, size_t cnt,
 	mutex_lock(&event_mutex);
 	list_for_each_entry(file, &tr->events, list) {
 		call = file->event_call;
-		if (!call->name || !call->class || !call->class->reg)
+		if (!ftrace_event_get_name(call) || !call->class || !call->class->reg)

Again, we need to test if tp is null. Remove the above change.

Ditto.

Quoted 54 lines
Quoted 54 lines
kernel/trace/trace_events.c +0 -0
 			continue;
 
kernel/trace/trace_events.c +2 -1
 		if (system && strcmp(call->class->system, system->name) != 0)
@@ -907,7 +910,7 @@ static int f_show(struct seq_file *m, void *v)
 
 	switch ((unsigned long)v) {
 	case FORMAT_HEADER:
-		seq_printf(m, "name: %s\n", call->name);
+		seq_printf(m, "name: %s\n", ftrace_event_get_name(call));
 		seq_printf(m, "ID: %d\n", call->event.type);
 		seq_printf(m, "format:\n");
 		return 0;
@@ -1527,6 +1530,7 @@ event_create_dir(struct dentry *parent, struct
 ftrace_event_file *file)
 	struct trace_array *tr = file->tr;
 	struct list_head *head;
 	struct dentry *d_events;
+	const char *name;
 	int ret;
 
kernel/trace/trace_events.c +4 -3
 	/*
@@ -1540,10 +1544,11 @@ event_create_dir(struct dentry *parent, struct
 ftrace_event_file *file)
 	} else
 		d_events = parent;
 
-	file->dir = debugfs_create_dir(call->name, d_events);
+	name = ftrace_event_get_name(call);
+	file->dir = debugfs_create_dir(name, d_events);
 	if (!file->dir) {
 		pr_warning("Could not create debugfs '%s' directory\n",
-			   call->name);
+			   name);
 		return -1;
 	}
@@ -1567,7 +1572,7 @@ event_create_dir(struct dentry *parent, struct
 ftrace_event_file *file)
 		ret = call->class->define_fields(call);
 		if (ret < 0) {
 			pr_warning("Could not initialize trace point"
-				   " events/%s\n", call->name);
+				   " events/%s\n", name);
 			return -1;
 		}
kernel/trace/trace_events.c +1 -0
 	}
@@ -1631,15 +1636,17 @@ static void event_remove(struct ftrace_event_call
 *call)
 static int event_init(struct ftrace_event_call *call)
 {
 	int ret = 0;
+	const char *name;
 
Quoted 6 lines

kernel/trace/trace_events.c static void event_remove(struct ftrace_event_call *call) · line 1642

Quoted 3 lines
kernel/trace/trace_events.c +2 -1
-	if (WARN_ON(!call->name))
+	name = ftrace_event_get_name(call);
+	if (WARN_ON(!name))

Again, remove the above change. We care if call->name or call->tp is NULL.

Ditto.

Quoted 36 lines

You can add another check if it is a tp to make sure tp has a name as well.

Quoted 32 lines
kernel/trace/trace_events.c +1 -1
 		return -EINVAL;
 
 	if (call->class->raw_init) {
 		ret = call->class->raw_init(call);
 		if (ret < 0 && ret != -ENOSYS)
 			pr_warn("Could not initialize trace events/%s\n",
-				call->name);
+				name);
 	}
 
kernel/trace/trace_events.c +3 -1
 	return ret;
@@ -1885,7 +1892,7 @@ __trace_add_event_dirs(struct trace_array *tr)
 		ret = __trace_add_new_event(call, tr);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
-				   call->name);
+				   ftrace_event_get_name(call));
 	}
 }
 
@@ -1894,18 +1901,20 @@ find_event_file(struct trace_array *tr, const char
 *system,  const char *event)
 {
 	struct ftrace_event_file *file;
 	struct ftrace_event_call *call;
+	const char *name;
 
 	list_for_each_entry(file, &tr->events, list) {
 
 		call = file->event_call;
+		name = ftrace_event_get_name(call);
 
Quoted 6 lines

kernel/trace/trace_events.c __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, · line 494

Quoted 3 lines
kernel/trace/trace_events.c +1 -1
-		if (!call->name || !call->class || !call->class->reg)
+		if (!name || !call->class || !call->class->reg)
 			continue;

Same here. We should be still testing !call->name, and move the assignment of the name down, before the strcmp.

Ditto.

Quoted 43 lines
Quoted 43 lines
kernel/trace/trace_events.c +3 -3
 		if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
 			continue;
 
-		if (strcmp(event, call->name) == 0 &&
+		if (strcmp(event, name) == 0 &&
 		    strcmp(system, call->class->system) == 0)
 			return file;
 	}
@@ -2193,7 +2202,7 @@ __trace_early_add_event_dirs(struct trace_array *tr)
 		ret = event_create_dir(tr->event_dir, file);
 		if (ret < 0)
 			pr_warning("Could not create directory for event %s\n",
-				   file->event_call->name);
+				   ftrace_event_get_name(file->event_call));
 	}
 }
 
@@ -2217,7 +2226,7 @@ __trace_early_add_events(struct trace_array *tr)
 		ret = __trace_early_add_new_event(call, tr);
 		if (ret < 0)
 			pr_warning("Could not create early event %s\n",
-				   call->name);
+				   ftrace_event_get_name(call));
 	}
 }
 
kernel/trace/trace_events_trigger.c +1 -1
index 8efbb69..66876df 100644
@@ -1095,7 +1095,7 @@ event_enable_trigger_print(struct seq_file *m, struct
 event_trigger_ops *ops,
 	seq_printf(m, "%s:%s:%s",
 		   enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
 		   enable_data->file->event_call->class->system,
-		   enable_data->file->event_call->name);
+		   ftrace_event_get_name(enable_data->file->event_call));
 
 	if (data->count == -1)

seq_puts(m, ":unlimited");

[...]

Quoted 9 lines

kernel/tracepoint.c

Quoted 4 lines
kernel/tracepoint.c +0 -0
index 50f8329..8c4f2f4 100644

I'll look at this file now. But might as well send a v9 of this patch, with the updates. Adding the '.u' is fine for finding all the locations you need to look at. But the final patch should strip it out, as it's just a distraction.

Allright. I'm preparing v9 now.

Thanks!

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com