mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Li Zefan <lizf@cn.fujitsu.com>,
	Jim Keniston <jkenisto@us.ibm.com>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Andi Kleen <ak@linux.intel.com>,
	Christoph Hellwig <hch@infradead.org>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
	Jason Baron <jbaron@redhat.com>,
	"K.Prasad" <prasad@linux.vnet.ibm.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	Tom Zanussi <tzanussi@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 21/24] tracing/kprobes: Add probe handler dispatcher to support perf and ftrace concurrent use
Date: Tue, 22 Sep 2009 21:38:19 +0200	[thread overview]
Message-ID: <1253648302-5771-22-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1253648302-5771-1-git-send-email-fweisbec@gmail.com>

From: Masami Hiramatsu <mhiramat@redhat.com>

Add kprobe_dispatcher and kretprobe_dispatcher to dispatch event
in both profile and tracing handlers.

This allows simultaneous kprobe uses by ftrace and perf.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20090914204920.18779.57555.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace_kprobe.c |   85 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 63 insertions(+), 22 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index ea0db8e..70b632c 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -185,10 +185,15 @@ struct probe_arg {
 	const char		*name;
 };
 
+/* Flags for trace_probe */
+#define TP_FLAG_TRACE	1
+#define TP_FLAG_PROFILE	2
+
 struct trace_probe {
 	struct list_head	list;
 	struct kretprobe	rp;	/* Use rp.kp for kprobe use */
 	unsigned long 		nhit;
+	unsigned int		flags;	/* For TP_FLAG_* */
 	const char		*symbol;	/* symbol name */
 	struct ftrace_event_call	call;
 	struct trace_event		event;
@@ -200,10 +205,6 @@ struct trace_probe {
 	(offsetof(struct trace_probe, args) +	\
 	(sizeof(struct probe_arg) * (n)))
 
-static int kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs);
-static int kretprobe_trace_func(struct kretprobe_instance *ri,
-				struct pt_regs *regs);
-
 static __kprobes int probe_is_return(struct trace_probe *tp)
 {
 	return tp->rp.handler != NULL;
@@ -263,6 +264,10 @@ static void unregister_probe_event(struct trace_probe *tp);
 static DEFINE_MUTEX(probe_lock);
 static LIST_HEAD(probe_list);
 
+static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);
+static int kretprobe_dispatcher(struct kretprobe_instance *ri,
+				struct pt_regs *regs);
+
 /*
  * Allocate new trace_probe and initialize it (including kprobes).
  */
@@ -288,11 +293,10 @@ static struct trace_probe *alloc_trace_probe(const char *group,
 	} else
 		tp->rp.kp.addr = addr;
 
-	/* Set handler here for checking whether this probe is return or not. */
 	if (is_return)
-		tp->rp.handler = kretprobe_trace_func;
+		tp->rp.handler = kretprobe_dispatcher;
 	else
-		tp->rp.kp.pre_handler = kprobe_trace_func;
+		tp->rp.kp.pre_handler = kprobe_dispatcher;
 
 	if (!event)
 		goto error;
@@ -379,6 +383,7 @@ static int register_trace_probe(struct trace_probe *tp)
 		goto end;
 	}
 
+	tp->flags = TP_FLAG_TRACE;
 	if (probe_is_return(tp))
 		ret = register_kretprobe(&tp->rp);
 	else
@@ -987,23 +992,24 @@ static int probe_event_enable(struct ftrace_event_call *call)
 {
 	struct trace_probe *tp = (struct trace_probe *)call->data;
 
-	if (probe_is_return(tp)) {
-		tp->rp.handler = kretprobe_trace_func;
+	tp->flags |= TP_FLAG_TRACE;
+	if (probe_is_return(tp))
 		return enable_kretprobe(&tp->rp);
-	} else {
-		tp->rp.kp.pre_handler = kprobe_trace_func;
+	else
 		return enable_kprobe(&tp->rp.kp);
-	}
 }
 
 static void probe_event_disable(struct ftrace_event_call *call)
 {
 	struct trace_probe *tp = (struct trace_probe *)call->data;
 
-	if (probe_is_return(tp))
-		disable_kretprobe(&tp->rp);
-	else
-		disable_kprobe(&tp->rp.kp);
+	tp->flags &= ~TP_FLAG_TRACE;
+	if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
+		if (probe_is_return(tp))
+			disable_kretprobe(&tp->rp);
+		else
+			disable_kprobe(&tp->rp.kp);
+	}
 }
 
 static int probe_event_raw_init(struct ftrace_event_call *event_call)
@@ -1212,22 +1218,57 @@ static int probe_profile_enable(struct ftrace_event_call *call)
 	if (atomic_inc_return(&call->profile_count))
 		return 0;
 
