Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

tanze and committed by
Namhyung Kim
ab29ff9f be806f06

+22 -17
+1 -4
tools/perf/util/arm-spe.c
··· 1733 1733 attr.sample_period = spe->synth_opts.period; 1734 1734 1735 1735 /* 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); 1740 1737 1741 1738 if (spe->synth_opts.flc) { 1742 1739 spe->sample_flc = true;
+16
tools/perf/util/auxtrace.c
··· 62 62 #include <internal/lib.h> 63 63 #include "util/sample.h" 64 64 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 + 65 81 /* 66 82 * Make a group from 'leader' to 'last', requiring that the events were not 67 83 * already grouped to a different leader.
+1
tools/perf/util/auxtrace.h
··· 648 648 void auxtrace__free(struct perf_session *session); 649 649 bool auxtrace__evsel_is_auxtrace(struct perf_session *session, 650 650 struct evsel *evsel); 651 + u64 auxtrace_synth_id_range_start(struct evsel *evsel); 651 652 652 653 #define ITRACE_HELP \ 653 654 " i[period]: synthesize instructions events\n" \
+1 -4
tools/perf/util/cs-etm.c
··· 1726 1726 attr.read_format = evsel->core.attr.read_format; 1727 1727 1728 1728 /* 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); 1733 1730 1734 1731 if (etm->synth_opts.branches) { 1735 1732 attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+1 -3
tools/perf/util/intel-bts.c
··· 777 777 attr.sample_id_all = evsel->core.attr.sample_id_all; 778 778 attr.read_format = evsel->core.attr.read_format; 779 779 780 - id = evsel->core.id[0] + 1000000000; 781 - if (!id) 782 - id = 1; 780 + id = auxtrace_synth_id_range_start(evsel); 783 781 784 782 if (bts->synth_opts.branches) { 785 783 attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+1 -3
tools/perf/util/intel-pt.c
··· 3987 3987 attr.sample_id_all = evsel->core.attr.sample_id_all; 3988 3988 attr.read_format = evsel->core.attr.read_format; 3989 3989 3990 - id = evsel->core.id[0] + 1000000000; 3991 - if (!id) 3992 - id = 1; 3990 + id = auxtrace_synth_id_range_start(evsel); 3993 3991 3994 3992 if (pt->synth_opts.branches) { 3995 3993 attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+1 -3
tools/perf/util/powerpc-vpadtl.c
··· 656 656 attr.config = PERF_SYNTH_POWERPC_VPA_DTL; 657 657 658 658 /* 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); 662 660 663 661 err = perf_session__deliver_synth_attr_event(session, &attr, id); 664 662 if (err)