perf jevents: Add idle metric for AMD zen models

Compute using the MSR PMU the percentage of wallclock cycles where the
CPUs are in a low power state.

Reviewed-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xu Yang <xu.yang_2@nxp.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-01-27 10:44:35 -08:00 committed by Arnaldo Carvalho de Melo
parent d10ae3a935
commit 6da95e1834
1 changed files with 14 additions and 2 deletions

View File

@ -3,8 +3,9 @@
import argparse
import math
import os
from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
LoadEvents, Metric, MetricGroup, Select)
from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric,
JsonEncodeMetricGroupDescriptions, LoadEvents, Metric,
MetricGroup, Select)
# Global command line arguments.
_args = None
@ -12,6 +13,16 @@ _args = None
interval_sec = Event("duration_time")
def Idle() -> Metric:
cyc = Event("msr/mperf/")
tsc = Event("msr/tsc/")
low = max(tsc - cyc, 0)
return Metric(
"lpm_idle",
"Percentage of total wallclock cycles where CPUs are in low power state (C1 or deeper sleep state)",
d_ratio(low, tsc), "100%")
def Rapl() -> MetricGroup:
"""Processor socket power consumption estimate.
@ -57,6 +68,7 @@ def main() -> None:
LoadEvents(directory)
all_metrics = MetricGroup("", [
Idle(),
Rapl(),
])