Commit 654986ed authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

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: default avatarIan 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: default avatarNamhyung Kim <namhyung@kernel.org>
parent 53cc0b35
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@
#include "off_cpu.h"
#include "pmu.h"
#include "pmus.h"
#include "hwmon_pmu.h"
#include "tool_pmu.h"
#include "rlimit.h"
#include "../perf-sys.h"
@@ -1799,6 +1800,9 @@ int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread)
	if (evsel__is_tool(evsel))
		return evsel__tool_pmu_read(evsel, cpu_map_idx, thread);

	if (evsel__is_hwmon(evsel))
		return evsel__hwmon_pmu_read(evsel, cpu_map_idx, thread);

	if (evsel__is_retire_lat(evsel))
		return evsel__read_retire_lat(evsel, cpu_map_idx, thread);

@@ -2465,6 +2469,11 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
					    start_cpu_map_idx,
					    end_cpu_map_idx);
	}
	if (evsel__is_hwmon(evsel)) {
		return evsel__hwmon_pmu_open(evsel, threads,
					     start_cpu_map_idx,
					     end_cpu_map_idx);
	}

	for (idx = start_cpu_map_idx; idx < end_cpu_map_idx; idx++) {

+20 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "debug.h"
#include "evsel.h"
#include "pmu.h"
#include "hwmon_pmu.h"
#include "pmus.h"
#include "tool_pmu.h"
#include <util/pmu-bison.h>
@@ -1529,6 +1530,9 @@ int perf_pmu__config_terms(const struct perf_pmu *pmu,
{
	struct parse_events_term *term;

	if (perf_pmu__is_hwmon(pmu))
		return hwmon_pmu__config_terms(pmu, attr, terms, err);

	list_for_each_entry(term, &terms->terms, list) {
		if (pmu_config_term(pmu, attr, term, terms, zero, apply_hardcoded, err))
			return -EINVAL;
@@ -1661,6 +1665,11 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_
	info->scale    = 0.0;
	info->snapshot = false;

	if (perf_pmu__is_hwmon(pmu)) {
		ret = hwmon_pmu__check_alias(head_terms, info, err);
		goto out;
	}

	/* Fake PMU doesn't rewrite terms. */
	if (perf_pmu__is_fake(pmu))
		goto out;
@@ -1834,6 +1843,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name)
		return false;
	if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name))
		return false;
	if (perf_pmu__is_hwmon(pmu))
		return hwmon_pmu__have_event(pmu, name);
	if (perf_pmu__find_alias(pmu, name, /*load=*/ true) != NULL)
		return true;
	if (pmu->cpu_aliases_added || !pmu->events_table)
@@ -1845,6 +1856,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu)
{
	size_t nr;

	if (perf_pmu__is_hwmon(pmu))
		return hwmon_pmu__num_events(pmu);

	pmu_aliases_parse(pmu);
	nr = pmu->sysfs_aliases + pmu->sys_json_aliases;

@@ -1908,6 +1922,9 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
	int ret = 0;
	struct strbuf sb;

	if (perf_pmu__is_hwmon(pmu))
		return hwmon_pmu__for_each_event(pmu, state, cb);

	strbuf_init(&sb, /*hint=*/ 0);
	pmu_aliases_parse(pmu);
	pmu_add_cpu_aliases(pmu);
@@ -2303,6 +2320,9 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename,

void perf_pmu__delete(struct perf_pmu *pmu)
{
	if (perf_pmu__is_hwmon(pmu))
		hwmon_pmu__exit(pmu);

	perf_pmu__del_formats(&pmu->format);
	perf_pmu__del_aliases(pmu);
	perf_pmu__del_caps(pmu);
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include "evsel.h"
#include "pmus.h"
#include "pmu.h"
#include "hwmon_pmu.h"
#include "tool_pmu.h"
#include "print-events.h"
#include "strbuf.h"
@@ -234,6 +235,7 @@ static void pmu_read_sysfs(bool core_only)
	if (!core_only) {
		tool_pmu = perf_pmus__tool_pmu();
		list_add_tail(&tool_pmu->list, &other_pmus);
		perf_pmus__read_hwmon_pmus(&other_pmus);
	}
	list_sort(NULL, &other_pmus, pmus_cmp);
	if (!list_empty(&core_pmus)) {