public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Start the perf.data mapping at data offset in perf trace
@ 2009-10-06 19:17 Frederic Weisbecker
  2009-10-06 19:21 ` [PATCH v2] " Frederic Weisbecker
  0 siblings, 1 reply; 4+ messages in thread
From: Frederic Weisbecker @ 2009-10-06 19:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Mike Galbraith, Paul Mackerras,
	Tom Zanussi

Currently, we are mapping perf.data in the beginning of the file
and use the data offset as a buffer offset. This may exceed the
mapping area if the data offset is upper than page_size * mmap_window
and result in a page fault (thing that happen if we merge trace.info
in perf.data).

Instead, let's start the mapping in the page that matches our data
offset.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/builtin-trace.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 5d4c84d..d9abb4a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -143,12 +143,12 @@ static int __cmd_trace(void)
 	int ret, rc = EXIT_FAILURE;
 	unsigned long offset = 0;
 	unsigned long head = 0;
+	unsigned long shift;
 	struct stat perf_stat;
 	event_t *event;
 	uint32_t size;
 	char *buf;
 
-	trace_report();
 	register_idle_thread(&threads, &last_match);
 
 	input = open(input_name, O_RDONLY);
@@ -180,6 +180,10 @@ static int __cmd_trace(void)
 		return EXIT_FAILURE;
 	}
 
+	shift = page_size * (head / page_size);
+	offset += shift;
+	head -= shift;
+
 remap:
 	buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
 			   MAP_SHARED, input, offset);
@@ -192,9 +196,9 @@ more:
 	event = (event_t *)(buf + head);
 
 	if (head + event->header.size >= page_size * mmap_window) {
-		unsigned long shift = page_size * (head / page_size);
 		int res;
 
+		shift = page_size * (head / page_size);
 		res = munmap(buf, page_size * mmap_window);
 		assert(res == 0);
 
-- 
1.6.2.3


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

* [PATCH v2] perf tools: Start the perf.data mapping at data offset in perf trace
  2009-10-06 19:17 [PATCH] perf tools: Start the perf.data mapping at data offset in perf trace Frederic Weisbecker
@ 2009-10-06 19:21 ` Frederic Weisbecker
  2009-10-06 22:29   ` Frederic Weisbecker
  2009-10-07  7:31   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
  0 siblings, 2 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2009-10-06 19:21 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Frederic Weisbecker, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Mike Galbraith, Paul Mackerras,
	Tom Zanussi

Currently, we are mapping perf.data in the beginning of the file
and use the data offset as a buffer offset. This may exceed the
mapping area if the data offset is upper than page_size * mmap_window
and result in a page fault (thing that happen if we merge trace.info
in perf.data).

Instead, let's start the mapping in the page that matches our data
offset.

v2: Drop a junk from another patch (trace_report() removal)

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/builtin-trace.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 5d4c84d..d573d4e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -143,6 +143,7 @@ static int __cmd_trace(void)
 	int ret, rc = EXIT_FAILURE;
 	unsigned long offset = 0;
 	unsigned long head = 0;
+	unsigned long shift;
 	struct stat perf_stat;
 	event_t *event;
 	uint32_t size;
@@ -180,6 +181,10 @@ static int __cmd_trace(void)
 		return EXIT_FAILURE;
 	}
 
+	shift = page_size * (head / page_size);
+	offset += shift;
+	head -= shift;
+
 remap:
 	buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
 			   MAP_SHARED, input, offset);
@@ -192,9 +197,9 @@ more:
 	event = (event_t *)(buf + head);
 
 	if (head + event->header.size >= page_size * mmap_window) {
-		unsigned long shift = page_size * (head / page_size);
 		int res;
 
+		shift = page_size * (head / page_size);
 		res = munmap(buf, page_size * mmap_window);
 		assert(res == 0);
 
-- 
1.6.2.3


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

* Re: [PATCH v2] perf tools: Start the perf.data mapping at data offset in perf trace
  2009-10-06 19:21 ` [PATCH v2] " Frederic Weisbecker
