Skip to contentSkip to conversation

Tracepoint API simplification/cleanup

RFC PATCH Superseded Mathieu Desnoyers 2 participants 6 messages Mar 19, 2014 – Mar 20, 2014

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

v6 cover Tracepoint API simplification/cleanup

Here is v6 of the tracepoint register/unregister API simplification.

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.

Still need testing.

Feedback is welcome,

Thanks!

Mathieu

Mathieu Desnoyers (3):
Tracepoint cleanup: remove unused API functions Tracepoint API doc update: data argument
Tracepoint: register/unregister struct tracepoint

 include/linux/ftrace_event.h |    1 +
 include/linux/tracepoint.h   |   62 ++--
 include/trace/ftrace.h       |    2 +
 kernel/trace/trace_events.c  |    8 +-
 kernel/tracepoint.c          |  707 ++++++++++++++----------------------------
 5 files changed, 268 insertions(+), 512 deletions(-)
Signature · 1 line
1.7.10.4
author reviewer
#1 lore raw

RFC PATCH v6 1/3 Tracepoint cleanup: remove unused API functions

After the following commit:

commit b75ef8b44b1cb95f5a26484b0e2fe37a63b12b44

Author: Mathieu Desnoyers <[email protected]>
Date:   Wed Aug 10 15:18:39 2011 -0400

Tracepoint: Dissociate from module mutex

The following functions became unnecessary:

- tracepoint_probe_register_noupdate,
- tracepoint_probe_unregister_noupdate,
- tracepoint_probe_update_all.

In fact, none of the in-kernel tracers, nor LTTng, nor SystemTAP use them. Remove those.

Moreover, the functions:

- tracepoint_iter_start,
- tracepoint_iter_next,
- tracepoint_iter_stop,
- tracepoint_iter_reset.

are unused by in-kernel tracers, LTTng and SystemTAP. Remove those too.

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/tracepoint.h |   18 ----
 kernel/tracepoint.c        |  221 +-------------------------------------------
 2 files changed, 5 insertions(+), 234 deletions(-)
include/linux/tracepoint.h +0 -18
index 7159a0a..812b255 100644
@@ -48,12 +48,6 @@ extern int tracepoint_probe_register(const char *name, void *probe, void *data);
 extern int
 tracepoint_probe_unregister(const char *name, void *probe, void *data);
 
-extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
-					      void *data);
-extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
-						void *data);
-extern void tracepoint_probe_update_all(void);
-
 #ifdef CONFIG_MODULES
 struct tp_module {
 	struct list_head list;
@@ -68,18 +62,6 @@ static inline bool trace_module_has_bad_taint(struct module *mod)
 }
 #endif /* CONFIG_MODULES */
 
