Skip to content

Commit ab29ff9

Browse files
tanzenamhyung
authored andcommitted
perf auxtrace: Add auxtrace_synth_id_range_start() helper
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>
1 parent be806f0 commit ab29ff9

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

tools/perf/util/arm-spe.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,10 +1733,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
17331733
attr.sample_period = spe->synth_opts.period;
17341734

17351735
/* create new id val to be a fixed offset from evsel id */
1736-
id = evsel->core.id[0] + 1000000000;
1737-
1738-
if (!id)
1739-
id = 1;
1736+
id = auxtrace_synth_id_range_start(evsel);
17401737

17411738
if (spe->synth_opts.flc) {
17421739
spe->sample_flc = true;

tools/perf/util/auxtrace.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@
6262
#include <internal/lib.h>
6363
#include "util/sample.h"
6464

65+
#define AUXTRACE_SYNTH_EVENT_ID_OFFSET 1000000000ULL
66+
67+
/*
68+
* Event IDs are allocated sequentially, so a big offset from any
69+
* existing ID will reach a unused range.
70+
*/
71+
u64 auxtrace_synth_id_range_start(struct evsel *evsel)
72+
{
73+
u64 id = evsel->core.id[0] + AUXTRACE_SYNTH_EVENT_ID_OFFSET;
74+
75+
if (!id)
76+
id = 1;
77+
78+
return id;
79+
}
80+
6581
/*
6682
* Make a group from 'leader' to 'last', requiring that the events were not
6783
* already grouped to a different leader.

tools/perf/util/auxtrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ void auxtrace__free_events(struct perf_session *session);
648648
void auxtrace__free(struct perf_session *session);
649649
bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
650650
struct evsel *evsel);
651+
u64 auxtrace_synth_id_range_start(struct evsel *evsel);
651652

652653
#define ITRACE_HELP \
653654
" i[period]: synthesize instructions events\n" \

tools/perf/util/cs-etm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,10 +1726,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
17261726
attr.read_format = evsel->core.attr.read_format;
17271727

17281728
/* create new id val to be a fixed offset from evsel id */
1729-
id = evsel->core.id[0] + 1000000000;
1730-
1731-
if (!id)
1732-
id = 1;
1729+
id = auxtrace_synth_id_range_start(evsel);
17331730

17341731
if (etm->synth_opts.branches) {
17351732
attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;

tools/perf/util/intel-bts.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
777777
attr.sample_id_all = evsel->core.attr.sample_id_all;
778778
attr.read_format = evsel->core.attr.read_format;
779779

780-
id = evsel->core.id[0] + 1000000000;
781-
if (!id)
782-
id = 1;
780+
id = auxtrace_synth_id_range_start(evsel);
783781

784782
if (bts->synth_opts.branches) {
785783
attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;

tools/perf/util/intel-pt.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,9 +3987,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
39873987
attr.sample_id_all = evsel->core.attr.sample_id_all;
39883988
attr.read_format = evsel->core.attr.read_format;
39893989

3990-
id = evsel->core.id[0] + 1000000000;
3991-
if (!id)
3992-
id = 1;
3990+
id = auxtrace_synth_id_range_start(evsel);
39933991

39943992
if (pt->synth_opts.branches) {
39953993
attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;

tools/perf/util/powerpc-vpadtl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,7 @@ powerpc_vpadtl_synth_events(struct powerpc_vpadtl *vpa, struct perf_session *ses
656656
attr.config = PERF_SYNTH_POWERPC_VPA_DTL;
657657

658658
/* create new id val to be a fixed offset from evsel id */
659-
id = evsel->core.id[0] + 1000000000;
660-
if (!id)
661-
id = 1;
659+
id = auxtrace_synth_id_range_start(evsel);
662660

663661
err = perf_session__deliver_synth_attr_event(session, &attr, id);
664662
if (err)

0 commit comments

Comments
 (0)