Skip to content

Commit 314add6

Browse files
ahunter6acmel
authored andcommitted
perf tools: change machine__findnew_thread() to set thread pid
Add a new parameter for 'pid' to machine__findnew_thread(). Change callers to pass 'pid' when it is known. Note that callers sometimes want to find the main thread which has the memory maps. The main thread has tid == pid so the usage in that case is: machine__findnew_thread(machine, pid, pid) whereas the usage to find the specific thread is: machine__findnew_thread(machine, pid, tid) Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: David Ahern <dsahern@gmail.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> 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/1377591794-30553-2-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 00e4cb1 commit 314add6

14 files changed

Lines changed: 55 additions & 32 deletions

‎tools/perf/builtin-inject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
198198

199199
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
200200

201-
thread = machine__findnew_thread(machine, event->ip.pid);
201+
thread = machine__findnew_thread(machine, event->ip.pid, event->ip.pid);
202202
if (thread == NULL) {
203203
pr_err("problem processing %d event, skipping it.\n",
204204
event->header.type);

‎tools/perf/builtin-kmem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
305305
struct perf_evsel *evsel,
306306
struct machine *machine)
307307
{
308-
struct thread *thread = machine__findnew_thread(machine, event->ip.pid);
308+
struct thread *thread = machine__findnew_thread(machine, event->ip.pid,
309+
event->ip.pid);
309310

310311
if (thread == NULL) {
311312
pr_debug("problem processing %d event, skipping it.\n",

‎tools/perf/builtin-kvm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static int process_sample_event(struct perf_tool *tool,
815815
if (skip_sample(kvm, sample))
816816
return 0;
817817

818-
thread = machine__findnew_thread(machine, sample->tid);
818+
thread = machine__findnew_thread(machine, sample->pid, sample->tid);
819819
if (thread == NULL) {
820820
pr_debug("problem processing %d event, skipping it.\n",
821821
event->header.type);

‎tools/perf/builtin-lock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,8 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
805805
struct perf_evsel *evsel,
806806
struct machine *machine)
807807
{
808-
struct thread *thread = machine__findnew_thread(machine, sample->tid);
808+
struct thread *thread = machine__findnew_thread(machine, sample->pid,
809+
sample->tid);
809810

810811
if (thread == NULL) {
811812
pr_debug("problem processing %d event, skipping it.\n",

‎tools/perf/builtin-sched.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ static int replay_fork_event(struct perf_sched *sched,
724724
{
725725
struct thread *child, *parent;
726726

727-
child = machine__findnew_thread(machine, event->fork.tid);
728-
parent = machine__findnew_thread(machine, event->fork.ptid);
727+
child = machine__findnew_thread(machine, event->fork.pid,
728+
event->fork.tid);
729+
parent = machine__findnew_thread(machine, event->fork.ppid,
730+
event->fork.ptid);
729731

730732
if (child == NULL || parent == NULL) {
731733
pr_debug("thread does not exist on fork event: child %p, parent %p\n",
@@ -934,8 +936,8 @@ static int latency_switch_event(struct perf_sched *sched,
934936
return -1;
935937
}
936938

937-
sched_out = machine__findnew_thread(machine, prev_pid);
938-
sched_in = machine__findnew_thread(machine, next_pid);
939+
sched_out = machine__findnew_thread(machine, 0, prev_pid);
940+
sched_in = machine__findnew_thread(machine, 0, next_pid);
939941

940942
out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid);
941943
if (!out_events) {
@@ -978,7 +980,7 @@ static int latency_runtime_event(struct perf_sched *sched,
978980
{
979981
const u32 pid = perf_evsel__intval(evsel, sample, "pid");
980982
const u64 runtime = perf_evsel__intval(evsel, sample, "runtime");
981-
struct thread *thread = machine__findnew_thread(machine, pid);
983+
struct thread *thread = machine__findnew_thread(machine, 0, pid);
982984
struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid);
983985
u64 timestamp = sample->time;
984986
int cpu = sample->cpu;
@@ -1016,7 +1018,7 @@ static int latency_wakeup_event(struct perf_sched *sched,
10161018
if (!success)
10171019
return 0;
10181020

1019-
wakee = machine__findnew_thread(machine, pid);
1021+
wakee = machine__findnew_thread(machine, 0, pid);
10201022
atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid);
10211023
if (!atoms) {
10221024
if (thread_atoms_insert(sched, wakee))
@@ -1070,7 +1072,7 @@ static int latency_migrate_task_event(struct perf_sched *sched,
10701072
if (sched->profile_cpu == -1)
10711073
return 0;
10721074

1073-
migrant = machine__findnew_thread(machine, pid);
1075+
migrant = machine__findnew_thread(machine, 0, pid);
10741076
atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid);
10751077
if (!atoms) {
10761078
if (thread_atoms_insert(sched, migrant))
@@ -1289,8 +1291,8 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
12891291
return -1;
12901292
}
12911293

1292-
sched_out = machine__findnew_thread(machine, prev_pid);
1293-
sched_in = machine__findnew_thread(machine, next_pid);
1294+
sched_out = machine__findnew_thread(machine, 0, prev_pid);
1295+
sched_in = machine__findnew_thread(machine, 0, next_pid);
12941296

12951297
sched->curr_thread[this_cpu] = sched_in;
12961298

‎tools/perf/builtin-script.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
501501
struct machine *machine)
502502
{
503503
struct addr_location al;
504-
struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
504+
struct thread *thread = machine__findnew_thread(machine, event->ip.pid,
505+
event->ip.tid);
505506

506507
if (thread == NULL) {
507508
pr_debug("problem processing %d event, skipping it.\n",

‎tools/perf/builtin-trace.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
521521
if (sc->filtered)
522522
return 0;
523523

524-
thread = machine__findnew_thread(&trace->host, sample->tid);
524+
thread = machine__findnew_thread(&trace->host, sample->pid,
525+
sample->tid);
525526
ttrace = thread__trace(thread, trace->output);
526527
if (ttrace == NULL)
527528
return -1;
@@ -572,7 +573,8 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
572573
if (sc->filtered)
573574
return 0;
574575

575-
thread = machine__findnew_thread(&trace->host, sample->tid);
576+
thread = machine__findnew_thread(&trace->host, sample->pid,
577+
sample->tid);
576578
ttrace = thread__trace(thread, trace->output);
577579
if (ttrace == NULL)
578580
return -1;
@@ -628,7 +630,9 @@ static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evs
628630
{
629631
u64 runtime = perf_evsel__intval(evsel, sample, "runtime");
630632
double runtime_ms = (double)runtime / NSEC_PER_MSEC;
631-
struct thread *thread = machine__findnew_thread(&trace->host, sample->tid);
633+
struct thread *thread = machine__findnew_thread(&trace->host,
634+
sample->pid,
635+
sample->tid);
632636
struct thread_trace *ttrace = thread__trace(thread, trace->output);
633637

634638
if (ttrace == NULL)

‎tools/perf/tests/code-reading.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int process_sample_event(struct machine *machine,
257257
return -1;
258258
}
259259

260-
thread = machine__findnew_thread(machine, sample.pid);
260+
thread = machine__findnew_thread(machine, sample.pid, sample.pid);
261261
if (!thread) {
262262
pr_debug("machine__findnew_thread failed\n");
263263
return -1;
@@ -446,7 +446,7 @@ static int do_test_code_reading(bool try_kcore)
446446
goto out_err;
447447
}
448448

449-
thread = machine__findnew_thread(machine, pid);
449+
thread = machine__findnew_thread(machine, pid, pid);
450450
if (!thread) {
451451
pr_debug("machine__findnew_thread failed\n");
452452
goto out_err;

‎tools/perf/tests/hists_link.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ static struct machine *setup_fake_machine(struct machines *machines)
8888
for (i = 0; i < ARRAY_SIZE(fake_threads); i++) {
8989
struct thread *thread;
9090

91-
thread = machine__findnew_thread(machine, fake_threads[i].pid);
91+
thread = machine__findnew_thread(machine, fake_threads[i].pid,
92+
fake_threads[i].pid);
9293
if (thread == NULL)
9394
goto out;
9495

‎tools/perf/util/build-id.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
2424
{
2525
struct addr_location al;
2626
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
27-
struct thread *thread = machine__findnew_thread(machine, event->ip.pid);
27+
struct thread *thread = machine__findnew_thread(machine, event->ip.pid,
28+
event->ip.pid);
2829

2930
if (thread == NULL) {
3031
pr_err("problem processing %d event, skipping it.\n",
@@ -47,7 +48,9 @@ static int perf_event__exit_del_thread(struct perf_tool *tool __maybe_unused,
4748
__maybe_unused,
4849
struct machine *machine)
4950
{
50-
struct thread *thread = machine__findnew_thread(machine, event->fork.tid);
51+
struct thread *thread = machine__findnew_thread(machine,
52+
event->fork.pid,
53+
event->fork.tid);
5154

5255
dump_printf("(%d:%d):(%d:%d)\n", event->fork.pid, event->fork.tid,
5356
event->fork.ppid, event->fork.ptid);

0 commit comments

Comments
 (0)