@ 2009-10-06 22:29   ` Frederic Weisbecker
  2009-10-07  7:31   ` [tip:perf/core] " tip-bot for Frederic Weisbecker
  1 sibling, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2009-10-06 22:29 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Peter Zijlstra, Arnaldo Carvalho de Melo, Mike Galbraith,
	Paul Mackerras, Tom Zanussi

On Tue, Oct 06, 2009 at 09:21:26PM +0200, Frederic Weisbecker wrote:
> Currently, we are mapping perf.data in the beginning of the file
> and use the data offset as a buffer offset. This may exceed the
> mapping area if the data offset is upper than page_size * mmap_window
> and result in a page fault (thing that happen if we merge trace.info
> in perf.data).
> 
> Instead, let's start the mapping in the page that matches our data
> offset.
> 
> v2: Drop a junk from another patch (trace_report() removal)
> 
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Mike Galbraith <efault@gmx.de>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Tom Zanussi <tzanussi@gmail.com>


I just tested the trace.info drop with perf sched, and we have the same bug
with mmap.

I guess we should rather have a common helper to use mmap on perf.data
and rely on a callback to process the events.
I'm putting this in my TODO list.


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

* [tip:perf/core] perf tools: Start the perf.data mapping at data offset in perf trace
  2009-10-06 19:21 ` [PATCH v2] " Frederic Weisbecker
  2009-10-06 22:29   ` Frederic Weisbecker
@ 2009-10-07  7:31   ` tip-bot for Frederic Weisbecker
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Frederic Weisbecker @ 2009-10-07  7:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, paulus, acme, hpa, mingo, tzanussi, efault, peterz,
	fweisbec, tglx, mingo

Commit-ID:  b209aa1f83964d49a332a7b6b818ebede5cdc6ef
Gitweb:     http://git.kernel.org/tip/b209aa1f83964d49a332a7b6b818ebede5cdc6ef
Author:     Frederic Weisbecker <fweisbec@gmail.com>
AuthorDate: Tue, 6 Oct 2009 21:21:26 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 7 Oct 2009 08:36:10 +0200

perf tools: Start the perf.data mapping at data offset in perf trace

Currently, we are mapping perf.data in the beginning of the file
and use the data offset as a buffer offset.

This may exceed the mapping area if the data offset is upper than
page_size * mmap_window and result in a page fault (thing that
happen if we merge trace.info in perf.data).

Instead, let's start the mapping in the page that matches our data
offset.

v2: Drop a junk from another patch (trace_report() removal)

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <1254856886-10348-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-trace.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 5d4c84d..d573d4e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -143,6 +143,7 @@ static int __cmd_trace(void)
 	int ret, rc = EXIT_FAILURE;
 	unsigned long offset = 0;
 	unsigned long head = 0;
+	unsigned long shift;
 	struct stat perf_stat;
 	event_t *event;
 	uint32_t size;
@@ -180,6 +181,10 @@ static int __cmd_trace(void)
 		return EXIT_FAILURE;
 	}
 
+	shift = page_size * (head / page_size);
+	offset += shift;
+	head -= shift;
+
 remap:
 	buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
 			   MAP_SHARED, input, offset);
@@ -192,9 +197,9 @@ more:
 	event = (event_t *)(buf + head);
 
 	if (head + event->header.size >= page_size * mmap_window) {
-		unsigned long shift = page_size * (head / page_size);
 		int res;
 
+		shift = page_size * (head / page_size);
 		res = munmap(buf, page_size * mmap_window);
 		assert(res == 0);
 

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

end of thread, other threads:[~2009-10-07  7:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-06 19:17 [PATCH] perf tools: Start the perf.data mapping at data offset in perf trace Frederic Weisbecker
2009-10-06 19:21 ` [PATCH v2] " Frederic Weisbecker
2009-10-06 22:29   ` Frederic Weisbecker
2009-10-07  7:31   ` [tip:perf/core] " tip-bot for Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox