diff mbox series

[2/2] perf intel-pt: Fix corrupt data after perf inject from

Message ID 20200819084751.17686-2-leo.yan@linaro.org (mailing list archive)
State Mainlined
Commit a347306fbec5dcaf7c276777b11d530eab6a4526
Headers show
Series [1/2] perf cs-etm: Fix corrupt data after perf inject from | expand

Commit Message

Leo Yan Aug. 19, 2020, 8:47 a.m. UTC
From: Al Grant <al.grant@arm.com>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
changed the format of branch stacks in perf samples. When samples use
this new format, a flag must be set in the corresponding event.
Synthesized branch stacks generated from Intel PT were using the new
format, but not setting the event attribute, leading to consumers
seeing corrupt data. This patch fixes the issue by setting the event
attribute to indicate use of the new format.

Fixes: 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
Signed-off-by: Al Grant <al.grant@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/intel-pt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Adrian Hunter Aug. 24, 2020, 12:41 p.m. UTC | #1
On 19/08/20 11:47 am, Leo Yan wrote:
> From: Al Grant <al.grant@arm.com>
> 
> Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> changed the format of branch stacks in perf samples. When samples use
> this new format, a flag must be set in the corresponding event.
> Synthesized branch stacks generated from Intel PT were using the new
> format, but not setting the event attribute, leading to consumers
> seeing corrupt data. This patch fixes the issue by setting the event
> attribute to indicate use of the new format.
> 
> Fixes: 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> Signed-off-by: Al Grant <al.grant@arm.com>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/intel-pt.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
> index 2a8d245351e7..0af4e81c46e2 100644
> --- a/tools/perf/util/intel-pt.c
> +++ b/tools/perf/util/intel-pt.c
> @@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
>  
>  	if (pt->synth_opts.callchain)
>  		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
> -	if (pt->synth_opts.last_branch)
> +	if (pt->synth_opts.last_branch) {
>  		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
> +		/*
> +		 * We don't use the hardware index, but the sample generation
> +		 * code uses the new format branch_stack with this field,
> +		 * so the event attributes must indicate that it's present.
> +		 */
> +		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
> +	}
>  
>  	if (pt->synth_opts.instructions) {
>  		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
>
Mathieu Poirier Aug. 31, 2020, 8:38 p.m. UTC | #2
On Wed, Aug 19, 2020 at 04:47:51PM +0800, Leo Yan wrote:
> From: Al Grant <al.grant@arm.com>
> 
> Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> changed the format of branch stacks in perf samples. When samples use
> this new format, a flag must be set in the corresponding event.
> Synthesized branch stacks generated from Intel PT were using the new
> format, but not setting the event attribute, leading to consumers
> seeing corrupt data. This patch fixes the issue by setting the event
> attribute to indicate use of the new format.
> 
> Fixes: 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> Signed-off-by: Al Grant <al.grant@arm.com>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>

Arnaldo, please consider.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> ---
>  tools/perf/util/intel-pt.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
> index 2a8d245351e7..0af4e81c46e2 100644
> --- a/tools/perf/util/intel-pt.c
> +++ b/tools/perf/util/intel-pt.c
> @@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
>  
>  	if (pt->synth_opts.callchain)
>  		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
> -	if (pt->synth_opts.last_branch)
> +	if (pt->synth_opts.last_branch) {
>  		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
> +		/*
> +		 * We don't use the hardware index, but the sample generation
> +		 * code uses the new format branch_stack with this field,
> +		 * so the event attributes must indicate that it's present.
> +		 */
> +		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
> +	}
>  
>  	if (pt->synth_opts.instructions) {
>  		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
> -- 
> 2.17.1
>
Arnaldo Carvalho de Melo Sept. 1, 2020, 2:53 p.m. UTC | #3
Em Mon, Aug 31, 2020 at 02:38:32PM -0600, Mathieu Poirier escreveu:
> On Wed, Aug 19, 2020 at 04:47:51PM +0800, Leo Yan wrote:
> > From: Al Grant <al.grant@arm.com>
> > 
> > Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> > changed the format of branch stacks in perf samples. When samples use
> > this new format, a flag must be set in the corresponding event.
> > Synthesized branch stacks generated from Intel PT were using the new
> > format, but not setting the event attribute, leading to consumers
> > seeing corrupt data. This patch fixes the issue by setting the event
> > attribute to indicate use of the new format.
> > 
> > Fixes: 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
> > Signed-off-by: Al Grant <al.grant@arm.com>
> > Signed-off-by: Leo Yan <leo.yan@linaro.org>
> 
> Arnaldo, please consider.
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Thanks, applied, and 1/2 too.

- Arnaldo
 
> > ---
> >  tools/perf/util/intel-pt.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
> > index 2a8d245351e7..0af4e81c46e2 100644
> > --- a/tools/perf/util/intel-pt.c
> > +++ b/tools/perf/util/intel-pt.c
> > @@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
> >  
> >  	if (pt->synth_opts.callchain)
> >  		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
> > -	if (pt->synth_opts.last_branch)
> > +	if (pt->synth_opts.last_branch) {
> >  		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
> > +		/*
> > +		 * We don't use the hardware index, but the sample generation
> > +		 * code uses the new format branch_stack with this field,
> > +		 * so the event attributes must indicate that it's present.
> > +		 */
> > +		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
> > +	}
> >  
> >  	if (pt->synth_opts.instructions) {
> >  		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
> > -- 
> > 2.17.1
> >
diff mbox series

Patch

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 2a8d245351e7..0af4e81c46e2 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -3017,8 +3017,15 @@  static int intel_pt_synth_events(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain)
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-	if (pt->synth_opts.last_branch)
+	if (pt->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;