From nobody Sun Feb 8 12:36:45 2026 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2BD18F5D for ; Thu, 29 Feb 2024 00:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165908; cv=none; b=HQbEF7Ja2/Z55FbQtgCv1yhZ21Yxf8XFlnulwRe5N+bQ2C0+Jnakun/IawlUmoiHiYTBa/F4i1S9aOfmy2UlFxT31TaqAGJVgaLxbPCJQFhdHwdJf+W1NnDegMI69os5dq8zNHEUzy+7e4/rc2LXX4NzeaEWwydThpJ73qQKilY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165908; c=relaxed/simple; bh=jivBKkzQZhLPmhBpl6x9D7v0XnWYu3hl5fkynoO+b40=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XlPnU3liTVu5WlV0MXvkpR69VMYRu/AFp/a03lTnEglknBoP70UGLPOnTK3gKWCVR21UiaQhGovTVnrAXRq619i4eA5qyJWJ2qHSGk529Auy8l8/Xa7hShzV4UdcK6w/vcbiKGpmind0Q8IG4XLjwfYKbVZN88x5uOj87TxhBrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I0WnU/Ok; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I0WnU/Ok" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5f38d676cecso20066517b3.0 for ; Wed, 28 Feb 2024 16:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709165906; x=1709770706; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=TEMsyy5Q+PTsgySwyrGbe044hOYiMe9dS9kqphPNxSM=; b=I0WnU/Ok+6DOlzzv9M1+5GNoocjSra7ld/yQ+J2ANNcBBZMzNL76zYqsK6mDQNbC1f bxkMUNy3j8Q8ZNrTyIyjS0DICXnBmtgMM6EJYeBCfk0ViohHEvGoRPoExUZbxF2ACCrD MC7LqWtt6AEgrTMMdgncGxVqp42XLtrtBf0bYol3yIttyNRV04ACZmDRQa0aVadihBpN 5I3mEp99+hQ50oWG+4llp9hYHkGEl5hI2UqOKOsoWLWE0TW9PKhvFzT8vu0DyFFk09FL LNBUttCq0P5M9z65lVkf0F2Whv6uAyPGyfStEJlGE8UA1OHW/ZRlSDfEmqFMGdojKeXH w2oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709165906; x=1709770706; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TEMsyy5Q+PTsgySwyrGbe044hOYiMe9dS9kqphPNxSM=; b=UTXoVX0CNXOVeJyI3OqWO11ck3AfRnEP3OGnyVwJ7SHaUXW4FRHmL7frOTgNNSdRNE Lj+CxNk3QwxhvB/s/TeUXrDL+XSTRDCFl2bZbFtsN0pcmWzQHwacAbXJktKz8we+wYXR W2web4M7ShCsMtGo3yYzDbyas6E/aURNpVFKll9EFmzLKjk+Ob/Qx7aVbe9O3agz5ovZ TsjK6BEVqeOWeT++hn3M3F8GPBL5kHAT0xwZnRPBPj7bdViJ8+e2cHOAWsl4t46XBT2x rVAKpqknSnidIHH4MYshx82F2SiEAveyvP69YVniQ3EV/NreZAXjqGZ7z9UWstkBlVr6 fPpA== X-Forwarded-Encrypted: i=1; AJvYcCXUQ0bu1y94nEFgBiaIRGOddrLYtucGE0HBLS60kiSpH00Fw4oZduBJ8x41jV5WvISpFeJnYIwb9UdFGEHs7is8EMmaVfXWJNWgc2pU X-Gm-Message-State: AOJu0Yw7QB1agrZEt5sT5cijNmRBukEssPpJXgaPYrv23ElA2V+fBfiI glLNjAG6j2KiKVZWlO1j+8BmiaatYhd5Z8t2zRD5iuOEHR90fRE6sP1WVwSTqFwmKCv4jJcN6Nb Of7FBgQ== X-Google-Smtp-Source: AGHT+IFDt2aybnwQo+NdWOIX4ENwZ5YTevONu6KTkETRd5htUgYOnqX0uWvjFZTSCaLLq4fF+RMjldYEARlS X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a5b:392:0:b0:dcc:5463:49a8 with SMTP id k18-20020a5b0392000000b00dcc546349a8mr45568ybp.6.1709165906002; Wed, 28 Feb 2024 16:18:26 -0800 (PST) Date: Wed, 28 Feb 2024 16:17:46 -0800 In-Reply-To: <20240229001806.4158429-1-irogers@google.com> Message-Id: <20240229001806.4158429-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240229001806.4158429-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 01/20] perf jevents: Add RAPL metrics for all Intel models From: Ian Rogers To: Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Andi Kleen , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , John Garry , Kan Liang , Jing Zhang , Thomas Richter , James Clark , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a 'cpu_power' metric group that computes the power consumption from RAPL events if they are present. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/intel_metrics.py | 45 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index 4fbb31c9eccd..5827f555005f 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, L= oadEvents, - MetricGroup) +from metric import (d_ratio, has_event, Event, JsonEncodeMetric, JsonEncod= eMetricGroupDescriptions, + LoadEvents, Metric, MetricGroup, Select) import argparse import json +import math import os =20 parser =3D argparse.ArgumentParser(description=3D"Intel perf json generato= r") @@ -14,7 +15,45 @@ args =3D parser.parse_args() directory =3D f"{os.path.dirname(os.path.realpath(__file__))}/arch/x86/{ar= gs.model}/" LoadEvents(directory) =20 -all_metrics =3D MetricGroup("",[]) +interval_sec =3D Event("duration_time") + +def Rapl() -> MetricGroup: + """Processor socket power consumption estimate. + + Use events from the running average power limit (RAPL) driver. + """ + # Watts =3D joules/second + pkg =3D Event("power/energy\-pkg/") + cond_pkg =3D Select(pkg, has_event(pkg), math.nan) + cores =3D Event("power/energy\-cores/") + cond_cores =3D Select(cores, has_event(cores), math.nan) + ram =3D Event("power/energy\-ram/") + cond_ram =3D Select(ram, has_event(ram), math.nan) + gpu =3D Event("power/energy\-gpu/") + cond_gpu =3D Select(gpu, has_event(gpu), math.nan) + psys =3D Event("power/energy\-psys/") + cond_psys =3D Select(psys, has_event(psys), math.nan) + scale =3D 2.3283064365386962890625e-10 + metrics =3D [ + Metric("cpu_power_pkg", "", + d_ratio(cond_pkg * scale, interval_sec), "Watts"), + Metric("cpu_power_cores", "", + d_ratio(cond_cores * scale, interval_sec), "Watts"), + Metric("cpu_power_ram", "", + d_ratio(cond_ram * scale, interval_sec), "Watts"), + Metric("cpu_power_gpu", "", + d_ratio(cond_gpu * scale, interval_sec), "Watts"), + Metric("cpu_power_psys", "", + d_ratio(cond_psys * scale, interval_sec), "Watts"), + ] + + return MetricGroup("cpu_power", metrics, + description=3D"Processor socket power consumption est= imates") + + +all_metrics =3D MetricGroup("", [ + Rapl(), +]) =20 if args.metricgroups: print(JsonEncodeMetricGroupDescriptions(all_metrics)) --=20 2.44.0.278.ge034bb2e1d-goog