summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-01-27 21:44:43 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-01-28 21:18:45 +0300
commitbab90b3b46cd74d5f562b0a7b2bef1222e8960af (patch)
tree53e27046847896bb04802239d0891165ade814e0 /tools
parent3563030d4f77856bd0a32492fbe9edc3d36248ec (diff)
downloadlinux-bab90b3b46cd74d5f562b0a7b2bef1222e8960af.tar.xz
perf jevents: Add RAPL metrics for all Intel models
Add a 'cpu_power' metric group that computes the power consumption from RAPL events if they are present. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Thomas Falcon <thomas.falcon@intel.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: Sandipan Das <sandipan.das@amd.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>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/perf/pmu-events/intel_metrics.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py
index b287ef115193..61778deedfff 100755
--- a/tools/perf/pmu-events/intel_metrics.py
+++ b/tools/perf/pmu-events/intel_metrics.py
@@ -1,12 +1,48 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
import argparse
+import math
import os
-from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, LoadEvents,
- MetricGroup)
+from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions,
+ LoadEvents, Metric, MetricGroup, Select)
# Global command line arguments.
_args = None
+interval_sec = Event("duration_time")
+
+
+def Rapl() -> MetricGroup:
+ """Processor power consumption estimate.
+
+ Use events from the running average power limit (RAPL) driver.
+ """
+ # Watts = joules/second
+ pkg = Event("power/energy\\-pkg/")
+ cond_pkg = Select(pkg, has_event(pkg), math.nan)
+ cores = Event("power/energy\\-cores/")
+ cond_cores = Select(cores, has_event(cores), math.nan)
+ ram = Event("power/energy\\-ram/")
+ cond_ram = Select(ram, has_event(ram), math.nan)
+ gpu = Event("power/energy\\-gpu/")
+ cond_gpu = Select(gpu, has_event(gpu), math.nan)
+ psys = Event("power/energy\\-psys/")
+ cond_psys = Select(psys, has_event(psys), math.nan)
+ scale = 2.3283064365386962890625e-10
+ metrics = [
+ Metric("lpm_cpu_power_pkg", "",
+ d_ratio(cond_pkg * scale, interval_sec), "Watts"),
+ Metric("lpm_cpu_power_cores", "",
+ d_ratio(cond_cores * scale, interval_sec), "Watts"),
+ Metric("lpm_cpu_power_ram", "",
+ d_ratio(cond_ram * scale, interval_sec), "Watts"),
+ Metric("lpm_cpu_power_gpu", "",
+ d_ratio(cond_gpu * scale, interval_sec), "Watts"),
+ Metric("lpm_cpu_power_psys", "",
+ d_ratio(cond_psys * scale, interval_sec), "Watts"),
+ ]
+
+ return MetricGroup("lpm_cpu_power", metrics,
+ description="Running Average Power Limit (RAPL) power consumption estimates")
def main() -> None:
@@ -33,7 +69,9 @@ def main() -> None:
directory = f"{_args.events_path}/x86/{_args.model}/"
LoadEvents(directory)
- all_metrics = MetricGroup("", [])
+ all_metrics = MetricGroup("", [
+ Rapl(),
+ ])
if _args.metricgroups:
print(JsonEncodeMetricGroupDescriptions(all_metrics))