From nobody Mon Feb 9 16:33:54 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 A3C2435E546 for ; Tue, 27 Jan 2026 18:45:59 +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=1769539561; cv=none; b=Pcm/Ldtfb0NxciV5WZnYsClzTAm8OqQBWqtv3/TVJB3u1bKe/LbOzgc0kA8EqZsMfijLAW6MIpualQq9ZUtK6ARqP3l5D/hF4SGuRfAdQFGTxSKL7/EQ/1sVjfJnSjvIudMzXzBjRL1aZ6BmYqpyALr3MhKLBmgvTgj+Ud098RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769539561; c=relaxed/simple; bh=e5HCiCuPrRhKQ5C7WVfdNlfmfEV5F34Gu+L6jhwfY7U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=D647QocbL4L19Du2lVqStwIWzVUzvFimPMdK+mGkXLiy5qy47jy0guy6y4y+2Vuni522xSOLnotFK0L/fu7JbE/g/g5GlA9m7YN5ECIhHVhyrJQorNkpnBhszVWPvwTjwSDTNGlY8pp1xf11fGeApQ4+HN3FCx9ybKyBjoJOWtg= 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=iyWNnWy8; 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="iyWNnWy8" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-124743cf760so5121205c88.1 for ; Tue, 27 Jan 2026 10:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769539559; x=1770144359; 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=xk6S0HgVzRXTxY7M8qgn9fyMiMtdB0df3ARIvh/RRkI=; b=iyWNnWy8qctDii97Ydrn813G+YM3mMrucrxEeTnP7Fs0E84t17nu+ML+hHQcXijbHl XvhP+1lPZhebDyMgbhf58vLz4FvQQZ0AA9SM71pN73cbwyQbM5yNh6izCj7Vg+6NN+Ka 5eYbkscCoecSa0xPIgYUQ/r7kTry1+GH60WBsEHGMoUYrUlhE8oWJ9namcfluHklxWnK PSCcN44ri8LfdbKND/utCTRG3uu7EYXAqdiM1w2M3xcDSZgH2RBFi+u7oFfI82zH3qNz kjjIDhhRfWf4wMm6/Zv+o6cMELiow/JNI807Lbst04otvAB1gSVn3dC5egVTXkTPhBJR Yuag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769539559; x=1770144359; 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=xk6S0HgVzRXTxY7M8qgn9fyMiMtdB0df3ARIvh/RRkI=; b=wPZPY/61J03WTe4TLnC12SKNExZLQMkdaiwmDMBhuTSrEYlraH+sUyKcBGTMjG5dNx hFov/W1ku0XtwLFrrXmUJfk6knWCZtoymzxgYpHrX2uzELXGTiJmMp7RkJbnqqR7Lqu7 wcydTmL2hvB/cd46RS+JWObLzJOqLB5NbWveDVyabpa2qLvLKCAyq/kwyqqbaM9jHVtR eoNmlPV6nMRo772rlJZ53ldbs20oTiZXetOsp+Xlt6rO1Rwf5PSqeab+6DUVu1LYY+ix lVeks007Hk+st3q/hiu8R3iIxYfoZ0glDVXmm3Z8Th9oL/zVlMJchR574FK0rFZaj4q0 kp+A== X-Forwarded-Encrypted: i=1; AJvYcCXLIEM+cDTLm+siGkAiJoLt4Ncn9qnueJ3eA8zGPpWvJQS6yyyiPgQoBuILwrIF/TyFhNWFmn7xAR2RSPg=@vger.kernel.org X-Gm-Message-State: AOJu0YxKn4iaeAlRijYBOAIGsJnK5VUIubJA5QXINhXiTlOK6IGp8yBW HblJLYuGy9ay1kKDlGsQs8kaN+yBUvC1Ti2jnwmd48Ua+mxM9CZMaPXPZnksfzBhYCTs2C0ohHu GHbVco4Xqyg== X-Received: from dlbvv5.prod.google.com ([2002:a05:7022:5f05:b0:124:a551:3498]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:670c:b0:119:e56b:c752 with SMTP id a92af1059eb24-124a00c6f30mr1509152c88.23.1769539558630; Tue, 27 Jan 2026 10:45:58 -0800 (PST) Date: Tue, 27 Jan 2026 10:44:48 -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-18-irogers@google.com> Subject: [PATCH v11 17/35] 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 , 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. Tested-by: Thomas Falcon 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.52.0.457.g6b5491de43-goog