aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-07-14 06:02:25 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-07-16 16:57:33 -0400
commit1fcb8768636d38cb6fdfeef83a5ee596c4bd9c56 (patch)
treeffefb332e8e0e035201fbe4b0f4cef9301ac76d1
parent57608cfd8827a74237d264a197722e2c99f72da4 (diff)
perf machine: Fix the value used for unknown pids
The value used for unknown pids cannot be zero because that is used by the "idle" task. Use -1 instead. Also handle the unknown pid case when creating map groups. Note that, threads with an unknown pid should not occur because fork (or synthesized) events precede the thread's existence. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1405332185-4050-2-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-sched.c12
-rw-r--r--tools/perf/util/machine.c6
-rw-r--r--tools/perf/util/session.c5
-rw-r--r--tools/perf/util/thread.c2
4 files changed, 13 insertions, 12 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c38d06c04775..b7f555add0c8 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -935,8 +935,8 @@ static int latency_switch_event(struct perf_sched *sched,
935 return -1; 935 return -1;
936 } 936 }
937 937
938 sched_out = machine__findnew_thread(machine, 0, prev_pid); 938 sched_out = machine__findnew_thread(machine, -1, prev_pid);
939 sched_in = machine__findnew_thread(machine, 0, next_pid); 939 sched_in = machine__findnew_thread(machine, -1, next_pid);
940 940
941 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); 941 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid);
942 if (!out_events) { 942 if (!out_events) {
@@ -979,7 +979,7 @@ static int latency_runtime_event(struct perf_sched *sched,
979{ 979{
980 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); 980 const u32 pid = perf_evsel__intval(evsel, sample, "pid");
981 const u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); 981 const u64 runtime = perf_evsel__intval(evsel, sample, "runtime");
982 struct thread *thread = machine__findnew_thread(machine, 0, pid); 982 struct thread *thread = machine__findnew_thread(machine, -1, pid);
983 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); 983 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid);
984 u64 timestamp = sample->time; 984 u64 timestamp = sample->time;
985 int cpu = sample->cpu; 985 int cpu = sample->cpu;
@@ -1012,7 +1012,7 @@ static int latency_wakeup_event(struct perf_sched *sched,
1012 struct thread *wakee; 1012 struct thread *wakee;
1013 u64 timestamp = sample->time; 1013 u64 timestamp = sample->time;
1014 1014
1015 wakee = machine__findnew_thread(machine, 0, pid); 1015 wakee = machine__findnew_thread(machine, -1, pid);
1016 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); 1016 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid);
1017 if (!atoms) { 1017 if (!atoms) {
1018 if (thread_atoms_insert(sched, wakee)) 1018 if (thread_atoms_insert(sched, wakee))
@@ -1072,7 +1072,7 @@ static int latency_migrate_task_event(struct perf_sched *sched,
1072 if (sched->profile_cpu == -1) 1072 if (sched->profile_cpu == -1)
1073 return 0; 1073 return 0;
1074 1074
1075 migrant = machine__findnew_thread(machine, 0, pid); 1075 migrant = machine__findnew_thread(machine, -1, pid);
1076 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); 1076 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid);
1077 if (!atoms) { 1077 if (!atoms) {
1078 if (thread_atoms_insert(sched, migrant)) 1078 if (thread_atoms_insert(sched, migrant))
@@ -1290,7 +1290,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
1290 return -1; 1290 return -1;
1291 } 1291 }
1292 1292
1293 sched_in = machine__findnew_thread(machine, 0, next_pid); 1293 sched_in = machine__findnew_thread(machine, -1, next_pid);
1294 1294
1295 sched->curr_thread[this_cpu] = sched_in; 1295 sched->curr_thread[this_cpu] = sched_in;
1296 1296
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index e9b943acaa5e..5b8087728f28 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -34,7 +34,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
34 return -ENOMEM; 34 return -ENOMEM;
35 35
36 if (pid != HOST_KERNEL_ID) { 36 if (pid != HOST_KERNEL_ID) {
37 struct thread *thread = machine__findnew_thread(machine, 0, 37 struct thread *thread = machine__findnew_thread(machine, -1,
38 pid); 38 pid);
39 char comm[64]; 39 char comm[64];
40 40
@@ -286,7 +286,7 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
286 * the full rbtree: 286 * the full rbtree:
287 */ 287 */
288 if (machine->last_match && machine->last_match->tid == tid) { 288 if (machine->last_match && machine->last_match->tid == tid) {
289 if (pid && pid != machine->last_match->pid_) 289 if (pid != -1 && pid != machine->last_match->pid_)
290 machine->last_match->pid_ = pid; 290 machine->last_match->pid_ = pid;
291 return machine->last_match; 291 return machine->last_match;
292 } 292 }
@@ -297,7 +297,7 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
297 297
298 if (th->tid == tid) { 298 if (th->tid == tid) {
299 machine->last_match = th; 299 machine->last_match = th;
300 if (pid && pid != th->pid_) 300 if (pid != -1 && pid != th->pid_)
301 th->pid_ = pid; 301 th->pid_ = pid;
302 return th; 302 return th;
303 } 303 }
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 64a186edc7be..c2f4ca917469 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1083,13 +1083,14 @@ void perf_event_header__bswap(struct perf_event_header *hdr)
1083 1083
1084struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) 1084struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
1085{ 1085{
1086 return machine__findnew_thread(&session->machines.host, 0, pid); 1086 return machine__findnew_thread(&session->machines.host, -1, pid);
1087} 1087}
1088 1088
1089static struct thread *perf_session__register_idle_thread(struct perf_session *session) 1089static struct thread *perf_session__register_idle_thread(struct perf_session *session)
1090{ 1090{
1091 struct thread *thread = perf_session__findnew(session, 0); 1091 struct thread *thread;
1092 1092
1093 thread = machine__findnew_thread(&session->machines.host, 0, 0);
1093 if (thread == NULL || thread__set_comm(thread, "swapper", 0)) { 1094 if (thread == NULL || thread__set_comm(thread, "swapper", 0)) {
1094 pr_err("problem inserting idle task.\n"); 1095 pr_err("problem inserting idle task.\n");
1095 thread = NULL; 1096 thread = NULL;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 2fde0d5e40b5..7a32f447a8e7 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -13,7 +13,7 @@ int thread__init_map_groups(struct thread *thread, struct machine *machine)
13 struct thread *leader; 13 struct thread *leader;
14 pid_t pid = thread->pid_; 14 pid_t pid = thread->pid_;
15 15
16 if (pid == thread->tid) { 16 if (pid == thread->tid || pid == -1) {
17 thread->mg = map_groups__new(); 17 thread->mg = map_groups__new();
18 } else { 18 } else {
19 leader = machine__findnew_thread(machine, pid, pid); 19 leader = machine__findnew_thread(machine, pid, pid);