Skip to contentSkip to conversation

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

PATCH Superseded Frederic Weisbecker 1 participant 4 messages Oct 6, 2009 – Oct 7, 2009 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
---
 tools/perf/builtin-trace.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-trace.c +6 -2
index 5d4c84d..d9abb4a 100644
@@ -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);
 
Signature · 1 line
1.6.2.3
#1 lore raw

PATCH v2 1/1 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)

Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
---
 tools/perf/builtin-trace.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tools/perf/builtin-trace.c +6 -1
index 5d4c84d..d573d4e 100644
@@ -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);
 
Signature · 1 line
1.6.2.3
#2 lore raw
Quoted 9 lines · Frederic Weisbecker

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.

Quoted 8 lines

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

Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>

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.

#3 lore raw
In reply to Frederic Weisbecker
Commit-ID:  b209aa1f83964d49a332a7b6b818ebede5cdc6ef
Gitweb:     http://git.kernel.org/tip/b209aa1f83964d49a332a7b6b818ebede5cdc6ef
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Tue, 6 Oct 2009 21:21:26 +0200
Committer:  Ingo Molnar <[email protected]>
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)

Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-trace.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tools/perf/builtin-trace.c +6 -1
index 5d4c84d..d573d4e 100644
@@ -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);