mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Masami Hiramatsu <mhiramat@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@redhat.com, peterz@infradead.org, fweisbec@gmail.com,
	rostedt@goodmis.org, ak@linux.intel.com, jbaron@redhat.com,
	tglx@linutronix.de, laijs@cn.fujitsu.com, mhiramat@redhat.com,
	linux-kernel@vger.kernel.org, hpa@zytor.com, fche@redhat.com,
	jkenisto@us.ibm.com, tzanussi@gmail.com, lizf@cn.fujitsu.com,
	hch@infradead.org, ananth@in.ibm.com, srikar@linux.vnet.ibm.com,
	mingo@elte.hu, prasad@linux.vnet.ibm.com
Subject: [tip:perf/probes] tracing/kprobes: Cleanup kprobe tracer code.
Date: Sat, 17 Oct 2009 09:59:35 GMT	[thread overview]
Message-ID: <tip-4a846b443b4e8633057946a2234e23559a67ce42@git.kernel.org> (raw)
In-Reply-To: <20090910235322.22412.52525.stgit@dhcp-100-2-132.bos.redhat.com>

Commit-ID:  4a846b443b4e8633057946a2234e23559a67ce42
Gitweb:     http://git.kernel.org/tip/4a846b443b4e8633057946a2234e23559a67ce42
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Fri, 11 Sep 2009 05:31:21 +0200
Committer:  Frederic Weisbecker <fweisbec@gmail.com>
CommitDate: Fri, 11 Sep 2009 05:31:21 +0200

tracing/kprobes: Cleanup kprobe tracer code.

Simplify trace_probe to remove a union, and remove some redundant
wrappers.
And also, cleanup create_trace_probe() function.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
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: Frederic Weisbecker <fweisbec@gmail.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: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20090910235322.22412.52525.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace_kprobe.c |   81 ++++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 47 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index c24b7e9..4ce728c 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -180,10 +180,7 @@ static __kprobes void free_indirect_fetch_data(struct indirect_fetch_data *data)
 
 struct trace_probe {
 	struct list_head	list;
-	union {
-		struct kprobe		kp;
-		struct kretprobe	rp;
-	};
+	struct kretprobe	rp;	/* Use rp.kp for kprobe use */
 	unsigned long 		nhit;
 	const char		*symbol;	/* symbol name */
 	struct ftrace_event_call	call;
@@ -202,7 +199,7 @@ static int kretprobe_trace_func(struct kretprobe_instance *ri,
 
 static __kprobes int probe_is_return(struct trace_probe *tp)
 {
-	return (tp->rp.handler == kretprobe_trace_func);
+	return tp->rp.handler != NULL;
 }
 
 static __kprobes const char *probe_symbol(struct trace_probe *tp)
@@ -210,16 +207,6 @@ static __kprobes const char *probe_symbol(struct trace_probe *tp)
 	return tp->symbol ? tp->symbol : "unknown";
 }
 
-static __kprobes unsigned int probe_offset(struct trace_probe *tp)
-{
-	return (probe_is_return(tp)) ? tp->rp.kp.offset : tp->kp.offset;
-}
-
-static __kprobes void *probe_address(struct trace_probe *tp)
-{
-	return (probe_is_return(tp)) ? tp->rp.kp.addr : tp->kp.addr;
-}
-
 static int probe_arg_string(char *buf, size_t n, struct fetch_func *ff)
 {
 	int ret = -EINVAL;
@@ -269,8 +256,14 @@ static void unregister_probe_event(struct trace_probe *tp);
 static DEFINE_MUTEX(probe_lock);
 static LIST_HEAD(probe_list);
 
-static struct trace_probe *alloc_trace_probe(const char *symbol,
-					     const char *event, int nargs)
+/*
+ * Allocate new trace_probe and initialize it (including kprobes).
+ */
+static struct trace_probe *alloc_trace_probe(const char *event,
+					     void *addr,
+					     const char *symbol,
+					     unsigned long offs,
+					     int nargs, int is_return)
 {
 	struct trace_probe *tp;
 
@@ -282,7 +275,16 @@ static struct trace_probe *alloc_trace_probe(const char *symbol,
 		tp->symbol = kstrdup(symbol, GFP_KERNEL);
 		if (!tp->symbol)
 			goto error;
-	}
+		tp->rp.kp.symbol_name = tp->symbol;
+		tp->rp.kp.offset = offs;
+	} else
+		tp->rp.kp.addr = addr;
+
+	if (is_return)
+		tp->rp.handler = kretprobe_trace_func;
+	else
+		tp->rp.kp.pre_handler = kprobe_trace_func;
+
 	if (!event)
 		goto error;
 	tp->call.name = kstrdup(event, GFP_KERNEL);
@@ -327,7 +329,7 @@ static void __unregister_trace_probe(struct trace_probe *tp)
 	if (probe_is_return(tp))
 		unregister_kretprobe(&tp->rp);
 	else
-		unregister_kprobe(&tp->kp);
+		unregister_kprobe(&tp->rp.kp);
 }
 
 /* Unregister a trace_probe and probe_event: call with locking probe_lock */
@@ -349,14 +351,14 @@ static int register_trace_probe(struct trace_probe *tp)
 	if (probe_is_return(tp))
 		ret = register_kretprobe(&tp->rp);
 	else
-		ret = register_kprobe(&tp->kp);
+		ret = register_kprobe(&tp->rp.kp);
 
 	if (ret) {
 		pr_warning("Could not insert probe(%d)\n", ret);
 		if (ret == -EILSEQ) {
 			pr_warning("Probing address(0x%p) is not an "
 				   "instruction boundary.\n",
-				   probe_address(tp));
+				   tp->rp.kp.addr);
 			ret = -EINVAL;
 		}
 		goto end;
@@ -530,12 +532,12 @@ static int create_trace_probe(int argc, char **argv)
 	 *  +|-offs(ARG) : fetch memory at ARG +|- offs address.
 	 */
 	struct trace_probe *tp;
-	struct kprobe *kp;
 	int i, ret = 0;
 	int is_return = 0;
 	char *symbol = NULL, *event = NULL;
 	unsigned long offset = 0;
 	void *addr = NULL;
+	char buf[MAX_EVENT_NAME_LEN];
 
 	if (argc < 2)
 		return -EINVAL;
@@ -577,33 +579,18 @@ static int create_trace_probe(int argc, char **argv)
 	/* setup a probe */
 	if (!event) {
 		/* Make a new event name */
-		char buf[MAX_EVENT_NAME_LEN];
 		if (symbol)
 			snprintf(buf, MAX_EVENT_NAME_LEN, "%c@%s%+ld",
 				 is_return ? 'r' : 'p', symbol, offset);
 		else
 			snprintf(buf, MAX_EVENT_NAME_LEN, "%c@0x%p",
 				 is_return ? 'r' : 'p', addr);
-		tp = alloc_trace_probe(symbol, buf, argc);
-	} else
-		tp = alloc_trace_probe(symbol, event, argc);
+		event = buf;
+	}
+	tp = alloc_trace_probe(event, addr, symbol, offset, argc, is_return);
 	if (IS_ERR(tp))
 		return PTR_ERR(tp);
 
