A couple of changes related to edge cases since commit 8d3031d39fe8 ("perf cs-etm: Track exception level").
I think the second one is low risk seeing as any path requiring a thread leading up to adding to the histogram would already have been crashing. Maybe the thread check could also be added to hist_entry_iter__add() although other users of it don't seem to have the same issue, and there is another use of al.thread above in builtin-report.c so it's probably ok where I've added it.
Applies to perf-tools-next/perf-tools-next (929ff679b69)
James Clark (2): perf cs-etm: Handle per-thread mode on EL1 host kernel case perf report: Don't add to histogram when there is no thread found
tools/perf/builtin-report.c | 3 +++ tools/perf/util/cs-etm.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
base-commit: 929ff679b694f0f9656aec38b3a7d5c440c5ca24
In per-thread mode there are no context packets so no way to determine which type of context packets exist. But because it's only possible to trace host processes in per-thread mode without context packets then assume host in this case.
This fixes the per-thread test case failures when running on nVHE:
98: Check Arm CoreSight trace data recording and synthesized samples: --- start --- ... Recording trace with '-e cs_etm/timestamp=0/ --per-thread' Looking at perf.data file for dumping branch samples: CoreSight basic testing with '-e cs_etm/timestamp=0/ --per-thread': FAIL Recording trace with '-e cs_etm/timestamp=1/ --per-thread' Looking at perf.data file for dumping branch samples: CoreSight basic testing with '-e cs_etm/timestamp=1/ --per-thread': FAIL ...
Fixes: 8d3031d39fe8 ("perf cs-etm: Track exception level") Signed-off-by: James Clark james.clark@arm.com --- tools/perf/util/cs-etm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 1419b40dfbe8..85821cc5650e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -900,10 +900,17 @@ static struct machine *cs_etm__get_machine(struct cs_etm_queue *etmq,
/* * For any virtualisation based on nVHE (e.g. pKVM), or host kernels - * running at EL1 assume everything is the host. + * running at EL1, or no context IDs (per-thread mode) assume everything + * is the host. */ - if (pid_fmt == CS_ETM_PIDFMT_CTXTID) + switch (pid_fmt) { + case CS_ETM_PIDFMT_CTXTID: + case CS_ETM_PIDFMT_NONE: return &etmq->etm->session->machines.host; + case CS_ETM_PIDFMT_CTXTID2: + default: + break; + }
/* * Not perfect, but otherwise assume anything in EL1 is the default
thread__find_map() chooses to exit without assigning a thread to the addr_location in some scenarios, for example when there are samples from a guest and perf_guest == false. This results in a segfault when adding to the histogram because it uses unguarded accesses to the thread member of the addr_location.
Fix it by exiting early if no thread is set. This fixes the referenced commit when using perf report with Coresight but probably isn't exclusive to that case.
Fixes: 8d3031d39fe8 ("perf cs-etm: Track exception level") Signed-off-by: James Clark james.clark@arm.com --- tools/perf/builtin-report.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index dcedfe00f04d..1a2caa4ce5c3 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -293,6 +293,9 @@ static int process_sample_event(struct perf_tool *tool, goto out_put; }
+ if (!al.thread) + goto out_put; + if (rep->stitch_lbr) thread__set_lbr_stitch_enable(al.thread, true);