diff mbox series

[2/2] perf: cs-etm: Fix corrupt inject files when only last branch option is enabled

Message ID 20220210200620.1227232-2-james.clark@arm.com (mailing list archive)
State New, archived
Headers show
Series [1/2] perf: cs-etm: No-op refactor of synth opt usage | expand

Commit Message

James Clark Feb. 10, 2022, 8:06 p.m. UTC
Perf inject with Coresight data generates files that cannot be opened
when only the last branch option is specified:

  perf inject -i perf.data --itrace=l -o inject.data
  perf script -i inject.data
  0x33faa8 [0x8]: failed to process type: 9 [Bad address]

This is because cs_etm__synth_instruction_sample() is called even when
the sample type for instructions hasn't been setup. Last branch records
are attached to instruction samples so it doesn't make sense to generate
them when --itrace=i isn't specified anyway.

This change disables all calls of cs_etm__synth_instruction_sample()
unless --itrace=i is specified, resulting in a file with no samples if
only --itrace=l is provided, rather than a bad file.

Signed-off-by: James Clark <james.clark@arm.com>
---
 tools/perf/util/cs-etm.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Leo Yan Feb. 11, 2022, 4:05 p.m. UTC | #1
On Thu, Feb 10, 2022 at 08:06:20PM +0000, James Clark wrote:
> Perf inject with Coresight data generates files that cannot be opened
> when only the last branch option is specified:
> 
>   perf inject -i perf.data --itrace=l -o inject.data
>   perf script -i inject.data
>   0x33faa8 [0x8]: failed to process type: 9 [Bad address]
> 
> This is because cs_etm__synth_instruction_sample() is called even when
> the sample type for instructions hasn't been setup. Last branch records
> are attached to instruction samples so it doesn't make sense to generate
> them when --itrace=i isn't specified anyway.
> 
> This change disables all calls of cs_etm__synth_instruction_sample()
> unless --itrace=i is specified, resulting in a file with no samples if
> only --itrace=l is provided, rather than a bad file.
> 
> Signed-off-by: James Clark <james.clark@arm.com>

Reviewed-by: Leo Yan <leo.yan@linaro.org>

