perf pmus: Make PMU alias name loading lazy
authorIan Rogers <irogers@google.com>
Mon, 25 Sep 2023 06:23:23 +0000 (23:23 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Sat, 30 Sep 2023 05:50:42 +0000 (22:50 -0700)
commitb1f05622fef39dded385f9e360e859846c1ddaf1
treeb56a5033daaca05810721527d02ebb88043ded33
parentee33a0ef8468063b34eed4330b0023c1a8d62f8f
perf pmus: Make PMU alias name loading lazy

PMU alias names were computed when the first perf_pmu is created,
scanning all PMUs in event sources for a file called alias that
generally doesn't exist. Switch to trying to load the file when all
PMU related files are loaded in lookup. This would cause a PMU name
lookup of an alias name to fail if no PMUs were loaded, so in that
case all PMUs are loaded and the find repeated. The overhead is
similar but in the (very) general case not all PMUs are scanned for
the alias file.

As the overhead occurs once per invocation it doesn't show in perf
bench internals pmu-scan. On a tigerlake machine, the number of openat
system calls for an event of cpu/cycles/ with perf stat reduces from
94 to 69 (ie 25 fewer openat calls).

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: James Clark <james.clark@arm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Link: https://lore.kernel.org/r/20230925062323.840799-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/arch/x86/util/pmu.c
tools/perf/util/pmu.c
tools/perf/util/pmu.h
tools/perf/util/pmus.c