[PATCH v3] perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event

Leo Yan posted 1 patch 4 years ago
tools/perf/builtin-report.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
[PATCH v3] perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event
Posted by Leo Yan 4 years ago
Since commit bb30acae4c4d ("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 ffab48705205 ("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: bb30acae4c4d ("perf report: Bail out --mem-mode if mem info is not available")
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Tested-by: German Gomez <german.gomez@arm.com>
Reviewed-by: James Clark <james.clark@arm.com>
---
v3: Remove warning log, add James' review tag.
v2: Change event name from "arm_spe_" to "arm_spe";
    Add German's test tag.

 tools/perf/builtin-report.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 1ad75c7ba074..afe4a5539ecc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -353,6 +353,7 @@ static int report__setup_sample_type(struct report *rep)
 	struct perf_session *session = rep->session;
 	u64 sample_type = evlist__combined_sample_type(session->evlist);
 	bool is_pipe = perf_data__is_pipe(session->data);
+	struct evsel *evsel;
 
 	if (session->itrace_synth_opts->callchain ||
 	    session->itrace_synth_opts->add_callchain ||
@@ -407,6 +408,19 @@ static int report__setup_sample_type(struct report *rep)
 	}
 
 	if (sort__mode == SORT_MODE__MEMORY) {
+		/*
+		 * FIXUP: prior to kernel 5.18, Arm SPE missed to set
+		 * PERF_SAMPLE_DATA_SRC bit in sample type.  For backward
+		 * compatibility, set the bit if it's an old perf data file.
+		 */
+		evlist__for_each_entry(session->evlist, evsel) {
+			if (strstr(evsel->name, "arm_spe") &&
+				!(sample_type & PERF_SAMPLE_DATA_SRC)) {
+				evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
+				sample_type |= PERF_SAMPLE_DATA_SRC;
+			}
+		}
+
 		if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
 			ui__error("Selected --mem-mode but no mem data. "
 				  "Did you call perf record without -d?\n");
-- 
2.25.1
Re: [PATCH v3] perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event
Posted by Arnaldo Carvalho de Melo 4 years ago
Em Thu, Apr 14, 2022 at 08:32:01PM +0800, Leo Yan escreveu:
> Since commit bb30acae4c4d ("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 ffab48705205 ("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.

Thanks, applied.

- Arnaldo

 
> Fixes: bb30acae4c4d ("perf report: Bail out --mem-mode if mem info is not available")
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> Tested-by: German Gomez <german.gomez@arm.com>
> Reviewed-by: James Clark <james.clark@arm.com>
> ---
> v3: Remove warning log, add James' review tag.
> v2: Change event name from "arm_spe_" to "arm_spe";
>     Add German's test tag.
> 
>  tools/perf/builtin-report.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 1ad75c7ba074..afe4a5539ecc 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -353,6 +353,7 @@ static int report__setup_sample_type(struct report *rep)
>  	struct perf_session *session = rep->session;
>  	u64 sample_type = evlist__combined_sample_type(session->evlist);
>  	bool is_pipe = perf_data__is_pipe(session->data);
> +	struct evsel *evsel;
>  
>  	if (session->itrace_synth_opts->callchain ||
>  	    session->itrace_synth_opts->add_callchain ||
> @@ -407,6 +408,19 @@ static int report__setup_sample_type(struct report *rep)
>  	}
>  
>  	if (sort__mode == SORT_MODE__MEMORY) {
> +		/*
> +		 * FIXUP: prior to kernel 5.18, Arm SPE missed to set
> +		 * PERF_SAMPLE_DATA_SRC bit in sample type.  For backward
> +		 * compatibility, set the bit if it's an old perf data file.
> +		 */
> +		evlist__for_each_entry(session->evlist, evsel) {
> +			if (strstr(evsel->name, "arm_spe") &&
> +				!(sample_type & PERF_SAMPLE_DATA_SRC)) {
> +				evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
> +				sample_type |= PERF_SAMPLE_DATA_SRC;
> +			}
> +		}
> +
>  		if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
>  			ui__error("Selected --mem-mode but no mem data. "
>  				  "Did you call perf record without -d?\n");
> -- 
> 2.25.1

-- 

- Arnaldo
Re: [PATCH v3] perf report: Set PERF_SAMPLE_DATA_SRC bit for Arm SPE event
Posted by Leo Yan 4 years ago
On Mon, Apr 18, 2022 at 06:56:26PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Apr 14, 2022 at 08:32:01PM +0800, Leo Yan escreveu:
> > Since commit bb30acae4c4d ("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 ffab48705205 ("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.
> 
> Thanks, applied.

Thank you, Arnaldo!

Leo