Skip to contentSkip to conversation

perf tools: Fix ppid for non-main thread

PATCH In review David Ahern 3 participants 4 messages Apr 9, 2015 – Apr 11, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: Fix ppid for non-main thread

Commit ca6c41c59b9 sets the ppid based on what is read from the /proc/pid/status file when synthesizing fork events. This is correct thing to do for new processes but not threads of a process. Fix ppid for threads to be the main thread when synthesizing fork events (ie., assume main thread spawned all sub-threads in a process).

---
 tools/perf/util/event.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
tools/perf/util/event.c +12 -2
index 186929a..ff866c4 100644
@@ -183,8 +183,18 @@ static int perf_event__synthesize_fork(struct perf_tool *tool,
 {
 	memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
 
-	event->fork.ppid = ppid;
-	event->fork.ptid = ppid;
+	/*
+	 * for main thread set parent to ppid from status file. For other
+	 * threads set parent pid to main thread. ie., assume main thread
+	 * spawns all threads in a process
+	*/
+	if (tgid == pid) {
+		event->fork.ppid = ppid;
+		event->fork.ptid = ppid;
+	} else {
+		event->fork.ppid = tgid;
+		event->fork.ptid = tgid;
+	}
 	event->fork.pid  = tgid;
 	event->fork.tid  = pid;
 	event->fork.header.type = PERF_RECORD_FORK;
Signature · 1 line
1.7.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · David Ahern

Commit ca6c41c59b9 sets the ppid based on what is read from the /proc/pid/status file when synthesizing fork events. This is correct thing to do for new processes but not threads of a process. Fix ppid for threads to be the main thread when synthesizing fork events (ie., assume main thread spawned all sub-threads in a process).

That sounds right. :-) Sorry I should have noticed that a couple of weeks ago.

Quoted 36 lines
---
 tools/perf/util/event.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
tools/perf/util/event.c +12 -2
index 186929a..ff866c4 100644
@@ -183,8 +183,18 @@ static int perf_event__synthesize_fork(struct perf_tool *tool,
 {
 	memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
 
-	event->fork.ppid = ppid;
-	event->fork.ptid = ppid;
+	/*
+	 * for main thread set parent to ppid from status file. For other
+	 * threads set parent pid to main thread. ie., assume main thread
+	 * spawns all threads in a process
+	*/
+	if (tgid == pid) {
+		event->fork.ppid = ppid;
+		event->fork.ptid = ppid;
+	} else {
+		event->fork.ppid = tgid;
+		event->fork.ptid = tgid;
+	}
 	event->fork.pid  = tgid;
 	event->fork.tid  = pid;
 	event->fork.header.type = PERF_RECORD_FORK;
Signature · 1 line
1.7.1
#2 lore raw
Quoted 11 lines · Don Zickus
Quoted 5 lines · David Ahern
Quoted 5 lines

Commit ca6c41c59b9 sets the ppid based on what is read from the /proc/pid/status file when synthesizing fork events. This is correct thing to do for new processes but not threads of a process. Fix ppid for threads to be the main thread when synthesizing fork events (ie., assume main thread spawned all sub-threads in a process).

That sounds right.:-) Sorry I should have noticed that a couple of weeks
ago.

I believe this explains the performance delta you noticed with specjbb/jvm. Arnaldo is the one that figured out the performance hit is from cloning maps; from that analysis I realized what the goof was.

David

#3 lore raw

[tip:perf/core] perf tools: Fix synthesizing fork_event.ppid for non-main thread

In reply to David Ahern
perf tools: Fix synthesizing fork_event.ppid for non-main thread
Commit-ID:  7764a385f60bd200304a33124bdb4e684caeabdf
Gitweb:     http://git.kernel.org/tip/7764a385f60bd200304a33124bdb4e684caeabdf
Author:     David Ahern <[email protected]>
AuthorDate: Thu, 9 Apr 2015 12:48:27 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 10 Apr 2015 10:10:55 -0300

perf tools: Fix synthesizing fork_event.ppid for non-main thread

Commit ca6c41c59b9 sets the ppid based on what is read from the /proc/pid/status file when synthesizing fork events.

This is correct thing to do for new processes but not threads of a process.

Fix ppid for threads to be the main thread when synthesizing fork events (ie., assume main thread spawned all sub-threads in a process).

---
 tools/perf/util/event.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/perf/util/event.c +12 -2
index 5516236..9d09851 100644
@@ -183,8 +183,18 @@ static int perf_event__synthesize_fork(struct perf_tool *tool,
 {
 	memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
 
-	event->fork.ppid = ppid;
-	event->fork.ptid = ppid;
+	/*
+	 * for main thread set parent to ppid from status file. For other
+	 * threads set parent pid to main thread. ie., assume main thread
+	 * spawns all threads in a process
+	*/
+	if (tgid == pid) {
+		event->fork.ppid = ppid;
+		event->fork.ptid = ppid;
+	} else {
+		event->fork.ppid = tgid;
+		event->fork.ptid = tgid;
+	}
 	event->fork.pid  = tgid;
 	event->fork.tid  = pid;
 	event->fork.header.type = PERF_RECORD_FORK;