From nobody Thu Dec 11 19:15:36 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 A288D2D47EE for ; Tue, 2 Dec 2025 17:53:35 +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=1764698017; cv=none; b=aW3T+lDaor/RG2IH5ff/MQpLrnoOYKweFwseJ/8tmJwSvgBFMf2m5ihVohSJO7VSgEgnwbDHuJLzhCRx/I4/VxOwofSwM9C1BzWeJqpmLvsEq/B+BfHqVlQl3cs9Xj/4Pk0U8CegjQuNjySvtLvIZs4smQzl40GHFrlAjwmpGDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698017; c=relaxed/simple; bh=NNOXiWGx3mkUhIhjrOqGTilOSUrSFRozKFaELeAVXuw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=HfZlDOZsDhOXRnz61XrcWql/BbP1c9H+N9fsotHYtriji2ZfDvT8jSikUUVMrZM5NI+Z0nu4JMJzUmE9yDuiHa2BuusWR4+dd3VjhdueL4IqCJzlrbbjHWv5v9XFwRmzOP9I3DevFZCox5JS1Vb4mongj5EelPrxTqTQ9/G2huM= 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=u8kuUsBD; 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="u8kuUsBD" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b969f3f5c13so5853627a12.0 for ; Tue, 02 Dec 2025 09:53:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764698015; x=1765302815; 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=kagJRUkunuf30Ut0TYFOO2mO5Mf8Y3yJj8xTm5T9Lkc=; b=u8kuUsBDfdWiP4xDWIQlNENeiMjBOKwm20+VTpOJbEqjXSkJ3JJQg2oYW7NCCaXQ4O 3BykdvBCqx6EuWSsRYw7PT4rNbc/nGh4T4q/bt/UrFyC7WhMwAdOvPb+WxW9r7iBxAB8 mFrWa1Cje3tOvcCPteRgWBi/HqR7gXP8Mpp1yBL2mYUDZV7UK2+8sB1sUE2BaHVcyR7P yjaHBOuHIy4iwQ6UcMH4NQ2ynFfq/UxQ8wPS/D4GiG1CM08tmu2yuwpi/H3/belzxTBr HuT0D5yDcT3Q7JIAvHZN5e8PfXtDDuNDgQnAYK5KNxPXV1rE2hyMBZf1ifqUT52ARBSe XrGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764698015; x=1765302815; 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=kagJRUkunuf30Ut0TYFOO2mO5Mf8Y3yJj8xTm5T9Lkc=; b=A3Hv0FRRRBGzXjsGgo9CAt8aAqaVCENr81ev6GpQhW/vptUZpqDmh3i5UZjLdmReY7 ClDRgUK0xcCp93wvheYtSmQs6IoP/HYvzHeJ3m79iLJ1qYJ39heUHzjR233jeXiU4/tJ gqukGZLsexbXJLcX2x+c1UtIMMTvj+AHCBM/fhHO3Btbmj7MqCtP13fYANAvyS8GP8+N 3PsNQsVK5xlqn5UO5yACbpNmTSDHynJZi2zLfmqigq2k75U5wO87kXUG0yP8+TushHV4 F+0vz+Je360qiYuhp88R1/dui3V8WCN0FaZ64NalFeFQN4DJo4O+i3gke8UjlFlyDenf 1O3g== X-Forwarded-Encrypted: i=1; AJvYcCXQege9XqUaqftAxOu480MEvlZr29noCMfjUVbiijBfoP8TGK0Ez143d3v+Ib0PzbpD12DWsGwQnX3v31E=@vger.kernel.org X-Gm-Message-State: AOJu0YwxylCTuE/zOfHxSzed08P6vyaUR2ZxQgdlYYRw2OJiwwVJ9nNV 4cbDvgLUwt/uGpP8njoF2FTrqltcZ5EgTNV+fN7sNEPCbKbwHJAmzTihdAlLkPAaRg+I9ATt+q/ eVQCeeIO70g== X-Google-Smtp-Source: AGHT+IHKteFVm3tJ6cIW/EiJxB6p25YtXwsAPClDJsG6Uot4gbu+RAEE2cp/sNQKuA69ZsWJcJ9F5ODtFroB X-Received: from dyer27.prod.google.com ([2002:a05:7300:231b:b0:2a4:6899:e5f0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:e827:b0:2a4:41c3:3a45 with SMTP id 5a478bee46e88-2a9415736femr19495183eec.2.1764698015038; Tue, 02 Dec 2025 09:53:35 -0800 (PST) Date: Tue, 2 Dec 2025 09:50:24 -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-30-irogers@google.com> Subject: [PATCH v9 29/48] 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 Tested-by: Thomas Falcon --- 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.158.g65b55ccf14-goog