-	if (probe_is_return(tp)) {
-		tp->rp.handler = kretprobe_profile_func;
+	tp->flags |= TP_FLAG_PROFILE;
+	if (probe_is_return(tp))
 		return enable_kretprobe(&tp->rp);
-	} else {
-		tp->rp.kp.pre_handler = kprobe_profile_func;
+	else
 		return enable_kprobe(&tp->rp.kp);
-	}
 }
 
 static void probe_profile_disable(struct ftrace_event_call *call)
 {
+	struct trace_probe *tp = (struct trace_probe *)call->data;
+
 	if (atomic_add_negative(-1, &call->profile_count))
-		probe_event_disable(call);
+		tp->flags &= ~TP_FLAG_PROFILE;
+
+	if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
+		if (probe_is_return(tp))
+			disable_kretprobe(&tp->rp);
+		else
+			disable_kprobe(&tp->rp.kp);
+	}
 }
+#endif	/* CONFIG_EVENT_PROFILE */
+
+
+static __kprobes
+int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
+{
+	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
 
+	if (tp->flags & TP_FLAG_TRACE)
+		kprobe_trace_func(kp, regs);
+#ifdef CONFIG_EVENT_PROFILE
+	if (tp->flags & TP_FLAG_PROFILE)
+		kprobe_profile_func(kp, regs);
 #endif	/* CONFIG_EVENT_PROFILE */
+	return 0;	/* We don't tweek kernel, so just return 0 */
+}
+
+static __kprobes
+int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+	struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
+
+	if (tp->flags & TP_FLAG_TRACE)
+		kretprobe_trace_func(ri, regs);
+#ifdef CONFIG_EVENT_PROFILE
+	if (tp->flags & TP_FLAG_PROFILE)
+		kretprobe_profile_func(ri, regs);
+#endif	/* CONFIG_EVENT_PROFILE */
+	return 0;	/* We don't tweek kernel, so just return 0 */
+}
 
 static int register_probe_event(struct trace_probe *tp)
 {
-- 
1.6.2.3


  parent reply	other threads:[~2009-09-22 19:39 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-22 19:37 [GIT PULL] tracing/kprobes: Kprobes core/tracing/profiling updates Frederic Weisbecker
2009-09-22 19:37 ` [PATCH 01/24] kprobes/x86: Call BUG() when reentering probe into KPROBES_HIT_SS Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 02/24] kprobes/x86-64: Allow to reenter probe on post_handler Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 03/24] kprobes/x86: Fix to add __kprobes to in-kernel fault handing functions Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 04/24] kprobes: Fix to add __kprobes to notify_die Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 05/24] kprobes/x86-64: Fix to move common_interrupt to .kprobes.text Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 06/24] kprobes: Prohibit to probe native_get_debugreg Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 07/24] x86: Allow x86-32 instruction decoder selftest on x86-64 Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 08/24] x86: Remove unused config macros from instruction decoder selftest Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 09/24] x86: Add MMX support for instruction decoder Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 10/24] kprobes/x86-32: Move irq-exit functions to kprobes section Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 11/24] x86/ptrace: Fix regs_get_argument_nth() to add correct offset Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 12/24] tracing/kprobes: Fix probe offset to be unsigned Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 13/24] tracing/kprobes: Cleanup kprobe tracer code Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 14/24] tracing/kprobes: Add event profiling support Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 15/24] tracing/kprobes: Add argument name support Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 16/24] tracing/kprobes: Show event name in trace output Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 17/24] tracing/kprobes: Support custom subsystem for each kprobe event Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 18/24] tracing/kprobes: Fix trace_probe registration order Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 19/24] ftrace: Fix trace_add_event_call() to initialize list Frederic Weisbecker
2009-09-23  1:11   ` Li Zefan
2009-09-23  8:16     ` Masami Hiramatsu
2009-09-22 19:38 ` [PATCH 20/24] ftrace: Fix trace_remove_event_call() to lock trace_event_mutex Frederic Weisbecker
2009-09-22 19:38 ` Frederic Weisbecker [this message]
2009-09-22 19:38 ` [PATCH 22/24] tracing/kprobes: Fix profiling alignment for perf_counter buffer Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 23/24] tracing/kprobes: Disable kprobe events by default after creation Frederic Weisbecker
2009-09-22 19:38 ` [PATCH 24/24] kprobes: Prevent re-registration of the same kprobe Frederic Weisbecker
2009-09-23 10:52 ` [GIT PULL] tracing/kprobes: Kprobes core/tracing/profiling updates Ingo Molnar
2009-09-23 12:04   ` Frédéric Weisbecker
2009-09-23 16:42   ` Masami Hiramatsu
2009-09-23 21:24   ` Frederic Weisbecker
2009-09-23 21:46     ` Ingo Molnar
2009-09-23 22:13       ` Ingo Molnar
2009-09-23 22:23         ` Frederic Weisbecker
2009-09-24  0:06         ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253648302-5771-22-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jbaron@redhat.com \
    --cc=jkenisto@us.ibm.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=tzanussi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®