All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Namhyung Kim <namhyung.kim@lge.com>,
	Hyeoncheol Lee <cheol.lee@lge.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	Oleg Nesterov <oleg@redhat.com>,
	"zhangwei(Jovi)" <jovi.zhangwei@huawei.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Subject: Re: [PATCH 07/13] tracing/kprobes: Remove duplicate set_print_fmt()
Date: Mon, 05 Aug 2013 15:46:12 +0900	[thread overview]
Message-ID: <51FF4A34.1000400@hitachi.com> (raw)
In-Reply-To: <1375261410-11219-8-git-send-email-namhyung@kernel.org>

Remove? or Integrate? :)

(2013/07/31 18:03), Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
> 
> The set_print_fmt() functions are implemented almost same for
> [ku]probes.  Move it to a common place and get rid of the duplication.

Anyway this looks good for me;)

Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Thanks!

> 
> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: zhangwei(Jovi) <jovi.zhangwei@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  kernel/trace/trace_kprobe.c | 63 +--------------------------------------------
>  kernel/trace/trace_probe.c  | 62 ++++++++++++++++++++++++++++++++++++++++++++
>  kernel/trace/trace_probe.h  |  1 +
>  kernel/trace/trace_uprobe.c | 55 +--------------------------------------
>  4 files changed, 65 insertions(+), 116 deletions(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index d4c10fb8b8f8..40018618cc08 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1069,67 +1069,6 @@ static int kretprobe_event_define_fields(struct ftrace_event_call *event_call)
>  	return 0;
>  }
>  
> -static int __set_print_fmt(struct trace_kprobe *tp, char *buf, int len)
> -{
> -	int i;
> -	int pos = 0;
> -
> -	const char *fmt, *arg;
> -
> -	if (!trace_kprobe_is_return(tp)) {
> -		fmt = "(%lx)";
> -		arg = "REC->" FIELD_STRING_IP;
> -	} else {
> -		fmt = "(%lx <- %lx)";
> -		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
> -	}
> -
> -	/* When len=0, we just calculate the needed length */
> -#define LEN_OR_ZERO (len ? len - pos : 0)
> -
> -	pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
> -
> -	for (i = 0; i < tp->p.nr_args; i++) {
> -		pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
> -				tp->p.args[i].name, tp->p.args[i].type->fmt);
> -	}
> -
> -	pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
> -
> -	for (i = 0; i < tp->p.nr_args; i++) {
> -		if (strcmp(tp->p.args[i].type->name, "string") == 0)
> -			pos += snprintf(buf + pos, LEN_OR_ZERO,
> -					", __get_str(%s)",
> -					tp->p.args[i].name);
> -		else
> -			pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
> -					tp->p.args[i].name);
> -	}
> -
> -#undef LEN_OR_ZERO
> -
> -	/* return the length of print_fmt */
> -	return pos;
> -}
> -
> -static int set_print_fmt(struct trace_kprobe *tp)
> -{
> -	int len;
> -	char *print_fmt;
> -
> -	/* First: called with 0 length to calculate the needed length */
> -	len = __set_print_fmt(tp, NULL, 0);
> -	print_fmt = kmalloc(len + 1, GFP_KERNEL);
> -	if (!print_fmt)
> -		return -ENOMEM;
> -
> -	/* Second: actually write the @print_fmt */
> -	__set_print_fmt(tp, print_fmt, len + 1);
> -	tp->p.call.print_fmt = print_fmt;
> -
> -	return 0;
> -}
> -
>  #ifdef CONFIG_PERF_EVENTS
>  
>  /* Kprobe profile handler */
> @@ -1280,7 +1219,7 @@ static int register_probe_event(struct trace_kprobe *tp)
>  		call->event.funcs = &kprobe_funcs;
>  		call->class->define_fields = kprobe_event_define_fields;
>  	}
> -	if (set_print_fmt(tp) < 0)
> +	if (set_print_fmt(&tp->p, trace_kprobe_is_return(tp)) < 0)
>  		return -ENOMEM;
>  	ret = register_ftrace_event(&call->event);
>  	if (!ret) {
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 5e491d82b6ad..76ab02143b5a 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -747,3 +747,65 @@ __kprobes void store_trace_args(int ent_size, struct trace_probe *tp,
>  				   data + tp->args[i].offset);
>  	}
>  }
> +
> +static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
> +			   bool is_return)
> +{
> +	int i;
> +	int pos = 0;
> +
> +	const char *fmt, *arg;
> +
> +	if (!is_return) {
> +		fmt = "(%lx)";
> +		arg = "REC->" FIELD_STRING_IP;
> +	} else {
> +		fmt = "(%lx <- %lx)";
> +		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
> +	}
> +
> +	/* When len=0, we just calculate the needed length */
> +#define LEN_OR_ZERO (len ? len - pos : 0)
> +
> +	pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
> +
> +	for (i = 0; i < tp->nr_args; i++) {
> +		pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
> +				tp->args[i].name, tp->args[i].type->fmt);
> +	}
> +
> +	pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
> +
> +	for (i = 0; i < tp->nr_args; i++) {
> +		if (strcmp(tp->args[i].type->name, "string") == 0)
> +			pos += snprintf(buf + pos, LEN_OR_ZERO,
> +					", __get_str(%s)",
> +					tp->args[i].name);
> +		else
> +			pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
> +					tp->args[i].name);
> +	}
> +
> +#undef LEN_OR_ZERO
> +
> +	/* return the length of print_fmt */
> +	return pos;
> +}
> +
> +int set_print_fmt(struct trace_probe *tp, bool is_return)
> +{
> +	int len;
> +	char *print_fmt;
> +
> +	/* First: called with 0 length to calculate the needed length */
> +	len = __set_print_fmt(tp, NULL, 0, is_return);
> +	print_fmt = kmalloc(len + 1, GFP_KERNEL);
> +	if (!print_fmt)
> +		return -ENOMEM;
> +
> +	/* Second: actually write the @print_fmt */
> +	__set_print_fmt(tp, print_fmt, len + 1, is_return);
> +	tp->call.print_fmt = print_fmt;
> +
> +	return 0;
> +}
> diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> index 888cd7d4cd3c..ec18e1b1487e 100644
> --- a/kernel/trace/trace_probe.h
> +++ b/kernel/trace/trace_probe.h
> @@ -301,3 +301,4 @@ extern int traceprobe_command(const char *buf, int (*createfn)(int, char**));
>  extern int __get_data_size(struct trace_probe *tp, struct pt_regs *regs);
>  extern void store_trace_args(int ent_size, struct trace_probe *tp,
>  			     struct pt_regs *regs, u8 *data, int maxlen);
> +extern int set_print_fmt(struct trace_probe *tp, bool is_return);
> diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> index cbb2ad76fd8c..bcc7bd300c99 100644
> --- a/kernel/trace/trace_uprobe.c
> +++ b/kernel/trace/trace_uprobe.c
> @@ -661,59 +661,6 @@ static int uprobe_event_define_fields(struct ftrace_event_call *event_call)
>  	return 0;
>  }
>  
> -#define LEN_OR_ZERO		(len ? len - pos : 0)
> -static int __set_print_fmt(struct trace_uprobe *tu, char *buf, int len)
> -{
> -	const char *fmt, *arg;
> -	int i;
> -	int pos = 0;
> -
> -	if (is_ret_probe(tu)) {
> -		fmt = "(%lx <- %lx)";
> -		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
> -	} else {
> -		fmt = "(%lx)";
> -		arg = "REC->" FIELD_STRING_IP;
> -	}
> -
> -	/* When len=0, we just calculate the needed length */
> -
> -	pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
> -
> -	for (i = 0; i < tu->p.nr_args; i++) {
> -		pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
> -				tu->p.args[i].name, tu->p.args[i].type->fmt);
> -	}
> -
> -	pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
> -
> -	for (i = 0; i < tu->p.nr_args; i++) {
> -		pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
> -				tu->p.args[i].name);
> -	}
> -
> -	return pos;	/* return the length of print_fmt */
> -}
> -#undef LEN_OR_ZERO
> -
> -static int set_print_fmt(struct trace_uprobe *tu)
> -{
> -	char *print_fmt;
> -	int len;
> -
> -	/* First: called with 0 length to calculate the needed length */
> -	len = __set_print_fmt(tu, NULL, 0);
> -	print_fmt = kmalloc(len + 1, GFP_KERNEL);
> -	if (!print_fmt)
> -		return -ENOMEM;
> -
> -	/* Second: actually write the @print_fmt */
> -	__set_print_fmt(tu, print_fmt, len + 1);
> -	tu->p.call.print_fmt = print_fmt;
> -
> -	return 0;
> -}
> -
>  #ifdef CONFIG_PERF_EVENTS
>  static bool
>  __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
> @@ -945,7 +892,7 @@ static int register_uprobe_event(struct trace_uprobe *tu)
>  	call->event.funcs = &uprobe_funcs;
>  	call->class->define_fields = uprobe_event_define_fields;
>  
> -	if (set_print_fmt(tu) < 0)
> +	if (set_print_fmt(&tu->p, is_ret_probe(tu)) < 0)
>  		return -ENOMEM;
>  
>  	ret = register_ftrace_event(&call->event);
> 


