All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: Peter Zijlstra <peterz@infradead.org>, <leo.yan@linux.dev>,
	Ian Rogers <irogers@google.com>,
	Kim Phillips <kim.phillips@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	Bill Wendling <morbo@google.com>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Zecheng Li <zli94@ncsu.edu>, <linux-perf-users@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <llvm@lists.linux.dev>,
	Li Huafei <lihuafei1@huawei.com>,
	Shuai Xue <xueshuai@linux.alibaba.com>,
	Namhyung Kim <namhyung@kernel.org>,
	James Clark <james.clark@linaro.org>
Subject: Re: [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type
Date: Wed, 22 Jul 2026 09:32:23 +0300	[thread overview]
Message-ID: <8fa4da51-6fee-450d-915a-eb4c4de03961@intel.com> (raw)
In-Reply-To: <f7a94138-e29f-4b1a-948d-ef4933e7d0c5@huaweicloud.com>

On 21/07/2026 14:39, Tengda Wu wrote:
> Hi Adrian,
> 
> On 2026/7/21 16:08, Adrian Hunter wrote:
>> 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?
>>
> 
> The 'M' case is just one example. On arm64, 't' and 'f' also have the
> same percent-zero issue.
> 
> How ARM SPE synthesizes events:
> 
> ARM SPE can synthesize multiple event types from a single instruction.
> For example, the 'M' case targets instructions that cause memory
> interaction events, while the 't' case targets instructions that trigger
> TLB access/miss events. Users can specify the desired event types via
> the itrace option to obtain corresponding data type profiling results.
> 
> How data type computes Percent:
> 
> Data type profiling computes Percent based on the period. The flow is as
> follows:
> 
> arm_spe_prep_sample():
>         sample->period = spe->synth_opts.period;

It seems like only arm-spe has the unusual period handling.
Please make the period non-zero when it is set up in
arm_spe_process_auxtrace_info() and add a comment explaining why.

> 
> __hists__add_entry():
>         he.stat.period = sample->period;
> 
> annotated_data_type__update_samples():
>         h->period += period;
>         h->addr[offset].period += period;
> 
> print_annotated_data_value():
>         double percent = h->period ? (100.0 * period / h->period) : 0;
> 
> Therefore, if synth_opts.period is not specified (remains zero), the
> final Percent calculation results in zero.
> 
> As you pointed out, if period is intended to be limited to only the 'i'
> and 'y' options, then setting period to 1 in the current patch may not
> be appropriate.
> 
> In fact, within print_annotated_data_value(), Percent could also be
> computed from the sample count. Moreover, I noticed that 'perf annotate'
> already has a --percent-type parameter that allows users to specify
> whether Percent is based on period or hit (which I understand to be the
> sample count). Perhaps it would be more reasonable to adapt
> print_annotated_data_value() to honor the --percent-type parameter
> instead.
> 
> Thanks,
> Tengda
> 
>>>
>>> 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 <wutengda@huaweicloud.com>
>>> ---
>>>  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:
>>
> 


  reply	other threads:[~2026-07-22  6:32 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  3:53 [PATCH v3 00/21] perf arm64: Support data type profiling Tengda Wu
2026-07-01  3:53 ` [PATCH v3 01/21] perf capstone: Fix kernel map reference count leak Tengda Wu
2026-07-09  5:57   ` Namhyung Kim
2026-07-10 21:49     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 02/21] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  6:44     ` Tengda Wu
2026-07-09  6:10       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 03/21] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-01  6:45     ` Tengda Wu
2026-07-09  6:18   ` Namhyung Kim
2026-07-09  7:49     ` Tengda Wu
2026-07-16 12:46       ` Tengda Wu
2026-07-16 21:07         ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 04/21] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-07-01  4:03   ` sashiko-bot
2026-07-01  6:57     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 05/21] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:03     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 06/21] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:14     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 07/21] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 08/21] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-01  7:29     ` Tengda Wu
2026-07-09  6:31       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 09/21] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-07-01  4:10   ` sashiko-bot
2026-07-01  7:36     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 10/21] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-09  6:47     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-21  8:08   ` Adrian Hunter
2026-07-21 11:39     ` Tengda Wu
2026-07-22  6:32       ` Adrian Hunter [this message]
2026-07-22  7:03         ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 12/21] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-07-01  3:53 ` [PATCH v3 13/21] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-07-01  4:12   ` sashiko-bot
2026-07-01  7:56     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 14/21] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-07-01  4:14   ` sashiko-bot
2026-07-01  8:37     ` Tengda Wu
2026-07-09  7:05       ` Namhyung Kim
2026-07-09  7:25         ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 15/21] perf annotate-arm64: Support store " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 16/21] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-09  7:11     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 17/21] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-07-01  4:21   ` sashiko-bot
2026-07-01  8:46     ` Tengda Wu
2026-07-09  7:17       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 18/21] perf annotate-arm64: Support 'add' " Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:47     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 19/21] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-07-01  4:15   ` sashiko-bot
2026-07-01  8:48     ` Tengda Wu
2026-07-09  7:31   ` Namhyung Kim
2026-07-09  7:42     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 20/21] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-07-01  4:18   ` sashiko-bot
2026-07-09  7:29   ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 21/21] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:56     ` Tengda Wu
2026-07-09  7:36       ` Namhyung Kim
2026-07-09  5:54 ` [PATCH v3 00/21] perf arm64: Support data type profiling Namhyung Kim
2026-07-09  8:01   ` Tengda Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fa4da51-6fee-450d-915a-eb4c4de03961@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=kim.phillips@arm.com \
    --cc=leo.yan@linux.dev \
    --cc=lihuafei1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=namhyung@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=peterz@infradead.org \
    --cc=wutengda@huaweicloud.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=zli94@ncsu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.