[PATCH v5 10/26] perf annotate: Default to --itrace=i1i for data type profiling
From: Tengda Wu
Date: Tue Sep 08 2026 - 09:47:11 EST
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.
Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>
---
tools/perf/builtin-annotate.c | 8 ++++++++
tools/perf/util/arm-spe.c | 5 ++++-
tools/perf/util/auxtrace.c | 12 ++++++++++--
tools/perf/util/auxtrace.h | 7 ++++++-
tools/perf/util/cs-etm.c | 2 +-
tools/perf/util/intel-bts.c | 2 +-
tools/perf/util/intel-pt.c | 3 ++-
7 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 69cb72b2082a..d5b66893c47c 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -873,6 +873,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;
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 401aab529309..ae7a5e9c3892 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -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;
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index aa749e1c3036..ed2113190785 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -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;
}
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 6947f3f284c0..5012bead1b92 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -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,
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 114b3cd2da49..2d1ab34f7b6b 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -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;
}
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 02df3e460489..4c9cca3acb6c 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -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;
}
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 9d6628169fd9..8c21c9f52d57 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -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;
--
2.34.1