From nobody Wed Dec 10 20:09:59 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 DC40D315775 for ; Thu, 13 Nov 2025 03:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763004119; cv=none; b=HR9eBJbyCXY2MFfDiSDhZC1oQZYtFceQvVysTzcZJ1PEGBAngo9wgwtFp8op+ruZG67jMfMko3QeWxUP/A4noXY61oJMi7eyhdwAjJvOHCiPYxjjN9+V0qrElbq6SIc3oc7Vxgf7nW1agNakJVYd4229Bqd3V63uYCaWAa/zvX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763004119; c=relaxed/simple; bh=LsyKcinNr3CPTX48GcFwcCHhWozpCKc5nBdCv3vLTew=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XPp7RyjJ0N2ROsQZzl6D+juGeVT9nlfwA+M/BvbJ91MgVMgMStfbW2Tgn4u+jAmqlSQW7ofOwR2eaXHjZ+a+u0EUrKVSs+q/yMiwHRn48ZgBEjcJjqRJAJn1b4KZukLZyNhlldyiQd8SQExOWqtHDduQO/IHaoqs/HcHdXuuI+Y= 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=I88IU/Kh; arc=none smtp.client-ip=209.85.214.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="I88IU/Kh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-297dabf9fd0so4715175ad.0 for ; Wed, 12 Nov 2025 19:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763004117; x=1763608917; 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=dNV1+CYAP59mMY84k0p51lR2XkbcJc2V/Ohr57nRnzk=; b=I88IU/Khfnv2a4sAYh+9ro7eYUXlVv3q9fyoxFREnojK4BQZP1C9xkDEMBOIs13CX2 s3pm4YWJ1S20ANgqKEqWA3tdj6SHxkoz/ctgjl6elnWQtwr61RYgEej7fj7Hz1V5SPIL 9UnV0CrGKVH9+dc9yh/JqguMx2ogfDUm1RGOQGIKPplo4Y0CjCQEMCIaJ8aWo6uyQnsK p0aCNtkz1kAS+HU+gZ1nlTE35EFxdniBMzEK3UGRhJ2xPkasIyVy+L8fPxH6yY3NJmYK eJTOhbuFeJLE74f0xtBxCWHXyM5qDFXiiBVLVGh19C7v5193t3QKZH5YZhRHMbVZgFXH ISgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763004117; x=1763608917; 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=dNV1+CYAP59mMY84k0p51lR2XkbcJc2V/Ohr57nRnzk=; b=Et2KXVMiCZ3px3On5cqeN3oMikLkRJwjJ1nIzEaoX493MobPpNcJNV0CtRKyYHFSzh nZ2gNL2qFQIytgO3UqyFcCyGeWNO3JkwRqZAzTd2LMbX1GUMyjhddfbBWq/eQphn7YMv nRBa7uaHSPyUzTi7hqQK6gv9JHsgM1bkK3MyDEGnrm8VFweJUjYn52o+pUd/1qShs6yV yR4bt75WGeuI7E37uWJ0aaKDF1p+xLrGH7MGvPQ7gmHc2wYma41vXS/VXos+DIUOH5SL 5xgFzxN5A931+jzMxppEBXI0SFmB50dVWzIYBNqZBpEiePqs5vFxGBFHecE79Xcv1c+F kkoQ== X-Forwarded-Encrypted: i=1; AJvYcCVrxVlvzpxHvzw+s9XZBctZXFnIUTIRU8xvUBrcnc9+f+8r29pCHw/JKqX6cU9emW/l3oIlaqMIYwSwMhI=@vger.kernel.org X-Gm-Message-State: AOJu0YygtynodekPV4iwfnyZMv7rCESg/GHnwYxj4Ej54C2PxujCwbvf 1Wr9dy54EWpJ1J71L/vtO8qrIfdjBTBr4+uiMMekaFCa+99wq1XSg1yvbZiAsrncSn1TrsyApOu gMJejZFwJzQ== X-Google-Smtp-Source: AGHT+IGA+Oqea8iVXOKqwkrhs9I9SGNm1GeMFGhgWmNebLYA/jXIr5+hkhGFbTjsFBUqXw5DiMYhNbZSyyJG X-Received: from dlqq42.prod.google.com ([2002:a05:7022:63aa:b0:119:c6ec:cc42]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:244a:b0:295:105:c87d with SMTP id d9443c01a7336-2984eda98ecmr62240625ad.32.1763004117305; Wed, 12 Nov 2025 19:21:57 -0800 (PST) Date: Wed, 12 Nov 2025 19:20:21 -0800 In-Reply-To: <20251113032040.1994090-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: <20251113032040.1994090-1-irogers@google.com> X-Mailer: git-send-email 2.51.2.1041.gc1ab5b90ca-goog Message-ID: <20251113032040.1994090-34-irogers@google.com> Subject: [PATCH v8 33/52] perf jevents: Add tsx metric group for Intel models 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" Allow duplicated metric to be dropped from json files. Detect when TSX is supported by a model by using the json events, use sysfs events at runtime as hypervisors, etc. may disable TSX. Add CheckPmu to metric to determine if which PMUs have been associated with the loaded events. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/intel_metrics.py | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index 94604b1b07d8..05f3d94ec5d5 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -3,6 +3,7 @@ import argparse import math import os +from typing import Optional from metric import (d_ratio, has_event, max, CheckPmu, Event, JsonEncodeMe= tric, JsonEncodeMetricGroupDescriptions, LoadEvents, Metric, MetricGroup, MetricRef, Select) @@ -75,6 +76,54 @@ def Smi() -> MetricGroup: ], description=3D'System Management Interrupt metrics') =20 =20 +def Tsx() -> Optional[MetricGroup]: + pmu =3D "cpu_core" if CheckPmu("cpu_core") else "cpu" + cycles =3D Event('cycles') + cycles_in_tx =3D Event(f'{pmu}/cycles\\-t/') + cycles_in_tx_cp =3D Event(f'{pmu}/cycles\\-ct/') + try: + # Test if the tsx event is present in the json, prefer the + # sysfs version so that we can detect its presence at runtime. + transaction_start =3D Event("RTM_RETIRED.START") + transaction_start =3D Event(f'{pmu}/tx\\-start/') + except: + return None + + elision_start =3D None + try: + # Elision start isn't supported by all models, but we'll not + # generate the tsx_cycles_per_elision metric in that + # case. Again, prefer the sysfs encoding of the event. + elision_start =3D Event("HLE_RETIRED.START") + elision_start =3D Event(f'{pmu}/el\\-start/') + except: + pass + + return MetricGroup('transaction', [ + Metric('tsx_transactional_cycles', + 'Percentage of cycles within a transaction region.', + Select(cycles_in_tx / cycles, has_event(cycles_in_tx), 0), + '100%'), + Metric('tsx_aborted_cycles', 'Percentage of cycles in aborted tran= sactions.', + Select(max(cycles_in_tx - cycles_in_tx_cp, 0) / cycles, + has_event(cycles_in_tx), + 0), + '100%'), + Metric('tsx_cycles_per_transaction', + 'Number of cycles within a transaction divided by the numbe= r of transactions.', + Select(cycles_in_tx / transaction_start, + has_event(cycles_in_tx), + 0), + "cycles / transaction"), + Metric('tsx_cycles_per_elision', + 'Number of cycles within a transaction divided by the numbe= r of elisions.', + Select(cycles_in_tx / elision_start, + has_event(elision_start), + 0), + "cycles / elision") if elision_start else None, + ], description=3D"Breakdown of transactional memory statistics") + + def main() -> None: global _args =20 @@ -103,6 +152,7 @@ def main() -> None: Idle(), Rapl(), Smi(), + Tsx(), ]) =20 if _args.metricgroups: --=20 2.51.2.1041.gc1ab5b90ca-goog