Skip to contentSkip to conversation

perf: Consolidate the event handling and ordering

PATCH In review Thomas Gleixner 4 participants 31 messages Dec 7, 2010 – Dec 22, 2010 perf events

lore
Share & tools
lore
#0 lore raw

cover perf: Consolidate the event handling and ordering

The following series fixes an unbound array access and further consolidates the event handling in session.c.

It now allows:

- time ordered dumps
- break time ordering when not all events provide timestamps

Thanks,

tglx

#1 lore raw

PATCH 1/9 perf: tools: Prevent unbound event__name array access

event__name[] is missing an entry for PERF_RECORD_FINISHED_ROUND, but we happily access the array from the dump code.

Make event__name[] static and provide an accessor function, fix up all callers and add the missing string.

---
 tools/perf/util/event.c   |   12 +++++++++++-
 tools/perf/util/event.h   |    2 +-
 tools/perf/util/hist.c    |    9 ++++++---
 tools/perf/util/session.c |    2 +-
 4 files changed, 19 insertions(+), 6 deletions(-)
tools/perf/util/event.c +11 -1
Index: linux-2.6-tip/tools/perf/util/event.c
===================================================================
@@ -7,7 +7,7 @@
 #include "strlist.h"
 #include "thread.h"
 
-const char *event__name[] = {
+static const char *event__name[] = {
 	[0]			 = "TOTAL",
 	[PERF_RECORD_MMAP]	 = "MMAP",
 	[PERF_RECORD_LOST]	 = "LOST",
@@ -22,8 +22,18 @@ const char *event__name[] = {
 	[PERF_RECORD_HEADER_EVENT_TYPE]	 = "EVENT_TYPE",
 	[PERF_RECORD_HEADER_TRACING_DATA]	 = "TRACING_DATA",
 	[PERF_RECORD_HEADER_BUILD_ID]	 = "BUILD_ID",
+	[PERF_RECORD_FINISHED_ROUND]	 = "FINISHED_ROUND",
 };
 
+const char *event__get_event_name(unsigned int id)
+{
+	if (id >= ARRAY_SIZE(event__name))
+		return "INVALID";
+	if (!event__name[id])
+		return "UNKNOWN";
+	return event__name[id];
+}
+
 static struct sample_data synth_sample = {
 	.pid	   = -1,
 	.tid	   = -1,
tools/perf/util/event.h +1 -1
Index: linux-2.6-tip/tools/perf/util/event.h
===================================================================
@@ -171,6 +171,6 @@ int event__preprocess_sample(const event
 int event__parse_sample(const event_t *event, struct perf_session *session,
 			struct sample_data *sample);
 
-extern const char *event__name[];
+const char *event__get_event_name(unsigned int id);
 
 #endif /* __PERF_RECORD_H */
tools/perf/util/hist.c +6 -3
Index: linux-2.6-tip/tools/perf/util/hist.c
===================================================================
@@ -1168,10 +1168,13 @@ size_t hists__fprintf_nr_events(struct h
 	size_t ret = 0;
 
 	for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
-		if (!event__name[i])
+		const char *name = event__get_event_name(i);
+
+		if (!strcmp(name, "UNKNOWN"))
 			continue;
-		ret += fprintf(fp, "%10s events: %10d\n",
-			       event__name[i], self->stats.nr_events[i]);
+
+		ret += fprintf(fp, "%16s events: %10d\n", name,
+			       self->stats.nr_events[i]);
 	}
 
 	return ret;
tools/perf/util/session.c +1 -1
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -718,7 +718,7 @@ static int perf_session__process_event(s
 	if (event->header.type < PERF_RECORD_HEADER_MAX) {
 		dump_printf("%#Lx [%#x]: PERF_RECORD_%s",
 			    file_offset, event->header.size,
-			    event__name[event->header.type]);
+			    event__get_event_name(event->header.type));
 		hists__inc_nr_events(&session->hists, event->header.type);
 	}
 
#2 lore raw

[tip:perf/core] perf event: Prevent unbound event__name array access

Commit-ID:  3835bc00c5b2d8e337a6e9d7b44f47e02760dba3
Gitweb:     http://git.kernel.org/tip/3835bc00c5b2d8e337a6e9d7b44f47e02760dba3
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:42 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 11:15:07 -0200

perf event: Prevent unbound event__name array access

event__name[] is missing an entry for PERF_RECORD_FINISHED_ROUND, but we happily access the array from the dump code.

Make event__name[] static and provide an accessor function, fix up all callers and add the missing string.

Cc: Frederic Weisbecker <[email protected]>
Cc: Ian Munsie <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>

---
 tools/perf/util/event.c   |   12 +++++++++++-
 tools/perf/util/event.h   |    2 +-
 tools/perf/util/hist.c    |    9 ++++++---
 tools/perf/util/session.c |    2 +-
 4 files changed, 19 insertions(+), 6 deletions(-)
tools/perf/util/event.c +11 -1
index e4cdc1e..183aedd 100644
@@ -7,7 +7,7 @@
 #include "strlist.h"
 #include "thread.h"
 
-const char *event__name[] = {
+static const char *event__name[] = {
 	[0]			 = "TOTAL",
 	[PERF_RECORD_MMAP]	 = "MMAP",
 	[PERF_RECORD_LOST]	 = "LOST",
@@ -22,8 +22,18 @@ const char *event__name[] = {
 	[PERF_RECORD_HEADER_EVENT_TYPE]	 = "EVENT_TYPE",
 	[PERF_RECORD_HEADER_TRACING_DATA]	 = "TRACING_DATA",
 	[PERF_RECORD_HEADER_BUILD_ID]	 = "BUILD_ID",
+	[PERF_RECORD_FINISHED_ROUND]	 = "FINISHED_ROUND",
 };
 
+const char *event__get_event_name(unsigned int id)
+{
+	if (id >= ARRAY_SIZE(event__name))
+		return "INVALID";
+	if (!event__name[id])
+		return "UNKNOWN";
+	return event__name[id];
+}
+
 static struct sample_data synth_sample = {
 	.pid	   = -1,
 	.tid	   = -1,
tools/perf/util/event.h +1 -1
index a95ab18..4716a8f 100644
@@ -171,6 +171,6 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
 int event__parse_sample(const event_t *event, struct perf_session *session,
 			struct sample_data *sample);
 
-extern const char *event__name[];
+const char *event__get_event_name(unsigned int id);
 
 #endif /* __PERF_RECORD_H */
tools/perf/util/hist.c +6 -3
index 2022e87..a3b8416 100644
@@ -1168,10 +1168,13 @@ size_t hists__fprintf_nr_events(struct hists *self, FILE *fp)
 	size_t ret = 0;
 
 	for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
-		if (!event__name[i])
+		const char *name = event__get_event_name(i);
+
+		if (!strcmp(name, "UNKNOWN"))
 			continue;
-		ret += fprintf(fp, "%10s events: %10d\n",
-			       event__name[i], self->stats.nr_events[i]);
+
+		ret += fprintf(fp, "%16s events: %10d\n", name,
+			       self->stats.nr_events[i]);
 	}
 
 	return ret;
tools/perf/util/session.c +1 -1
index 3074d38..b3b145a 100644
@@ -718,7 +718,7 @@ static int perf_session__process_event(struct perf_session *session,
 	if (event->header.type < PERF_RECORD_HEADER_MAX) {
 		dump_printf("%#Lx [%#x]: PERF_RECORD_%s",
 			    file_offset, event->header.size,
-			    event__name[event->header.type]);
+			    event__get_event_name(event->header.type));
 		hists__inc_nr_events(&session->hists, event->header.type);
 	}
 
#3 lore raw

PATCH 2/9 perf: session: Dont queue events w/o timestamps

In reply to Thomas Gleixner

If the event has no timestamp assigned then the parse code sets it to ~0ULL which causes the ordering code to enqueue it at the end.

Process it right away.

---
 tools/perf/util/session.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/session.c +1 -1
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -603,7 +603,7 @@ static int perf_session_queue_event(stru
 	u64 timestamp = data->time;
 	struct sample_queue *new;
 
-	if (!timestamp)
+	if (!timestamp || timestamp == ~0ULL)
 		return -ETIME;
 
 	if (timestamp < s->ordered_samples.last_flush) {
#4 lore raw

[tip:perf/core] perf session: Dont queue events w/o timestamps

Commit-ID:  79a14c1f458d598642bf11f09512c83d33a114e6
Gitweb:     http://git.kernel.org/tip/79a14c1f458d598642bf11f09512c83d33a114e6
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:44 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 11:15:38 -0200

perf session: Dont queue events w/o timestamps

If the event has no timestamp assigned then the parse code sets it to ~0ULL which causes the ordering code to enqueue it at the end.

Process it right away.

Cc Frederic Weisbecker <[email protected]>
Cc Ian Munsie <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/session.c +1 -1
index b3b145a..e5d0ed9 100644
@@ -603,7 +603,7 @@ static int perf_session_queue_event(struct perf_session *s, event_t *event,
 	u64 timestamp = data->time;
 	struct sample_queue *new;
 
-	if (!timestamp)
+	if (!timestamp || timestamp == ~0ULL)
 		return -ETIME;
 
 	if (timestamp < s->ordered_samples.last_flush) {
#5 lore raw

PATCH 3/9 perf: session: Consolidate the dump code

In reply to Thomas Gleixner

The dump code used by perf report -D is scattered all over the place. Move it to separate functions.

---
 tools/perf/util/event.h   |    1 
 tools/perf/util/session.c |   64 ++++++++++++++++++++++++++++------------------
 2 files changed, 40 insertions(+), 25 deletions(-)
tools/perf/util/event.h +1 -0
Index: linux-2.6-tip/tools/perf/util/event.h
===================================================================
@@ -85,6 +85,7 @@ struct build_id_event {
 };
 
 enum perf_user_event_type { /* above any possible kernel type */
+	PERF_RECORD_USER_TYPE_START		= 64,
 	PERF_RECORD_HEADER_ATTR			= 64,
 	PERF_RECORD_HEADER_EVENT_TYPE		= 65,
 	PERF_RECORD_HEADER_TRACING_DATA		= 66,
tools/perf/util/session.c +39 -25

104 lines not on this page · raw message

Acked-by on v1 3/9
#6 lore raw

Re: [patch 3/9] perf: session: Consolidate the dump code

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:48:47 UTC 2010:

Quoted 2 lines

The dump code used by perf report -D is scattered all over the place. Move it to separate functions.

It's cleaner than my patch, and does the same thing, so:

#7 lore raw

[tip:perf/core] perf session: Consolidate the dump code

In reply to Thomas Gleixner
Commit-ID:  9aefcab0de472ee2b3ab195a6827ddd4b170e3a7
Gitweb:     http://git.kernel.org/tip/9aefcab0de472ee2b3ab195a6827ddd4b170e3a7
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:47 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 11:18:06 -0200

perf session: Consolidate the dump code

The dump code used by perf report -D is scattered all over the place. Move it to separate functions.

Cc Frederic Weisbecker <[email protected]>
Cc Ian Munsie <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/event.h   |    1 +
 tools/perf/util/session.c |   64 +++++++++++++++++++++++++++-----------------
 2 files changed, 40 insertions(+), 25 deletions(-)
tools/perf/util/event.h +1 -0
index 4716a8f..2b7e919 100644
@@ -85,6 +85,7 @@ struct build_id_event {
 };
 
 enum perf_user_event_type { /* above any possible kernel type */
+	PERF_RECORD_USER_TYPE_START		= 64,
 	PERF_RECORD_HEADER_ATTR			= 64,
 	PERF_RECORD_HEADER_EVENT_TYPE		= 65,
 	PERF_RECORD_HEADER_TRACING_DATA		= 66,
tools/perf/util/session.c +39 -25

104 lines not on this page · raw message

#8 lore raw

PATCH 4/9 perf: session: Store file offset in sample_queue

In reply to Thomas Gleixner

Preparatory patch for ordered output of perf report -D

---
 tools/perf/util/session.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/session.c +5 -2
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -444,6 +444,7 @@ static event__swap_op event__swap_ops[] 
 
 struct sample_queue {
 	u64			timestamp;
+	u64			file_offset;
 	event_t			*event;
 	struct list_head	list;
 };
@@ -596,7 +597,7 @@ static void __queue_event(struct sample_
 #define MAX_SAMPLE_BUFFER	(64 * 1024 / sizeof(struct sample_queue))
 
 static int perf_session_queue_event(struct perf_session *s, event_t *event,
-				    struct sample_data *data)
+				    struct sample_data *data, u64 file_offset)
 {
 	struct ordered_samples *os = &s->ordered_samples;
 	struct list_head *sc = &os->sample_cache;
@@ -628,6 +629,7 @@ static int perf_session_queue_event(stru
 	}
 
 	new->timestamp = timestamp;
+	new->file_offset = file_offset;
 	new->event = event;
 
 	__queue_event(new, s);
@@ -780,7 +782,8 @@ static int perf_session__process_event(s
 	}
 
 	if (ops->ordered_samples) {
-		ret = perf_session_queue_event(session, event, &sample);
+		ret = perf_session_queue_event(session, event, &sample,
+					       file_offset);
 		if (ret != -ETIME)
 			return ret;
 	}
Acked-by on v1 4/9
#9 lore raw

Re: [patch 4/9] perf: session: Store file offset in sample_queue

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:48:50 UTC 2010:

Quoted 1 line

Subject: [patch 4/9] perf: session: Store file offset in sample_queue

Looks the same as mine, so:

#10 lore raw

[tip:perf/core] perf session: Store file offset in sample_queue

In reply to Thomas Gleixner
Commit-ID:  e4c2df132fef60a28b851abc1859a531e64f350c
Gitweb:     http://git.kernel.org/tip/e4c2df132fef60a28b851abc1859a531e64f350c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:50 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 12:09:18 -0200

perf session: Store file offset in sample_queue

Preparatory patch for ordered output of perf report -D.

Cc Frederic Weisbecker <[email protected]>
Cc Ian Munsie <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/session.c +5 -2
index 12761d5..a433954 100644
@@ -444,6 +444,7 @@ static event__swap_op event__swap_ops[] = {
 
 struct sample_queue {
 	u64			timestamp;
+	u64			file_offset;
 	event_t			*event;
 	struct list_head	list;
 };
@@ -596,7 +597,7 @@ static void __queue_event(struct sample_queue *new, struct perf_session *s)
 #define MAX_SAMPLE_BUFFER	(64 * 1024 / sizeof(struct sample_queue))
 
 static int perf_session_queue_event(struct perf_session *s, event_t *event,
-				    struct sample_data *data)
+				    struct sample_data *data, u64 file_offset)
 {
 	struct ordered_samples *os = &s->ordered_samples;
 	struct list_head *sc = &os->sample_cache;
@@ -628,6 +629,7 @@ static int perf_session_queue_event(struct perf_session *s, event_t *event,
 	}
 
 	new->timestamp = timestamp;
+	new->file_offset = file_offset;
 	new->event = event;
 
 	__queue_event(new, s);
@@ -780,7 +782,8 @@ static int perf_session__process_event(struct perf_session *session,
 	}
 
 	if (ops->ordered_samples) {
-		ret = perf_session_queue_event(session, event, &sample);
+		ret = perf_session_queue_event(session, event, &sample,
+					       file_offset);
 		if (ret != -ETIME)
 			return ret;
 	}
#11 lore raw

PATCH 5/9 perf: session: Add file_offset to event delivery function

In reply to Thomas Gleixner

Preparatory patch for ordered output of perf report -D

---
 tools/perf/util/session.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/util/session.c +8 -4
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -465,7 +465,8 @@ static void perf_session_free_sample_buf
 static int perf_session_deliver_event(struct perf_session *session,
 				      event_t *event,
 				      struct sample_data *sample,
-				      struct perf_event_ops *ops);
+				      struct perf_event_ops *ops,
+				      u64 file_offset);
 
 static void flush_sample_queue(struct perf_session *s,
 			       struct perf_event_ops *ops)
@@ -485,7 +486,8 @@ static void flush_sample_queue(struct pe
 			break;
 
 		event__parse_sample(iter->event, s, &sample);
-		perf_session_deliver_event(s, iter->event, &sample, ops);
+		perf_session_deliver_event(s, iter->event, &sample, ops,
+					   iter->file_offset);
 
 		os->last_flush = iter->timestamp;
 		list_del(&iter->list);
@@ -699,7 +701,8 @@ static void dump_sample(struct perf_sess
 static int perf_session_deliver_event(struct perf_session *session,
 				      event_t *event,
 				      struct sample_data *sample,
-				      struct perf_event_ops *ops)
+				      struct perf_event_ops *ops,
+				      u64 file_offset __used)
 {
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
@@ -788,7 +791,8 @@ static int perf_session__process_event(s
 			return ret;
 	}
 
-	return perf_session_deliver_event(session, event, &sample, ops);
+	return perf_session_deliver_event(session, event, &sample, ops,
+					  file_offset);
 }
 
 void perf_event_header__bswap(struct perf_event_header *self)
Acked-by on v1 5/9
#12 lore raw

Re: [patch 5/9] perf: session: Add file_offset to event delivery function

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:48:53 UTC 2010:

Quoted 1 line

Subject: [patch 5/9] perf: session: Add file_offset to event delivery function

#13 lore raw

[tip:perf/core] perf session: Add file_offset to event delivery function

In reply to Thomas Gleixner
Commit-ID:  f74725dcf2f6931c26bc65e77e34e693eeb8441c
Gitweb:     http://git.kernel.org/tip/f74725dcf2f6931c26bc65e77e34e693eeb8441c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:53 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 12:09:51 -0200

perf session: Add file_offset to event delivery function

Preparatory patch for ordered output of perf report -D

Cc Frederic Weisbecker <[email protected]>
Cc Ian Munsie <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
tools/perf/util/session.c +8 -4
index a433954..d43e56c 100644
@@ -465,7 +465,8 @@ static void perf_session_free_sample_buffers(struct perf_session *session)
 static int perf_session_deliver_event(struct perf_session *session,
 				      event_t *event,
 				      struct sample_data *sample,
-				      struct perf_event_ops *ops);
+				      struct perf_event_ops *ops,
+				      u64 file_offset);
 
 static void flush_sample_queue(struct perf_session *s,
 			       struct perf_event_ops *ops)
@@ -485,7 +486,8 @@ static void flush_sample_queue(struct perf_session *s,
 			break;
 
 		event__parse_sample(iter->event, s, &sample);
-		perf_session_deliver_event(s, iter->event, &sample, ops);
+		perf_session_deliver_event(s, iter->event, &sample, ops,
+					   iter->file_offset);
 
 		os->last_flush = iter->timestamp;
 		list_del(&iter->list);
@@ -699,7 +701,8 @@ static void dump_sample(struct perf_session *session, event_t *event,
 static int perf_session_deliver_event(struct perf_session *session,
 				      event_t *event,
 				      struct sample_data *sample,
-				      struct perf_event_ops *ops)
+				      struct perf_event_ops *ops,
+				      u64 file_offset __used)
 {
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
@@ -788,7 +791,8 @@ static int perf_session__process_event(struct perf_session *session,
 			return ret;
 	}
 
-	return perf_session_deliver_event(session, event, &sample, ops);
+	return perf_session_deliver_event(session, event, &sample, ops,
+					  file_offset);
 }
 
 void perf_event_header__bswap(struct perf_event_header *self)
#14 lore raw

PATCH 6/9 perf: session: Move dump code to event delivery path

In reply to Thomas Gleixner

Preparatory patch for ordered perf report -D

---
 tools/perf/util/session.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/session.c +5 -5
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -702,10 +702,13 @@ static int perf_session_deliver_event(st
 				      event_t *event,
 				      struct sample_data *sample,
 				      struct perf_event_ops *ops,
-				      u64 file_offset __used)
+				      u64 file_offset)
 {
+	dump_event(session, event, file_offset, sample);
+
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
+		dump_sample(session, event, sample);
 		return ops->sample(event, sample, session);
 	case PERF_RECORD_MMAP:
 		return ops->mmap(event, sample, session);
@@ -747,10 +750,8 @@ static int perf_session__process_event(s
 
 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
 		dump_event(session, event, file_offset, NULL);
-	else {
+	else
 		event__parse_sample(event, session, &sample);
-		dump_event(session, event, file_offset, &sample);
-	}
 
 	/* These events are processed right away */
 	switch (event->header.type) {
@@ -765,7 +766,6 @@ static int perf_session__process_event(s
 				return 0;
 			}
 		}
-		dump_sample(session, event, &sample);
 		break;
 
 	case PERF_RECORD_HEADER_ATTR:
Acked-by on v1 6/9
#15 lore raw

Re: [patch 6/9] perf: session: Move dump code to event delivery path

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:48:55 UTC 2010:

Quoted 1 line

Subject: [patch 6/9] perf: session: Move dump code to event delivery path

#16 lore raw

[tip:perf/core] perf session: Move dump code to event delivery path

In reply to Thomas Gleixner
Commit-ID:  532e7269c01098f0be6e08113c6947ec6ed11bfa
Gitweb:     http://git.kernel.org/tip/532e7269c01098f0be6e08113c6947ec6ed11bfa
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:55 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 12:10:53 -0200

perf session: Move dump code to event delivery path

Preparatory patch for ordered perf report -D

Cc Frederic Weisbecker <[email protected]>
Cc Ian Munsie <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/util/session.c +5 -5
index d43e56c..7c5cc12 100644
@@ -702,10 +702,13 @@ static int perf_session_deliver_event(struct perf_session *session,
 				      event_t *event,
 				      struct sample_data *sample,
 				      struct perf_event_ops *ops,
-				      u64 file_offset __used)
+				      u64 file_offset)
 {
+	dump_event(session, event, file_offset, sample);
+
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
+		dump_sample(session, event, sample);
 		return ops->sample(event, sample, session);
 	case PERF_RECORD_MMAP:
 		return ops->mmap(event, sample, session);
@@ -747,10 +750,8 @@ static int perf_session__process_event(struct perf_session *session,
 
 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
 		dump_event(session, event, file_offset, NULL);
-	else {
+	else
 		event__parse_sample(event, session, &sample);
-		dump_event(session, event, file_offset, &sample);
-	}
 
 	/* These events are processed right away */
 	switch (event->header.type) {
@@ -765,7 +766,6 @@ static int perf_session__process_event(struct perf_session *session,
 				return 0;
 			}
 		}
-		dump_sample(session, event, &sample);
 		break;
 
 	case PERF_RECORD_HEADER_ATTR:
#17 lore raw

PATCH 7/9 perf: session: Split out sample preprocessing

In reply to Thomas Gleixner

Simplify the code a bit

---
 tools/perf/util/session.c |   40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)
tools/perf/util/session.c +25 -15
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -732,6 +732,22 @@ static int perf_session_deliver_event(st
 	}
 }
 
+static int preprocess_sample_record(struct perf_session *session,
+				    event_t *event, struct sample_data *sample)
+{
+	if (event->header.type != PERF_RECORD_SAMPLE ||
+	    !(session->sample_type & PERF_SAMPLE_CALLCHAIN))
+		return 0;
+
+	if (!ip_callchain__valid(sample->callchain, event)) {
+		pr_debug("call-chain problem with event, skipping it.\n");
+		++session->hists.stats.nr_invalid_chains;
+		session->hists.stats.total_invalid_chains += sample->period;
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int perf_session__process_event(struct perf_session *session,
 				       event_t *event,
 				       struct perf_event_ops *ops,
@@ -750,24 +766,9 @@ static int perf_session__process_event(s
 
 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
 		dump_event(session, event, file_offset, NULL);
-	else
-		event__parse_sample(event, session, &sample);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
-	case PERF_RECORD_SAMPLE:
-		if (session->sample_type & PERF_SAMPLE_CALLCHAIN) {
-			if (!ip_callchain__valid(sample.callchain, event)) {
-				pr_debug("call-chain problem with event, "
-					 "skipping it.\n");
-				++session->hists.stats.nr_invalid_chains;
-				session->hists.stats.total_invalid_chains +=
-					sample.period;
-				return 0;
-			}
-		}
-		break;
-
 	case PERF_RECORD_HEADER_ATTR:
 		return ops->attr(event, session);
 	case PERF_RECORD_HEADER_EVENT_TYPE:
@@ -784,6 +785,15 @@ static int perf_session__process_event(s
 		break;
 	}
 
+	/*
+	 * For all kernel events we get the sample data
+	 */
+	event__parse_sample(event, session, &sample);
+
+	/* Preprocess sample records - precheck callchains */
+	if (preprocess_sample_record(session, event, &sample))
+		return 0;
+
 	if (ops->ordered_samples) {
 		ret = perf_session_queue_event(session, event, &sample,
 					       file_offset);
#18 lore raw

[tip:perf/core] perf session: Split out sample preprocessing

Commit-ID:  3dfc2c0aee789843d18f6e4675658e6879465a56
Gitweb:     http://git.kernel.org/tip/3dfc2c0aee789843d18f6e4675658e6879465a56
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:48:58 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 12:13:13 -0200

perf session: Split out sample preprocessing

Simplify the code a bit.

Cc: Frederic Weisbecker <[email protected]>
Cc: Ian Munsie <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |   40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 deletions(-)
tools/perf/util/session.c +25 -15
index 7c5cc12..a765b27 100644
@@ -732,6 +732,22 @@ static int perf_session_deliver_event(struct perf_session *session,
 	}
 }
 
+static int perf_session__preprocess_sample(struct perf_session *session,
+					   event_t *event, struct sample_data *sample)
+{
+	if (event->header.type != PERF_RECORD_SAMPLE ||
+	    !(session->sample_type & PERF_SAMPLE_CALLCHAIN))
+		return 0;
+
+	if (!ip_callchain__valid(sample->callchain, event)) {
+		pr_debug("call-chain problem with event, skipping it.\n");
+		++session->hists.stats.nr_invalid_chains;
+		session->hists.stats.total_invalid_chains += sample->period;
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int perf_session__process_event(struct perf_session *session,
 				       event_t *event,
 				       struct perf_event_ops *ops,
@@ -750,24 +766,9 @@ static int perf_session__process_event(struct perf_session *session,
 
 	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
 		dump_event(session, event, file_offset, NULL);
-	else
-		event__parse_sample(event, session, &sample);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
-	case PERF_RECORD_SAMPLE:
-		if (session->sample_type & PERF_SAMPLE_CALLCHAIN) {
-			if (!ip_callchain__valid(sample.callchain, event)) {
-				pr_debug("call-chain problem with event, "
-					 "skipping it.\n");
-				++session->hists.stats.nr_invalid_chains;
-				session->hists.stats.total_invalid_chains +=
-					sample.period;
-				return 0;
-			}
-		}
-		break;
-
 	case PERF_RECORD_HEADER_ATTR:
 		return ops->attr(event, session);
 	case PERF_RECORD_HEADER_EVENT_TYPE:
@@ -784,6 +785,15 @@ static int perf_session__process_event(struct perf_session *session,
 		break;
 	}
 
+	/*
+	 * For all kernel events we get the sample data
+	 */
+	event__parse_sample(event, session, &sample);
+
+	/* Preprocess sample records - precheck callchains */
+	if (perf_session__preprocess_sample(session, event, &sample))
+		return 0;
+
 	if (ops->ordered_samples) {
 		ret = perf_session_queue_event(session, event, &sample,
 					       file_offset);
#19 lore raw

PATCH 8/9 perf: session: Split out user event processing

In reply to Thomas Gleixner

Simplify further.

---
 tools/perf/util/session.c |   42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)
tools/perf/util/session.c +24 -18
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -748,24 +748,10 @@ static int preprocess_sample_record(stru
 	return 0;
 }
 
-static int perf_session__process_event(struct perf_session *session,
-				       event_t *event,
-				       struct perf_event_ops *ops,
-				       u64 file_offset)
+static int process_user_event(struct perf_session *session, event_t *event,
+			      struct perf_event_ops *ops, u64 file_offset)
 {
-	struct sample_data sample;
-	int ret;
-
-	if (session->header.needs_swap && event__swap_ops[event->header.type])
-		event__swap_ops[event->header.type](event);
-
-	if (event->header.type >= PERF_RECORD_HEADER_MAX)
-		return -EINVAL;
-
-	hists__inc_nr_events(&session->hists, event->header.type);
-
-	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
-		dump_event(session, event, file_offset, NULL);
+	dump_event(session, event, file_offset, NULL);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
@@ -782,8 +768,28 @@ static int perf_session__process_event(s
 	case PERF_RECORD_FINISHED_ROUND:
 		return ops->finished_round(event, session, ops);
 	default:
-		break;
+		return -EINVAL;
 	}
+}
+
+static int perf_session__process_event(struct perf_session *session,
+				       event_t *event,
+				       struct perf_event_ops *ops,
+				       u64 file_offset)
+{
+	struct sample_data sample;
+	int ret;
+
+	if (session->header.needs_swap && event__swap_ops[event->header.type])
+		event__swap_ops[event->header.type](event);
+
+	if (event->header.type >= PERF_RECORD_HEADER_MAX)
+		return -EINVAL;
+
+	hists__inc_nr_events(&session->hists, event->header.type);
+
+	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
+		return process_user_event(session, event, ops, file_offset);
 
 	/*
 	 * For all kernel events we get the sample data
#20 lore raw

[tip:perf/core] perf session: Split out user event processing

Commit-ID:  ba74f0640d963ccc914ac533cb0ba133ee07bcf2
Gitweb:     http://git.kernel.org/tip/ba74f0640d963ccc914ac533cb0ba133ee07bcf2
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Tue, 7 Dec 2010 12:49:01 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 9 Dec 2010 12:15:43 -0200

perf session: Split out user event processing

Simplify further.

Cc: Frederic Weisbecker <[email protected]>
Cc: Ian Munsie <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <[email protected]>

---
 tools/perf/util/session.c |   42 ++++++++++++++++++++++++------------------
 1 files changed, 24 insertions(+), 18 deletions(-)
tools/perf/util/session.c +24 -18
index a765b27..69760cd 100644
@@ -748,24 +748,10 @@ static int perf_session__preprocess_sample(struct perf_session *session,
 	return 0;
 }
 
-static int perf_session__process_event(struct perf_session *session,
-				       event_t *event,
-				       struct perf_event_ops *ops,
-				       u64 file_offset)
+static int perf_session__process_user_event(struct perf_session *session, event_t *event,
+					    struct perf_event_ops *ops, u64 file_offset)
 {
-	struct sample_data sample;
-	int ret;
-
-	if (session->header.needs_swap && event__swap_ops[event->header.type])
-		event__swap_ops[event->header.type](event);
-
-	if (event->header.type >= PERF_RECORD_HEADER_MAX)
-		return -EINVAL;
-
-	hists__inc_nr_events(&session->hists, event->header.type);
-
-	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
-		dump_event(session, event, file_offset, NULL);
+	dump_event(session, event, file_offset, NULL);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
@@ -782,8 +768,28 @@ static int perf_session__process_event(struct perf_session *session,
 	case PERF_RECORD_FINISHED_ROUND:
 		return ops->finished_round(event, session, ops);
 	default:
-		break;
+		return -EINVAL;
 	}
+}
+
+static int perf_session__process_event(struct perf_session *session,
+				       event_t *event,
+				       struct perf_event_ops *ops,
+				       u64 file_offset)
+{
+	struct sample_data sample;
+	int ret;
+
+	if (session->header.needs_swap && event__swap_ops[event->header.type])
+		event__swap_ops[event->header.type](event);
+
+	if (event->header.type >= PERF_RECORD_HEADER_MAX)
+		return -EINVAL;
+
+	hists__inc_nr_events(&session->hists, event->header.type);
+
+	if (event->header.type >= PERF_RECORD_USER_TYPE_START)
+		return perf_session__process_user_event(session, event, ops, file_offset);
 
 	/*
 	 * For all kernel events we get the sample data
#21 lore raw

PATCH 9/9 pref: session: Break event ordering when timestamps are missing

In reply to Thomas Gleixner

Allow the session client to specify that event ordering should be stopped when not all events have time stamps.

---
 tools/perf/util/session.c |   13 ++++++++++++-
 tools/perf/util/session.h |    1 +
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/perf/util/session.c +12 -1
Index: linux-2.6-tip/tools/perf/util/session.c
===================================================================
@@ -751,12 +751,23 @@ static int preprocess_sample_record(stru
 static int process_user_event(struct perf_session *session, event_t *event,
 			      struct perf_event_ops *ops, u64 file_offset)
 {
+	int ret;
+
 	dump_event(session, event, file_offset, NULL);
 
 	/* These events are processed right away */
 	switch (event->header.type) {
 	case PERF_RECORD_HEADER_ATTR:
-		return ops->attr(event, session);
+		/* This updates session->sample_id_all */
+		ret = ops->attr(event, session);
+		/* Break ordering if sample_id_all is false */
+		if (ops->ordering_requires_timestamps &&
+		    ops->ordered_samples && !session->sample_id_all) {
+			session->ordered_samples.next_flush = ULLONG_MAX;
+			flush_sample_queue(session, ops);
+			ops->ordered_samples = false;
+		}
+		return ret;
 	case PERF_RECORD_HEADER_EVENT_TYPE:
 		return ops->event_type(event, session);
 	case PERF_RECORD_HEADER_TRACING_DATA:
tools/perf/util/session.h +1 -0
Index: linux-2.6-tip/tools/perf/util/session.h
===================================================================
@@ -78,6 +78,7 @@ struct perf_event_ops {
 			build_id;
 	event_op2	finished_round;
 	bool		ordered_samples;
+	bool		ordering_requires_timestamps;
 };
 
 struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
#22 lore raw

Re: [patch 9/9] pref: session: Break event ordering when timestamps are missing

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:49:04 UTC 2010:

Quoted 7 lines

Allow the session client to specify that event ordering should be stopped when not all events have time stamps.

tools/perf/util/session.c +0 -1
 	/* These events are processed right away */
 	switch (event->header.type) {
 	case PERF_RECORD_HEADER_ATTR:
-		return ops->attr(event, session);

tools/perf/util/session.c static int preprocess_sample_record(stru · line 770

Quoted 10 lines
tools/perf/util/session.c +10 -0
+		/* This updates session->sample_id_all */
+		ret = ops->attr(event, session);
+		/* Break ordering if sample_id_all is false */
+		if (ops->ordering_requires_timestamps &&
+		    ops->ordered_samples && !session->sample_id_all) {
+			session->ordered_samples.next_flush = ULLONG_MAX;
+			flush_sample_queue(session, ops);
+			ops->ordered_samples = false;
+		}
+		return ret;

This fallback still relies on receiving a PERF_RECORD_HEADER_ATTR, which will only happen if the output is being piped:

$ git grep event__synthesize_attr
builtin-record.c:               err = event__synthesize_attrs(&session->header,
util/header.c:int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
util/header.c:int event__synthesize_attrs(struct perf_header *self, event__handler_t process,
util/header.c:          err = event__synthesize_attr(&attr->attr, attr->ids, attr->id,
util/header.h:int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
util/header.h:int event__synthesize_attrs(struct perf_header *self,
$ less builtin-record.c
<SNIP>
	if (pipe_output) {
		err = event__synthesize_attrs(&session->header,
					      process_synthesized_event,
					      session);
<SNIP>

So this will work in this situation (timestamps on samples, but this is an old kernel so not on other events):

delenn% ./perf record -T -o - ~/tests/cachetest | ./perf report -i - Initialising array...
Trying approach 1: 0x18fff7eb26fd058
Trying approach 2: 0x18fff7eb26fd058
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.081 MB - (~3549 samples) ] # Events: 1K cycles
#
# Overhead Command Shared Object Symbol

# ........  .......  .................  .......................
#
    70.23%  cachetest  cachetest          [.] sumArrayNaive
    28.54%  cachetest  cachetest          [.] sumArrayOptimal
     0.43%  cachetest  [kernel.kallsyms]  [k] insert_work
     0.39%  cachetest  [kernel.kallsyms]  [k] machine_kexec_prepare
     0.35%  cachetest  libc-2.11.2.so     [.] __random
     0.06%  cachetest  [kernel.kallsyms]  [k] print_cfs_rq
     0.01%  cachetest  [kernel.kallsyms]  [k] __register_sysctl_paths

#
# (For a higher level overview, try: perf report --sort comm,dso) #

But will fail in this case:

delenn% ./perf record -T ~/tests/cachetest ~/linus/tools/perf
Initialising array...
Trying approach 1: 0x18fff7eb26fd058
Trying approach 2: 0x18fff7eb26fd058
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.081 MB perf.data (~3543 samples) ]

delenn% ./perf report|cat ~/linus/tools/perf
# Events: 1K cycles
#
# Overhead Command Shared Object Symbol

# ........  .......  .................  .......................
#
    99.47%    :5593  [unknown]          [.] 0xf770cff5
     0.48%    :5593  [kernel.kallsyms]  [k] hpet_next_event
     0.05%    :5593  [libahci]          [k] ahci_scr_read
     0.01%    :5593  [kernel.kallsyms]  [k] flush_signal_handlers
     0.00%    :5593  [kernel.kallsyms]  [k] native_write_msr_safe

#
# (For a higher level overview, try: perf report --sort comm,dso) #

Since the fall back isn't triggered, not only are COMM and MMAP events processed first (from patch 2 in this series), but EXIT will as well, which causes no userspace events to be attributed.

Cheers,
-Ian

#23 lore raw

Re: [patch 9/9] pref: session: Break event ordering when timestamps are missing

Quoted 13 lines · Ian Munsie

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:49:04 UTC 2010:

Quoted 12 lines

Allow the session client to specify that event ordering should be stopped when not all events have time stamps.

tools/perf/util/session.c +5 -1
 	/* These events are processed right away */
 	switch (event->header.type) {
 	case PERF_RECORD_HEADER_ATTR:
-		return ops->attr(event, session);
+		/* This updates session->sample_id_all */
+		ret = ops->attr(event, session);
+		/* Break ordering if sample_id_all is false */
+		if (ops->ordering_requires_timestamps &&
+		    ops->ordered_samples && !session->sample_id_all) {
Quoted 8 lines

tools/perf/util/session.c static int preprocess_sample_record(stru · line 770

Quoted 5 lines
tools/perf/util/session.c +5 -0
+			session->ordered_samples.next_flush = ULLONG_MAX;
+			flush_sample_queue(session, ops);
+			ops->ordered_samples = false;
+		}
+		return ret;

Since the fall back isn't triggered, not only are COMM and MMAP events processed first (from patch 2 in this series), but EXIT will as well, which causes no userspace events to be attributed.

So we need to check this in every event processing path? Or do we have for this kind of processing some other method which allows us to disable the ordered_samples bit once ?

Thanks,

tglx

#24 lore raw

Re: [patch 9/9] pref: session: Break event ordering when timestamps are missing

Em Thu, Dec 09, 2010 at 02:58:10PM +0100, Thomas Gleixner escreveu:

Quoted 23 lines · Ian Munsie
Quoted 13 lines

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:49:04 UTC 2010:

Quoted 12 lines

Allow the session client to specify that event ordering should be stopped when not all events have time stamps.

tools/perf/util/session.c +5 -1
 	/* These events are processed right away */
 	switch (event->header.type) {
 	case PERF_RECORD_HEADER_ATTR:
-		return ops->attr(event, session);
+		/* This updates session->sample_id_all */
+		ret = ops->attr(event, session);
+		/* Break ordering if sample_id_all is false */
+		if (ops->ordering_requires_timestamps &&
+		    ops->ordered_samples && !session->sample_id_all) {
Quoted 8 lines

tools/perf/util/session.c static int preprocess_sample_record(stru · line 770

Quoted 5 lines
tools/perf/util/session.c +5 -0
+			session->ordered_samples.next_flush = ULLONG_MAX;
+			flush_sample_queue(session, ops);
+			ops->ordered_samples = false;
+		}
+		return ret;

Since the fall back isn't triggered, not only are COMM and MMAP events processed first (from patch 2 in this series), but EXIT will as well, which causes no userspace events to be attributed.

Quoted 3 lines

So we need to check this in every event processing path? Or do we have for this kind of processing some other method which allows us to disable the ordered_samples bit once ?

FYI: I merged everything up to 8/9 and will push to Ingo soon, holler if you disagree.

- Arnaldo

#25 lore raw

Re: [patch 9/9] pref: session: Break event ordering when timestamps are missing

In reply to Thomas Gleixner

Excerpts from Thomas Gleixner's message of Fri Dec 10 00:58:10 +1100 2010:

Quoted 19 lines · Ian Munsie
Quoted 18 lines

Excerpts from Thomas Gleixner's message of Tue Dec 07 12:49:04 UTC 2010:

Quoted 17 lines

Allow the session client to specify that event ordering should be stopped when not all events have time stamps.

     /* These events are processed right away */
     switch (event->header.type) {
     case PERF_RECORD_HEADER_ATTR:
(quoted diff) +10 -1
-        return ops->attr(event, session);
+        /* This updates session->sample_id_all */
+        ret = ops->attr(event, session);
+        /* Break ordering if sample_id_all is false */
+        if (ops->ordering_requires_timestamps &&
+            ops->ordered_samples && !session->sample_id_all) {
+            session->ordered_samples.next_flush = ULLONG_MAX;
+            flush_sample_queue(session, ops);
+            ops->ordered_samples = false;
+        }
+        return ret;
Quoted 7 lines
Quoted 3 lines

Since the fall back isn't triggered, not only are COMM and MMAP events processed first (from patch 2 in this series), but EXIT will as well, which causes no userspace events to be attributed.

So we need to check this in every event processing path? Or do we have for this kind of processing some other method which allows us to disable the ordered_samples bit once ?

Any reason we couldn't put it in the perf_session__new function? It means passing the event_ops to it as well, but I can't see any reason why not to:

Quoted 1 line

From 711157f13a9adeab87a83eb8e0d9bc67cf1e2be8 Mon Sep 17 00:00:00 2001

From: Ian Munsie <[email protected]>
Date: Fri, 10 Dec 2010 14:09:16 +1100
Subject: [PATCH] perf session: Fallback to unordered processing if no sample_id_all

If we are running the new perf on an old kernel without support for sample_id_all, we should fall back to the old unordered processing of events. If we didn't than we would *always* process events without timestamps out of order, whether or not we hit a reordering race. In other words, instead of there being a chance of not attributing samples correctly, we would guarantee that samples would not be attributed.

While processing all events without timestamps before events with timestamps may seem like an intuitive solution, it falls down as PERF_RECORD_EXIT events would also be processed before any samples. Even with a workaround for that case, samples before/after an exec would not be attributed correctly.

This patch allows commands to indicate whether they need to fall back to unordered processing, so that commands that do not care about timestamps on every event will not be affected. If we do fallback, this will print out a warning if report -D was invoked.

This patch adds the test in perf_session__new so that we only need to test once per session. Commands that do not use an event_ops (such as record and top) can simply pass NULL in it's place.

---
 tools/perf/builtin-annotate.c     |    2 +-
 tools/perf/builtin-buildid-list.c |    3 ++-
 tools/perf/builtin-diff.c         |    4 ++--
 tools/perf/builtin-inject.c       |    2 +-
 tools/perf/builtin-kmem.c         |    3 ++-
 tools/perf/builtin-lock.c         |    2 +-
 tools/perf/builtin-record.c       |    2 +-
 tools/perf/builtin-report.c       |    2 +-
 tools/perf/builtin-sched.c        |    3 ++-
 tools/perf/builtin-script.c       |    2 +-
 tools/perf/builtin-timechart.c    |    3 ++-
 tools/perf/builtin-top.c          |    2 +-
 tools/perf/util/session.c         |   11 ++++++++++-
 tools/perf/util/session.h         |    5 ++++-
 14 files changed, 31 insertions(+), 15 deletions(-)
tools/perf/builtin-annotate.c +1 -1
index 793db36..c056cdc 100644
@@ -384,7 +384,7 @@ static int __cmd_annotate(void)
 	int ret;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-buildid-list.c +2 -1
index 44a47e1..3b06f9c 100644
@@ -39,7 +39,8 @@ static int __cmd_buildid_list(void)
 	int err = -1;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false,
+				    &build_id__mark_dso_hit_ops);
 	if (session == NULL)
 		return -1;
 
tools/perf/builtin-diff.c +2 -2
index d21dc25a..97846dc 100644
@@ -144,8 +144,8 @@ static int __cmd_diff(void)
 	int ret, i;
 	struct perf_session *session[2];
 
-	session[0] = perf_session__new(input_old, O_RDONLY, force, false);
-	session[1] = perf_session__new(input_new, O_RDONLY, force, false);
+	session[0] = perf_session__new(input_old, O_RDONLY, force, false, &event_ops);
+	session[1] = perf_session__new(input_new, O_RDONLY, force, false, &event_ops);
 	if (session[0] == NULL || session[1] == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-inject.c +1 -1
index 4b66b85..0c78ffa 100644
@@ -196,7 +196,7 @@ static int __cmd_inject(void)
 		inject_ops.tracing_data	= event__repipe_tracing_data;
 	}
 
-	session = perf_session__new(input_name, O_RDONLY, false, true);
+	session = perf_session__new(input_name, O_RDONLY, false, true, &inject_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-kmem.c +2 -1
index c9620ff..def7ddc 100644
@@ -481,7 +481,8 @@ static void sort_result(void)
 static int __cmd_kmem(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-lock.c +1 -1
index b41b449..b9c6e54 100644
@@ -858,7 +858,7 @@ static struct perf_event_ops eops = {
 
 static int read_events(void)
 {
-	session = perf_session__new(input_name, O_RDONLY, 0, false);
+	session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
 	if (!session)
 		die("Initializing perf session failed\n");
 
tools/perf/builtin-record.c +1 -1
index 310dd21..184c444 100644
@@ -574,7 +574,7 @@ static int __cmd_record(int argc, const char **argv)
 	}
 
 	session = perf_session__new(output_name, O_WRONLY,
-				    write_mode == WRITE_FORCE, false);
+				    write_mode == WRITE_FORCE, false, NULL);
 	if (session == NULL) {
 		pr_err("Not enough memory for reading perf file header\n");
 		return -1;
tools/perf/builtin-report.c +1 -1
index ccaea63..4af7ce6 100644
@@ -310,7 +310,7 @@ static int __cmd_report(void)
 
 	signal(SIGINT, sig_handler);
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-sched.c +2 -1
index c775394..7a4ebeb 100644
@@ -1643,7 +1643,8 @@ static struct perf_event_ops event_ops = {
 static int read_events(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-script.c +1 -1
index 54f1ea8..6ef65c0 100644
@@ -779,7 +779,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 	if (!script_name)
 		setup_pager();
 
-	session = perf_session__new(input_name, O_RDONLY, 0, false);
+	session = perf_session__new(input_name, O_RDONLY, 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-timechart.c +2 -1
index d2fc461..459b5e3 100644
@@ -937,7 +937,8 @@ static struct perf_event_ops event_ops = {
 
 static int __cmd_timechart(void)
 {
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	int ret = -EINVAL;
 
 	if (session == NULL)
tools/perf/builtin-top.c +1 -1
index 0515ce9..ae15f04 100644
@@ -1272,7 +1272,7 @@ static int __cmd_top(void)
 	 * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
 	 * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
 	 */
-	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false);
+	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false, NULL);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/util/session.c +10 -1
index b59abf5..0f7e544 100644
@@ -125,7 +125,9 @@ static void perf_session__destroy_kernel_maps(struct perf_session *self)
 	machines__destroy_guest_kernel_maps(&self->machines);
 }
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe)
+struct perf_session *perf_session__new(const char *filename, int mode,
+				       bool force, bool repipe,
+				       struct perf_event_ops *ops)
 {
 	size_t len = filename ? strlen(filename) + 1 : 0;
 	struct perf_session *self = zalloc(sizeof(*self) + len);
@@ -170,6 +172,13 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 	}
 
 	perf_session__update_sample_type(self);
+
+	if (ops && ops->ordering_requires_timestamps &&
+	    ops->ordered_samples && !self->sample_id_all) {
+		dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
+		ops->ordered_samples = false;
+	}
+
 out:
 	return self;
 out_free:
tools/perf/util/session.h +4 -1
index ac36f99..ffe4b98 100644
@@ -78,9 +78,12 @@ struct perf_event_ops {
 			build_id;
 	event_op2	finished_round;
 	bool		ordered_samples;
+	bool		ordering_requires_timestamps;
 };
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
+struct perf_session *perf_session__new(const char *filename, int mode,
+				       bool force, bool repipe,
+				       struct perf_event_ops *ops);
 void perf_session__delete(struct perf_session *self);
 
 void perf_event_header__bswap(struct perf_event_header *self);
Signature · 1 line
1.7.2.3
#26 lore raw

[tip:perf/core] perf session: Fallback to unordered processing if no sample_id_all

Commit-ID:  21ef97f05a7da5bc23b26cb34d6746f83ca9bf20
Gitweb:     http://git.kernel.org/tip/21ef97f05a7da5bc23b26cb34d6746f83ca9bf20
Author:     Ian Munsie <[email protected]>
AuthorDate: Fri, 10 Dec 2010 14:09:16 +1100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 21 Dec 2010 20:17:51 -0200

perf session: Fallback to unordered processing if no sample_id_all

If we are running the new perf on an old kernel without support for sample_id_all, we should fall back to the old unordered processing of events. If we didn't than we would *always* process events without timestamps out of order, whether or not we hit a reordering race. In other words, instead of there being a chance of not attributing samples correctly, we would guarantee that samples would not be attributed.

While processing all events without timestamps before events with timestamps may seem like an intuitive solution, it falls down as PERF_RECORD_EXIT events would also be processed before any samples. Even with a workaround for that case, samples before/after an exec would not be attributed correctly.

This patch allows commands to indicate whether they need to fall back to unordered processing, so that commands that do not care about timestamps on every event will not be affected. If we do fallback, this will print out a warning if report -D was invoked.

This patch adds the test in perf_session__new so that we only need to test once per session. Commands that do not use an event_ops (such as record and top) can simply pass NULL in it's place.

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-annotate.c     |    2 +-
 tools/perf/builtin-buildid-list.c |    3 ++-
 tools/perf/builtin-diff.c         |    4 ++--
 tools/perf/builtin-inject.c       |    2 +-
 tools/perf/builtin-kmem.c         |    3 ++-
 tools/perf/builtin-lock.c         |    2 +-
 tools/perf/builtin-record.c       |    2 +-
 tools/perf/builtin-report.c       |    2 +-
 tools/perf/builtin-sched.c        |    3 ++-
 tools/perf/builtin-script.c       |    2 +-
 tools/perf/builtin-timechart.c    |    3 ++-
 tools/perf/builtin-top.c          |    2 +-
 tools/perf/util/session.c         |   11 ++++++++++-
 tools/perf/util/session.h         |    5 ++++-
 14 files changed, 31 insertions(+), 15 deletions(-)
tools/perf/builtin-annotate.c +1 -1
index 569a276..48dbab4 100644
@@ -382,7 +382,7 @@ static int __cmd_annotate(void)
 	int ret;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-buildid-list.c +2 -1
index 44a47e1..3b06f9c 100644
@@ -39,7 +39,8 @@ static int __cmd_buildid_list(void)
 	int err = -1;
 	struct perf_session *session;
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false,
+				    &build_id__mark_dso_hit_ops);
 	if (session == NULL)
 		return -1;
 
tools/perf/builtin-diff.c +2 -2
index 5e1a043..af84e1c 100644
@@ -142,8 +142,8 @@ static int __cmd_diff(void)
 	int ret, i;
 	struct perf_session *session[2];
 
-	session[0] = perf_session__new(input_old, O_RDONLY, force, false);
-	session[1] = perf_session__new(input_new, O_RDONLY, force, false);
+	session[0] = perf_session__new(input_old, O_RDONLY, force, false, &event_ops);
+	session[1] = perf_session__new(input_new, O_RDONLY, force, false, &event_ops);
 	if (session[0] == NULL || session[1] == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-inject.c +1 -1
index 4b66b85..0c78ffa 100644
@@ -196,7 +196,7 @@ static int __cmd_inject(void)
 		inject_ops.tracing_data	= event__repipe_tracing_data;
 	}
 
-	session = perf_session__new(input_name, O_RDONLY, false, true);
+	session = perf_session__new(input_name, O_RDONLY, false, true, &inject_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-kmem.c +2 -1
index c9620ff..def7ddc 100644
@@ -481,7 +481,8 @@ static void sort_result(void)
 static int __cmd_kmem(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-lock.c +1 -1
index b41b449..b9c6e54 100644
@@ -858,7 +858,7 @@ static struct perf_event_ops eops = {
 
 static int read_events(void)
 {
-	session = perf_session__new(input_name, O_RDONLY, 0, false);
+	session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
 	if (!session)
 		die("Initializing perf session failed\n");
 
tools/perf/builtin-record.c +1 -1
index e9be6ae..efd1b3c 100644
@@ -572,7 +572,7 @@ static int __cmd_record(int argc, const char **argv)
 	}
 
 	session = perf_session__new(output_name, O_WRONLY,
-				    write_mode == WRITE_FORCE, false);
+				    write_mode == WRITE_FORCE, false, NULL);
 	if (session == NULL) {
 		pr_err("Not enough memory for reading perf file header\n");
 		return -1;
tools/perf/builtin-report.c +1 -1
index b6a2a89..fd4c450 100644
@@ -308,7 +308,7 @@ static int __cmd_report(void)
 
 	signal(SIGINT, sig_handler);
 
-	session = perf_session__new(input_name, O_RDONLY, force, false);
+	session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-sched.c +2 -1
index c775394..7a4ebeb 100644
@@ -1643,7 +1643,8 @@ static struct perf_event_ops event_ops = {
 static int read_events(void)
 {
 	int err = -EINVAL;
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-script.c +1 -1
index 54f1ea8..6ef65c0 100644
@@ -779,7 +779,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 	if (!script_name)
 		setup_pager();
 
-	session = perf_session__new(input_name, O_RDONLY, 0, false);
+	session = perf_session__new(input_name, O_RDONLY, 0, false, &event_ops);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/builtin-timechart.c +2 -1
index d2fc461..459b5e3 100644
@@ -937,7 +937,8 @@ static struct perf_event_ops event_ops = {
 
 static int __cmd_timechart(void)
 {
-	struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
+	struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+							 0, false, &event_ops);
 	int ret = -EINVAL;
 
 	if (session == NULL)
tools/perf/builtin-top.c +1 -1
index 0515ce9..ae15f04 100644
@@ -1272,7 +1272,7 @@ static int __cmd_top(void)
 	 * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
 	 * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
 	 */
-	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false);
+	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false, NULL);
 	if (session == NULL)
 		return -ENOMEM;
 
tools/perf/util/session.c +10 -1
index b59abf5..0f7e544 100644
@@ -125,7 +125,9 @@ static void perf_session__destroy_kernel_maps(struct perf_session *self)
 	machines__destroy_guest_kernel_maps(&self->machines);
 }
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe)
+struct perf_session *perf_session__new(const char *filename, int mode,
+				       bool force, bool repipe,
+				       struct perf_event_ops *ops)
 {
 	size_t len = filename ? strlen(filename) + 1 : 0;
 	struct perf_session *self = zalloc(sizeof(*self) + len);
@@ -170,6 +172,13 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 	}
 
 	perf_session__update_sample_type(self);
+
+	if (ops && ops->ordering_requires_timestamps &&
+	    ops->ordered_samples && !self->sample_id_all) {
+		dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
+		ops->ordered_samples = false;
+	}
+
 out:
 	return self;
 out_free:
tools/perf/util/session.h +4 -1
index ac36f99..ffe4b98 100644
@@ -78,9 +78,12 @@ struct perf_event_ops {
 			build_id;
 	event_op2	finished_round;
 	bool		ordered_samples;
+	bool		ordering_requires_timestamps;
 };
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
+struct perf_session *perf_session__new(const char *filename, int mode,
+				       bool force, bool repipe,
+				       struct perf_event_ops *ops);
 void perf_session__delete(struct perf_session *self);
 
 void perf_event_header__bswap(struct perf_event_header *self);
#27 lore raw
In reply to Thomas Gleixner

Em Tue, Dec 07, 2010 at 12:48:38PM -0000, Thomas Gleixner escreveu:

Quoted 7 lines

The following series fixes an unbound array access and further consolidates the event handling in session.c.

It now allows:

- time ordered dumps
- break time ordering when not all events provide timestamps

Hi Ian,

Have you had the chance of reviewing/testing this patch series
so that we know that your needs are satisfied with it?

Thanks,

- Arnaldo

#28 lore raw

Excerpts from Arnaldo Carvalho de Melo's message of Thu Dec 09 07:24:52 +1100 2010:

Quoted 4 lines

Hi Ian,

Have you had the chance of reviewing/testing this patch series
so that we know that your needs are satisfied with it?

Hi Arnaldo,

Sorry I didn't get around to reviewing them yesterday. Overall they look pretty good, other than the fall back issue running them the userspace tool on an unpatched kernel I mentioned.

I've added my patch to enable the sorting in perf record. This time I also enabled it in perf annotate and perf diff as I realised they would also need the ordering to properly attribute the samples. I haven't added it to any other commands - some already enable ordered_samples, so we wouldn't want to enable ordering_requires_timestamps on them, and I don't think any of the remaining commands need it.

Cheers,
-Ian

#29 lore raw

PATCH v4 1/1 perf record,report,annotate,diff: Process events in order

In reply to Thomas Gleixner

From: Ian Munsie <[email protected]>

This patch changes perf report to ask for the ID info on all events be default if recording from multiple CPUs.

Perf report, annotate and diff will now process the events in order if the kernel is able to provide timestamps on all events. This ensures that events such as COMM and MMAP which are necessary to correctly interpret samples are processed prior to those samples so that they are attributed correctly.

Before:

 # perf record ./cachetest
 # perf report

# Events: 6K cycles
#
# Overhead Command Shared Object Symbol

 # ........  .......  .................  ...............................
 #
     74.11%    :3259  [unknown]          [k] 0x4a6c
      1.50%  cachetest  ld-2.11.2.so       [.] 0x1777c
      1.46%    :3259  [kernel.kallsyms]  [k] .perf_event_mmap_ctx
      1.25%    :3259  [kernel.kallsyms]  [k] restore
      0.74%    :3259  [kernel.kallsyms]  [k] ._raw_spin_lock
      0.71%    :3259  [kernel.kallsyms]  [k] .filemap_fault
      0.66%    :3259  [kernel.kallsyms]  [k] .memset
      0.54%  cachetest  [kernel.kallsyms]  [k] .sha_transform
      0.54%    :3259  [kernel.kallsyms]  [k] .copy_4K_page
      0.54%    :3259  [kernel.kallsyms]  [k] .find_get_page
      0.52%    :3259  [kernel.kallsyms]  [k] .trace_hardirqs_off
      0.50%    :3259  [kernel.kallsyms]  [k] .__do_fault
<SNIP>

After:

 # perf report

# Events: 6K cycles
#
# Overhead Command Shared Object Symbol

 # ........  .......  .................  ...............................
 #
     44.28%  cachetest  cachetest          [.] sumArrayNaive
     22.53%  cachetest  cachetest          [.] sumArrayOptimal
      6.59%  cachetest  ld-2.11.2.so       [.] 0x1777c
      2.13%  cachetest  [unknown]          [k] 0x340
      1.46%  cachetest  [kernel.kallsyms]  [k] .perf_event_mmap_ctx
      1.25%  cachetest  [kernel.kallsyms]  [k] restore
      0.74%  cachetest  [kernel.kallsyms]  [k] ._raw_spin_lock
      0.71%  cachetest  [kernel.kallsyms]  [k] .filemap_fault
      0.66%  cachetest  [kernel.kallsyms]  [k] .memset
      0.54%  cachetest  [kernel.kallsyms]  [k] .copy_4K_page
      0.54%  cachetest  [kernel.kallsyms]  [k] .find_get_page
      0.54%  cachetest  [kernel.kallsyms]  [k] .sha_transform
      0.52%  cachetest  [kernel.kallsyms]  [k] .trace_hardirqs_off
      0.50%  cachetest  [kernel.kallsyms]  [k] .__do_fault
<SNIP>

---

Changelog:
v4
- Rebased on Thomas' new userspace perf patches (with report -D reordering)
- Also cause perf annotate and perf diff to process events in order

v3
- Rebased on Thomas' userspace perf patch
- Dropped my userspace changes that Thomas' patch also addressed
- Dropped report -D reordering

v2
- Rebased on Arnaldo's ABI changes

v1
- Original patch with my ABI changes & report -D reordering

 tools/perf/builtin-annotate.c |    2 ++
 tools/perf/builtin-diff.c     |    2 ++
 tools/perf/builtin-record.c   |    5 ++++-
 tools/perf/builtin-report.c   |    2 ++
 4 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/builtin-annotate.c +2 -0
index 569a276..793db36 100644
@@ -375,6 +375,8 @@ static struct perf_event_ops event_ops = {
 	.mmap	= event__process_mmap,
 	.comm	= event__process_comm,
 	.fork	= event__process_task,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 static int __cmd_annotate(void)
tools/perf/builtin-diff.c +2 -0
index 5e1a043..d21dc25a 100644
@@ -61,6 +61,8 @@ static struct perf_event_ops event_ops = {
 	.exit	= event__process_task,
 	.fork	= event__process_task,
 	.lost	= event__process_lost,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
tools/perf/builtin-record.c +4 -1
index 699dd21..310dd21 100644
@@ -285,7 +285,7 @@ static void create_counter(int counter, int cpu)
 	if (system_wide)
 		attr->sample_type	|= PERF_SAMPLE_CPU;
 
-	if (sample_time)
+	if (sample_time || system_wide || !no_inherit || cpu_list)
 		attr->sample_type	|= PERF_SAMPLE_TIME;
 
 	if (raw_samples) {
@@ -327,6 +327,9 @@ try_again:
 				 * Old kernel, no attr->sample_id_type_all field
 				 */
 				sample_id_all_avail = false;
+				if (!sample_time && !raw_samples)
+					attr->sample_type &= ~PERF_SAMPLE_TIME;
+
 				goto retry_sample_id;
 			}
 
tools/perf/builtin-report.c +2 -0
index 904519f..5f01503 100644
@@ -244,6 +244,8 @@ static struct perf_event_ops event_ops = {
 	.event_type = event__process_event_type,
 	.tracing_data = event__process_tracing_data,
 	.build_id = event__process_build_id,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 extern volatile int session_done;
Signature · 1 line
1.7.2.3
#30 lore raw

[tip:perf/core] perf record,report,annotate,diff: Process events in order

Commit-ID:  eac23d1c384b55e4bbb89ea9e5a6bb77fb4d1140
Gitweb:     http://git.kernel.org/tip/eac23d1c384b55e4bbb89ea9e5a6bb77fb4d1140
Author:     Ian Munsie <[email protected]>
AuthorDate: Thu, 9 Dec 2010 16:33:53 +1100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 21 Dec 2010 20:17:51 -0200

perf record,report,annotate,diff: Process events in order

This patch changes perf report to ask for the ID info on all events be default if recording from multiple CPUs.

Perf report, annotate and diff will now process the events in order if the kernel is able to provide timestamps on all events. This ensures that events such as COMM and MMAP which are necessary to correctly interpret samples are processed prior to those samples so that they are attributed correctly.

Before:

 # perf record ./cachetest
 # perf report

# Events: 6K cycles
#
# Overhead Command Shared Object Symbol

 # ........  .......  .................  ...............................
 #
     74.11%    :3259  [unknown]          [k] 0x4a6c
      1.50%  cachetest  ld-2.11.2.so       [.] 0x1777c
      1.46%    :3259  [kernel.kallsyms]  [k] .perf_event_mmap_ctx
      1.25%    :3259  [kernel.kallsyms]  [k] restore
      0.74%    :3259  [kernel.kallsyms]  [k] ._raw_spin_lock
      0.71%    :3259  [kernel.kallsyms]  [k] .filemap_fault
      0.66%    :3259  [kernel.kallsyms]  [k] .memset
      0.54%  cachetest  [kernel.kallsyms]  [k] .sha_transform
      0.54%    :3259  [kernel.kallsyms]  [k] .copy_4K_page
      0.54%    :3259  [kernel.kallsyms]  [k] .find_get_page
      0.52%    :3259  [kernel.kallsyms]  [k] .trace_hardirqs_off
      0.50%    :3259  [kernel.kallsyms]  [k] .__do_fault
<SNIP>

After:

 # perf report

# Events: 6K cycles
#
# Overhead Command Shared Object Symbol

 # ........  .......  .................  ...............................
 #
     44.28%  cachetest  cachetest          [.] sumArrayNaive
     22.53%  cachetest  cachetest          [.] sumArrayOptimal
      6.59%  cachetest  ld-2.11.2.so       [.] 0x1777c
      2.13%  cachetest  [unknown]          [k] 0x340
      1.46%  cachetest  [kernel.kallsyms]  [k] .perf_event_mmap_ctx
      1.25%  cachetest  [kernel.kallsyms]  [k] restore
      0.74%  cachetest  [kernel.kallsyms]  [k] ._raw_spin_lock
      0.71%  cachetest  [kernel.kallsyms]  [k] .filemap_fault
      0.66%  cachetest  [kernel.kallsyms]  [k] .memset
      0.54%  cachetest  [kernel.kallsyms]  [k] .copy_4K_page
      0.54%  cachetest  [kernel.kallsyms]  [k] .find_get_page
      0.54%  cachetest  [kernel.kallsyms]  [k] .sha_transform
      0.52%  cachetest  [kernel.kallsyms]  [k] .trace_hardirqs_off
      0.50%  cachetest  [kernel.kallsyms]  [k] .__do_fault
<SNIP>

Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
LKML-Reference: <[email protected]>

---
 tools/perf/builtin-annotate.c |    2 ++
 tools/perf/builtin-diff.c     |    2 ++
 tools/perf/builtin-record.c   |    5 ++++-
 tools/perf/builtin-report.c   |    2 ++
 4 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/builtin-annotate.c +2 -0
index 48dbab4..c056cdc 100644
@@ -375,6 +375,8 @@ static struct perf_event_ops event_ops = {
 	.mmap	= event__process_mmap,
 	.comm	= event__process_comm,
 	.fork	= event__process_task,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 static int __cmd_annotate(void)
tools/perf/builtin-diff.c +2 -0
index af84e1c..97846dc 100644
@@ -61,6 +61,8 @@ static struct perf_event_ops event_ops = {
 	.exit	= event__process_task,
 	.fork	= event__process_task,
 	.lost	= event__process_lost,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
tools/perf/builtin-record.c +4 -1
index efd1b3c..5149e3d 100644
@@ -285,7 +285,7 @@ static void create_counter(int counter, int cpu)
 	if (system_wide)
 		attr->sample_type	|= PERF_SAMPLE_CPU;
 
-	if (sample_time)
+	if (sample_time || system_wide || !no_inherit || cpu_list)
 		attr->sample_type	|= PERF_SAMPLE_TIME;
 
 	if (raw_samples) {
@@ -327,6 +327,9 @@ try_again:
 				 * Old kernel, no attr->sample_id_type_all field
 				 */
 				sample_id_all_avail = false;
+				if (!sample_time && !raw_samples)
+					attr->sample_type &= ~PERF_SAMPLE_TIME;
+
 				goto retry_sample_id;
 			}
 
tools/perf/builtin-report.c +2 -0
index fd4c450..4af7ce6 100644
@@ -244,6 +244,8 @@ static struct perf_event_ops event_ops = {
 	.event_type = event__process_event_type,
 	.tracing_data = event__process_tracing_data,
 	.build_id = event__process_build_id,
+	.ordered_samples = true,
+	.ordering_requires_timestamps = true,
 };
 
 extern volatile int session_done;