-	if (is_return) {
-		kp = &tp->rp.kp;
-		tp->rp.handler = kretprobe_trace_func;
-	} else {
-		kp = &tp->kp;
-		tp->kp.pre_handler = kprobe_trace_func;
-	}
-
-	if (tp->symbol) {
-		kp->symbol_name = tp->symbol;
-		kp->offset = (unsigned int)offset;
-	} else
-		kp->addr = addr;
-
 	/* parse arguments */
 	ret = 0;
 	for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
@@ -670,9 +657,9 @@ static int probes_seq_show(struct seq_file *m, void *v)
 	seq_printf(m, ":%s", tp->call.name);
 
 	if (tp->symbol)
-		seq_printf(m, " %s+%u", probe_symbol(tp), probe_offset(tp));
+		seq_printf(m, " %s+%u", probe_symbol(tp), tp->rp.kp.offset);
 	else
-		seq_printf(m, " 0x%p", probe_address(tp));
+		seq_printf(m, " 0x%p", tp->rp.kp.addr);
 
 	for (i = 0; i < tp->nr_args; i++) {
 		ret = probe_arg_string(buf, MAX_ARGSTR_LEN, &tp->args[i]);
@@ -783,7 +770,7 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
 	struct trace_probe *tp = v;
 
 	seq_printf(m, "  %-44s %15lu %15lu\n", tp->call.name, tp->nhit,
-		   probe_is_return(tp) ? tp->rp.kp.nmissed : tp->kp.nmissed);
+		   tp->rp.kp.nmissed);
 
 	return 0;
 }
@@ -811,7 +798,7 @@ static const struct file_operations kprobe_profile_ops = {
 /* Kprobe handler */
 static __kprobes int kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
 {
-	struct trace_probe *tp = container_of(kp, struct trace_probe, kp);
+	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
 	struct kprobe_trace_entry *entry;
 	struct ring_buffer_event *event;
 	struct ring_buffer *buffer;
@@ -866,7 +853,7 @@ static __kprobes int kretprobe_trace_func(struct kretprobe_instance *ri,
 
 	entry = ring_buffer_event_data(event);
 	entry->nargs = tp->nr_args;
-	entry->func = (unsigned long)probe_address(tp);
+	entry->func = (unsigned long)tp->rp.kp.addr;
 	entry->ret_ip = (unsigned long)ri->ret_addr;
 	for (i = 0; i < tp->nr_args; i++)
 		entry->args[i] = call_fetch(&tp->args[i], regs);
@@ -945,7 +932,7 @@ static int probe_event_enable(struct ftrace_event_call *call)
 	if (probe_is_return(tp))
 		return enable_kretprobe(&tp->rp);
 	else
-		return enable_kprobe(&tp->kp);
+		return enable_kprobe(&tp->rp.kp);
 }
 
 static void probe_event_disable(struct ftrace_event_call *call)
@@ -955,7 +942,7 @@ static void probe_event_disable(struct ftrace_event_call *call)
 	if (probe_is_return(tp))
 		disable_kretprobe(&tp->rp);
 	else
-		disable_kprobe(&tp->kp);
+		disable_kprobe(&tp->rp.kp);
 }
 
 static int probe_event_raw_init(struct ftrace_event_call *event_call)

  parent reply	other threads:[~2009-10-17 10:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-10 23:52 [PATCH tracing/kprobes 0/7] tracing/kprobes: kprobe-based event tracer update and perf support Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 1/7] x86/ptrace: Fix regs_get_argument_nth() to add correct offset Masami Hiramatsu
2009-09-11  1:43   ` Steven Rostedt
2009-10-17  9:59   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 2/7] tracing/kprobes: Fix probe offset to be unsigned Masami Hiramatsu
2009-10-17  9:59   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 3/7] tracing/kprobes: Cleanup kprobe tracer code Masami Hiramatsu
2009-09-11  2:33   ` Daniel Walker
2009-09-11  2:36     ` Frederic Weisbecker
2009-10-17  9:59   ` tip-bot for Masami Hiramatsu [this message]
2009-09-10 23:53 ` [PATCH tracing/kprobes 4/7] tracing/kprobes: Add event profiling support Masami Hiramatsu
2009-09-11  3:12   ` Frederic Weisbecker
2009-09-11 16:22     ` Masami Hiramatsu
2009-09-14  3:02       ` Frederic Weisbecker
2009-09-14 16:54         ` Masami Hiramatsu
2009-09-14 18:55           ` Frederic Weisbecker
2009-09-14 19:36             ` Masami Hiramatsu
2009-09-14 21:07               ` Frederic Weisbecker
2009-09-15  4:52                 ` Ananth N Mavinakayanahalli
2009-09-11 19:30     ` Masami Hiramatsu
2009-09-14  3:08       ` Frederic Weisbecker
2009-09-13 10:07     ` [BUGFIX] kprobes: prevent re-registration of the same kprobe Ananth N Mavinakayanahalli
2009-09-14  1:47       ` Masami Hiramatsu
2009-09-14 10:04         ` [BUGFIX] kprobes: prevent re-registration of the same kprobe - take2 Ananth N Mavinakayanahalli
2009-09-14 16:25           ` Masami Hiramatsu
2009-09-15  5:13             ` Ananth N Mavinakayanahalli
2009-09-15 13:29               ` Masami Hiramatsu
2009-10-17 10:02               ` [tip:perf/probes] kprobes: Prevent re-registration of the same kprobe tip-bot for Ananth N Mavinakayanahalli
2009-10-17  9:59   ` [tip:perf/probes] tracing/kprobes: Add event profiling support tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 5/7] tracing/kprobes: Add argument name support Masami Hiramatsu
2009-09-11 14:07   ` Steven Rostedt
2009-09-11 16:11     ` Masami Hiramatsu
2009-09-11 16:32       ` Masami Hiramatsu
2009-10-17 10:00   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 6/7] tracing/kprobes: Show event name in trace output Masami Hiramatsu
2009-10-17 10:00   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-10 23:53 ` [PATCH tracing/kprobes 7/7] tracing/kprobes: Support custom subsystem for each kprobe event Masami Hiramatsu
2009-10-17 10:00   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-11  1:33 ` [PATCH tracing/kprobes 0/7] tracing/kprobes: kprobe-based event tracer update and perf support Frederic Weisbecker
2009-09-11  1:45   ` Steven Rostedt
2009-09-11 16:03   ` Masami Hiramatsu
2009-09-14  2:59     ` Frederic Weisbecker
2009-09-14 17:16       ` Masami Hiramatsu
2009-09-14 20:52         ` Frederic Weisbecker
2009-09-14 21:10           ` Masami Hiramatsu
2009-09-14 21:09             ` Frederic Weisbecker
2009-09-11 19:03   ` Frank Ch. Eigler
2009-09-11 19:06     ` Christoph Hellwig
2009-09-11 19:50       ` Mark Wielaard
2009-09-11 20:03         ` Christoph Hellwig
2009-09-12  1:23           ` Masami Hiramatsu
2009-09-11 19:15     ` Frederic Weisbecker
2009-09-11 15:36 ` Frederic Weisbecker
2009-09-11 21:48   ` Masami Hiramatsu
2009-09-14  2:22     ` Frederic Weisbecker

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=tip-4a846b443b4e8633057946a2234e23559a67ce42@git.kernel.org \
    --to=mhiramat@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=fweisbec@gmail.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=linux-tip-commits@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --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

Powered by JetHome