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

perf pmus: Factor perf_pmus__find_by_attr out of evsel__find_pmu

Allow a PMU to be found by a perf_event_attr, useful when creating
evsels.

Reviewed-by: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250719030517.1990983-10-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
3cb614a2 f958537f

+19 -12
+17 -12
tools/perf/util/pmus.c
··· 814 814 return perf_pmus__do_support_extended_type; 815 815 } 816 816 817 - struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) 817 + struct perf_pmu *perf_pmus__find_by_attr(const struct perf_event_attr *attr) 818 818 { 819 - struct perf_pmu *pmu = evsel->pmu; 820 - bool legacy_core_type; 819 + struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type); 820 + u32 type = attr->type; 821 + bool legacy_core_type = type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE; 821 822 822 - if (pmu) 823 - return pmu; 824 - 825 - pmu = perf_pmus__find_by_type(evsel->core.attr.type); 826 - legacy_core_type = 827 - evsel->core.attr.type == PERF_TYPE_HARDWARE || 828 - evsel->core.attr.type == PERF_TYPE_HW_CACHE; 829 823 if (!pmu && legacy_core_type && perf_pmus__supports_extended_type()) { 830 - u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; 824 + type = attr->config >> PERF_PMU_TYPE_SHIFT; 831 825 832 826 pmu = perf_pmus__find_by_type(type); 833 827 } 834 - if (!pmu && (legacy_core_type || evsel->core.attr.type == PERF_TYPE_RAW)) { 828 + if (!pmu && (legacy_core_type || type == PERF_TYPE_RAW)) { 835 829 /* 836 830 * For legacy events, if there was no extended type info then 837 831 * assume the PMU is the first core PMU. ··· 836 842 */ 837 843 pmu = perf_pmus__find_core_pmu(); 838 844 } 845 + return pmu; 846 + } 847 + 848 + struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) 849 + { 850 + struct perf_pmu *pmu = evsel->pmu; 851 + 852 + if (pmu) 853 + return pmu; 854 + 855 + pmu = perf_pmus__find_by_attr(&evsel->core.attr); 839 856 ((struct evsel *)evsel)->pmu = pmu; 840 857 return pmu; 841 858 }
+2
tools/perf/util/pmus.h
··· 5 5 #include <stdbool.h> 6 6 #include <stddef.h> 7 7 8 + struct perf_event_attr; 8 9 struct perf_pmu; 9 10 struct print_callbacks; 10 11 ··· 17 16 18 17 struct perf_pmu *perf_pmus__find(const char *name); 19 18 struct perf_pmu *perf_pmus__find_by_type(unsigned int type); 19 + struct perf_pmu *perf_pmus__find_by_attr(const struct perf_event_attr *attr); 20 20 21 21 struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); 22 22 struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu);