Skip to contentSkip to conversation

perf tools: Use tid for finding thread

PATCH Superseded Namhyung Kim 4 participants 5 messages May 7, 2014 – May 12, 2014 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf tools: Use tid for finding thread

I believe that passing pid (instead of tid) as the 3rd arg of the machine__find*_thread() was to find a main thread so that it can search proper map group for symbols. However with the map sharing patch applied, it now can do it in any thread.

It fixes a bug when each thread has different name, it only reports a main thread for samples in other threads.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-inject.c     | 2 +-
 tools/perf/builtin-kmem.c       | 2 +-
 tools/perf/tests/code-reading.c | 2 +-
 tools/perf/util/build-id.c      | 2 +-
 tools/perf/util/event.c         | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-inject.c +1 -1
index 3a7387551369..6a3af0013d68 100644
@@ -209,7 +209,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
 
 	cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
-	thread = machine__findnew_thread(machine, sample->pid, sample->pid);
+	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
 	if (thread == NULL) {
 		pr_err("problem processing %d event, skipping it.\n",
 		       event->header.type);
tools/perf/builtin-kmem.c +1 -1
index f91fa4376f4b..bef3376bfaf3 100644
@@ -235,7 +235,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 				struct machine *machine)
 {
 	struct thread *thread = machine__findnew_thread(machine, sample->pid,
-							sample->pid);
+							sample->tid);
 
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
tools/perf/tests/code-reading.c +1 -1
index adf3de3e38d6..67f2d6323558 100644
@@ -256,7 +256,7 @@ static int process_sample_event(struct machine *machine,
 		return -1;
 	}
 
