[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <095bbbb8-4a65-4888-aa7d-39ea09a52b84@amd.com>
Date: Wed, 26 Nov 2025 10:35:11 +0530
From: Sandipan Das <sandipan.das@....com>
To: Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Benjamin Gray <bgray@...ux.ibm.com>, Caleb Biggers
<caleb.biggers@...el.com>, Edward Baker <edward.baker@...el.com>,
Ingo Molnar <mingo@...hat.com>, James Clark <james.clark@...aro.org>,
Jing Zhang <renyu.zj@...ux.alibaba.com>, Jiri Olsa <jolsa@...nel.org>,
John Garry <john.g.garry@...cle.com>, Leo Yan <leo.yan@....com>,
Namhyung Kim <namhyung@...nel.org>, Perry Taylor <perry.taylor@...el.com>,
Peter Zijlstra <peterz@...radead.org>, Samantha Alt
<samantha.alt@...el.com>, Thomas Falcon <thomas.falcon@...el.com>,
Weilin Wang <weilin.wang@...el.com>, Xu Yang <xu.yang_2@....com>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v8 15/52] perf jevents: Add RAPL event metric for AMD zen
models
On 11/13/2025 8:50 AM, Ian Rogers wrote:
> Add power per second metrics based on RAPL.
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
> tools/perf/pmu-events/amd_metrics.py | 31 +++++++++++++++++++++++++---
> 1 file changed, 28 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py
> index bc91d9c120fa..b6cdeb4f09fe 100755
> --- a/tools/perf/pmu-events/amd_metrics.py
> +++ b/tools/perf/pmu-events/amd_metrics.py
> @@ -1,13 +1,36 @@
> #!/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 socket power consumption estimate.
> +
> + Use events from the running average power limit (RAPL) driver.
> + """
> + # Watts = joules/second
> + # Currently only energy-pkg is supported by AMD:
> + # https://lore.kernel.org/lkml/20220105185659.643355-1-eranian@google.com/
> + pkg = Event("power/energy\\-pkg/")
> + cond_pkg = Select(pkg, has_event(pkg), math.nan)
> + scale = 2.3283064365386962890625e-10
It is unlikely that the scale factor will change, but would it still be safer to read
it from /sys/bus/event_source/devices/power/events/energy-pkg.scale?
> + metrics = [
> + Metric("lpm_cpu_power_pkg", "",
> + d_ratio(cond_pkg * scale, interval_sec), "Watts"),
> + ]
> +
> + return MetricGroup("lpm_cpu_power", metrics,
> + description="Processor socket power consumption estimates")
> +
>
> def main() -> None:
> global _args
> @@ -33,7 +56,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))
Powered by blists - more mailing lists