-struct tracepoint_iter {
-#ifdef CONFIG_MODULES
-	struct tp_module *module;
-#endif /* CONFIG_MODULES */
-	struct tracepoint * const *tracepoint;
-};
-
-extern void tracepoint_iter_start(struct tracepoint_iter *iter);
-extern void tracepoint_iter_next(struct tracepoint_iter *iter);
-extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
-extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
-
 /*
  * tracepoint_synchronize_unregister must be called between the last tracepoint
  * probe unregistration and the end of module exit to make sure there is no
kernel/tracepoint.c +5 -216

257 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author reviewer
#2 lore raw

RFC PATCH v6 2/3 Tracepoint API doc update: data argument

In reply to Mathieu Desnoyers

Describe the @data argument (probe private data).

Fixes 38516ab59fbc "tracing: Let tracepoints have data passed to tracepoint callbacks"
CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
---
 kernel/tracepoint.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/tracepoint.c +2 -0
index f27e5f0..2e4bfcb 100644
@@ -370,6 +370,7 @@ tracepoint_add_probe(const char *name, void *probe, void *data)
  * tracepoint_probe_register -  Connect a probe to a tracepoint
  * @name: tracepoint name
  * @probe: probe handler
+ * @data: probe private data
  *
  * Returns 0 if ok, error value on error.
  * The probe address must at least be aligned on the architecture pointer size.
@@ -412,6 +413,7 @@ tracepoint_remove_probe(const char *name, void *probe, void *data)
  * tracepoint_probe_unregister -  Disconnect a probe from a tracepoint
  * @name: tracepoint name
  * @probe: probe function pointer
+ * @data: probe private data
  *
  * We do not need to call a synchronize_sched to make sure the probes have
  * finished running before doing a module unload, because the module unload
Signature · 1 line
1.7.10.4
maintainer
#3 lore raw

Re: [RFC PATCH v6 2/3] Tracepoint API doc update: data argument

Quoted 1 line · On Wed, 19 Mar 2014 18:31:01 -0400 Mathieu Desnoyers…

Describe the @data argument (probe private data).

As you probably noticed, I added your previous patch to my tree. You don't need to keep this with your patches.

-- Steve

Quoted 31 lines
Fixes 38516ab59fbc "tracing: Let tracepoints have data passed to tracepoint callbacks"
CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
---
 kernel/tracepoint.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/tracepoint.c +2 -0
index f27e5f0..2e4bfcb 100644
@@ -370,6 +370,7 @@ tracepoint_add_probe(const char *name, void *probe, void *data)
  * tracepoint_probe_register -  Connect a probe to a tracepoint
  * @name: tracepoint name
  * @probe: probe handler
+ * @data: probe private data
  *
  * Returns 0 if ok, error value on error.
  * The probe address must at least be aligned on the architecture pointer size.
@@ -412,6 +413,7 @@ tracepoint_remove_probe(const char *name, void *probe, void *data)
  * tracepoint_probe_unregister -  Disconnect a probe from a tracepoint
  * @name: tracepoint name
  * @probe: probe function pointer
+ * @data: probe private data
  *
  * We do not need to call a synchronize_sched to make sure the probes have
  * finished running before doing a module unload, because the module unload
author reviewer
#4 lore raw

Re: [RFC PATCH v6 2/3] Tracepoint API doc update: data argument

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

Quoted 7 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]>
Sent: Wednesday, March 19, 2014 11:01:32 PM
Subject: Re: [RFC PATCH v6 2/3] Tracepoint API doc update: data argument

Quoted 7 lines
Quoted 1 line · On Wed, 19 Mar 2014 18:31:01 -0400 Mathieu Desnoyers…

Describe the @data argument (probe private data).

As you probably noticed, I added your previous patch to my tree. You don't need to keep this with your patches.

OK, thanks!

Mathieu

Quoted 41 lines

-- Steve

Quoted 36 lines
Fixes 38516ab59fbc "tracing: Let tracepoints have data passed to

tracepoint callbacks"

CC Steven Rostedt <[email protected]>
CC Ingo Molnar <[email protected]>
CC Frederic Weisbecker <[email protected]>
CC Andrew Morton <[email protected]>
---
 kernel/tracepoint.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/tracepoint.c +1 -0
index f27e5f0..2e4bfcb 100644
@@ -370,6 +370,7 @@ tracepoint_add_probe(const char *name, void *probe,
 void *data)
  * tracepoint_probe_register -  Connect a probe to a tracepoint
  * @name: tracepoint name
  * @probe: probe handler
+ * @data: probe private data
  *
  * Returns 0 if ok, error value on error.

* The probe address must at least be aligned on the architecture pointer size.

kernel/tracepoint.c +1 -0
@@ -412,6 +413,7 @@ tracepoint_remove_probe(const char *name, void *probe,
 void *data)
  * tracepoint_probe_unregister -  Disconnect a probe from a tracepoint
  * @name: tracepoint name
  * @probe: probe function pointer
+ * @data: probe private data
  *
  * We do not need to call a synchronize_sched to make sure the probes have

* finished running before doing a module unload, because the module unload

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
author reviewer
#5 lore raw

RFC PATCH v6 3/3 Tracepoint: register/unregister struct tracepoint

In reply to Mathieu Desnoyers

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.

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 |    1 +
 include/linux/tracepoint.h   |   44 ++--
 include/trace/ftrace.h       |    2 +
 kernel/trace/trace_events.c  |    8 +-
 kernel/tracepoint.c          |  536 ++++++++++++++++++++----------------------
 5 files changed, 287 insertions(+), 304 deletions(-)
include/linux/ftrace_event.h +1 -0
index 4e4cc28..1592c1c 100644
@@ -230,6 +230,7 @@ struct ftrace_event_call {
 	struct list_head	list;
 	struct ftrace_event_class *class;
 	char			*name;
+	struct tracepoint	*tp;
 	struct trace_event	event;
 	const char		*print_fmt;
 	struct event_filter	*filter;
include/linux/tracepoint.h +23 -21

74 lines not on this page · raw message

include/trace/ftrace.h +2 -0
index 1a8b28d..415b986 100644
@@ -625,6 +625,7 @@ static struct ftrace_event_class __used __refdata event_class_##call = { \
 									\
 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,			\
@@ -639,6 +640,7 @@ 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,			\
kernel/trace/trace_events.c +4 -4
index f3989ce..0e39692 100644
@@ -201,22 +201,22 @@ int ftrace_event_reg(struct ftrace_event_call *call,
 
 	switch (type) {
 	case TRACE_REG_REGISTER:
-		return tracepoint_probe_register(call->name,
+		return tracepoint_probe_register(call->tp,
 						 call->class->probe,
 						 file);
 	case TRACE_REG_UNREGISTER:
-		tracepoint_probe_unregister(call->name,
+		tracepoint_probe_unregister(call->tp,
 					    call->class->probe,
 					    file);
 		return 0;
 
 #ifdef CONFIG_PERF_EVENTS
 	case TRACE_REG_PERF_REGISTER:
-		return tracepoint_probe_register(call->name,
+		return tracepoint_probe_register(call->tp,
 						 call->class->perf_probe,
 						 call);
 	case TRACE_REG_PERF_UNREGISTER:
-		tracepoint_probe_unregister(call->name,
+		tracepoint_probe_unregister(call->tp,
 					    call->class->perf_probe,
 					    call);
 		return 0;
kernel/tracepoint.c +257 -279

732 lines not on this page · raw message

Signature · 1 line
1.7.10.4