From nobody Sun Feb 8 19:55:03 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (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 D6FF5329E5F for ; Thu, 8 Jan 2026 19:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767899521; cv=none; b=To0REeB2BT1lDr4zz2Oqb+2Xg72729YOMtrry8VXleX+vazTfGUJPIgBGcH46bAlbQSpZdsoM0K3QmI0RXLbKL8MB0gE9m5L4zCxW7hRCY5ws9UWFNA5BS2Io1HyVO+GMqsrX0YJK/iNdPUNziilsbV5kxddNldIyfJ/2yQpL8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767899521; c=relaxed/simple; bh=e5HCiCuPrRhKQ5C7WVfdNlfmfEV5F34Gu+L6jhwfY7U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=nbiiRJ2WuN+XgEluXpgkhoumZFjdtBgiDS5wwKhFiDZUZMgSVSTbfQARy2pG3WI/33bLpeHziQwg4AjCWqDgk9JXsk02DlJCD2aTh15vMyOxyCmVBUd4Zmuys4ELMoz7b7gZuXKVb6cBMoyWjpp3ZMhrhiMY2+1+QI/79W2yLUY= 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=kWRQAuTr; arc=none smtp.client-ip=74.125.82.201 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="kWRQAuTr" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b0531e07e3so2876506eec.1 for ; Thu, 08 Jan 2026 11:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767899519; x=1768504319; 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=kWRQAuTrQI0pOQh0Ll4cL1uEIgMeh9EOrKuOMekNXbDZc8KUKhQjN2KPCb8C42lM/+ h8r79hImoaviMLQM+xs6y66oxv4nqiNPco5o2zx281V28J8N4xRLDneQ1LrHrlcly7BY PuPpSTYzPAj+5bWdaTdh6q0Gk5lbgnLj0X6FdbVSXeginx6OJM152QiuI39j3IaOiOOl Fqmn2VqKbI7AdkKOobPOpIwfbyV9XrT7RG8bz4HJMcx5OJGqq/U18vJdCemFDYHDjAI4 nWQDvv4qy8DQDWwOVcipuv4fsMiXFxi7GOFEmDbpFywajyXo2HjdF1XF/L8UiK1OPLwF RSPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767899519; x=1768504319; 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=flRjOsYoKowUDzthUPWyEPQUEDJA57kw3v24WbZ/UzggK3NhJD3M1etXTSjcjXSDQw G2y2zCv7G8uQp71ER3yMu35fAl2t2RNj2tksxOeaw+XZGmusWdHprr/PXQmHtoSNU2HV Q+izVRxqpQ+ABY2rL9fd07TMPFEJz3pNB/8kVfkPU5X/VdIoXll5nHvYIw7TpC1nhFFj 55rOZq/GAdk6LrZ60sx2y+dIVjPOmbgJeFRp9xkSybjNMIXTOvo/ZgGOeYRYgVJidquL phspgOFmJwvfzfdSzj1x9D24wO/q3ah+U1qIpca28wRneKZOHHzNMHT7hPWEiV8PVaZV qrKg== X-Forwarded-Encrypted: i=1; AJvYcCVCvY09yElyDEPvk8QjfKzajgrechgcFI+QG8zcrAYvgVLvbMRxbkW6bvbBeOYMzorLwSpRuDFIg+9/gPo=@vger.kernel.org X-Gm-Message-State: AOJu0YyrSaT9MuoaLmJaM+sN4UouJOghkdDpPE/Q+HZNml9IkmIWsW7N w0BTiKsxPZbCHl58ccQ/czdfy81ae1nnx3qx2GMUWuuqlfUj8QDG/Dp1LcaA+6CEnHgRmlC4KhQ LneTfS/BV4A== X-Google-Smtp-Source: AGHT+IE0YYVq29C6WQ6XFAWFEiR28SaNnN+3y7gJb4bYD9PO6loo2xXE8EyJOZ5RP0E0T6/QEkZ+ciLweTId X-Received: from dycrr1.prod.google.com ([2002:a05:693c:2c81:b0:2a2:47b6:b541]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:b90d:b0:2b0:4965:8829 with SMTP id 5a478bee46e88-2b17d325943mr4556597eec.34.1767899518910; Thu, 08 Jan 2026 11:11:58 -0800 (PST) Date: Thu, 8 Jan 2026 11:10:47 -0800 In-Reply-To: <20260108191105.695131-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: <20260108191105.695131-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260108191105.695131-18-irogers@google.com> Subject: [PATCH v10 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 , 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. 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