All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] perf tests: take into account address of each objdump line
@ 2015-09-02  8:19 Jan Stancek
  2015-09-02  8:19 ` [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks Jan Stancek
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Jan Stancek @ 2015-09-02  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

objdump output can contain repeated bytes. At the moment test reads
all output sequentially, assuming each address is represented in
output only once:

  ffffffff8164efb3 <retint_swapgs+0x9>:
  ffffffff8164efb3:  c1 5d 00 eb        rcrl   $0xeb,0x0(%rbp)
  ffffffff8164efb7:  00 4c 8b 5c        add    %cl,0x5c(%rbx,%rcx,4)

  ffffffff8164efb8 <restore_c_regs_and_iret>:
  ffffffff8164efb8:  4c 8b 5c 24 30     mov    0x30(%rsp),%r11
  ffffffff8164efbd:  4c 8b 54 24 38     mov    0x38(%rsp),%r10

Store objdump output to buffer according to offset calculated
from address on each line.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 51 ++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 13 deletions(-)

Changes in v2:
  patch split into series

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 39c784a100a9..38ee90bc2228 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -33,20 +33,20 @@ static unsigned int hex(char c)
 	return c - 'A' + 10;
 }
 
-static void read_objdump_line(const char *line, size_t line_len, void **buf,
-			      size_t *len)
+static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
+			      size_t len)
 {
 	const char *p;
-	size_t i;
+	size_t i, j = 0;
 
 	/* Skip to a colon */
 	p = strchr(line, ':');
 	if (!p)
-		return;
+		return 0;
 	i = p + 1 - line;
 
 	/* Read bytes */
-	while (*len) {
+	while (j < len) {
 		char c1, c2;
 
 		/* Skip spaces */
@@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf,
 		if (i < line_len && line[i] && !isspace(line[i]))
 			break;
 		/* Store byte */
-		*(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);
-		*buf += 1;
-		*len -= 1;
+		*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
+		buf += 1;
+		j++;
 	}
+	/* return number of successfully read bytes */
+	return j;
 }
 
-static int read_objdump_output(FILE *f, void **buf, size_t *len)
+static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 {
 	char *line = NULL;
-	size_t line_len;
+	size_t line_len, off_last = 0;
 	ssize_t ret;
 	int err = 0;
+	u64 addr;
+
+	while (off_last < *len) {
+		size_t off, read_bytes, written_bytes;
+		unsigned char tmp[BUFSZ];
 
-	while (1) {
 		ret = getline(&line, &line_len, f);
 		if (feof(f))
 			break;
@@ -87,9 +93,28 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len)
 			err = -1;
 			break;
 		}
-		read_objdump_line(line, ret, buf, len);
+
+		/* read objdump data into temporary buffer */
+		read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
+		if (!read_bytes)
+			continue;
+
+		if (sscanf(line, "%"PRIx64, &addr) != 1)
+			continue;
+
+		/* copy it from temporary buffer to 'buf' according
+		 * to address on current objdump line */
+		off = addr - start_addr;
+		if (off >= *len)
+			break;
+		written_bytes = MIN(read_bytes, *len - off);
+		memcpy(buf + off, tmp, written_bytes);
+		off_last = off + written_bytes;
 	}
 
+	/* len returns number of bytes that could not be read */
+	*len -= off_last;
+
 	free(line);
 
 	return err;
@@ -120,7 +145,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 		return -1;
 	}
 
-	ret = read_objdump_output(f, &buf, &len);
+	ret = read_objdump_output(f, buf, &len, addr);
 	if (len) {
 		pr_debug("objdump read too few bytes\n");
 		if (!ret)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
@ 2015-09-02  8:19 ` Jan Stancek
  2015-09-03  9:11   ` Adrian Hunter
  2015-09-02  8:19 ` [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections Jan Stancek
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Jan Stancek @ 2015-09-02  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

Add -z parameter to avoid skipping zero blocks:

 ffffffff816704fe <sysret_check+0x4b>:
 ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
       ...
 ffffffff81670501 <sysret_careful>:
 ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
 ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 38ee90bc2228..375ba30e4ed0 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -128,7 +128,8 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	FILE *f;
 	int ret;
 
-	fmt = "%s -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
+	fmt = "%s -z -d --start-address=0x%"PRIx64\
+		" --stop-address=0x%"PRIx64" %s";
 	ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
 		       filename);
 	if (ret <= 0 || (size_t)ret >= sizeof(cmd))
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections
  2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
  2015-09-02  8:19 ` [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks Jan Stancek
@ 2015-09-02  8:19 ` Jan Stancek
  2015-09-03  9:12   ` Adrian Hunter
  2015-09-15  6:58   ` [tip:perf/core] perf tests: Stop " tip-bot for Jan Stancek
  2015-09-02  8:19 ` [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match Jan Stancek
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 19+ messages in thread
From: Jan Stancek @ 2015-09-02  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

objdump output can span across multiple sections:

  Disassembly of section .text:
    0000000000000008 <crc32c+0x8>:
       8:       48 89 e5                mov    %rsp,%rbp
       b:       53                      push   %rbx
       c:       8b 01                   mov    (%rcx),%eax
    <snip>
      6b:       90                      nop

  Disassembly of section .init.text:
    0000000000000008 <init_module+0x8>:
       8:       00 00                   add    %al,(%rax)
       a:       00 00                   add    %al,(%rax)
       c:       48 89 e5

Stop further reading if address starts going backwards,
assuming we crossed sections.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 375ba30e4ed0..e6bf47ff7e91 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -79,7 +79,7 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 	size_t line_len, off_last = 0;
 	ssize_t ret;
 	int err = 0;
-	u64 addr;
+	u64 addr, last_addr = start_addr;
 
 	while (off_last < *len) {
 		size_t off, read_bytes, written_bytes;
@@ -101,6 +101,11 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 
 		if (sscanf(line, "%"PRIx64, &addr) != 1)
 			continue;
+		if (addr < last_addr) {
+			pr_debug("addr going backwards, read beyond section?\n");
+			break;
+		}
+		last_addr = addr;
 
 		/* copy it from temporary buffer to 'buf' according
 		 * to address on current objdump line */
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match
  2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
  2015-09-02  8:19 ` [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks Jan Stancek
  2015-09-02  8:19 ` [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections Jan Stancek
@ 2015-09-02  8:19 ` Jan Stancek
  2015-09-03  9:12   ` Adrian Hunter
  2015-09-15  6:58   ` [tip:perf/core] perf tests: Print objdump/dso buffers if they don 't match tip-bot for Jan Stancek
  2015-09-03  9:08 ` [PATCH v2 1/4] perf tests: take into account address of each objdump line Adrian Hunter
  2015-09-15  6:57 ` [tip:perf/core] perf tests: Take " tip-bot for Jan Stancek
  4 siblings, 2 replies; 19+ messages in thread
From: Jan Stancek @ 2015-09-02  8:19 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index e6bf47ff7e91..53a04f899d18 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -163,6 +163,18 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	return ret;
 }
 
+static void dump_buf(unsigned char *buf, size_t len)
+{
+	size_t i;
+
+	for (i = 0; i < len; i++) {
+		pr_debug("0x%02x ", buf[i]);
+		if (i % 16 == 15)
+			pr_debug("\n");
+	}
+	pr_debug("\n");
+}
+
 static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			    struct thread *thread, struct state *state)
 {
@@ -265,6 +277,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 	/* The results should be identical */
 	if (memcmp(buf1, buf2, len)) {
 		pr_debug("Bytes read differ from those read by objdump\n");
+		pr_debug("buf1 (dso):\n");
+		dump_buf(buf1, len);
+		pr_debug("buf2 (objdump):\n");
+		dump_buf(buf2, len);
 		return -1;
 	}
 	pr_debug("Bytes read match those read by objdump\n");
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/4] perf tests: take into account address of each objdump line
  2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
                   ` (2 preceding siblings ...)
  2015-09-02  8:19 ` [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match Jan Stancek
@ 2015-09-03  9:08 ` Adrian Hunter
  2015-09-03 11:23   ` [PATCH v3 " Jan Stancek
  2015-09-15  6:57 ` [tip:perf/core] perf tests: Take " tip-bot for Jan Stancek
  4 siblings, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03  9:08 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 02/09/15 11:19, Jan Stancek wrote:
> objdump output can contain repeated bytes. At the moment test reads
> all output sequentially, assuming each address is represented in
> output only once:
> 
>   ffffffff8164efb3 <retint_swapgs+0x9>:
>   ffffffff8164efb3:  c1 5d 00 eb        rcrl   $0xeb,0x0(%rbp)
>   ffffffff8164efb7:  00 4c 8b 5c        add    %cl,0x5c(%rbx,%rcx,4)
> 
>   ffffffff8164efb8 <restore_c_regs_and_iret>:
>   ffffffff8164efb8:  4c 8b 5c 24 30     mov    0x30(%rsp),%r11
>   ffffffff8164efbd:  4c 8b 54 24 38     mov    0x38(%rsp),%r10
> 
> Store objdump output to buffer according to offset calculated
> from address on each line.
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>

Apart from a couple of nitpicks below:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/tests/code-reading.c | 51 ++++++++++++++++++++++++++++++-----------
>  1 file changed, 38 insertions(+), 13 deletions(-)
> 
> Changes in v2:
>   patch split into series
> 
> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
> index 39c784a100a9..38ee90bc2228 100644
> --- a/tools/perf/tests/code-reading.c
> +++ b/tools/perf/tests/code-reading.c
> @@ -33,20 +33,20 @@ static unsigned int hex(char c)
>  	return c - 'A' + 10;
>  }
>  
> -static void read_objdump_line(const char *line, size_t line_len, void **buf,
> -			      size_t *len)
> +static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
> +			      size_t len)

Some (e.g. checkpatch) suggest that alignment should match open parenthesis

>  {
>  	const char *p;
> -	size_t i;
> +	size_t i, j = 0;
>  
>  	/* Skip to a colon */
>  	p = strchr(line, ':');
>  	if (!p)
> -		return;
> +		return 0;
>  	i = p + 1 - line;
>  
>  	/* Read bytes */
> -	while (*len) {
> +	while (j < len) {
>  		char c1, c2;
>  
>  		/* Skip spaces */
> @@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf,
>  		if (i < line_len && line[i] && !isspace(line[i]))
>  			break;
>  		/* Store byte */
> -		*(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);
> -		*buf += 1;
> -		*len -= 1;
> +		*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
> +		buf += 1;
> +		j++;
>  	}
> +	/* return number of successfully read bytes */
> +	return j;
>  }
>  
> -static int read_objdump_output(FILE *f, void **buf, size_t *len)
> +static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
>  {
>  	char *line = NULL;
> -	size_t line_len;
> +	size_t line_len, off_last = 0;
>  	ssize_t ret;
>  	int err = 0;
> +	u64 addr;
> +
> +	while (off_last < *len) {
> +		size_t off, read_bytes, written_bytes;
> +		unsigned char tmp[BUFSZ];
>  
> -	while (1) {
>  		ret = getline(&line, &line_len, f);
>  		if (feof(f))
>  			break;
> @@ -87,9 +93,28 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len)
>  			err = -1;
>  			break;
>  		}
> -		read_objdump_line(line, ret, buf, len);
> +
> +		/* read objdump data into temporary buffer */
> +		read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
> +		if (!read_bytes)
> +			continue;
> +
> +		if (sscanf(line, "%"PRIx64, &addr) != 1)
> +			continue;
> +
> +		/* copy it from temporary buffer to 'buf' according
> +		 * to address on current objdump line */

The preferred style for long (multi-line) comments is:

		/*
		 * Copy it from temporary buffer to 'buf' according
		 * to address on current objdump line.
		 */

> +		off = addr - start_addr;
> +		if (off >= *len)
> +			break;
> +		written_bytes = MIN(read_bytes, *len - off);

We don't use MIN.  Use min() instead.

> +		memcpy(buf + off, tmp, written_bytes);
> +		off_last = off + written_bytes;
>  	}
>  
> +	/* len returns number of bytes that could not be read */
> +	*len -= off_last;
> +
>  	free(line);
>  
>  	return err;
> @@ -120,7 +145,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
>  		return -1;
>  	}
>  
> -	ret = read_objdump_output(f, &buf, &len);
> +	ret = read_objdump_output(f, buf, &len, addr);
>  	if (len) {
>  		pr_debug("objdump read too few bytes\n");
>  		if (!ret)
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-02  8:19 ` [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks Jan Stancek
@ 2015-09-03  9:11   ` Adrian Hunter
  2015-09-03 11:23     ` [PATCH v3 " Jan Stancek
  0 siblings, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03  9:11 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 02/09/15 11:19, Jan Stancek wrote:
> Add -z parameter to avoid skipping zero blocks:
> 
>  ffffffff816704fe <sysret_check+0x4b>:
>  ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
>        ...
>  ffffffff81670501 <sysret_careful>:
>  ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
>  ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>

Apart from nitpick below:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/tests/code-reading.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
> index 38ee90bc2228..375ba30e4ed0 100644
> --- a/tools/perf/tests/code-reading.c
> +++ b/tools/perf/tests/code-reading.c
> @@ -128,7 +128,8 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
>  	FILE *f;
>  	int ret;
>  
> -	fmt = "%s -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
> +	fmt = "%s -z -d --start-address=0x%"PRIx64\

The line continuation is not needed but we are not that religious about long
lines especially if they contain string literals, so you could just make it
one line.

> +		" --stop-address=0x%"PRIx64" %s";
>  	ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
>  		       filename);
>  	if (ret <= 0 || (size_t)ret >= sizeof(cmd))
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections
  2015-09-02  8:19 ` [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections Jan Stancek
@ 2015-09-03  9:12   ` Adrian Hunter
  2015-09-15  6:58   ` [tip:perf/core] perf tests: Stop " tip-bot for Jan Stancek
  1 sibling, 0 replies; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03  9:12 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 02/09/15 11:19, Jan Stancek wrote:
> objdump output can span across multiple sections:
> 
>   Disassembly of section .text:
>     0000000000000008 <crc32c+0x8>:
>        8:       48 89 e5                mov    %rsp,%rbp
>        b:       53                      push   %rbx
>        c:       8b 01                   mov    (%rcx),%eax
>     <snip>
>       6b:       90                      nop
> 
>   Disassembly of section .init.text:
>     0000000000000008 <init_module+0x8>:
>        8:       00 00                   add    %al,(%rax)
>        a:       00 00                   add    %al,(%rax)
>        c:       48 89 e5
> 
> Stop further reading if address starts going backwards,
> assuming we crossed sections.
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>


Acked-by: Adrian Hunter <adrian.hunter@intel.com>


> ---
>  tools/perf/tests/code-reading.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
> index 375ba30e4ed0..e6bf47ff7e91 100644
> --- a/tools/perf/tests/code-reading.c
> +++ b/tools/perf/tests/code-reading.c
> @@ -79,7 +79,7 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
>  	size_t line_len, off_last = 0;
>  	ssize_t ret;
>  	int err = 0;
> -	u64 addr;
> +	u64 addr, last_addr = start_addr;
>  
>  	while (off_last < *len) {
>  		size_t off, read_bytes, written_bytes;
> @@ -101,6 +101,11 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
>  
>  		if (sscanf(line, "%"PRIx64, &addr) != 1)
>  			continue;
> +		if (addr < last_addr) {
> +			pr_debug("addr going backwards, read beyond section?\n");
> +			break;
> +		}
> +		last_addr = addr;
>  
>  		/* copy it from temporary buffer to 'buf' according
>  		 * to address on current objdump line */
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match
  2015-09-02  8:19 ` [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match Jan Stancek
@ 2015-09-03  9:12   ` Adrian Hunter
  2015-09-15  6:58   ` [tip:perf/core] perf tests: Print objdump/dso buffers if they don 't match tip-bot for Jan Stancek
  1 sibling, 0 replies; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03  9:12 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 02/09/15 11:19, Jan Stancek wrote:
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>


Acked-by: Adrian Hunter <adrian.hunter@intel.com>


> ---
>  tools/perf/tests/code-reading.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
> index e6bf47ff7e91..53a04f899d18 100644
> --- a/tools/perf/tests/code-reading.c
> +++ b/tools/perf/tests/code-reading.c
> @@ -163,6 +163,18 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
>  	return ret;
>  }
>  
> +static void dump_buf(unsigned char *buf, size_t len)
> +{
> +	size_t i;
> +
> +	for (i = 0; i < len; i++) {
> +		pr_debug("0x%02x ", buf[i]);
> +		if (i % 16 == 15)
> +			pr_debug("\n");
> +	}
> +	pr_debug("\n");
> +}
> +
>  static int read_object_code(u64 addr, size_t len, u8 cpumode,
>  			    struct thread *thread, struct state *state)
>  {
> @@ -265,6 +277,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
>  	/* The results should be identical */
>  	if (memcmp(buf1, buf2, len)) {
>  		pr_debug("Bytes read differ from those read by objdump\n");
> +		pr_debug("buf1 (dso):\n");
> +		dump_buf(buf1, len);
> +		pr_debug("buf2 (objdump):\n");
> +		dump_buf(buf2, len);
>  		return -1;
>  	}
>  	pr_debug("Bytes read match those read by objdump\n");
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 1/4] perf tests: take into account address of each objdump line
  2015-09-03  9:08 ` [PATCH v2 1/4] perf tests: take into account address of each objdump line Adrian Hunter
@ 2015-09-03 11:23   ` Jan Stancek
  2015-09-03 11:35     ` Adrian Hunter
  0 siblings, 1 reply; 19+ messages in thread
From: Jan Stancek @ 2015-09-03 11:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

objdump output can contain repeated bytes. At the moment test reads
all output sequentially, assuming each address is represented in
output only once:

  ffffffff8164efb3 <retint_swapgs+0x9>:
  ffffffff8164efb3:  c1 5d 00 eb        rcrl   $0xeb,0x0(%rbp)
  ffffffff8164efb7:  00 4c 8b 5c        add    %cl,0x5c(%rbx,%rcx,4)

  ffffffff8164efb8 <restore_c_regs_and_iret>:
  ffffffff8164efb8:  4c 8b 5c 24 30     mov    0x30(%rsp),%r11
  ffffffff8164efbd:  4c 8b 54 24 38     mov    0x38(%rsp),%r10

Store objdump output to buffer according to offset calculated
from address on each line.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 53 +++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 13 deletions(-)

Changes in v3:
  align read_objdump_line parameters on 2nd line
  fix multiline comment
  replace MIN with min

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 39c784a100a9..7fd7ebc0b692 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -33,20 +33,20 @@ static unsigned int hex(char c)
 	return c - 'A' + 10;
 }
 
-static void read_objdump_line(const char *line, size_t line_len, void **buf,
-			      size_t *len)
+static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
+				size_t len)
 {
 	const char *p;
-	size_t i;
+	size_t i, j = 0;
 
 	/* Skip to a colon */
 	p = strchr(line, ':');
 	if (!p)
-		return;
+		return 0;
 	i = p + 1 - line;
 
 	/* Read bytes */
-	while (*len) {
+	while (j < len) {
 		char c1, c2;
 
 		/* Skip spaces */
@@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf,
 		if (i < line_len && line[i] && !isspace(line[i]))
 			break;
 		/* Store byte */
-		*(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);
-		*buf += 1;
-		*len -= 1;
+		*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
+		buf += 1;
+		j++;
 	}
+	/* return number of successfully read bytes */
+	return j;
 }
 
-static int read_objdump_output(FILE *f, void **buf, size_t *len)
+static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 {
 	char *line = NULL;
-	size_t line_len;
+	size_t line_len, off_last = 0;
 	ssize_t ret;
 	int err = 0;
+	u64 addr;
+
+	while (off_last < *len) {
+		size_t off, read_bytes, written_bytes;
+		unsigned char tmp[BUFSZ];
 
-	while (1) {
 		ret = getline(&line, &line_len, f);
 		if (feof(f))
 			break;
@@ -87,9 +93,30 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len)
 			err = -1;
 			break;
 		}
-		read_objdump_line(line, ret, buf, len);
+
+		/* read objdump data into temporary buffer */
+		read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
+		if (!read_bytes)
+			continue;
+
+		if (sscanf(line, "%"PRIx64, &addr) != 1)
+			continue;
+
+		/*
+		 * Copy it from temporary buffer to 'buf' according
+		 * to address on current objdump line.
+		 */
+		off = addr - start_addr;
+		if (off >= *len)
+			break;
+		written_bytes = min(read_bytes, *len - off);
+		memcpy(buf + off, tmp, written_bytes);
+		off_last = off + written_bytes;
 	}
 
+	/* len returns number of bytes that could not be read */
+	*len -= off_last;
+
 	free(line);
 
 	return err;
@@ -120,7 +147,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 		return -1;
 	}
 
-	ret = read_objdump_output(f, &buf, &len);
+	ret = read_objdump_output(f, buf, &len, addr);
 	if (len) {
 		pr_debug("objdump read too few bytes\n");
 		if (!ret)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-03  9:11   ` Adrian Hunter
@ 2015-09-03 11:23     ` Jan Stancek
  2015-09-03 11:35       ` Adrian Hunter
  2015-09-15  6:58       ` [tip:perf/core] perf tests: Make " tip-bot for Jan Stancek
  0 siblings, 2 replies; 19+ messages in thread
From: Jan Stancek @ 2015-09-03 11:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, jolsa, adrian.hunter, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra, jstancek

Add -z parameter to avoid skipping zero blocks:

 ffffffff816704fe <sysret_check+0x4b>:
 ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
       ...
 ffffffff81670501 <sysret_careful>:
 ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
 ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/tests/code-reading.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Changes in v3:
  don't split the string to multiple lines

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 7fd7ebc0b692..bbca3ce2ecef 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -130,7 +130,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	FILE *f;
 	int ret;
 
-	fmt = "%s -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
+	fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
 	ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
 		       filename);
 	if (ret <= 0 || (size_t)ret >= sizeof(cmd))
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 1/4] perf tests: take into account address of each objdump line
  2015-09-03 11:23   ` [PATCH v3 " Jan Stancek
@ 2015-09-03 11:35     ` Adrian Hunter
  0 siblings, 0 replies; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03 11:35 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 03/09/15 14:23, Jan Stancek wrote:
> objdump output can contain repeated bytes. At the moment test reads
> all output sequentially, assuming each address is represented in
> output only once:
> 
>   ffffffff8164efb3 <retint_swapgs+0x9>:
>   ffffffff8164efb3:  c1 5d 00 eb        rcrl   $0xeb,0x0(%rbp)
>   ffffffff8164efb7:  00 4c 8b 5c        add    %cl,0x5c(%rbx,%rcx,4)
> 
>   ffffffff8164efb8 <restore_c_regs_and_iret>:
>   ffffffff8164efb8:  4c 8b 5c 24 30     mov    0x30(%rsp),%r11
>   ffffffff8164efbd:  4c 8b 54 24 38     mov    0x38(%rsp),%r10
> 
> Store objdump output to buffer according to offset calculated
> from address on each line.
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> ---
>  tools/perf/tests/code-reading.c | 53 +++++++++++++++++++++++++++++++----------
>  1 file changed, 40 insertions(+), 13 deletions(-)
> 
> Changes in v3:
>   align read_objdump_line parameters on 2nd line
>   fix multiline comment
>   replace MIN with min
> 

Acked-by: Adrian Hunter <adrian.hunter@intel.com>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-03 11:23     ` [PATCH v3 " Jan Stancek
@ 2015-09-03 11:35       ` Adrian Hunter
  2015-09-03 15:14         ` Arnaldo Carvalho de Melo
  2015-09-15  6:58       ` [tip:perf/core] perf tests: Make " tip-bot for Jan Stancek
  1 sibling, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2015-09-03 11:35 UTC (permalink / raw)
  To: Jan Stancek
  Cc: linux-kernel, acme, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

On 03/09/15 14:23, Jan Stancek wrote:
> Add -z parameter to avoid skipping zero blocks:
> 
>  ffffffff816704fe <sysret_check+0x4b>:
>  ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
>        ...
>  ffffffff81670501 <sysret_careful>:
>  ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
>  ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> ---
>  tools/perf/tests/code-reading.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Changes in v3:
>   don't split the string to multiple lines
> 

Acked-by: Adrian Hunter <adrian.hunter@intel.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-03 11:35       ` Adrian Hunter
@ 2015-09-03 15:14         ` Arnaldo Carvalho de Melo
  2015-09-03 16:19           ` Jan Stancek
  0 siblings, 1 reply; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-09-03 15:14 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Jan Stancek, linux-kernel, jolsa, dsahern, cjashfor, fweisbec,
	mingo, namhyung, paulus, a.p.zijlstra

Em Thu, Sep 03, 2015 at 02:35:55PM +0300, Adrian Hunter escreveu:
> On 03/09/15 14:23, Jan Stancek wrote:
> > Add -z parameter to avoid skipping zero blocks:
> > 
> >  ffffffff816704fe <sysret_check+0x4b>:
> >  ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
> >        ...
> >  ffffffff81670501 <sysret_careful>:
> >  ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
> >  ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>
> 
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

Ok, I am applying this, but it would be nice to know in which systems,
with which objdump/binutils versions which 'perf test' entry fails, with
the output of such failure.

Jan, can you please provide this info?

- Arnaldo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-03 15:14         ` Arnaldo Carvalho de Melo
@ 2015-09-03 16:19           ` Jan Stancek
  2015-09-03 16:37             ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 19+ messages in thread
From: Jan Stancek @ 2015-09-03 16:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Adrian Hunter
  Cc: linux-kernel, jolsa, dsahern, cjashfor, fweisbec, mingo,
	namhyung, paulus, a.p.zijlstra

[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]

On 09/03/2015 05:14 PM, Arnaldo Carvalho de Melo wrote:
> Em Thu, Sep 03, 2015 at 02:35:55PM +0300, Adrian Hunter escreveu:
>> On 03/09/15 14:23, Jan Stancek wrote:
>>> Add -z parameter to avoid skipping zero blocks:
>>>
>>>  ffffffff816704fe <sysret_check+0x4b>:
>>>  ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
>>>        ...
>>>  ffffffff81670501 <sysret_careful>:
>>>  ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
>>>  ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>
>>
>> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
> 
> Ok, I am applying this, but it would be nice to know in which systems,
> with which objdump/binutils versions which 'perf test' entry fails, with
> the output of such failure.
> 
> Jan, can you please provide this info?

Since my original report last year [1], I've seen it fail many times on
various HW (we run perf tests daily on RHEL). I haven't noticed any pattern
regarding HW it fails on.

Binutils versions go from binutils-2.23.52 to current latest from git.

It was always about "object code reading", from times it was perf test 21,
until now, when it's perf test 23.

I'm attaching examples of test output along with objdump output, that I
just ran on a random system using kernel 4.2.0.

HTH, regards,
Jan

[1] https://lkml.org/lkml/2014/12/11/222


[-- Attachment #2: perf_failures_examples_with_4.2.0.txt --]
[-- Type: text/plain, Size: 8676 bytes --]

HP ProLiant DL360p G8
Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz
kernel 4.2.0

Example 1, binutils-2.23.52
----------------------------

# perf test 23 -v
23: Test object code reading                                 :
--- start ---
test child forked, pid 31014
Looking at the vmlinux_path (7 entries long)
Using /lib/modules/4.2.0/build/vmlinux for symbols
Parsing event 'cycles'
mmap size 528384B
<snip>
Reading object code for memory address: 0xffffffffa001c010
File is: /lib/modules/4.2.0/kernel/lib/libcrc32c.ko
On file address is: 0x80
dso open failed: No such file or directory
Objdump command is: objdump -d --start-address=0x10 --stop-address=0x90 /lib/modules/4.2.0/kernel/lib/libcrc32c.ko
objdump read too few bytes
Reducing len to 120
Bytes read differ from those read by objdump
test child finished with -1
---- end ----
Test object code reading: FAILED!

# objdump -d --start-address=0x10 --stop-address=0x90 /lib/modules/4.2.0/kernel/lib/libcrc32c.ko

/lib/modules/4.2.0/kernel/lib/libcrc32c.ko:     file format elf64-x86-64

Disassembly of section .text:

0000000000000010 <crc32c+0x10>:
  10:   8b 01                   mov    (%rcx),%eax
  12:   48 83 c0 26             add    $0x26,%rax
  16:   48 c1 e8 04             shr    $0x4,%rax
  1a:   48 c1 e0 04             shl    $0x4,%rax
  1e:   48 29 c4                sub    %rax,%rsp
  21:   48 8d 5c 24 07          lea    0x7(%rsp),%rbx
  26:   48 c1 eb 03             shr    $0x3,%rbx
  2a:   48 8d 04 dd 00 00 00    lea    0x0(,%rbx,8),%rax
  31:   00
  32:   89 3c dd 10 00 00 00    mov    %edi,0x10(,%rbx,8)
  39:   48 89 0c dd 00 00 00    mov    %rcx,0x0(,%rbx,8)
  40:   00
  41:   c7 04 dd 08 00 00 00    movl   $0x0,0x8(,%rbx,8)
  48:   00 00 00 00
  4c:   48 89 c7                mov    %rax,%rdi
  4f:   e8 00 00 00 00          callq  54 <crc32c+0x54>
  54:   85 c0                   test   %eax,%eax
  56:   75 0d                   jne    65 <crc32c+0x65>
  58:   8b 04 dd 10 00 00 00    mov    0x10(,%rbx,8),%eax
  5f:   48 8b 5d f8             mov    -0x8(%rbp),%rbx
  63:   c9                      leaveq
  64:   c3                      retq
  65:   0f 0b                   ud2
  67:   90                      nop

Disassembly of section .init.text:

0000000000000010 <init_module+0x10>:
  10:   00 00                   add    %al,(%rax)
  12:   00 00                   add    %al,(%rax)
  14:   31 d2                   xor    %edx,%edx
  16:   48 3d 01 f0 ff ff       cmp    $0xfffffffffffff001,%rax
  1c:   48 89 05 00 00 00 00    mov    %rax,0x0(%rip)        # 23 <init_module+0x23>
  23:   0f 43 d0                cmovae %eax,%edx
  26:   89 d0                   mov    %edx,%eax
  28:   5d                      pop    %rbp
  29:   c3                      retq

Disassembly of section .exit.text:

0000000000000010 <cleanup_module+0x10>:
  10:   00 00                   add    %al,(%rax)
  12:   00 00                   add    %al,(%rax)
  14:   5d                      pop    %rbp
  15:   c3                      retq

Example 2, binutils-2.23.52
----------------------------

# perf test 23 -v
23: Test object code reading                                 :
--- start ---
test child forked, pid 34729
Looking at the vmlinux_path (7 entries long)
Using /lib/modules/4.2.0/build/vmlinux for symbols
Parsing event 'cycles'
mmap size 528384B
<snip>
Reading object code for memory address: 0xffffffff816829ac
File is: /lib/modules/4.2.0/build/vmlinux
On file address is: 0x8829ac
Objdump command is: objdump -d --start-address=0xffffffff816829ac --stop-address=0xffffffff81682a2c /lib/modules/4.2.0/build/vmlinux
Bytes read differ from those read by objdump
test child finished with -1
---- end ----
Test object code reading: FAILED!

# objdump -d --start-address=0xffffffff816829ac --stop-address=0xffffffff81682a2c /lib/modules/4.2.0/build/vmlinux

/lib/modules/4.2.0/build/vmlinux:     file format elf64-x86-64

Disassembly of section .text:

ffffffff816829ac <syscall_return_via_sysret+0x2e>:
ffffffff816829ac:       8c 35 00 ff 15 2b       mov    %?,0x2b15ff00(%rip)        # ffffffffac7e28b2 <__brk_limit+0x2a7e38b2>

ffffffff816829af <opportunistic_sysret_failed>:
ffffffff816829af:       ff 15 2b 8c 35 00       callq  *0x358c2b(%rip)        # ffffffff819db5e0 <pv_cpu_ops+0x120>
ffffffff816829b5:       e9 fe 08 00 00          jmpq   ffffffff816832b8 <restore_c_regs_and_iret>
ffffffff816829ba:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)

ffffffff816829c0 <stub_clone>:
ffffffff816829c0:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff816829c5:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff816829ca:       4c 89 6c 24 18          mov    %r13,0x18(%rsp)
ffffffff816829cf:       4c 89 64 24 20          mov    %r12,0x20(%rsp)
ffffffff816829d4:       48 89 6c 24 28          mov    %rbp,0x28(%rsp)
ffffffff816829d9:       48 89 5c 24 30          mov    %rbx,0x30(%rsp)
ffffffff816829de:       e9 3d e7 9f ff          jmpq   ffffffff81081120 <SyS_clone>
ffffffff816829e3:       66 66 66 66 2e 0f 1f    data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)
ffffffff816829ea:       84 00 00 00 00 00

ffffffff816829f0 <stub_fork>:
ffffffff816829f0:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff816829f5:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff816829fa:       4c 89 6c 24 18          mov    %r13,0x18(%rsp)
ffffffff816829ff:       4c 89 64 24 20          mov    %r12,0x20(%rsp)
ffffffff81682a04:       48 89 6c 24 28          mov    %rbp,0x28(%rsp)
ffffffff81682a09:       48 89 5c 24 30          mov    %rbx,0x30(%rsp)
ffffffff81682a0e:       e9 ad e6 9f ff          jmpq   ffffffff810810c0 <sys_fork>
ffffffff81682a13:       66 66 66 66 2e 0f 1f    data32 data32 data32 nopw %cs:0x0(%rax,%rax,1)
ffffffff81682a1a:       84 00 00 00 00 00

ffffffff81682a20 <stub_vfork>:
ffffffff81682a20:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff81682a25:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff81682a2a:       4c 89 6c 24 18          mov    %r13,0x18(%rsp)


Example 3, latest objdump from git://sourceware.org/git/binutils-gdb.git
HEAD == 1a91555 Fix seg-fault in readelf when scanniing a corrupt binary.
over same data as previous example
--------------------------------------------------------------------------

# ./binutils/objdump -d --start-address=0xffffffff816829ac --stop-address=0xffffffff81682a2c /lib/modules/4.2.0/build/vmlinux

/lib/modules/4.2.0/build/vmlinux:     file format elf64-x86-64

Disassembly of section .text:

ffffffff816829ac <syscall_return_via_sysret+0x2e>:
ffffffff816829ac:       8c                      .byte 0x8c
ffffffff816829ad:       35                      .byte 0x35
        ...

ffffffff816829af <opportunistic_sysret_failed>:
ffffffff816829af:       ff 15 2b 8c 35 00       callq  *0x358c2b(%rip)        # ffffffff819db5e0 <pv_cpu_ops+0x120>
ffffffff816829b5:       e9 fe 08 00 00          jmpq   ffffffff816832b8 <restore_c_regs_and_iret>
ffffffff816829ba:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)

ffffffff816829c0 <stub_clone>:
ffffffff816829c0:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff816829c5:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff816829ca:       4c 89 6c 24 18          mov    %r13,0x18(%rsp)
ffffffff816829cf:       4c 89 64 24 20          mov    %r12,0x20(%rsp)
ffffffff816829d4:       48 89 6c 24 28          mov    %rbp,0x28(%rsp)
ffffffff816829d9:       48 89 5c 24 30          mov    %rbx,0x30(%rsp)
ffffffff816829de:       e9 3d e7 9f ff          jmpq   ffffffff81081120 <SyS_clone>
ffffffff816829e3:       66 66 66 66 2e 0f 1f    data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
ffffffff816829ea:       84 00 00 00 00 00

ffffffff816829f0 <stub_fork>:
ffffffff816829f0:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff816829f5:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff816829fa:       4c 89 6c 24 18          mov    %r13,0x18(%rsp)
ffffffff816829ff:       4c 89 64 24 20          mov    %r12,0x20(%rsp)
ffffffff81682a04:       48 89 6c 24 28          mov    %rbp,0x28(%rsp)
ffffffff81682a09:       48 89 5c 24 30          mov    %rbx,0x30(%rsp)
ffffffff81682a0e:       e9 ad e6 9f ff          jmpq   ffffffff810810c0 <sys_fork>
ffffffff81682a13:       66 66 66 66 2e 0f 1f    data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
ffffffff81682a1a:       84 00 00 00 00 00

ffffffff81682a20 <stub_vfork>:
ffffffff81682a20:       4c 89 7c 24 08          mov    %r15,0x8(%rsp)
ffffffff81682a25:       4c 89 74 24 10          mov    %r14,0x10(%rsp)
ffffffff81682a2a:       4c                      rex.WR
ffffffff81682a2b:       89                      .byte 0x89

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/4] perf tests: make objdump disassemble zero blocks
  2015-09-03 16:19           ` Jan Stancek
@ 2015-09-03 16:37             ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-09-03 16:37 UTC (permalink / raw)
  To: Jan Stancek
  Cc: Adrian Hunter, linux-kernel, jolsa, dsahern, cjashfor, fweisbec,
	mingo, namhyung, paulus, a.p.zijlstra

Em Thu, Sep 03, 2015 at 06:19:04PM +0200, Jan Stancek escreveu:
> On 09/03/2015 05:14 PM, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Sep 03, 2015 at 02:35:55PM +0300, Adrian Hunter escreveu:
> >> On 03/09/15 14:23, Jan Stancek wrote:
> >>> Add -z parameter to avoid skipping zero blocks:
> >>>
> >>>  ffffffff816704fe <sysret_check+0x4b>:
> >>>  ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
> >>>        ...
> >>>  ffffffff81670501 <sysret_careful>:
> >>>  ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
> >>>  ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>
> >>
> >> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
> > 
> > Ok, I am applying this, but it would be nice to know in which systems,
> > with which objdump/binutils versions which 'perf test' entry fails, with
> > the output of such failure.
> > 
> > Jan, can you please provide this info?
> 
> Since my original report last year [1], I've seen it fail many times on

Ok, so it is a longstanding bug and now I have some tool output where it
fails to complement what was in these two patches, thanks, I'll update
it and put it on my next perf/urgent pull request to upstream.

- Arnaldo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tests: Take into account address of each objdump line
  2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
                   ` (3 preceding siblings ...)
  2015-09-03  9:08 ` [PATCH v2 1/4] perf tests: take into account address of each objdump line Adrian Hunter
@ 2015-09-15  6:57 ` tip-bot for Jan Stancek
  4 siblings, 0 replies; 19+ messages in thread
From: tip-bot for Jan Stancek @ 2015-09-15  6:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, linux-kernel, fweisbec, cjashfor, a.p.zijlstra, mingo,
	paulus, tglx, hpa, jolsa, adrian.hunter, namhyung, acme,
	jstancek

Commit-ID:  729a7ed103ae1b04a5c87a5855885e0973161da4
Gitweb:     http://git.kernel.org/tip/729a7ed103ae1b04a5c87a5855885e0973161da4
Author:     Jan Stancek <jstancek@redhat.com>
AuthorDate: Wed, 2 Sep 2015 10:19:14 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Sep 2015 12:50:10 -0300

perf tests: Take into account address of each objdump line

objdump output can contain repeated bytes. At the moment test reads all
output sequentially, assuming each address is represented in output only
once:

  ffffffff8164efb3 <retint_swapgs+0x9>:
  ffffffff8164efb3:  c1 5d 00 eb        rcrl   $0xeb,0x0(%rbp)
  ffffffff8164efb7:  00 4c 8b 5c        add    %cl,0x5c(%rbx,%rcx,4)

  ffffffff8164efb8 <restore_c_regs_and_iret>:
  ffffffff8164efb8:  4c 8b 5c 24 30     mov    0x30(%rsp),%r11
  ffffffff8164efbd:  4c 8b 54 24 38     mov    0x38(%rsp),%r10

Store objdump output to buffer according to offset calculated from
address on each line.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/ad13289a55d6350f7717757c7e32c2d4286402bd.1441181335.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/code-reading.c | 51 ++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 39c784a..38ee90b 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -33,20 +33,20 @@ static unsigned int hex(char c)
 	return c - 'A' + 10;
 }
 
-static void read_objdump_line(const char *line, size_t line_len, void **buf,
-			      size_t *len)
+static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
+			      size_t len)
 {
 	const char *p;
-	size_t i;
+	size_t i, j = 0;
 
 	/* Skip to a colon */
 	p = strchr(line, ':');
 	if (!p)
-		return;
+		return 0;
 	i = p + 1 - line;
 
 	/* Read bytes */
-	while (*len) {
+	while (j < len) {
 		char c1, c2;
 
 		/* Skip spaces */
@@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf,
 		if (i < line_len && line[i] && !isspace(line[i]))
 			break;
 		/* Store byte */
-		*(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);
-		*buf += 1;
-		*len -= 1;
+		*(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
+		buf += 1;
+		j++;
 	}
+	/* return number of successfully read bytes */
+	return j;
 }
 
-static int read_objdump_output(FILE *f, void **buf, size_t *len)
+static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 {
 	char *line = NULL;
-	size_t line_len;
+	size_t line_len, off_last = 0;
 	ssize_t ret;
 	int err = 0;
+	u64 addr;
+
+	while (off_last < *len) {
+		size_t off, read_bytes, written_bytes;
+		unsigned char tmp[BUFSZ];
 
-	while (1) {
 		ret = getline(&line, &line_len, f);
 		if (feof(f))
 			break;
@@ -87,9 +93,28 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len)
 			err = -1;
 			break;
 		}
-		read_objdump_line(line, ret, buf, len);
+
+		/* read objdump data into temporary buffer */
+		read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
+		if (!read_bytes)
+			continue;
+
+		if (sscanf(line, "%"PRIx64, &addr) != 1)
+			continue;
+
+		/* copy it from temporary buffer to 'buf' according
+		 * to address on current objdump line */
+		off = addr - start_addr;
+		if (off >= *len)
+			break;
+		written_bytes = MIN(read_bytes, *len - off);
+		memcpy(buf + off, tmp, written_bytes);
+		off_last = off + written_bytes;
 	}
 
+	/* len returns number of bytes that could not be read */
+	*len -= off_last;
+
 	free(line);
 
 	return err;
@@ -120,7 +145,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 		return -1;
 	}
 
-	ret = read_objdump_output(f, &buf, &len);
+	ret = read_objdump_output(f, buf, &len, addr);
 	if (len) {
 		pr_debug("objdump read too few bytes\n");
 		if (!ret)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tests: Make objdump disassemble zero blocks
  2015-09-03 11:23     ` [PATCH v3 " Jan Stancek
  2015-09-03 11:35       ` Adrian Hunter
@ 2015-09-15  6:58       ` tip-bot for Jan Stancek
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for Jan Stancek @ 2015-09-15  6:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, tglx, dsahern, adrian.hunter, linux-kernel, cjashfor,
	mingo, a.p.zijlstra, hpa, paulus, acme, jolsa, jstancek,
	fweisbec

Commit-ID:  06f679c18fcf414cc8462938466f8361315f18cb
Gitweb:     http://git.kernel.org/tip/06f679c18fcf414cc8462938466f8361315f18cb
Author:     Jan Stancek <jstancek@redhat.com>
AuthorDate: Thu, 3 Sep 2015 13:23:32 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Sep 2015 12:50:11 -0300

perf tests: Make objdump disassemble zero blocks

Add -z parameter to avoid skipping zero blocks:

 ffffffff816704fe <sysret_check+0x4b>:
 ffffffff816704fe:  7b 34         jnp ffffffff81670534 <sysret_signal+0x1c>
       ...
 ffffffff81670501 <sysret_careful>:
 ffffffff81670501:  0f ba e2 03   bt  $0x3,%edx
 ffffffff81670505:  73 11         jae ffffffff81670518 <sysret_signal>

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/130c6267fbdb9af506633a9efa06f3269ff5bd2c.1441275982.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/code-reading.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 38ee90b..c409409 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -128,7 +128,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	FILE *f;
 	int ret;
 
-	fmt = "%s -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
+	fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
 	ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
 		       filename);
 	if (ret <= 0 || (size_t)ret >= sizeof(cmd))

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tests: Stop reading if objdump output crossed sections
  2015-09-02  8:19 ` [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections Jan Stancek
  2015-09-03  9:12   ` Adrian Hunter
@ 2015-09-15  6:58   ` tip-bot for Jan Stancek
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for Jan Stancek @ 2015-09-15  6:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, adrian.hunter, paulus, hpa, fweisbec, tglx,
	cjashfor, a.p.zijlstra, acme, dsahern, mingo, jolsa, jstancek,
	namhyung

Commit-ID:  edfdb7eab0fe5f98f2951598dc679b71bdb3e16b
Gitweb:     http://git.kernel.org/tip/edfdb7eab0fe5f98f2951598dc679b71bdb3e16b
Author:     Jan Stancek <jstancek@redhat.com>
AuthorDate: Wed, 2 Sep 2015 10:19:16 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Sep 2015 12:50:12 -0300

perf tests: Stop reading if objdump output crossed sections

objdump output can span across multiple sections:

  Disassembly of section .text:
    0000000000000008 <crc32c+0x8>:
       8:       48 89 e5                mov    %rsp,%rbp
       b:       53                      push   %rbx
       c:       8b 01                   mov    (%rcx),%eax
    <snip>
      6b:       90                      nop

  Disassembly of section .init.text:
    0000000000000008 <init_module+0x8>:
       8:       00 00                   add    %al,(%rax)
       a:       00 00                   add    %al,(%rax)
       c:       48 89 e5

Stop further reading if an address starts going backwards, assuming we
crossed sections.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/9d1ea95e5f9884fdff1be6f761a2feabef37412c.1441181335.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/code-reading.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index c409409..8145c67 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -79,7 +79,7 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 	size_t line_len, off_last = 0;
 	ssize_t ret;
 	int err = 0;
-	u64 addr;
+	u64 addr, last_addr = start_addr;
 
 	while (off_last < *len) {
 		size_t off, read_bytes, written_bytes;
@@ -101,6 +101,11 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 
 		if (sscanf(line, "%"PRIx64, &addr) != 1)
 			continue;
+		if (addr < last_addr) {
+			pr_debug("addr going backwards, read beyond section?\n");
+			break;
+		}
+		last_addr = addr;
 
 		/* copy it from temporary buffer to 'buf' according
 		 * to address on current objdump line */

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tests: Print objdump/dso buffers if they don 't match
  2015-09-02  8:19 ` [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match Jan Stancek
  2015-09-03  9:12   ` Adrian Hunter
@ 2015-09-15  6:58   ` tip-bot for Jan Stancek
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for Jan Stancek @ 2015-09-15  6:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: fweisbec, mingo, cjashfor, acme, paulus, linux-kernel, tglx,
	jstancek, adrian.hunter, dsahern, namhyung, jolsa, a.p.zijlstra,
	hpa

Commit-ID:  fd405cf6cfddd300377bd5fd9b93d2ff66fbc32d
Gitweb:     http://git.kernel.org/tip/fd405cf6cfddd300377bd5fd9b93d2ff66fbc32d
Author:     Jan Stancek <jstancek@redhat.com>
AuthorDate: Wed, 2 Sep 2015 10:19:17 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Sep 2015 12:50:13 -0300

perf tests: Print objdump/dso buffers if they don't match

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/d0f42f786bc0e965918e0f422df25617a12a4021.1441181335.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/code-reading.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 8145c67..2d21183 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -162,6 +162,18 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
 	return ret;
 }
 
+static void dump_buf(unsigned char *buf, size_t len)
+{
+	size_t i;
+
+	for (i = 0; i < len; i++) {
+		pr_debug("0x%02x ", buf[i]);
+		if (i % 16 == 15)
+			pr_debug("\n");
+	}
+	pr_debug("\n");
+}
+
 static int read_object_code(u64 addr, size_t len, u8 cpumode,
 			    struct thread *thread, struct state *state)
 {
@@ -264,6 +276,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 	/* The results should be identical */
 	if (memcmp(buf1, buf2, len)) {
 		pr_debug("Bytes read differ from those read by objdump\n");
+		pr_debug("buf1 (dso):\n");
+		dump_buf(buf1, len);
+		pr_debug("buf2 (objdump):\n");
+		dump_buf(buf2, len);
 		return -1;
 	}
 	pr_debug("Bytes read match those read by objdump\n");

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-09-15  6:59 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02  8:19 [PATCH v2 1/4] perf tests: take into account address of each objdump line Jan Stancek
2015-09-02  8:19 ` [PATCH v2 2/4] perf tests: make objdump disassemble zero blocks Jan Stancek
2015-09-03  9:11   ` Adrian Hunter
2015-09-03 11:23     ` [PATCH v3 " Jan Stancek
2015-09-03 11:35       ` Adrian Hunter
2015-09-03 15:14         ` Arnaldo Carvalho de Melo
2015-09-03 16:19           ` Jan Stancek
2015-09-03 16:37             ` Arnaldo Carvalho de Melo
2015-09-15  6:58       ` [tip:perf/core] perf tests: Make " tip-bot for Jan Stancek
2015-09-02  8:19 ` [PATCH v2 3/4] perf tests: stop reading if objdump output crossed sections Jan Stancek
2015-09-03  9:12   ` Adrian Hunter
2015-09-15  6:58   ` [tip:perf/core] perf tests: Stop " tip-bot for Jan Stancek
2015-09-02  8:19 ` [PATCH v2 4/4] perf tests: print objdump/dso buffers if they don't match Jan Stancek
2015-09-03  9:12   ` Adrian Hunter
2015-09-15  6:58   ` [tip:perf/core] perf tests: Print objdump/dso buffers if they don 't match tip-bot for Jan Stancek
2015-09-03  9:08 ` [PATCH v2 1/4] perf tests: take into account address of each objdump line Adrian Hunter
2015-09-03 11:23   ` [PATCH v3 " Jan Stancek
2015-09-03 11:35     ` Adrian Hunter
2015-09-15  6:57 ` [tip:perf/core] perf tests: Take " tip-bot for Jan Stancek

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.