From nobody Mon Feb 9 12:24:00 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 3A151365A11 for ; Tue, 27 Jan 2026 18:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769539593; cv=none; b=VBG60d01UxAQrbO0jXxDvAjlMs9lO5JJGDvqWgAHfb5nFEhJzzunYIwjZ4K1XnBLUWcwwBbpFE27F4v43C8SMZa4ILRoctFH4zkdF/b6YJr7D7xwlztQFJR4ovHcefDBYjkkYv4ySQUIa5DYExM3xIuvvf8np3fGu4kcHnVVofc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769539593; c=relaxed/simple; bh=1zUi4F0wnFrKUNubA5dgAmMBGudhKmfRBZtS61CeTbE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=WyKkiWF4IOobPnLKlBuQ20qu0zYopLmj4JFhknP5mf5HLm9XH74UOmT0JZwDiwGokql2PMdaey36NTEBZrVONFvjXSwSDS82Mx+4n8+7Rx1QmqMAoRtEi0IYUaFD1Xl9bM4coF36dKEqsegOnZfTLWnn9ShD9iIFZhhLcT8kyjc= 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=kBUnFBWo; arc=none smtp.client-ip=74.125.82.74 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="kBUnFBWo" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-123377038f9so3981769c88.0 for ; Tue, 27 Jan 2026 10:46:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769539591; x=1770144391; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=gpcaviiC3LGw00gXygGe2ykJpAMPCjE5SQ665o5d7iE=; b=kBUnFBWoH+jsZOhcMyaUKR1xZm3A9haJp5GdmM1rupdSXaeF3tgV1cnW1C+jjD8U0A GVmTu7E+ZmC9FICkWV+V2OZCQj2IKDFp89wBmhEuy9NwadYTE1AhPyL66gt/MzSSYAsC 6pgHPglmKjLqBBAmBuBTrlYAbEkTEP++TqG7O6kEysIHmU7FlYl9bErUw52D8+Z2Xuj0 6pKlOGc3/vUM/EWFHOv5dXCl79YfiOiwZUjbCR1DLF9b+Wo73KY8vqxxSotUgtOIJgM+ SNJF1oMCIqQZmpFqFhRWxZSB1FCklgXmTKPMRz1oRY40EjxRxh7mPzZAVrAT0e+yz7Fi n33Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769539591; x=1770144391; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gpcaviiC3LGw00gXygGe2ykJpAMPCjE5SQ665o5d7iE=; b=nnFHQbkFCSxgrii3RH6x0UfwABLCdk0Fpl/hv2fdFQw4oah1G9xYwVtoYTo5GXd95b WFAwOlZORmgbwjRPekVak2EgzhyjNV3gOcVB8tEuidU2Kp+U3qMFhbWB3b12rMN2UaRL /hVR8/hjswZBrrvQreQwQCt3ErFI4iClaGWyJPUYs7eFcedaWZnL1FyIPdqB7BTnRIxJ AcVWZ19P93mfpTm2zSKn4ax/LEjlICJI9ySwWgszW1qpvyUqUe80Eg/I/BlA5xuBIH+4 hgJQLYNmPvFTorwY63SUamIOtxzzj01/svpx2/wyzR0V1aIkt/qdWTKrk6sH4XGtiMPL UCfQ== X-Forwarded-Encrypted: i=1; AJvYcCXAXVpMF1WEGPm4oIYNpfb9PL9AOEETvhk7cpcs6H1l+P8fo1aShplu7vIHVyxK5RAaanmBDfs+58htTa4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1ER+ci2mkEtRAmBcuhu21Jg7NqpYjA1qvb8NchLluOTuLeGV8 GBu8KTFhszMfxnvjIC0RoEzTH3j7/sx1GmSHl6hU5qT6H4VIqUC1EMFjtzOVkOW+E6JM6mjVs1d NWtcsZ/tGOw== X-Received: from dlbeb5.prod.google.com ([2002:a05:7022:d45:b0:121:7b85:782a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701a:c94e:b0:11d:fcb2:3311 with SMTP id a92af1059eb24-124a00c7d5dmr1467924c88.27.1769539591175; Tue, 27 Jan 2026 10:46:31 -0800 (PST) Date: Tue, 27 Jan 2026 10:45:05 -0800 In-Reply-To: <20260127184506.3059493-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260127184506.3059493-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260127184506.3059493-35-irogers@google.com> Subject: [PATCH v11 34/35] perf jevents: Add cycles breakdown metric for arm64/AMD/Intel From: Ian Rogers To: Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Benjamin Gray , Caleb Biggers , Edward Baker , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , John Garry , Leo Yan , Namhyung Kim , Perry Taylor , Peter Zijlstra , Sandipan Das , Thomas Falcon , Weilin Wang , Xu Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Breakdown cycles to user, kernel and guest. Add a common_metrics.py file for such metrics. Tested-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/pmu-events/Build | 2 +- tools/perf/pmu-events/amd_metrics.py | 2 ++ tools/perf/pmu-events/arm64_metrics.py | 5 ++++- tools/perf/pmu-events/common_metrics.py | 19 +++++++++++++++++++ tools/perf/pmu-events/intel_metrics.py | 2 ++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tools/perf/pmu-events/common_metrics.py diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 4878d922a732..537d27851ca9 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -44,7 +44,7 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) $(call rule_mkdir) $(Q)$(call echo-cmd,gen)$(PYTHON) $(LEGACY_CACHE_PY) > $@ =20 -GEN_METRIC_DEPS :=3D pmu-events/metric.py +GEN_METRIC_DEPS :=3D pmu-events/metric.py pmu-events/common_metrics.py =20 # Generate AMD Json ZENS =3D $(shell ls -d pmu-events/arch/x86/amdzen*) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/a= md_metrics.py index 83e77ccc059e..e2defaffde3e 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -4,6 +4,7 @@ import argparse import math import os from typing import Optional +from common_metrics import Cycles from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, Metric, MetricGroup, Select) @@ -475,6 +476,7 @@ def main() -> None: AmdItlb(), AmdLdSt(), AmdUpc(), + Cycles(), Idle(), Rapl(), UncoreL3(), diff --git a/tools/perf/pmu-events/arm64_metrics.py b/tools/perf/pmu-events= /arm64_metrics.py index ac717ca3513a..4ecda96d11fa 100755 --- a/tools/perf/pmu-events/arm64_metrics.py +++ b/tools/perf/pmu-events/arm64_metrics.py @@ -4,6 +4,7 @@ import argparse import os from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, L= oadEvents, MetricGroup) +from common_metrics import Cycles =20 # Global command line arguments. _args =3D None @@ -34,7 +35,9 @@ def main() -> None: directory =3D f"{_args.events_path}/arm64/{_args.vendor}/{_args.model}= /" LoadEvents(directory) =20 - all_metrics =3D MetricGroup("", []) + all_metrics =3D MetricGroup("", [ + Cycles(), + ]) =20 if _args.metricgroups: print(JsonEncodeMetricGroupDescriptions(all_metrics)) diff --git a/tools/perf/pmu-events/common_metrics.py b/tools/perf/pmu-event= s/common_metrics.py new file mode 100644 index 000000000000..fcdfb9d3e648 --- /dev/null +++ b/tools/perf/pmu-events/common_metrics.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +from metric import (d_ratio, Event, Metric, MetricGroup) + + +def Cycles() -> MetricGroup: + cyc_k =3D Event("cpu\\-cycles:kHh") # exclude user and guest + cyc_g =3D Event("cpu\\-cycles:G") # exclude host + cyc_u =3D Event("cpu\\-cycles:uH") # exclude kernel, hypervisor and g= uest + cyc =3D cyc_k + cyc_g + cyc_u + + return MetricGroup("lpm_cycles", [ + Metric("lpm_cycles_total", "Total number of cycles", cyc, "cycles"= ), + Metric("lpm_cycles_user", "User cycles as a percentage of all cycl= es", + d_ratio(cyc_u, cyc), "100%"), + Metric("lpm_cycles_kernel", "Kernel cycles as a percentage of all = cycles", + d_ratio(cyc_k, cyc), "100%"), + Metric("lpm_cycles_guest", "Hypervisor guest cycles as a percentag= e of all cycles", + d_ratio(cyc_g, cyc), "100%"), + ], description=3D"cycles breakdown per privilege level (users, kernel,= guest)") diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index d56bab7337df..52035433b505 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -6,6 +6,7 @@ import math import os import re from typing import Optional +from common_metrics import Cycles from metric import (d_ratio, has_event, max, source_count, CheckPmu, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, Metric, MetricConstraint, MetricG= roup, @@ -1095,6 +1096,7 @@ def main() -> None: LoadEvents(directory) =20 all_metrics =3D MetricGroup("", [ + Cycles(), Idle(), Rapl(), Smi(), --=20 2.52.0.457.g6b5491de43-goog