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

perf pmu: Add calls enabling the hwmon_pmu

Add the base PMU calls necessary for hwmon_pmu(s) to be
created/deleted and events found, listed, opened and read.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Yoshihiro Furudera <fj5100bi@fujitsu.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ze Gao <zegao2021@gmail.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Junhao He <hejunhao3@huawei.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Link: https://lore.kernel.org/r/20241109003759.473460-6-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
654986ed 53cc0b35

+31
+9
tools/perf/util/evsel.c
··· 56 56 #include "off_cpu.h" 57 57 #include "pmu.h" 58 58 #include "pmus.h" 59 + #include "hwmon_pmu.h" 59 60 #include "tool_pmu.h" 60 61 #include "rlimit.h" 61 62 #include "../perf-sys.h" ··· 1800 1799 if (evsel__is_tool(evsel)) 1801 1800 return evsel__tool_pmu_read(evsel, cpu_map_idx, thread); 1802 1801 1802 + if (evsel__is_hwmon(evsel)) 1803 + return evsel__hwmon_pmu_read(evsel, cpu_map_idx, thread); 1804 + 1803 1805 if (evsel__is_retire_lat(evsel)) 1804 1806 return evsel__read_retire_lat(evsel, cpu_map_idx, thread); 1805 1807 ··· 2468 2464 return evsel__tool_pmu_open(evsel, threads, 2469 2465 start_cpu_map_idx, 2470 2466 end_cpu_map_idx); 2467 + } 2468 + if (evsel__is_hwmon(evsel)) { 2469 + return evsel__hwmon_pmu_open(evsel, threads, 2470 + start_cpu_map_idx, 2471 + end_cpu_map_idx); 2471 2472 } 2472 2473 2473 2474 for (idx = start_cpu_map_idx; idx < end_cpu_map_idx; idx++) {
+20
tools/perf/util/pmu.c
··· 18 18 #include "debug.h" 19 19 #include "evsel.h" 20 20 #include "pmu.h" 21 + #include "hwmon_pmu.h" 21 22 #include "pmus.h" 22 23 #include "tool_pmu.h" 23 24 #include <util/pmu-bison.h> ··· 1530 1529 { 1531 1530 struct parse_events_term *term; 1532 1531 1532 + if (perf_pmu__is_hwmon(pmu)) 1533 + return hwmon_pmu__config_terms(pmu, attr, terms, err); 1534 + 1533 1535 list_for_each_entry(term, &terms->terms, list) { 1534 1536 if (pmu_config_term(pmu, attr, term, terms, zero, apply_hardcoded, err)) 1535 1537 return -EINVAL; ··· 1664 1660 info->unit = NULL; 1665 1661 info->scale = 0.0; 1666 1662 info->snapshot = false; 1663 + 1664 + if (perf_pmu__is_hwmon(pmu)) { 1665 + ret = hwmon_pmu__check_alias(head_terms, info, err); 1666 + goto out; 1667 + } 1667 1668 1668 1669 /* Fake PMU doesn't rewrite terms. */ 1669 1670 if (perf_pmu__is_fake(pmu)) ··· 1843 1834 return false; 1844 1835 if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) 1845 1836 return false; 1837 + if (perf_pmu__is_hwmon(pmu)) 1838 + return hwmon_pmu__have_event(pmu, name); 1846 1839 if (perf_pmu__find_alias(pmu, name, /*load=*/ true) != NULL) 1847 1840 return true; 1848 1841 if (pmu->cpu_aliases_added || !pmu->events_table) ··· 1855 1844 size_t perf_pmu__num_events(struct perf_pmu *pmu) 1856 1845 { 1857 1846 size_t nr; 1847 + 1848 + if (perf_pmu__is_hwmon(pmu)) 1849 + return hwmon_pmu__num_events(pmu); 1858 1850 1859 1851 pmu_aliases_parse(pmu); 1860 1852 nr = pmu->sysfs_aliases + pmu->sys_json_aliases; ··· 1921 1907 }; 1922 1908 int ret = 0; 1923 1909 struct strbuf sb; 1910 + 1911 + if (perf_pmu__is_hwmon(pmu)) 1912 + return hwmon_pmu__for_each_event(pmu, state, cb); 1924 1913 1925 1914 strbuf_init(&sb, /*hint=*/ 0); 1926 1915 pmu_aliases_parse(pmu); ··· 2320 2303 2321 2304 void perf_pmu__delete(struct perf_pmu *pmu) 2322 2305 { 2306 + if (perf_pmu__is_hwmon(pmu)) 2307 + hwmon_pmu__exit(pmu); 2308 + 2323 2309 perf_pmu__del_formats(&pmu->format); 2324 2310 perf_pmu__del_aliases(pmu); 2325 2311 perf_pmu__del_caps(pmu);
+2
tools/perf/util/pmus.c
··· 15 15 #include "evsel.h" 16 16 #include "pmus.h" 17 17 #include "pmu.h" 18 + #include "hwmon_pmu.h" 18 19 #include "tool_pmu.h" 19 20 #include "print-events.h" 20 21 #include "strbuf.h" ··· 235 234 if (!core_only) { 236 235 tool_pmu = perf_pmus__tool_pmu(); 237 236 list_add_tail(&tool_pmu->list, &other_pmus); 237 + perf_pmus__read_hwmon_pmus(&other_pmus); 238 238 } 239 239 list_sort(NULL, &other_pmus, pmus_cmp); 240 240 if (!list_empty(&core_pmus)) {