From nobody Thu Dec 11 19:20:47 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 9B6BE2DECBF for ; Tue, 2 Dec 2025 17:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698035; cv=none; b=ITDo90xbO1nh9pzPRADWQHsXDJ7pQ9rmL8s4iCvVxNtPBkA0XrDOTfF7E/gfsexu/HgQZXfYwyeS0R3ybd0wKywkaAJi5UQDC/P2qFNJVaa3P+9ZOGgDhU0quJVLq+HsGz6RT72Qta3r89ApaOkuCLD1wgh8SGu+3ftZhuwCG24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698035; c=relaxed/simple; bh=f/zAPLMgLEoZV5Qea+vBOLAPk45QdYaXzdW1d7eayBM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=J6Zm6zfk4fuMI0jCkuK+FjzjqmcRyZJCChowOLDU6/KVlyJP4dnTXVTSqv1ascZUtJ2j+5JcWAvHNzUC5qb4Zd/DELnPc7xHu6l5WufDuQFBEqBPMrlCMkvhR7TDVV0ymhuyLLUilKVXi/3LapbOd2k7tHFXZ5ulAKyd2HFzKQs= 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=e/7voazM; arc=none smtp.client-ip=209.85.215.202 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="e/7voazM" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b969f3f5bb1so8322748a12.0 for ; Tue, 02 Dec 2025 09:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764698033; x=1765302833; 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=iHpRFpym5+i6zLNza6g5W+ofHyML5n4SAWgymZ5csvA=; b=e/7voazMBRn+GNkiYpuZPw9aGWvzqbWHM/DnBxxt77zL/j16lCXpDPNMEPcIM8YY2n VOKTzmOXY9VPWVg08NBh366QY7uacXmGSljXDkwvA7LnlGa/gzEeTZFL0n/Gsv72BBI1 SM9A/fpzFmlVl/y3k64d8fu+dGtkBbYYox0v+8UXmG7g5WofAqIgx12UW7ZYvbNb2+vt GepsRia++kdGlCLzafOYvaOy8hIwvNdWLXHmUzGwMw8wxRGC3SJKTS88AmRF9ZJvc6RV 0AcLT8mHsL8V3ldhrs9Ly+sbrSWyzaHJYmnC8fOx8855mYtjjrYae0+HCApbS5bA2kuE GO1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764698033; x=1765302833; 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=iHpRFpym5+i6zLNza6g5W+ofHyML5n4SAWgymZ5csvA=; b=FavQtwe4gmH84R/diKUsRzdUGp5fBrecZjLTlJsCBCNbobvjUd11+Aq+OgYE2gwGS+ iAB28wqZzAKlX3RBbGje4ldWByVnu480w/QaWH7i2/SRkY+lYzfiTmzZUg/vDFhtke+Z qrR1I4vpmwTUth+8QmGboIV1dUY6aVX3tAUfdyw0BVDENEDnsi/Wn7EhDleC92VCS8oa oA6Wo/Wp4RL4ygg1QZ71Oq22X+a1vSpY6IWIaks2Xlpl6WMDAxxJHRL7VZnkrx4Rhony 42th6zeVl7g0B+R3rYrSoClMZtNxSnA0PzcQNg75npM5yY0Z2DvyEpPT3Jy3ZiJXrft1 L5kg== X-Forwarded-Encrypted: i=1; AJvYcCUnopV5q4GxllzJjk4GQNJdO0Tix7KjpX48NT+WoZFDbnj2GPb4Di5rxzmoagczvdmQa5xXhKflkRRHl2A=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0+feo6s/vfzjoNJqU5vOzYcxPczj1fLtwwrYFWhQx/GSUuLLD iE8FVvYXygm2kyVSRF/U1XclvmdO1CBVVAFY+Odgc6EVCb6jwU8PYR4I2dIP0ASSsqCynu8W8Zy CuB/+0bq8Pw== X-Google-Smtp-Source: AGHT+IEqAUTg+KXUlvohtFVJIF0Rt6q8c/u7JtQImlQYGxMu83U67D973qgRjEufUnMTwIPUrLipMkigq1So X-Received: from dyboy20.prod.google.com ([2002:a05:7300:ed14:b0:2a4:4bd0:6ed8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:8008:b0:2a4:3593:c7e3 with SMTP id 5a478bee46e88-2ab8fb873e1mr160771eec.35.1764698032849; Tue, 02 Dec 2025 09:53:52 -0800 (PST) Date: Tue, 2 Dec 2025 09:50:27 -0800 In-Reply-To: <20251202175043.623597-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: <20251202175043.623597-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251202175043.623597-33-irogers@google.com> Subject: [PATCH v9 32/48] perf jevents: Add ports metric group giving utilization on 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 , Samantha Alt , 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" The ports metric group contains a metric for each port giving its utilization as a ratio of cycles. The metrics are created by looking for UOPS_DISPATCHED.PORT events. Signed-off-by: Ian Rogers Tested-by: Thomas Falcon --- tools/perf/pmu-events/intel_metrics.py | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index 919a058c343a..7fcc0a1c544d 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -1,12 +1,14 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) import argparse +import json import math import os +import re from typing import Optional from metric import (d_ratio, has_event, max, CheckPmu, Event, JsonEncodeMe= tric, - JsonEncodeMetricGroupDescriptions, LoadEvents, Metric, - MetricGroup, MetricRef, Select) + JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, + Metric, MetricGroup, MetricRef, Select) =20 # Global command line arguments. _args =3D None @@ -261,6 +263,34 @@ def IntelBr(): description=3D"breakdown of retired branch instruct= ions") =20 =20 +def IntelPorts() -> Optional[MetricGroup]: + pipeline_events =3D json.load( + open(f"{_args.events_path}/x86/{_args.model}/pipeline.json")) + + core_cycles =3D Event("CPU_CLK_UNHALTED.THREAD_P_ANY", + "CPU_CLK_UNHALTED.DISTRIBUTED", + "cycles") + # Number of CPU cycles scaled for SMT. + smt_cycles =3D Select(core_cycles / 2, Literal("#smt_on"), core_cycles) + + metrics =3D [] + for x in pipeline_events: + if "EventName" in x and re.search("^UOPS_DISPATCHED.PORT", x["Even= tName"]): + name =3D x["EventName"] + port =3D re.search(r"(PORT_[0-9].*)", name).group(0).lower() + if name.endswith("_CORE"): + cyc =3D core_cycles + else: + cyc =3D smt_cycles + metrics.append(Metric(f"lpm_{port}", f"{port} utilization (hig= her is better)", + d_ratio(Event(name), cyc), "100%")) + if len(metrics) =3D=3D 0: + return None + + return MetricGroup("lpm_ports", metrics, "functional unit (port) utili= zation -- " + "fraction of cycles each port is utilized (higher i= s better)") + + def IntelSwpf() -> Optional[MetricGroup]: ins =3D Event("instructions") try: @@ -356,6 +386,7 @@ def main() -> None: Smi(), Tsx(), IntelBr(), + IntelPorts(), IntelSwpf(), ]) =20 --=20 2.52.0.158.g65b55ccf14-goog