Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event

Since commit bb30acae4c4dacfa ("perf report: Bail out --mem-mode if mem
info is not available") "perf mem report" and "perf report --mem-mode"
don't report result if the PERF_SAMPLE_DATA_SRC bit is missed in sample
type.

The commit ffab487052054162 ("perf: arm-spe: Fix perf report
--mem-mode") partially fixes the issue. It adds PERF_SAMPLE_DATA_SRC
bit for Arm SPE event, this allows the perf data file generated by
kernel v5.18-rc1 or later version can be reported properly.

On the other hand, perf tool still fails to be backward compatibility
for a data file recorded by an older version's perf which contains Arm
SPE trace data. This patch is a workaround in reporting phase, when
detects ARM SPE PMU event and without PERF_SAMPLE_DATA_SRC bit, it will
force to set the bit in the sample type and give a warning info.

Fixes: bb30acae4c4dacfa ("perf report: Bail out --mem-mode if mem info is not available")
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Tested-by: German Gomez <german.gomez@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: https://lore.kernel.org/r/20220414123201.842754-1-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
ccb17cae c6d8df01

+14
+14
tools/perf/builtin-report.c
··· 353 353 struct perf_session *session = rep->session; 354 354 u64 sample_type = evlist__combined_sample_type(session->evlist); 355 355 bool is_pipe = perf_data__is_pipe(session->data); 356 + struct evsel *evsel; 356 357 357 358 if (session->itrace_synth_opts->callchain || 358 359 session->itrace_synth_opts->add_callchain || ··· 408 407 } 409 408 410 409 if (sort__mode == SORT_MODE__MEMORY) { 410 + /* 411 + * FIXUP: prior to kernel 5.18, Arm SPE missed to set 412 + * PERF_SAMPLE_DATA_SRC bit in sample type. For backward 413 + * compatibility, set the bit if it's an old perf data file. 414 + */ 415 + evlist__for_each_entry(session->evlist, evsel) { 416 + if (strstr(evsel->name, "arm_spe") && 417 + !(sample_type & PERF_SAMPLE_DATA_SRC)) { 418 + evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC; 419 + sample_type |= PERF_SAMPLE_DATA_SRC; 420 + } 421 + } 422 + 411 423 if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) { 412 424 ui__error("Selected --mem-mode but no mem data. " 413 425 "Did you call perf record without -d?\n");