Commit 7c0135e4 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

perf perf_api_probe: Avoid scanning all PMUs, try software PMU first



Scan the software PMU first rather than last as it is the least likely
to fail the probe. Specifying the software PMU by name was enabled by
commit 9957d8c8 ("perf jevents: Add common software event
json"). For hardware events, add core PMU names when getting events to
probe so that not all PMUs are scanned. For example, when legacy
events support wildcards and for the event "cycles:u" on x86, we want
to only scan the "cpu" PMU and not all uncore PMUs for the event too.

Tested-by: default avatarThomas Richter <tmricht@linux.ibm.com>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarJames Clark <james.clark@linaro.org>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent b7b76f60
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -59,10 +59,10 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha

static bool perf_probe_api(setup_probe_fn_t fn)
{
	const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL};
	struct perf_pmu *pmu;
	struct perf_cpu_map *cpus;
	struct perf_cpu cpu;
	int ret, i = 0;
	int ret = 0;

	cpus = perf_cpu_map__new_online_cpus();
	if (!cpus)
@@ -70,12 +70,23 @@ static bool perf_probe_api(setup_probe_fn_t fn)
	cpu = perf_cpu_map__cpu(cpus, 0);
	perf_cpu_map__put(cpus);

	do {
		ret = perf_do_probe_api(fn, cpu, try[i++]);
	ret = perf_do_probe_api(fn, cpu, "software/cpu-clock/u");
	if (!ret)
		return true;
	} while (ret == -EAGAIN && try[i]);

	pmu = perf_pmus__scan_core(/*pmu=*/NULL);
	if (pmu) {
		const char *try[] = {"cycles", "instructions", NULL};
		char buf[256];
		int i = 0;

		while (ret == -EAGAIN && try[i]) {
			snprintf(buf, sizeof(buf), "%s/%s/u", pmu->name, try[i++]);
			ret = perf_do_probe_api(fn, cpu, buf);
			if (!ret)
				return true;
		}
	}
	return false;
}