> ---
>  tools/perf/util/cs-etm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 796a065a500e..8b95fb3c4d7b 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1553,6 +1553,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>  		goto swap_packet;
>  
>  	if (etmq->etm->synth_opts.last_branch &&
> +	    etmq->etm->synth_opts.instructions &&
>  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
>  		u64 addr;
>  
> @@ -1610,6 +1611,7 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
>  	 * the trace.
>  	 */
>  	if (etmq->etm->synth_opts.last_branch &&
> +	    etmq->etm->synth_opts.instructions &&
>  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
>  		u64 addr;
>  
> -- 
> 2.28.0
>
Arnaldo Carvalho de Melo Feb. 15, 2022, 3:07 p.m. UTC | #2
Em Sat, Feb 12, 2022 at 12:05:16AM +0800, Leo Yan escreveu:
> On Thu, Feb 10, 2022 at 08:06:20PM +0000, James Clark wrote:
> > Perf inject with Coresight data generates files that cannot be opened
> > when only the last branch option is specified:
> > 
> >   perf inject -i perf.data --itrace=l -o inject.data
> >   perf script -i inject.data
> >   0x33faa8 [0x8]: failed to process type: 9 [Bad address]
> > 
> > This is because cs_etm__synth_instruction_sample() is called even when
> > the sample type for instructions hasn't been setup. Last branch records
> > are attached to instruction samples so it doesn't make sense to generate
> > them when --itrace=i isn't specified anyway.
> > 
> > This change disables all calls of cs_etm__synth_instruction_sample()
> > unless --itrace=i is specified, resulting in a file with no samples if
> > only --itrace=l is provided, rather than a bad file.
> > 
> > Signed-off-by: James Clark <james.clark@arm.com>
> 
> Reviewed-by: Leo Yan <leo.yan@linaro.org>

Thanks, applied.

- Arnaldo

 
> > ---
> >  tools/perf/util/cs-etm.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> > index 796a065a500e..8b95fb3c4d7b 100644
> > --- a/tools/perf/util/cs-etm.c
> > +++ b/tools/perf/util/cs-etm.c
> > @@ -1553,6 +1553,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
> >  		goto swap_packet;
> >  
> >  	if (etmq->etm->synth_opts.last_branch &&
> > +	    etmq->etm->synth_opts.instructions &&
> >  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
> >  		u64 addr;
> >  
> > @@ -1610,6 +1611,7 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
> >  	 * the trace.
> >  	 */
> >  	if (etmq->etm->synth_opts.last_branch &&
> > +	    etmq->etm->synth_opts.instructions &&
> >  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
> >  		u64 addr;
> >  
> > -- 
> > 2.28.0
> >
James Clark Feb. 22, 2022, 3:49 p.m. UTC | #3
On 15/02/2022 15:07, Arnaldo Carvalho de Melo wrote:
> Em Sat, Feb 12, 2022 at 12:05:16AM +0800, Leo Yan escreveu:
>> On Thu, Feb 10, 2022 at 08:06:20PM +0000, James Clark wrote:
>>> Perf inject with Coresight data generates files that cannot be opened
>>> when only the last branch option is specified:
>>>
>>>   perf inject -i perf.data --itrace=l -o inject.data
>>>   perf script -i inject.data
>>>   0x33faa8 [0x8]: failed to process type: 9 [Bad address]
>>>
>>> This is because cs_etm__synth_instruction_sample() is called even when
>>> the sample type for instructions hasn't been setup. Last branch records
>>> are attached to instruction samples so it doesn't make sense to generate
>>> them when --itrace=i isn't specified anyway.
>>>
>>> This change disables all calls of cs_etm__synth_instruction_sample()
>>> unless --itrace=i is specified, resulting in a file with no samples if
>>> only --itrace=l is provided, rather than a bad file.
>>>
>>> Signed-off-by: James Clark <james.clark@arm.com>
>>
>> Reviewed-by: Leo Yan <leo.yan@linaro.org>
> 
> Thanks, applied.
> 
> - Arnaldo
> 

Thanks Leo and Arnaldo!

>  
>>> ---
>>>  tools/perf/util/cs-etm.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
>>> index 796a065a500e..8b95fb3c4d7b 100644
>>> --- a/tools/perf/util/cs-etm.c
>>> +++ b/tools/perf/util/cs-etm.c
>>> @@ -1553,6 +1553,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>>>  		goto swap_packet;
>>>  
>>>  	if (etmq->etm->synth_opts.last_branch &&
>>> +	    etmq->etm->synth_opts.instructions &&
>>>  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
>>>  		u64 addr;
>>>  
>>> @@ -1610,6 +1611,7 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq,
>>>  	 * the trace.
>>>  	 */
>>>  	if (etmq->etm->synth_opts.last_branch &&
>>> +	    etmq->etm->synth_opts.instructions &&
>>>  	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
>>>  		u64 addr;
>>>  
>>> -- 
>>> 2.28.0
>>>
>
diff mbox series

Patch

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 796a065a500e..8b95fb3c4d7b 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1553,6 +1553,7 @@  static int cs_etm__flush(struct cs_etm_queue *etmq,
 		goto swap_packet;
 
 	if (etmq->etm->synth_opts.last_branch &&
+	    etmq->etm->synth_opts.instructions &&
 	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
 		u64 addr;
 
@@ -1610,6 +1611,7 @@  static int cs_etm__end_block(struct cs_etm_queue *etmq,
 	 * the trace.
 	 */
 	if (etmq->etm->synth_opts.last_branch &&
+	    etmq->etm->synth_opts.instructions &&
 	    tidq->prev_packet->sample_type == CS_ETM_RANGE) {
 		u64 addr;