Skip to contentSkip to conversation

perf/trace: use read() instead of lseek() in trace_event_read.c:skip()

PATCH Applied Tom Zanussi 5 participants 7 messages May 5, 2010 – May 20, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/trace: use read() instead of lseek() in trace_event_read.c:skip()

Hi,

Here's a small fix for a problem affecting live-mode, introduced in the past day or so:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl

Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode. This patch re-implements skip() to use read() instead of lseek() to fix that.

---
 tools/perf/util/trace-event-read.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
tools/perf/util/trace-event-read.c +13 -6
index cb54cd0..f55cc3a 100644
@@ -53,12 +53,6 @@ static unsigned long	page_size;
 static ssize_t calc_data_size;
 static bool repipe;
 
-/* If it fails, the next read will report it */
-static void skip(int size)
-{
-	lseek(input_fd, size, SEEK_CUR);
-}
-
 static int do_read(int fd, void *buf, int size)
 {
 	int rsize = size;
@@ -98,6 +92,19 @@ static int read_or_die(void *data, int size)
 	return r;
 }
 
+/* If it fails, the next read will report it */
+static void skip(int size)
+{
+	char buf[BUFSIZ];
+	int r;
+
+	while (size) {
+		r = size > BUFSIZ ? BUFSIZ : size;
+		read_or_die(buf, r);
+		size -= r;
+	};
+}
+
 static unsigned int read4(void)
 {
 	unsigned int data;
Signature · 1 line
1.6.4.GIT
#1 lore raw

From: Tom Zanussi <[email protected]>
Date: Tue, May 04, 2010 at 11:02:10PM -0500

Hi,

Quoted 7 lines

Here's a small fix for a problem affecting live-mode, introduced in the past day or so:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl
Quoted 8 lines

Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode. This patch re-implements skip() to use read() instead of lseek() to fix that.

has this one landed in any tree in the meantime?

tip/perf/core doesn't have it.

Signature · 5 lines
Regards/Gruss,
Boris.

Operating Systems Research Center
Advanced Micro Devices, Inc.
#2 lore raw
Quoted 19 lines · Borislav Petkov

From: Tom Zanussi <[email protected]>
Date: Tue, May 04, 2010 at 11:02:10PM -0500

Hi,

Quoted 14 lines

Here's a small fix for a problem affecting live-mode, introduced in the past day or so:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl

Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode. This patch re-implements skip() to use read() instead of lseek() to fix that.

Quoted 5 lines
Quoted 1 line

has this one landed in any tree in the meantime?

tip/perf/core doesn't have it.

I forgot to queue it, my bad.

Queued, thanks.

#3 lore raw

[tip:perf/core] perf: Use read() instead of lseek() in trace_event_read.c:skip()

In reply to Tom Zanussi
Commit-ID:  cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Gitweb:     http://git.kernel.org/tip/cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 4 May 2010 23:02:10 -0500
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 20 May 2010 08:37:17 +0200

perf: Use read() instead of lseek() in trace_event_read.c:skip()

This is a small fix for a problem affecting live-mode, introduced recently:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl

Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode. This patch re-implements skip() to use read() instead of lseek() to fix that.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>

LKML-Reference: <1273032130.6383.28.camel@tropicana>

---
 tools/perf/util/trace-event-read.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
tools/perf/util/trace-event-read.c +13 -6
index cb54cd0..f55cc3a 100644
@@ -53,12 +53,6 @@ static unsigned long	page_size;
 static ssize_t calc_data_size;
 static bool repipe;
 
-/* If it fails, the next read will report it */
-static void skip(int size)
-{
-	lseek(input_fd, size, SEEK_CUR);
-}
-
 static int do_read(int fd, void *buf, int size)
 {
 	int rsize = size;
@@ -98,6 +92,19 @@ static int read_or_die(void *data, int size)
 	return r;
 }
 
+/* If it fails, the next read will report it */
+static void skip(int size)
+{
+	char buf[BUFSIZ];
+	int r;
+
+	while (size) {
+		r = size > BUFSIZ ? BUFSIZ : size;
+		read_or_die(buf, r);
+		size -= r;
+	};
+}
+
 static unsigned int read4(void)
 {
 	unsigned int data;
#4 lore raw

Re: [tip:perf/core] perf: Use read() instead of lseek() in trace_event_read.c:skip()

Quoted 16 lines · tip-bot for Tom Zanussi

Commit-ID:  cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Gitweb:     http://git.kernel.org/tip/cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 4 May 2010 23:02:10 -0500
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 20 May 2010 08:37:17 +0200

perf: Use read() instead of lseek() in trace_event_read.c:skip()

This is a small fix for a problem affecting live-mode, introduced recently:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl
Quoted 6 lines

 Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode.  This patch re-implements skip() to use read() instead of lseek() to fix that.

Out of curiosity: why doesn't lseek() work and why can't we fix that?

#5 lore raw

Re: [tip:perf/core] perf: Use read() instead of lseek() in trace_event_read.c:skip()

Quoted 18 lines · Pekka Enberg
Quoted 16 lines · tip-bot for Tom Zanussi

Commit-ID:  cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Gitweb:     http://git.kernel.org/tip/cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 4 May 2010 23:02:10 -0500
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 20 May 2010 08:37:17 +0200

perf: Use read() instead of lseek() in trace_event_read.c:skip()

This is a small fix for a problem affecting live-mode, introduced recently:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl
Quoted 8 lines
Quoted 6 lines

 Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode.  This patch re-implements skip() to use read() instead of lseek() to fix that.

Out of curiosity: why doesn't lseek() work and why can't we fix that?

Because depending on the mode we are, that may or may not work.

We have the normal mode, when the input in a regular file (perf.data) where it works. And we have the pipe mode, where the seek fails.

#6 lore raw

Re: [tip:perf/core] perf: Use read() instead of lseek() in trace_event_read.c:skip()

In reply to Pekka Enberg
Quoted 18 lines · Pekka Enberg
Quoted 16 lines · tip-bot for Tom Zanussi
Commit-ID:  cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Gitweb:     http://git.kernel.org/tip/cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d
Author:     Tom Zanussi <[email protected]>
AuthorDate: Tue, 4 May 2010 23:02:10 -0500
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Thu, 20 May 2010 08:37:17 +0200

perf: Use read() instead of lseek() in trace_event_read.c:skip()

This is a small fix for a problem affecting live-mode, introduced recently:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl
Quoted 8 lines
Quoted 6 lines

Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip() function to skip over e.g. header_page, but this doesn't work for live mode. This patch re-implements skip() to use read() instead of lseek() to fix that.

Out of curiosity: why doesn't lseek() work and why can't we fix that?

Presumably because we're reading from a nonseekable stream?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.