Re: [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type

Adrian Hunter <[email protected]> Tue, 21 Jul 2026 11:08:57 +0300
Newsgroups dev.linux.lists.llvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-perf-users
Organization Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki
Message-ID <[email protected]>
On 01/07/2026 06:53, Tengda Wu wrote:
> When using --itrace=M for data type profiling on arm64, the 'Percent'
> values in perf annotate output are all zero:
> 
> Annotate type: 'struct mmu_gather_batch' in [kernel.kallsyms] (15 samples):
> ============================================================================
>  Percent     offset       size  field
>     0.00          0       0x10  struct mmu_gather_batch  {
>     0.00          0        0x8      struct mmu_gather_batch*    next;
>     0.00        0x8        0x4      unsigned int        nr;
>     0.00        0xc        0x4      unsigned int        max;
>     0.00       0x10          0      struct encoded_page*[]      encoded_pages;
>                                 };
> 
> However, adding the -n option reveals non-zero sample counts:
> 
> Annotate type: 'struct mmu_gather_batch' in [kernel.kallsyms] (15 samples):
> ============================================================================
>  Samples     offset       size  field
>       15          0       0x10  struct mmu_gather_batch  {
>       13          0        0x8      struct mmu_gather_batch*    next;
>        2        0x8        0x4      unsigned int        nr;
>        0        0xc        0x4      unsigned int        max;
>        0       0x10          0      struct encoded_page*[]      encoded_pages;
>                                 };
> 
> The root cause is that when period is not explicitly specified in the
> --itrace option, it remains zero after itrace_do_parse_synth_opts().
> The zero period then flows through annotated_data_type__update_samples()
> where h->period accumulates to zero, and print_annotated_data_type_value()
> calculates the 'Percent' as zero.

The period is for instructions samples i.e. options 'i' or 'y'.  Why is
it being used in the 'M' case?  What samples are being synthesized in
that case?

> 
> In itrace_do_parse_synth_opts(), non-'iy' options have their period
> type set to PERF_ITRACE_PERIOD_INSTRUCTIONS, but period remains zero.
> Since a zero period is meaningless for this type, default to 1 (one
> sample per instruction).
> 
> With this fix applied, the result is as follows:
> 
> Annotate type: 'struct mmu_gather_batch' in [kernel.kallsyms] (15 samples):
> ============================================================================
>  Percent     offset       size  field
>   100.00          0       0x10  struct mmu_gather_batch  {
>    86.67          0        0x8      struct mmu_gather_batch*    next;
>    13.33        0x8        0x4      unsigned int        nr;
>     0.00        0xc        0x4      unsigned int        max;
>     0.00       0x10          0      struct encoded_page*[]      encoded_pages;
>                                 };
> 
> Signed-off-by: Tengda Wu <[email protected]>
> ---
>  tools/perf/util/auxtrace.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index 0b851f32e98c..415b68a2bba9 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -1759,6 +1759,12 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
>  			synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
>  	}
>  
> +	if (!period_set &&
> +	    synth_opts->period_type == PERF_ITRACE_PERIOD_INSTRUCTIONS) {
> +		/* Indicates a sample is taken for every instruction. */
> +		synth_opts->period = 1;
> +	}
> +
>  	return 0;
>  
>  out_err: