Skip to contentSkip to conversation

perf tool: Fix cross-endian analysis

PATCH Applied David Ahern 4 participants 5 messages Apr 9, 2015 – Apr 11, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tool: Fix cross-endian analysis

Trying to analyze a big endian data file on little endian system fails with the error:
0xa9b40 [0x70]: failed to process type: 9

The problem is that header parsing is not done correctly because the file attributes are not swapped. Make it so. With this patch able to analyze a sparc64 data file on x86_64.

Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/header.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/perf/util/header.c +4 -1
index e38cf62..45b7e72 100644
@@ -2586,8 +2586,11 @@ int perf_session__read_header(struct perf_session *session)
 		if (read_attr(fd, header, &f_attr) < 0)
 			goto out_errno;
 
-		if (header->needs_swap)
+		if (header->needs_swap) {
+			f_attr.ids.size   = bswap_64(f_attr.ids.size);
+			f_attr.ids.offset = bswap_64(f_attr.ids.offset);
 			perf_event__attr_swap(&f_attr.attr);
+		}
 
 		tmp = lseek(fd, 0, SEEK_CUR);
 		evsel = perf_evsel__new(&f_attr.attr);
Signature · 1 line
1.7.1
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · David Ahern

Trying to analyze a big endian data file on little endian system fails with the error:
0xa9b40 [0x70]: failed to process type: 9

The problem is that header parsing is not done correctly because the file attributes are not swapped. Make it so. With this patch able to analyze a sparc64 data file on x86_64.

Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/header.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/perf/util/header.c +0 -0
index e38cf62..45b7e72 100644

tools/perf/util/header.c int perf_session__read_header(struct perf_session *session) · line 2593

Quoted 9 lines
tools/perf/util/header.c +4 -1
@@ -2586,8 +2586,11 @@ int perf_session__read_header(struct perf_session *session)
 		if (read_attr(fd, header, &f_attr) < 0)
 			goto out_errno;
 
-		if (header->needs_swap)
+		if (header->needs_swap) {
+			f_attr.ids.size   = bswap_64(f_attr.ids.size);
+			f_attr.ids.offset = bswap_64(f_attr.ids.offset);
 			perf_event__attr_swap(&f_attr.attr);
+		}

so people do actually use it ;-)

thanks,
jirka

maintainer Applied
#2 lore raw

Em Fri, Apr 10, 2015 at 10:27:26AM +0200, Jiri Olsa escreveu:

Quoted 33 lines · David Ahern
Quoted 20 lines

Trying to analyze a big endian data file on little endian system fails with the error:
0xa9b40 [0x70]: failed to process type: 9

The problem is that header parsing is not done correctly because the file attributes are not swapped. Make it so. With this patch able to analyze a sparc64 data file on x86_64.

Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/header.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/perf/util/header.c +0 -0
index e38cf62..45b7e72 100644

tools/perf/util/header.c int perf_session__read_header(struct perf_session *session) · line 2593

Quoted 9 lines
tools/perf/util/header.c +4 -1
@@ -2586,8 +2586,11 @@ int perf_session__read_header(struct perf_session *session)
 		if (read_attr(fd, header, &f_attr) < 0)
 			goto out_errno;
 
-		if (header->needs_swap)
+		if (header->needs_swap) {
+			f_attr.ids.size   = bswap_64(f_attr.ids.size);
+			f_attr.ids.offset = bswap_64(f_attr.ids.offset);
 			perf_event__attr_swap(&f_attr.attr);
+		}

so people do actually use it ;-)

Quoted 1 line

Thanks, applied.

- Arnaldo

#3 lore raw
In reply to Jiri Olsa
Quoted 1 line · Jiri Olsa

so people do actually use it;-)

not when it's broken :-)

I've had to fix this a few times over the years, but before ppc on x86 with top of tree was not frequent enough. sparc on x86 will be.

#4 lore raw

[tip:perf/core] perf tools: Fix cross-endian analysis

In reply to David Ahern
perf tools: Fix cross-endian analysis
Commit-ID:  1060ab857f64f33a9445881fd31fa91470aeb622
Gitweb:     http://git.kernel.org/tip/1060ab857f64f33a9445881fd31fa91470aeb622
Author:     David Ahern <[email protected]>
AuthorDate: Thu, 9 Apr 2015 16:15:46 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 10 Apr 2015 10:13:58 -0300

perf tools: Fix cross-endian analysis

Trying to analyze a big endian data file on little endian system fails with the error:

0xa9b40 [0x70]: failed to process type: 9

The problem is that header parsing is not done correctly because the file attributes are not swapped. Make it so. With this patch able to analyze a sparc64 data file on x86_64.

---
 tools/perf/util/header.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/header.c +4 -1
index fff3b2a..918fd8a 100644
@@ -2504,8 +2504,11 @@ int perf_session__read_header(struct perf_session *session)
 		if (read_attr(fd, header, &f_attr) < 0)
 			goto out_errno;
 
-		if (header->needs_swap)
+		if (header->needs_swap) {
+			f_attr.ids.size   = bswap_64(f_attr.ids.size);
+			f_attr.ids.offset = bswap_64(f_attr.ids.offset);
 			perf_event__attr_swap(&f_attr.attr);
+		}
 
 		tmp = lseek(fd, 0, SEEK_CUR);
 		evsel = perf_evsel__new(&f_attr.attr);