perf annotate: Default to --itrace=i1i for data type profiling

ARM SPE-based sampling can synthesize multiple events on a single
instruction, as shown below. This would affect data type profiling
statistics:

  Available samples
  0 arm_spe_0/ts_enable=1,pa_enable=1,load_filter=1,store_filter=1,min_latency=30/
  0 dummy:u
  84K l1d-miss
  95K l1d-access
  77K llc-miss
  58K llc-access
  9K tlb-miss
  108K tlb-access
  0 branch
  13K remote-access
  108K memory
  108K instructions

While 'perf report' provides an interactive menu for users to select a
specific event to prevent duplicate counting, 'perf annotate' lacks such
a mechanism. Consequently, it counts all instructions across these
overlapping events, which inflates the profile and distorts the data
type statistics.

Although using the '--itrace' option can work around this issue (e.g.:
perf annotate --data-type --stdio --itrace=i1i), it is inconvenient for
users to specify this explicitly every time.

To address this, introduce itrace_synth_opts.default_single_event_per_ip.
Set this field to true when data type profiling is enabled and the user
has not explicitly specified an itrace option. In itrace_synth_opts__set_default(),
use this flag to default to synthesizing at most one event per IP (equivalent
to --itrace=i1i) to prevent duplicate sample counts.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Tengda Wu 2026-09-16 01:29:24 +00:00 committed by Arnaldo Carvalho de Melo
parent 20aca19350
commit 035efae7df
7 changed files with 32 additions and 7 deletions

View File

@ -885,6 +885,14 @@ int cmd_annotate(int argc, const char **argv)
annotate.session = perf_session__new(&data, &annotate.tool);
if (IS_ERR(annotate.session))
return PTR_ERR(annotate.session);
/*
* Hardware tracing (e.g., ARM SPE) may synthesize multiple events per
* instruction. When data type profiling is enabled, default to synthesizing
* at most one event (equivalent to --itrace=i1i) to prevent skewed
* statistics.
*/
if (annotate.data_type && !itrace_synth_opts.set)
itrace_synth_opts.default_single_event_per_ip = true;
annotate.session->itrace_synth_opts = &itrace_synth_opts;

View File

@ -2029,7 +2029,10 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
spe->synth_opts = *session->itrace_synth_opts;
} else {
itrace_synth_opts__set_default(&spe->synth_opts, false);
struct itrace_synth_opts *opts = session->itrace_synth_opts;
bool single_event_per_ip = opts ? opts->default_single_event_per_ip : false;
itrace_synth_opts__set_default(&spe->synth_opts, false, single_event_per_ip);
/* Default nanoseconds period not supported */
spe->synth_opts.period_type = PERF_ITRACE_PERIOD_INSTRUCTIONS;
spe->synth_opts.period = 1;

View File

@ -1478,8 +1478,15 @@ s64 perf_event__process_auxtrace(const struct perf_tool *tool __maybe_unused,
#define PERF_ITRACE_MAX_LAST_BRANCH_SZ 1024
void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
bool no_sample)
bool no_sample, bool single_event_per_ip)
{
if (single_event_per_ip) {
synth_opts->instructions = true;
synth_opts->period_type = PERF_ITRACE_PERIOD_INSTRUCTIONS;
synth_opts->period = 1;
return;
}
synth_opts->branches = true;
synth_opts->transactions = true;
synth_opts->ptwrites = true;
@ -1582,7 +1589,8 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
if (!str) {
itrace_synth_opts__set_default(synth_opts,
synth_opts->default_no_sample);
synth_opts->default_no_sample,
synth_opts->default_single_event_per_ip);
return 0;
}

View File

@ -65,6 +65,10 @@ enum itrace_period_type {
* struct itrace_synth_opts - AUX area tracing synthesis options.
* @set: indicates whether or not options have been set
* @default_no_sample: Default to no sampling.
* @default_single_event_per_ip: Default to synthesizing at most 1 event per IP
* (equivalent to --itrace=i1i). Used by commands
* like 'perf annotate --data-type' to avoid duplicate
* sample counts for a single instruction.
* @inject: indicates the event (not just the sample) must be fully synthesized
* because 'perf inject' will write it out
* @instructions: whether to synthesize 'instructions' events
@ -117,6 +121,7 @@ enum itrace_period_type {
struct itrace_synth_opts {
bool set;
bool default_no_sample;
bool default_single_event_per_ip;
bool inject;
bool instructions;
bool cycles;
@ -622,7 +627,7 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
int itrace_parse_synth_opts(const struct option *opt, const char *str,
int unset);
void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
bool no_sample);
bool no_sample, bool single_event_per_ip);
size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp);
void perf_session__auxtrace_error_inc(struct perf_session *session,

View File

@ -3626,7 +3626,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,
etm->synth_opts = *session->itrace_synth_opts;
} else {
itrace_synth_opts__set_default(&etm->synth_opts,
session->itrace_synth_opts->default_no_sample);
session->itrace_synth_opts->default_no_sample, false);
etm->synth_opts.callchain = false;
etm->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack;
}

View File

@ -877,7 +877,7 @@ int intel_bts_process_auxtrace_info(union perf_event *event,
bts->synth_opts = *session->itrace_synth_opts;
} else {
itrace_synth_opts__set_default(&bts->synth_opts,
session->itrace_synth_opts->default_no_sample);
session->itrace_synth_opts->default_no_sample, false);
bts->synth_opts.thread_stack =
session->itrace_synth_opts->thread_stack;
}

View File

@ -4463,7 +4463,8 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
} else {
struct itrace_synth_opts *opts = session->itrace_synth_opts;
itrace_synth_opts__set_default(&pt->synth_opts, opts->default_no_sample);
itrace_synth_opts__set_default(&pt->synth_opts,
opts->default_no_sample, false);
if (!opts->default_no_sample && !opts->inject) {
pt->synth_opts.branches = false;
pt->synth_opts.callchain = true;