[PATCH 0/2] perf/x86: Package residency counter improvements

From: Tero Kristo
Date: Wed Aug 23 2023 - 01:57:51 EST


Hello,

Following two patches address a couple of different issues with Intel
C-state package residency counters, which are used to track power saving
state usage on Intel chips. The patches don't have any dependencies to
each other and can be applied separately.

1) The residency counters are always read from the first CPU of the
package via an SMP call, even if they are available from any CPU.
This causes extra latency. Patch #1 fixes this issue by flagging
the perf event properly and allowing to execute it on any CPU of
the package.
2) The residency counters are completely impossible to read from a BPF
program running on any other than the first CPU of the package, as the
SMP call is not available in this context. Patch #2 addresses this
issue by allowing the read of the perf event from the local CPU,
similar to what is done in perf_read_event(). This patch also allows
reading any other package scope perf events (RAPL/UNCORE) from
arbitrary CPUs on a package via BPF.

-Tero