Skip to contentSkip to conversation

perf fixes

GIT PULL New Frederic Weisbecker 2 participants 6 messages May 31, 2010 – Jun 1, 2010 perf events

lore
Share & tools
lore
#0 lore raw

Ingo,

Please pull the perf/urgent branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgent

Thanks,
Frederic
---

Frederic Weisbecker (3):
perf: Process comm events by tid
perf: Use event__process_task from perf sched
perf: Do the comm inheritance per thread in event__process_task

Borislav Petkov (1):
perf-record: Check correct pid when forking

 tools/perf/builtin-record.c |    3 +--
 tools/perf/builtin-sched.c  |    1 +
 tools/perf/util/event.c     |   13 ++++---------
 3 files changed, 6 insertions(+), 11 deletions(-)
#1 lore raw

PATCH 1/4 perf: Process comm events by tid

When we synthetize the existing running tasks though procfs, we walk through every threads of a process, queuing one comm events per tid.

But then on report time, event__process_comm() only creates and sets the comm on a per process granularity. This is the right thing for comm events that came from the kernel, as they are only created on exec. Sub-threads then inherit their comm from fork events. But that doesn't work with our synthetized comm events taken from procfs informations as the per thread granularity is done on comm events directly there.

Hence we need event__process_comm() to work with the tid rather than the pid. It won't change anything for comm events coming from the kernel but this will fix the synthetized ones.

Before:

	$ ./perf report -D | grep COMM | grep firefox
	0x2c7b8 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c7d0 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c7e8 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c800 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c818 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c830 [0x18]: PERF_RECORD_COMM: firefox:5297

After:

	$ ./perf report -D | grep COMM | grep firefox
	0x2c7b8 [0x18]: PERF_RECORD_COMM: firefox:5297
	0x2c7d0 [0x18]: PERF_RECORD_COMM: firefox:5299
	0x2c7e8 [0x18]: PERF_RECORD_COMM: firefox:5300
	0x2c800 [0x18]: PERF_RECORD_COMM: firefox:5308
	0x2c818 [0x18]: PERF_RECORD_COMM: firefox:5309
	0x2c830 [0x18]: PERF_RECORD_COMM: firefox:5312

This fixes various unresolved pid on perf sched.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/event.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/event.c +2 -2
index 50771b5..d28d809 100644
@@ -370,9 +370,9 @@ static int thread__set_comm_adjust(struct thread *self, const char *comm)
 
 int event__process_comm(event_t *self, struct perf_session *session)
 {
-	struct thread *thread = perf_session__findnew(session, self->comm.pid);
+	struct thread *thread = perf_session__findnew(session, self->comm.tid);
 
-	dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid);
+	dump_printf(": %s:%d\n", self->comm.comm, self->comm.tid);
 
 	if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm)) {
 		dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
Signature · 1 line
1.6.2.3
#2 lore raw

PATCH 2/4 perf: Use event__process_task from perf sched

In reply to Frederic Weisbecker

perf sched uses event__process_comm(), which means it can resolve comms from:

- tasks that have exec'ed (kernel comm events)
- tasks that were running when perf record started the actual recording (synthetized comm events)

But perf sched can't resolve the pids of tasks that were created after the recording started.

To solve this, we need to inherit the comms on fork events using event__process_task().

This fixes various unresolved pids in perf sched, easily visible with:
perf sched record perf bench sched messaging

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-sched.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/builtin-sched.c +1 -0
index f67bce2..55f3b5d 100644
@@ -1645,6 +1645,7 @@ static struct perf_event_ops event_ops = {
 	.sample			= process_sample_event,
 	.comm			= event__process_comm,
 	.lost			= event__process_lost,
+	.fork			= event__process_task,
 	.ordered_samples	= true,
 };
 
Signature · 1 line
1.6.2.3
#3 lore raw

PATCH 3/4 perf: Do the comm inheritance per thread in event__process_task

In reply to Frederic Weisbecker

event__process_task() doesn't propagate the comm copy on clone, but only on process fork. So we loose all the tid:comm resolution for tasks that aren't a main process thread.

Progragate the per thread granularity to event__process_task for pid resolution.

This fixes various unresolved pids in perf sched, especially when we trace multithread processes. The problem is quickly reproducible with the messaging benchmark using the multithread mode "-t" :

perf sched record perf bench sched messaging -t

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/event.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
tools/perf/util/event.c +2 -7
index d28d809..1f08f00 100644
@@ -532,16 +532,11 @@ out_problem:
 
 int event__process_task(event_t *self, struct perf_session *session)
 {
-	struct thread *thread = perf_session__findnew(session, self->fork.pid);
-	struct thread *parent = perf_session__findnew(session, self->fork.ppid);
+	struct thread *thread = perf_session__findnew(session, self->fork.tid);
+	struct thread *parent = perf_session__findnew(session, self->fork.ptid);
 
 	dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
 		    self->fork.ppid, self->fork.ptid);
-	/*
-	 * A thread clone will have the same PID for both parent and child.
-	 */
-	if (thread == parent)
-		return 0;
 
 	if (self->header.type == PERF_RECORD_EXIT)
 		return 0;
Signature · 1 line
1.6.2.3
#4 lore raw

PATCH 4/4 perf-record: Check correct pid when forking

In reply to Frederic Weisbecker

From: Borislav Petkov <[email protected]>

When forking the child to be traced, we should check the correct return value from fork() and not a local variable which is otherwise unused.

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

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-record.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +1 -2
index 9bc8905..dc3435e 100644
@@ -503,7 +503,6 @@ static int __cmd_record(int argc, const char **argv)
 {
 	int i, counter;
 	struct stat st;
-	pid_t pid = 0;
 	int flags;
 	int err;
 	unsigned long waking = 0;
@@ -572,7 +571,7 @@ static int __cmd_record(int argc, const char **argv)
 
 	if (forks) {
 		child_pid = fork();
-		if (pid < 0) {
+		if (child_pid < 0) {
 			perror("failed to fork");
 			exit(-1);
 		}
Signature · 1 line
1.6.2.3
#5 lore raw
In reply to Frederic Weisbecker
Quoted 16 lines · Frederic Weisbecker

Ingo,

Please pull the perf/urgent branch that can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/urgent

Thanks,
Frederic
---

Frederic Weisbecker (3):
perf: Process comm events by tid
perf: Use event__process_task from perf sched
perf: Do the comm inheritance per thread in event__process_task

Quoted 8 lines

Borislav Petkov (1):
perf-record: Check correct pid when forking

 tools/perf/builtin-record.c |    3 +--
 tools/perf/builtin-sched.c  |    1 +
 tools/perf/util/event.c     |   13 ++++---------
 3 files changed, 6 insertions(+), 11 deletions(-)

Pulled, thanks a lot Frederic!

Ingo