linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alexis Berlemont <alexis.berlemont@gmail.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com,
	hemant@linux.vnet.ibm.com
Subject: Re: [PATCH v4 2/2] perf probe: add sdt probes arguments into the uprobe cmd string
Date: Fri, 9 Dec 2016 12:14:30 -0300	[thread overview]
Message-ID: <20161209151430.GN8257@kernel.org> (raw)
In-Reply-To: <20161207122610.008da636793d38a39accf29b@kernel.org>

Em Wed, Dec 07, 2016 at 12:26:10PM +0900, Masami Hiramatsu escreveu:
> Hello Alexis,
> 
> On Sat, 26 Nov 2016 01:58:03 +0100
> Alexis Berlemont <alexis.berlemont@gmail.com> wrote:
> 
> > An sdt probe can be associated with arguments but they were not passed
> > to the user probe tracing interface (uprobe_events); this patch adapts
> > the sdt argument descriptors according to the uprobe input format.
> 
> Great!

Yeah, good to see work in this area!

I applied the first patch, with Masami's ack, waiting for his concerns
on this one to be addressed, ok?

- Arnaldo
 
> > 
> > As the uprobe parser does not support scaled address mode, perf will
> > skip arguments which cannot be adapted to the uprobe format.
> 
> OK, it seems that skipping argument is a good idea :)
> I just tried to support fixed-number arguments in probe events,
> but skipping it is better with older kernel.
> 
> I have some comments.
> 
> > Here are the results:
> > 
> > $ perf buildid-cache -v --add test_sdt
> > $ perf probe -x test_sdt sdt_libfoo:table_frob
> > $ perf probe -x test_sdt sdt_libfoo:table_diddle
> > $ perf record -e sdt_libfoo:table_frob -e sdt_libfoo:table_diddle test_sdt
> > $ perf script
> > test_sdt  ...   666.255678:   sdt_libfoo:table_frob: (4004d7) arg0=0 arg1=0
> > test_sdt  ...   666.255683: sdt_libfoo:table_diddle: (40051a) arg0=0 arg1=0
> > test_sdt  ...   666.255686:   sdt_libfoo:table_frob: (4004d7) arg0=1 arg1=2
> > test_sdt  ...   666.255689: sdt_libfoo:table_diddle: (40051a) arg0=3 arg1=4
> > test_sdt  ...   666.255692:   sdt_libfoo:table_frob: (4004d7) arg0=2 arg1=4
> > test_sdt  ...   666.255694: sdt_libfoo:table_diddle: (40051a) arg0=6 arg1=8
> 
> We'd better start with arg1, since sdt.h and original Dtrace SDT starts
> arguments from arg1 (I'm not sure why) and dtrace/systemtap scripts
> call it "arg1".
> 
> > 
> > Signed-off-by: Alexis Berlemont <alexis.berlemont@gmail.com>
> > ---
> >  tools/perf/arch/x86/util/perf_regs.c |  18 ++++
> >  tools/perf/util/perf_regs.c          |   4 +
> >  tools/perf/util/perf_regs.h          |  13 +++
> >  tools/perf/util/probe-file.c         | 169 ++++++++++++++++++++++++++++++++++-
> >  4 files changed, 200 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
> > index c5db14f..52a1e65 100644
> > --- a/tools/perf/arch/x86/util/perf_regs.c
> > +++ b/tools/perf/arch/x86/util/perf_regs.c
> > @@ -26,3 +26,21 @@ const struct sample_reg sample_reg_masks[] = {
> >  #endif
> >  	SMPL_REG_END
> >  };
> > +
> > +const struct sdt_name_reg sdt_reg_renamings[] = {
> > +	SDT_NAME_REG(eax, ax),
> > +	SDT_NAME_REG(rax, ax),
> > +	SDT_NAME_REG(ebx, bx),
> > +	SDT_NAME_REG(rbx, bx),
> > +	SDT_NAME_REG(ecx, cx),
> > +	SDT_NAME_REG(rcx, cx),
> > +	SDT_NAME_REG(edx, dx),
> > +	SDT_NAME_REG(rdx, dx),
> > +	SDT_NAME_REG(esi, si),
> > +	SDT_NAME_REG(rsi, si),
> > +	SDT_NAME_REG(edi, di),
> > +	SDT_NAME_REG(rdi, di),
> > +	SDT_NAME_REG(ebp, bp),
> > +	SDT_NAME_REG(rbp, bp),
> > +	SDT_NAME_REG_END,
> > +};
> 
> It is not enough, rNN registers also have to take care, since
> gcc adds 'd', 'w' or 'b'suffixes for those registers to indicate
> its size. e.g. r15d means r15 register with 32 lower bits.
> What we need is just cut them off, since probe event uses
> length modifiers (like :u32)
> 
> > diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
> > index c4023f2..1c21150 100644
> > --- a/tools/perf/util/perf_regs.c
> > +++ b/tools/perf/util/perf_regs.c
> > @@ -6,6 +6,10 @@ const struct sample_reg __weak sample_reg_masks[] = {
> >  	SMPL_REG_END
> >  };
> >  
> > +const struct sdt_name_reg __weak sdt_reg_renamings[] = {
> > +	SDT_NAME_REG_END,
> > +};
> > +
> >  #ifdef HAVE_PERF_REGS_SUPPORT
> >  int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
> >  {
> > diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
> > index 679d6e4..41815ca 100644
> > --- a/tools/perf/util/perf_regs.h
> > +++ b/tools/perf/util/perf_regs.h
> > @@ -15,6 +15,19 @@ struct sample_reg {
> >  
> >  extern const struct sample_reg sample_reg_masks[];
> >  
> > +struct sdt_name_reg {
> > +	const char *sdt_name;
> > +	const char *uprobe_name;
> > +};
> > +#define SDT_NAME_REG(n, m) {.sdt_name = "%" #n, .uprobe_name = "%" #m}
> > +#define SDT_NAME_REG_END {.sdt_name = NULL, .uprobe_name = NULL}
> > +
> > +/*
> > + * The table sdt_reg_renamings is used for adjusting gcc/gas-generated
> > + * registers before filling the uprobe tracer interface.
> > + */
> > +extern const struct sdt_name_reg sdt_reg_renamings[];
> > +
> >  #ifdef HAVE_PERF_REGS_SUPPORT
> >  #include <perf_regs.h>
> >  
> > diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> > index 436b647..75033c7 100644
> > --- a/tools/perf/util/probe-file.c
> > +++ b/tools/perf/util/probe-file.c
> > @@ -27,6 +27,7 @@
> >  #include "probe-event.h"
> >  #include "probe-file.h"
> >  #include "session.h"
> > +#include "perf_regs.h"
> >  
> >  #define MAX_CMDLEN 256
> >  
> > @@ -687,6 +688,165 @@ static unsigned long long sdt_note__get_addr(struct sdt_note *note)
> >  		 : (unsigned long long)note->addr.a64[0];
> >  }
> >  
> > +static const char * const type_to_suffix[] = {
> > +	":s64", "", "", "", ":s32", "", ":s16", ":s8",
> > +	"", ":u8", ":u16", "", ":u32", "", "", "", ":u64"
> > +};
> > +
> > +static int synthesize_sdt_probe_arg(struct strbuf *buf, int i, const char *arg)
> > +{
> > +	const struct sdt_name_reg *rnames;
> > +	char *tmp, *desc = strdup(arg);
> > +	const char *prefix = "", *suffix = "";
> > +	int ret = -1;
> > +
> > +	if (desc == NULL) {
> > +		pr_debug4("Allocation error\n");
> > +		return ret;
> > +	}
> > +
> > +	tmp = strchr(desc, '@');
> > +	if (tmp) {
> > +		long type_idx;
> > +		/*
> > +		 * Isolate the string number and convert it into a
> > +		 * binary value; this will be an index to get suffix
> > +		 * of the uprobe name (defining the type)
> > +		 */
> > +		tmp[0] = '\0';
> > +		type_idx = strtol(desc, NULL, 10);
> > +		if (type_idx == LONG_MIN ||
> > +			type_idx == LONG_MAX) {
> > +			pr_debug4("Failed to get sdt type\n");
> > +			goto error;
> > +		}
> 
> 	You must ensure 0 <= type_idx + 8 <= 16 here.
> 
> > +		suffix = type_to_suffix[type_idx + 8];
> > +		/* Get rid of the sdt prefix which is now useless */
> > +		tmp++;
> > +		memmove(desc, tmp, strlen(tmp) + 1);
> > +	}
> > +
> > +	/*
> > +	 * The uprobe tracer format does not support all the
> > +	 * addressing modes (notably: in x86 the scaled mode); so, we
> > +	 * detect ',' characters, if there is just one, there is no
> > +	 * use converting the sdt arg into a uprobe one.
> > +	 */
> > +	if (strchr(desc, ',')) {
> > +		pr_debug4("SDT argument format not supported\n");
> 
> 	Please print 'desc' by %s too. 
> 
> > +		goto out;
> > +	}
> > +
> > +	/*
> > +	 * If the argument addressing mode is indirect, we must check
> > +	 * a few things...
> > +	 */
> > +	tmp = strchr(desc, '(');
> > +	if (tmp) {
> > +		int j;
> > +
> > +		/*
> > +		 * ...if the addressing mode is indirect with a
> > +		 * positive offset (ex.: "1608(%ax)"), we need to add
> > +		 * a '+' prefix so as to be compliant with uprobe
> > +		 * format.
> > +		 */
> > +		if (desc[0] != '+' && desc[0] != '-')
> > +			prefix = "+";
> > +
> > +		/*
> > +		 * ...or if the addressing mode is indirect with a symbol
> > +		 * as offset, the argument will not be supported by
> > +		 * the uprobe tracer format; so, let's skip this one.
> > +		 */
> > +		for (j = 0; j < tmp - desc; j++) {
> > +			if (desc[j] != '+' && desc[j] != '-' &&
> > +				!isdigit(desc[j]))
> > +				goto out;
> > +		}
> > +	}
> > +
> > +	/*
> > +	 * The uprobe parser does not support all gas register names;
> > +	 * so, we have to replace them (ex. for x86_64: %rax -> %ax);
> > +	 * the loop below performs all the needed renamings if needed.
> > +	 */
> > +	for (rnames = sdt_reg_renamings; rnames->sdt_name != NULL; rnames++) {
> > +		char *new_desc, *sdt_name;
> > +		size_t prefix_len, uprobe_len, mid_ofs, desc_len;
> > +
> > +		sdt_name = strstr(desc, rnames->sdt_name);
> > +		if (sdt_name == NULL)
> > +			continue;
> 
> It is better to search '%' from the desc and parse it.
> And here, we also find fixed numbers which starts with '$',
> since that is not supported yet.
> 
> For example, with your patch, I still see some entries which have fixed num.
> 
> $ perf buildid-cache --add /usr/lib64/libglib-2.0.so
> $ grep \$[0-9] ~/.debug/usr/lib64/libglib-2.0.so.0.5000.2/fda1ca4181ba7135d41bf3cfadc813a432f31066/probes | tail -n 2
> p:sdt_glib/mem__realloc /usr/lib64/libglib-2.0.so.0.5000.2:0x4f670 arg0=%ax:u64 arg1=%bx:u64 arg2=%bp:u32 arg3=$0:s32
> p:sdt_glib/mem__realloc /usr/lib64/libglib-2.0.so.0.5000.2:0x4f75d arg0=%ax:u64 arg1=%bp:u64 arg2=%bx:u32 arg3=$1:s32
> 
> These arguments should be skipped.
> 
> Thank you,
> 
> > +
> > +		new_desc = zalloc(strlen(desc) + 1 +
> > +				strlen(rnames->uprobe_name) -
> > +				strlen(rnames->sdt_name));
> > +		if (new_desc == NULL)
> > +			goto error;
> > +
> > +		prefix_len = sdt_name - desc;
> > +		if (prefix_len != 0)
> > +			memcpy(new_desc, desc, prefix_len);
> > +
> > +		uprobe_len = strlen(rnames->uprobe_name);
> > +		memcpy(new_desc + prefix_len, rnames->uprobe_name, uprobe_len);
> > +
> > +		mid_ofs = prefix_len + strlen(rnames->sdt_name);
> > +		desc_len = strlen(desc);
> > +		if (mid_ofs < desc_len)
> > +			memcpy(new_desc + prefix_len + uprobe_len,
> > +				desc + mid_ofs, desc_len - mid_ofs);
> > +
> > +		free(desc);
> > +		desc = new_desc;
> > +	}
> > +
> > +	if (strbuf_addf(buf, " arg%d=%s%s%s", i, prefix, desc, suffix) < 0)
> > +		goto error;
> > +
> > +out:
> > +	ret = 0;
> > +error:
> > +	free(desc);
> > +	return ret;
> > +}
> > +
> > +static char *synthesize_sdt_probe_command(struct sdt_note *note,
> > +					const char *pathname,
> > +					const char *sdtgrp)
> > +{
> > +	struct strbuf buf;
> > +	char *ret = NULL, **args;
> > +	int i, args_count;
> > +
> > +	if (strbuf_init(&buf, 32) < 0)
> > +		return NULL;
> > +
> > +	if (strbuf_addf(&buf, "p:%s/%s %s:0x%llx",
> > +				sdtgrp, note->name, pathname,
> > +				sdt_note__get_addr(note)) < 0)
> > +		goto error;
> > +
> > +	if (!note->args)
> > +		goto out;
> > +
> > +	if (note->args) {
> > +		args = argv_split(note->args, &args_count);
> > +
> > +		for (i = 0; i < args_count; ++i) {
> > +			if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
> > +				goto error;
> > +		}
> > +	}
> > +
> > +out:
> > +	ret = strbuf_detach(&buf, NULL);
> > +error:
> > +	strbuf_release(&buf);
> > +	return ret;
> > +}
> > +
> >  int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
> >  {
> >  	struct probe_cache_entry *entry = NULL;
> > @@ -723,11 +883,12 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
> >  			entry->pev.group = strdup(sdtgrp);
> >  			list_add_tail(&entry->node, &pcache->entries);
> >  		}
> > -		ret = asprintf(&buf, "p:%s/%s %s:0x%llx",
> > -				sdtgrp, note->name, pathname,
> > -				sdt_note__get_addr(note));
> > -		if (ret < 0)
> > +		buf = synthesize_sdt_probe_command(note, pathname, sdtgrp);
> > +		if (!buf) {
> > +			ret = -ENOMEM;
> >  			break;
> > +		}
> > +
> >  		strlist__add(entry->tevlist, buf);
> >  		free(buf);
> >  		entry = NULL;
> > -- 
> > 2.10.2
> > 
> 
> 
> -- 
> Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2016-12-09 15:14 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16 23:55 [PATCH 0/2] perf: add support of SDT probes arguments Alexis Berlemont
2016-11-16 23:56 ` [PATCH 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont
2016-11-16 23:56 ` [PATCH 2/2] perf probe: add sdt probes arguments into the uprobe cmd string Alexis Berlemont
2016-11-17  9:04   ` Hemant Kumar
2016-11-18 23:56     ` [PATCH v2 0/2] " Alexis Berlemont
2016-11-18 23:56     ` [PATCH v2 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont
2016-11-25 14:40       ` Arnaldo Carvalho de Melo
2016-11-26  0:58         ` [PATCH v4 0/2] perf probe: add sdt probes arguments into the uprobe cmd string Alexis Berlemont
2016-12-05 23:42           ` Alexis Berlemont
2016-12-06 14:45             ` Arnaldo Carvalho de Melo
2016-11-26  0:58         ` [PATCH v4 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont
2016-12-07  2:44           ` Masami Hiramatsu
2016-11-26  0:58         ` [PATCH v4 2/2] perf probe: add sdt probes arguments into the uprobe cmd string Alexis Berlemont
2016-12-07  3:26           ` Masami Hiramatsu
2016-12-09 15:14             ` Arnaldo Carvalho de Melo [this message]
2016-12-10 10:00               ` Masami Hiramatsu
2016-12-14  0:07             ` [PATCH v5 0/2] " Alexis Berlemont
2016-12-14  7:36               ` Ingo Molnar
2017-01-23 11:23                 ` Ravi Bangoria
2017-02-22 22:41                   ` Alexis Berlemont
2017-01-24  6:58                 ` Ravi Bangoria
2017-01-24  8:22                   ` Ingo Molnar
2017-01-24  8:36                     ` Ravi Bangoria
2017-02-02 11:11               ` [PATCH 0/5] perf/sdt: Argument support for x86 and powepc Ravi Bangoria
2017-02-02 11:11                 ` [PATCH 1/5] perf/sdt: Show proper hint Ravi Bangoria
2017-02-02 13:40                   ` Ingo Molnar
2017-02-02 16:20                     ` Arnaldo Carvalho de Melo
2017-02-03 10:26                       ` [PATCH v2] " Ravi Bangoria
2017-02-03 15:18                         ` Arnaldo Carvalho de Melo
2017-02-07  7:53                           ` Ingo Molnar
2017-02-07 15:50                             ` Arnaldo Carvalho de Melo
2017-02-07  8:00                           ` Ingo Molnar
2017-02-16 10:16                           ` [RFC] perf/sdt: Directly record SDT event with 'perf record' Ravi Bangoria
2017-02-20  7:08                             ` Ingo Molnar
2017-02-20  8:21                               ` Ravi Bangoria
2017-02-20  8:42                                 ` Ingo Molnar
2017-02-20 11:01                                   ` Ravi Bangoria
2017-02-20 14:11                                     ` Arnaldo Carvalho de Melo
2017-02-23  8:13                                       ` Ravi Bangoria
2017-02-23 12:48                                         ` Arnaldo Carvalho de Melo
2017-02-07  1:13                         ` [PATCH v2] perf/sdt: Show proper hint Masami Hiramatsu
2017-02-10  7:44                         ` [tip:perf/core] perf sdt: Show proper hint when event not yet in place via 'perf probe' tip-bot for Ravi Bangoria
2017-02-02 11:11                 ` [PATCH 2/5] perf/sdt/x86: Add renaming logic for rNN and other registers Ravi Bangoria
2017-02-07  3:11                   ` Masami Hiramatsu
2017-03-21 14:08                     ` Arnaldo Carvalho de Melo
2017-03-24 18:45                   ` [tip:perf/core] perf sdt x86: " tip-bot for Ravi Bangoria
2017-02-02 11:11                 ` [PATCH 3/5] perf/sdt/x86: Move OP parser to tools/perf/arch/x86/ Ravi Bangoria
2017-02-07  3:11                   ` Masami Hiramatsu
2017-02-07  5:22                     ` Ravi Bangoria
2017-03-21 14:10                       ` Arnaldo Carvalho de Melo
2017-03-21 23:00                         ` Masami Hiramatsu
2017-03-22 11:22                           ` Arnaldo Carvalho de Melo
2017-03-21 14:55                   ` Masami Hiramatsu
2017-02-02 11:11                 ` [PATCH 4/5] perf/sdt/powerpc: Add argument support Ravi Bangoria
2017-02-02 11:11                 ` [PATCH 5/5] perf/probe: Change MAX_CMDLEN Ravi Bangoria
2017-02-07  1:40                   ` Masami Hiramatsu
2017-02-07  5:45                     ` [PATCH v2] " Ravi Bangoria
2017-03-21  5:19                       ` Masami Hiramatsu
2017-03-21 13:37                         ` Arnaldo Carvalho de Melo
2017-03-24 18:43                       ` [tip:perf/core] perf probe: " tip-bot for Ravi Bangoria
2017-02-07  2:55                 ` [PATCH 0/5] perf/sdt: Argument support for x86 and powepc Masami Hiramatsu
2017-03-06  7:53                   ` Ravi Bangoria
2017-03-06 13:42                     ` Masami Hiramatsu
2017-03-21  5:08               ` [PATCH v5 0/2] perf probe: add sdt probes arguments into the uprobe cmd string Masami Hiramatsu
2016-12-14  0:07             ` [PATCH v5 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont
2017-03-06 13:39               ` Masami Hiramatsu
2017-03-21 13:52                 ` Arnaldo Carvalho de Melo
2017-03-24 18:44               ` [tip:perf/core] perf sdt: Add scanning of sdt probes arguments tip-bot for Alexis Berlemont
2016-12-14  0:07             ` [PATCH v5 2/2] perf probe: add sdt probes arguments into the uprobe cmd string Alexis Berlemont
2017-01-24  8:50               ` Ravi Bangoria
2017-03-06 17:23               ` Masami Hiramatsu
2017-03-24 18:44               ` [tip:perf/core] perf probe: Add " tip-bot for Alexis Berlemont
2016-11-18 23:56     ` [PATCH v2 2/2] perf probe: add " Alexis Berlemont
2016-11-21 10:25       ` Hemant Kumar
2016-11-24 23:13         ` [PATCH v3 0/2] " Alexis Berlemont
2016-11-24 23:13         ` [PATCH v3 1/2] perf sdt: add scanning of sdt probles arguments Alexis Berlemont
2016-11-24 23:13         ` [PATCH v3 2/2] perf probe: add sdt probes arguments into the uprobe cmd string Alexis Berlemont

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=20161209151430.GN8257@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexis.berlemont@gmail.com \
    --cc=hemant@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).