Skip to content

Commit 9dc9855

Browse files
namhyungacmel
authored andcommitted
perf arm-spe: Track task context switch for cpu-mode events
When perf report synthesize events from ARM SPE data, it refers to current cpu, pid and tid in the machine. But there's no place to set them in the ARM SPE decoder. I'm seeing all pid/tid is set to -1 and user symbols are not resolved in the output. # perf record -a -e arm_spe_0/ts_enable=1/ sleep 1 # perf report -q | head 8.77% 8.77% :-1 [kernel.kallsyms] [k] format_decode 7.02% 7.02% :-1 [kernel.kallsyms] [k] seq_printf 7.02% 7.02% :-1 [unknown] [.] 0x0000ffff9f687c34 5.26% 5.26% :-1 [kernel.kallsyms] [k] vsnprintf 3.51% 3.51% :-1 [kernel.kallsyms] [k] string 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f66ae20 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f670b3c 3.51% 3.51% :-1 [unknown] [.] 0x0000ffff9f67c040 1.75% 1.75% :-1 [kernel.kallsyms] [k] ___cache_free 1.75% 1.75% :-1 [kernel.kallsyms] [k] __count_memcg_events Like Intel PT, add context switch records to track task info. As ARM SPE support was added later than PERF_RECORD_SWITCH_CPU_WIDE, I think we can safely set the attr.context_switch bit and use it. Reviewed-by: Leo Yan <leo.yan@linaro.org> Signed-off-by: German Gomez <german.gomez@arm.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: John Garry <john.garry@huawei.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20211111133625.193568-2-german.gomez@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3ca3af7 commit 9dc9855

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tools/perf/arch/arm64/util/arm-spe.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
251251
tracking_evsel->core.attr.sample_period = 1;
252252

253253
/* In per-cpu case, always need the time of mmap events etc */
254-
if (!perf_cpu_map__empty(cpus))
254+
if (!perf_cpu_map__empty(cpus)) {
255255
evsel__set_sample_bit(tracking_evsel, TIME);
256+
evsel__set_sample_bit(tracking_evsel, CPU);
257+
/* also track task context switch */
258+
tracking_evsel->core.attr.context_switch = 1;
259+
}
256260

257261
return 0;
258262
}

tools/perf/util/arm-spe.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,25 @@ static int arm_spe_process_timeless_queues(struct arm_spe *spe, pid_t tid,
681681
return 0;
682682
}
683683

684+
static int arm_spe_context_switch(struct arm_spe *spe, union perf_event *event,
685+
struct perf_sample *sample)
686+
{
687+
pid_t pid, tid;
688+
int cpu;
689+
690+
if (!(event->header.misc & PERF_RECORD_MISC_SWITCH_OUT))
691+
return 0;
692+
693+
pid = event->context_switch.next_prev_pid;
694+
tid = event->context_switch.next_prev_tid;
695+
cpu = sample->cpu;
696+
697+
if (tid == -1)
698+
pr_warning("context_switch event has no tid\n");
699+
700+
return machine__set_current_tid(spe->machine, cpu, pid, tid);
701+
}
702+
684703
static int arm_spe_process_event(struct perf_session *session,
685704
union perf_event *event,
686705
struct perf_sample *sample,
@@ -718,6 +737,12 @@ static int arm_spe_process_event(struct perf_session *session,
718737
}
719738
} else if (timestamp) {
720739
err = arm_spe_process_queues(spe, timestamp);
740+
if (err)
741+
return err;
742+
743+
if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE ||
744+
event->header.type == PERF_RECORD_SWITCH)
745+
err = arm_spe_context_switch(spe, event, sample);
721746
}
722747

723748
return err;

0 commit comments

Comments
 (0)