From nobody Sun Feb 8 16:32:02 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 1B7DE3612D for ; Thu, 29 Feb 2024 00:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165922; cv=none; b=YxjNBhgfoilh8njZa2akJ8HH8Sg/IvXhnG3T2Po2zP2m6yRYFsfp/ERj3+h0egdpbfTCG3sThN6UlABsc8dBN2SRyz4saOj/CtyjdafENaskvCo7M1VsRbyH55wJgyGgUStfeN1j8C3KpFhyU51zb2FjFNSZCci4uGaEv5ABFt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165922; c=relaxed/simple; bh=yjVC8LCNIc1SkJJNK1huvdVoLuihBnJ8/xrqhZCq4ak=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eBNxNGGeld5pOFhE5fREmNnLrOcTNkgenYXEo6soIer3xbFTP8ed1YCEjkLbuxEoLyY570l+LOj7PtLtxceExIbqdB8W3fzNV7B5yvbtRpgm+5RvlKfWU4cwAYwlIuGfnEnd/2TMrf/ZB2mO79Z1Ey8AhAPRKZq+8dOUBkXcJ5Q= 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=TXbLB6zI; arc=none smtp.client-ip=209.85.219.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="TXbLB6zI" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so555114276.0 for ; Wed, 28 Feb 2024 16:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709165920; x=1709770720; 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=KevBgsY4J/pffn7xcpMTC+4LgPUcMPV9xIrPsMU+9Ks=; b=TXbLB6zI+0/6+6vGkPpMthp8Vsxif4X0xxUustURUo4Ess3YNY0eTvkuNQgS3r8zrY 6tlSV5TwfJrVlkb2PNv6N2pmo6e/TfPgtzYAVWl5m5j2odk4t4guhryu4+IbHnSLrj92 hrFDri20zNOA+nBXBbIMxat0QybrWMIEJBprb6UIarzcJlbERzpMlijNb4tEY68XAR8I 8Y0vo1TH8e1VI/6Cr7bO2quv70VLeeHdfdzzIugHyLdoblgX6BWnqWhG0mMaOGoicXk+ 16FuSWbkmuopilPWZY2FZiiajN9CaXBAAjN82uasqnF7GQLiYixrnjRl1HCfMF+5xwhq nUYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709165920; x=1709770720; 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=KevBgsY4J/pffn7xcpMTC+4LgPUcMPV9xIrPsMU+9Ks=; b=ChhEais+obh0hyWhmwR/wBPEXj+wGPabVpiyTXS9ZhRzvgaPjGGm+Qm97ESnBK8AnT ukFwJzcTb4mYqROvkeezxYwEyS5j6JWMp30pb2BMEM7+ffZueX0sT5O1MVighKuDh9sX affxzmYHrDFCde5GvF+3sz3vsMJ0VcvPI1GBTQVNPnCCAPko8yYZ7eVYE5skNCoAknlm 2dFF/mj2tbuFs/7avBDcfXX9vrWW8eIaeZpwSz4unS/WLJ7gmaI6SONFOw34sVDcD+jI IO1IHHZWQIG83sRvD6kgVuEzUOOBB8cpCzoy/h0YybFyL34DbBUSbTCBn2r4t5zyi3il 0cBQ== X-Forwarded-Encrypted: i=1; AJvYcCWyeWuLuaPbp0kQiGCPIYQriuZd6C0X1A8+nDZAAzp1EE4VvP5wVOt/NguT4NjUU2zI0P7i1UtQHSSDwiF+AYr547qASHTp6ljfWadr X-Gm-Message-State: AOJu0YwMATyLp8bMP5yFoTaExqreGM92geYBDNvHJZ/9Cvkr6xy4E1OS h3ys9EcWoGiH8sV8+z/BvDjTxtMLu8d5DkwFqHXL3i29Gx/ILO8Vrr9YD6PXz5WeDzRKTjMsET8 l8ycHjw== X-Google-Smtp-Source: AGHT+IFlP6eN2j1eRfy7sjBDk7E7RwirfhLDiu6aNv3eb7Zo8EY3zKs948Zt9E48owNMTBeAfysMTufX7A6o X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a05:6902:e90:b0:dc6:b813:5813 with SMTP id dg16-20020a0569020e9000b00dc6b8135813mr41854ybb.9.1709165920173; Wed, 28 Feb 2024 16:18:40 -0800 (PST) Date: Wed, 28 Feb 2024 16:17:52 -0800 In-Reply-To: <20240229001806.4158429-1-irogers@google.com> Message-Id: <20240229001806.4158429-8-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 07/20] perf jevents: Add ports metric group giving utilization on Intel 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" 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 --- tools/perf/pmu-events/intel_metrics.py | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index f11273e9935c..63d46ee1dca9 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) from metric import (d_ratio, has_event, max, Event, JsonEncodeMetric, - JsonEncodeMetricGroupDescriptions, LoadEvents, Metric, - MetricGroup, MetricRef, Select) + JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, + Metric, MetricGroup, MetricRef, Select) import argparse import json import math import os +import re from typing import Optional =20 parser =3D argparse.ArgumentParser(description=3D"Intel perf json generato= r") @@ -18,6 +19,11 @@ directory =3D f"{os.path.dirname(os.path.realpath(__file= __))}/arch/x86/{args.model LoadEvents(directory) =20 interval_sec =3D Event("duration_time") +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) =20 =20 def Idle() -> Metric: @@ -265,6 +271,28 @@ def IntelBr(): description=3D"breakdown of retired branch instructio= ns") =20 =20 +def IntelPorts() -> Optional[MetricGroup]: + pipeline_events =3D json.load(open(f"{os.path.dirname(os.path.realpath(_= _file__))}" + f"/arch/x86/{args.model}/pipeline.json"= )) + + metrics =3D [] + for x in pipeline_events: + if "EventName" in x and re.search("^UOPS_DISPATCHED.PORT", x["EventNam= e"]): + 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(port, f"{port} utilization (higher is better)", + d_ratio(Event(name), cyc), "100%")) + if len(metrics) =3D=3D 0: + return None + + return MetricGroup("ports", metrics, "functional unit (port) utilization= -- " + "fraction of cycles each port is utilized (higher is = better)") + + def IntelSwpf() -> Optional[MetricGroup]: ins =3D Event("instructions") try: @@ -335,6 +363,7 @@ all_metrics =3D MetricGroup("", [ Smi(), Tsx(), IntelBr(), + IntelPorts(), IntelSwpf(), ]) =20 --=20 2.44.0.278.ge034bb2e1d-goog