-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2013-08-05  6:46 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31  9:03 [PATCHSET 00/13] tracing/uprobes: Add support for more fetch methods (v2) Namhyung Kim
2013-07-31  9:03 ` [PATCH 01/13] tracing/kprobes: Move fetch functions to trace_kprobe.c Namhyung Kim
2013-08-05  5:30   ` Masami Hiramatsu
2013-08-05  8:44     ` Namhyung Kim
2013-07-31  9:03 ` [PATCH 02/13] tracing/kprobes: Add fetch{,_size} member into symbol and deref fetch method Namhyung Kim
2013-08-05  8:19   ` Masami Hiramatsu
2013-08-05  8:58     ` Namhyung Kim
2013-07-31  9:03 ` [PATCH 03/13] tracing/kprobes: Make stack and memory fetch functions static Namhyung Kim
2013-08-05  9:04   ` Masami Hiramatsu
2013-08-09  7:35     ` Namhyung Kim
2013-08-09  9:15       ` Masami Hiramatsu
2013-07-31  9:03 ` [PATCH 04/13] tracing/kprobes: Factor out struct trace_probe Namhyung Kim
2013-08-05  6:00   ` Masami Hiramatsu
2013-08-05  8:49     ` Namhyung Kim
2013-07-31  9:03 ` [PATCH 05/13] tracing/uprobes: Convert to " Namhyung Kim
2013-07-31  9:03 ` [PATCH 06/13] tracing/kprobes: Move common functions to trace_probe.c Namhyung Kim
2013-08-05  6:03   ` Masami Hiramatsu
2013-08-05  8:50     ` Namhyung Kim
2013-07-31  9:03 ` [PATCH 07/13] tracing/kprobes: Remove duplicate set_print_fmt() Namhyung Kim
2013-08-05  6:46   ` Masami Hiramatsu [this message]
2013-07-31  9:03 ` [PATCH 08/13] tracing/uprobes: Fetch args before reserving a ring buffer Namhyung Kim
2013-07-31  9:03 ` [PATCH 09/13] tracing/uprobes: Fix a comment for uprobe registration syntax Namhyung Kim
2013-08-05  5:59   ` Masami Hiramatsu
2013-08-05  8:47     ` Namhyung Kim
2013-07-31  9:03 ` [PATCH 10/13] tracing/kprobes: Add priv argument to fetch functions Namhyung Kim
2013-07-31  9:03 ` [PATCH 11/13] tracing/uprobes: Add more " Namhyung Kim
2013-07-31  9:03 ` [PATCH 12/13] tracing/uprobes: Add support for full argument access methods Namhyung Kim
2013-07-31  9:03 ` [PATCH 13/13] tracing/probes: Fix basic print type functions Namhyung Kim
2013-08-05  6:22   ` Masami Hiramatsu
2013-08-05  6:31     ` Joe Perches
2013-08-05  7:27       ` Masami Hiramatsu
2013-08-05  8:55       ` Namhyung Kim
2013-08-05  8:51     ` Namhyung Kim

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=51FF4A34.1000400@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=acme@ghostprotocols.net \
    --cc=cheol.lee@lge.com \
    --cc=jovi.zhangwei@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.