-	thread = machine__findnew_thread(machine, sample.pid, sample.pid);
+	thread = machine__findnew_thread(machine, sample.pid, sample.tid);
 	if (!thread) {
 		pr_debug("machine__findnew_thread failed\n");
 		return -1;
tools/perf/util/build-id.c +1 -1
index 6baabe63182b..a904a4cfe7d3 100644
@@ -25,7 +25,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
 	struct addr_location al;
 	u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 	struct thread *thread = machine__findnew_thread(machine, sample->pid,
-							sample->pid);
+							sample->tid);
 
 	if (thread == NULL) {
 		pr_err("problem processing %d event, skipping it.\n",
tools/perf/util/event.c +1 -1
index dbcaea1a8180..65795b835b39 100644
@@ -788,7 +788,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
 {
 	u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 	struct thread *thread = machine__findnew_thread(machine, sample->pid,
-							sample->pid);
+							sample->tid);
 
 	if (thread == NULL)
 		return -1;
Signature · 1 line
1.9.2
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Namhyung Kim

I believe that passing pid (instead of tid) as the 3rd arg of the machine__find*_thread() was to find a main thread so that it can search proper map group for symbols. However with the map sharing patch applied, it now can do it in any thread.

Your patch makes the code more meaningful for sure.
The pid, pid looked like a bug to me at first, but then I realized, that yes, it is
look for the main thread.

Quoted 84 lines

It fixes a bug when each thread has different name, it only reports a main thread for samples in other threads.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-inject.c     | 2 +-
 tools/perf/builtin-kmem.c       | 2 +-
 tools/perf/tests/code-reading.c | 2 +-
 tools/perf/util/build-id.c      | 2 +-
 tools/perf/util/event.c         | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-inject.c +1 -1
index 3a7387551369..6a3af0013d68 100644
@@ -209,7 +209,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
 
        cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
-       thread = machine__findnew_thread(machine, sample->pid, sample->pid);
+       thread = machine__findnew_thread(machine, sample->pid, sample->tid);
        if (thread == NULL) {
                pr_err("problem processing %d event, skipping it.\n",
                       event->header.type);
tools/perf/builtin-kmem.c +1 -1
index f91fa4376f4b..bef3376bfaf3 100644
@@ -235,7 +235,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
                                struct machine *machine)
 {
        struct thread *thread = machine__findnew_thread(machine, sample->pid,
-                                                       sample->pid);
+                                                       sample->tid);
 
        if (thread == NULL) {
                pr_debug("problem processing %d event, skipping it.\n",
tools/perf/tests/code-reading.c +1 -1
index adf3de3e38d6..67f2d6323558 100644
@@ -256,7 +256,7 @@ static int process_sample_event(struct machine *machine,
                return -1;
        }
 
-       thread = machine__findnew_thread(machine, sample.pid, sample.pid);
+       thread = machine__findnew_thread(machine, sample.pid, sample.tid);
        if (!thread) {
                pr_debug("machine__findnew_thread failed\n");
                return -1;
tools/perf/util/build-id.c +1 -1
index 6baabe63182b..a904a4cfe7d3 100644
@@ -25,7 +25,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
        struct addr_location al;
        u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
        struct thread *thread = machine__findnew_thread(machine, sample->pid,
-                                                       sample->pid);
+                                                       sample->tid);
 
        if (thread == NULL) {
                pr_err("problem processing %d event, skipping it.\n",
tools/perf/util/event.c +1 -2
index dbcaea1a8180..65795b835b39 100644
@@ -788,7 +788,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
 {
        u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
        struct thread *thread = machine__findnew_thread(machine, sample->pid,
-                                                       sample->pid);
+                                                       sample->tid);
 
        if (thread == NULL)
                return -1;
--

1.9.2

Acked-by on v1 1/1
#2 lore raw
In reply to Namhyung Kim
Quoted 5 lines · Namhyung Kim

I believe that passing pid (instead of tid) as the 3rd arg of the machine__find*_thread() was to find a main thread so that it can search proper map group for symbols. However with the map sharing patch applied, it now can do it in any thread.

Quoted 7 lines

It fixes a bug when each thread has different name, it only reports a main thread for samples in other threads.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Stephane Eranian <[email protected]>
#3 lore raw
In reply to Namhyung Kim
Quoted 7 lines · Namhyung Kim

I believe that passing pid (instead of tid) as the 3rd arg of the machine__find*_thread() was to find a main thread so that it can search proper map group for symbols. However with the map sharing patch applied, it now can do it in any thread.

It fixes a bug when each thread has different name, it only reports a main thread for samples in other threads.

and breaks tests 14 and 26 ;-)

...

14: Test matching and linking multiple hists               : FAILED!
15: Try 'use perf' in python, checking link problems       : Ok
16: Test breakpoint overflow signal handler                : Ok
17: Test breakpoint overflow sampling                      : Ok
18: Test number of exit event of a simple workload         : Ok
19: Test software clock events have valid period values    : Ok
20: Test converting perf time to TSC                       : Ok
21: Test object code reading                               : Ok
22: Test sample parsing                                    : Ok
23: Test using a dummy software event to keep tracking     : Ok
24: Test parsing with no sample_id_all bit set             : Ok
25: Test dwarf unwind                                      : Ok
26: Test filtering hist entries                            : FAILED!

...

jirka

author maintainer
#4 lore raw
Quoted 25 lines · Jiri Olsa
Quoted 7 lines · Namhyung Kim

I believe that passing pid (instead of tid) as the 3rd arg of the machine__find*_thread() was to find a main thread so that it can search proper map group for symbols. However with the map sharing patch applied, it now can do it in any thread.

It fixes a bug when each thread has different name, it only reports a main thread for samples in other threads.

and breaks tests 14 and 26 ;-)

...

14: Test matching and linking multiple hists               : FAILED!
15: Try 'use perf' in python, checking link problems       : Ok
16: Test breakpoint overflow signal handler                : Ok
17: Test breakpoint overflow sampling                      : Ok
18: Test number of exit event of a simple workload         : Ok
19: Test software clock events have valid period values    : Ok
20: Test converting perf time to TSC                       : Ok
21: Test object code reading                               : Ok
22: Test sample parsing                                    : Ok
23: Test using a dummy software event to keep tracking     : Ok
24: Test parsing with no sample_id_all bit set             : Ok
25: Test dwarf unwind                                      : Ok
26: Test filtering hist entries                            : FAILED!
Quoted 1 line

...

Forgot to set sample->tid for those cases. Will fix.

Thanks,
Namhyung