[RFC PATCH 7/8] jump label v4 - tracepoint support

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jason Baron
Date: Tuesday, January 12, 2010 - 9:26 am

Make use of the jump label infrastructure for tracepoints.

Signed-off-by: Jason Baron <jbaron@redhat.com>
---
 include/linux/tracepoint.h |   34 +++++++++++++++++++---------------
 kernel/tracepoint.c        |    8 ++++++++
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index f59604e..c18b9c0 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -16,6 +16,7 @@
 
 #include <linux/types.h>
 #include <linux/rcupdate.h>
+#include <linux/jump_label.h>
 
 struct module;
 struct tracepoint;
@@ -63,20 +64,22 @@ struct tracepoint {
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
  */
-#define DECLARE_TRACE(name, proto, args)				\
-	extern struct tracepoint __tracepoint_##name;			\
-	static inline void trace_##name(proto)				\
-	{								\
-		if (unlikely(__tracepoint_##name.state))		\
-			__DO_TRACE(&__tracepoint_##name,		\
-				TP_PROTO(proto), TP_ARGS(args));	\
-	}								\
-	static inline int register_trace_##name(void (*probe)(proto))	\
-	{								\
-		return tracepoint_probe_register(#name, (void *)probe);	\
-	}								\
-	static inline int unregister_trace_##name(void (*probe)(proto))	\
-	{								\
+#define DECLARE_TRACE(name, proto, args)				 \
+	extern struct tracepoint __tracepoint_##name;			 \
+	static inline void trace_##name(proto)				 \
+	{								 \
+		JUMP_LABEL(name, do_trace, __tracepoint_##name.state);   \
+		return;							 \
+do_trace:								 \
+		__DO_TRACE(&__tracepoint_##name,			 \
+			   TP_PROTO(proto), TP_ARGS(args));		 \
+	}								 \
+	static inline int register_trace_##name(void (*probe)(proto))	 \
+	{								 \
+		return tracepoint_probe_register(#name, (void *)probe);	 \
+	}								 \
+	static inline int unregister_trace_##name(void (*probe)(proto))	 \
+	{								 \
 		return tracepoint_probe_unregister(#name, (void *)probe);\
 	}
 
@@ -86,7 +89,8 @@ struct tracepoint {
 	__attribute__((section("__tracepoints_strings"))) = #name;	\
 	struct tracepoint __tracepoint_##name				\
 	__attribute__((section("__tracepoints"), aligned(32))) =	\
-		{ __tpstrtab_##name, 0, reg, unreg, NULL }
+		{ __tpstrtab_##name, 0, reg, unreg, NULL };		\
+	DEFINE_JUMP_LABEL(name);
 
 #define DEFINE_TRACE(name)						\
 	DEFINE_TRACE_FN(name, NULL, NULL);
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index cc89be5..8acced8 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -25,6 +25,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/jump_label.h>
 
 extern struct tracepoint __start___tracepoints[];
 extern struct tracepoint __stop___tracepoints[];
@@ -256,6 +257,10 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 	 * is used.
 	 */
 	rcu_assign_pointer(elem->funcs, (*entry)->funcs);
+	if (!elem->state && active)
+		enable_jump_label(elem->name);
+	if (elem->state && !active)
+		disable_jump_label(elem->name);
 	elem->state = active;
 }
 
@@ -270,6 +275,9 @@ static void disable_tracepoint(struct tracepoint *elem)
 	if (elem->unregfunc && elem->state)
 		elem->unregfunc();
 
+	if (elem->state)
+		disable_jump_label(elem->name);
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
-- 
1.6.5.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC PATCH 0/8] jump label v4 , Jason Baron, (Tue Jan 12, 9:26 am)
[RFC PATCH 5/8] jump label v4 - base patch, Jason Baron, (Tue Jan 12, 9:26 am)
[RFC PATCH 6/8] jump label v4 - x86 support, Jason Baron, (Tue Jan 12, 9:26 am)
[RFC PATCH 7/8] jump label v4 - tracepoint support, Jason Baron, (Tue Jan 12, 9:26 am)
[RFC PATCH 8/8] jump label v4 - add module support, Jason Baron, (Tue Jan 12, 9:26 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Tue Jan 12, 7:06 pm)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Masami Hiramatsu, (Tue Jan 12, 10:38 pm)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Wed Jan 13, 7:30 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Masami Hiramatsu, (Wed Jan 13, 11:57 pm)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Thu Jan 14, 8:39 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Masami Hiramatsu, (Thu Jan 14, 11:45 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Sun Jan 17, 11:55 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Arjan van de Ven, (Sun Jan 17, 12:16 pm)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Mon Jan 18, 9:52 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Mon Jan 18, 9:54 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Masami Hiramatsu, (Mon Jan 18, 11:21 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Mon Jan 18, 11:33 am)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Mon Jan 18, 2:32 pm)
Re: [RFC PATCH 2/8] jump label v4 - x86: Introduce generic ..., Mathieu Desnoyers, (Tue Apr 13, 10:16 am)