]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf auxtrace: Add auxtrace_synth_id_range_start() helper
authortanze <tanze@kylinos.cn>
Fri, 24 Oct 2025 08:56:25 +0000 (16:56 +0800)
committerNamhyung Kim <namhyung@kernel.org>
Sun, 26 Oct 2025 00:44:57 +0000 (17:44 -0700)
To avoid hardcoding the offset value for synthetic event IDs
in multiple auxtrace modules (arm-spe, cs-etm, intel-pt, etc.),
and to improve code reusability, this patch unifies
the handling of the ID offset via a dedicated helper function.

Signed-off-by: tanze <tanze@kylinos.cn>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/arm-spe.c
tools/perf/util/auxtrace.c
tools/perf/util/auxtrace.h
tools/perf/util/cs-etm.c
tools/perf/util/intel-bts.c
tools/perf/util/intel-pt.c
tools/perf/util/powerpc-vpadtl.c

index 9561951a005547a54b5ac31678f7faf6cddf4c88..614ce032f87e46d1f3754258f51bb1693ec128b7 100644 (file)
@@ -1733,10 +1733,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
        attr.sample_period = spe->synth_opts.period;
 
        /* create new id val to be a fixed offset from evsel id */
-       id = evsel->core.id[0] + 1000000000;
-
-       if (!id)
-               id = 1;
+       id = auxtrace_synth_id_range_start(evsel);
 
        if (spe->synth_opts.flc) {
                spe->sample_flc = true;
index 1539c1dc823c2072d83bbb9cb199b910317bbbe8..35f4745f6b2bf09a7838bf1de99d37f09510c03b 100644 (file)
 #include <internal/lib.h>
 #include "util/sample.h"
 
+#define AUXTRACE_SYNTH_EVENT_ID_OFFSET 1000000000ULL
+
+/*
+ * Event IDs are allocated sequentially, so a big offset from any
+ * existing ID will reach a unused range.
+ */
+u64 auxtrace_synth_id_range_start(struct evsel *evsel)
+{
+       u64 id = evsel->core.id[0] + AUXTRACE_SYNTH_EVENT_ID_OFFSET;
+
+       if (!id)
+               id = 1;
+
+       return id;
+}
+
 /*
  * Make a group from 'leader' to 'last', requiring that the events were not
  * already grouped to a different leader.
index e0a5b39fed1235d05ceeca5390c150b1cb9e4cc8..ed3a1aaaf5d9df5c7f6ba523924d1a24d7dcf354 100644 (file)
@@ -648,6 +648,7 @@ void auxtrace__free_events(struct perf_session *session);
 void auxtrace__free(struct perf_session *session);
 bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
                                 struct evsel *evsel);
+u64 auxtrace_synth_id_range_start(struct evsel *evsel);
 
 #define ITRACE_HELP \
 "                              i[period]:              synthesize instructions events\n" \
index 30f4bb3e7fa30305ae2371c1fcf2946d65c450ff..62812bef1edfee609c8cd2f30518070597775e55 100644 (file)
@@ -1726,10 +1726,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
        attr.read_format = evsel->core.attr.read_format;
 
        /* create new id val to be a fixed offset from evsel id */
-       id = evsel->core.id[0] + 1000000000;
-
-       if (!id)
-               id = 1;
+       id = auxtrace_synth_id_range_start(evsel);
 
        if (etm->synth_opts.branches) {
                attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
index 3625c622475024b49d2229bd9732ee3ec665b96b..382255393fb3bf6b934c3485d5beab229eb36ad9 100644 (file)
@@ -777,9 +777,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
        attr.sample_id_all = evsel->core.attr.sample_id_all;
        attr.read_format = evsel->core.attr.read_format;
 
-       id = evsel->core.id[0] + 1000000000;
-       if (!id)
-               id = 1;
+       id = auxtrace_synth_id_range_start(evsel);
 
        if (bts->synth_opts.branches) {
                attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
index 9b1011fe48267106b58c9e094b715430497608c3..fc9eec8b54b824b9804e34f6dd9d10087d40acd9 100644 (file)
@@ -3987,9 +3987,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
        attr.sample_id_all = evsel->core.attr.sample_id_all;
        attr.read_format = evsel->core.attr.read_format;
 
-       id = evsel->core.id[0] + 1000000000;
-       if (!id)
-               id = 1;
+       id = auxtrace_synth_id_range_start(evsel);
 
        if (pt->synth_opts.branches) {
                attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
index 39a3fb3f1330136f81723736adaf87754080bdda..bfa4156d7a9782caa4112f5b949cdc50cb291c89 100644 (file)
@@ -656,9 +656,7 @@ powerpc_vpadtl_synth_events(struct powerpc_vpadtl *vpa, struct perf_session *ses
        attr.config = PERF_SYNTH_POWERPC_VPA_DTL;
 
        /* create new id val to be a fixed offset from evsel id */
-       id = evsel->core.id[0] + 1000000000;
-       if (!id)
-               id = 1;
+       id = auxtrace_synth_id_range_start(evsel);
 
        err = perf_session__deliver_synth_attr_event(session, &attr, id);
        if (err)