From patchwork Fri Mar 1 18:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp87487dyc; Fri, 1 Mar 2024 10:57:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVp3Y7N3qclUngkcI2iwbA5+nH5qZG2gkhcvQm39P91C1ihdv9QkDNHcJmmy96Yt+EPgW/UpEYNxRaHTecJpmwG6yJkhg== X-Google-Smtp-Source: AGHT+IFCakyJ5uogwFSuc52CeLiSaWD+uRgosHU5YqVt5IlSMVs/JxLPovk96U9nucdYB7WebMtM X-Received: by 2002:a17:906:3b81:b0:a43:86f3:af37 with SMTP id u1-20020a1709063b8100b00a4386f3af37mr1991004ejf.53.1709319463246; Fri, 01 Mar 2024 10:57:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709319463; cv=pass; d=google.com; s=arc-20160816; b=gsGqAy2wXQkn54Q+arTmvLkXGt64AqPiIhZGJ5dhq9H84Jjim3nnwPwpcJnouh3zPX Q4+qn3NuGgrblQTvh9KvfPoiY3hlF5nQZGw7uyPFkaFc8mFb9zNRlhXqu1L1TI1S6mHd iewnb6fCsRTsGyxyizPfL4Px/qnRIgbhb1+tHQJH/7JBYrBmHYmPxqLxl1iP1Uv+6GmR DnlIIByRBoTtRBBiI3wZHT2uIKnw6bhTr666Ro6PsJJofPYwl/yA/rfuWhLn35YetSAL KH0Mjxo88NtUFtN6LhsWsVpEelDrbnrNMkp0ytuJfemQguy4Jxkb9WDybkYko4FK823j GVPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=L68TwYEEJpFcSpLsVXn02dHEJdoYMq6WnWpBdckYRf8=; fh=Eltj0JGfwZITDURiNecPUXXqOAZGFb2fFTZsGOtec7g=; b=YxaFjVwz40T0JjEcYDtc9cCwNQwIkv5qOn5m4qNUNEWPOETh6naBY0D4Pf0ZRfaiwx RUMvJXKecx/6VkQwWTk0iMCfUi1rr1+XivZ6zEHhX04Z+sQ4XoRgDsOGmyEguvTvhQN7 MIap8dgfy8EFYlVBsh8ZyR2SQproB0cMp2i2Yrflndnop3aZDLjCCP5Wequ/5jK3+JAY 8Exg9R0vxgtoO1eQaszrIWUgG4LBHPSEQvbYUHndpiTLDDZAd17p8IMothuZQOJnWpNK PqbNYxJLoNycbvGAFybcl0Hed+1KixRnk9wq/Nh27DyFyG3vj2c2TdsrGgSmOe2pbl+4 wVFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WQYNPWHT; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88962-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g25-20020a17090613d900b00a4425e2c2a5si1631962ejc.298.2024.03.01.10.57.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:57:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88962-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WQYNPWHT; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-88962-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AE5961F21F3D for ; Fri, 1 Mar 2024 18:57:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E7AE3C097; Fri, 1 Mar 2024 18:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WQYNPWHT" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 0F63139FC9 for ; Fri, 1 Mar 2024 18:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709319385; cv=none; b=fMzALEk2RY0/bHbfgf4e58aMVScCK7M9ewlpv6C0Appvl2Zxdor67gjFv/Y9aARKiKLSNh3oB1yQ0Ez1JmN/DHQ8ucuBvtK8WVYCOcvdKtcx/rDbWHqRgWJStYDefjLb/6PsQdXKH4mHVVrj6QErsbFIcn4ezVEkf6Kg+vfXAlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709319385; c=relaxed/simple; bh=zOERgnuO1Bl3NMcQJgmZ4s42PwosJ4JFp5OUJlYIO44=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=QLFFLIiDLutf3vVSsoYPaeo9Orzsjvqh9hUvJ0kxlsl8otWUnS8O29VYHRPl6y1ji+1IJiEF/e7pXZ5ZETNYyfgy16FtR47Jqp8Nnd5+a3TmyOOopK9+vUVnBkmUreigdpzNAdYgY5VPsqLdSos08PWMz09ugKpMFYl+WE8XZdY= 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=WQYNPWHT; arc=none smtp.client-ip=209.85.128.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 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6096493f3d3so35131687b3.2 for ; Fri, 01 Mar 2024 10:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709319383; x=1709924183; 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=L68TwYEEJpFcSpLsVXn02dHEJdoYMq6WnWpBdckYRf8=; b=WQYNPWHTlGRr0HEaXr2GgwUPHIRvFAEAofaSmp0aG5V9xnj/I2Qu+IN1vDPop3RjdJ nXkBg9MMusnsXEV81TESokisplV4q67LjjuTTcBeUI7PJlhrktEaQQBVUhgrNk9tZfum HpgVRGSHlREvqzBWhVLlbG34dn4O08jC7jc5ZHVo+hJvsFW2jNCf0pHtXGuo6T0p0kr+ 56o/XXaumo1QmabGpUPZ28Z0abPTO6HUij4ZIC9tc7yHPGTPvs/ISZ5JkrZ5mw8yO5tq ckFuc2aDsn2MV9SCt0uEMqJVK7ZB9WMMHn8sYajK1ZFFjZpxwjxQ2K0Tnj+XRgfY3E/K b5TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709319383; x=1709924183; 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=L68TwYEEJpFcSpLsVXn02dHEJdoYMq6WnWpBdckYRf8=; b=c/a1plmQhAW6hnEvTuxMjIRiWv9BJTukDgBEI8e/y1+u2PPsDlejfUFkTF1o3j2ysC Gu2nPR3+bePS31BlyW0ceseL6OD4w3EIW+XMuMBGf20r3KNSO6pehpsOOoFmxApqaS0P Cnnyb4FjKEBfWas0bNQV5MBHwVqt1vzyrIrxQnGSRI9ZKcUh5lfwXDjpX27c6hBN45qI ETQj3s5GqJSvTzthx96jrZjzybIX88PaF4eB6EgyKhuYiLPTdT7uO0JFFAdOowC+4Grv HlwHme/oGygP2bJyBECEJbDiR4q0xT9nxwCLD6zKoTOyHYjDzex+eOQ6Kk2U4oyTkkmi G2Qg== X-Forwarded-Encrypted: i=1; AJvYcCWoqGsbZ4Yed+wdGjMlvn29Kj7MzfN1odZ1gtU+JVLqcdfeyqESCpaIf+ftBw5DEptpicYo/LUgm05WBiPem4wAM2USnow1tYC2DLH2 X-Gm-Message-State: AOJu0Yy2OEdxD0LhMBweBawwaLb5R850hxMbRqDxtKe/fk8k2xjEwy/z fCk3ooPKi2Yt4cgwcHM717KgyX3LbDCnIUDdw78v0q2mFxQSDpiM2JjzX5qXdQVAdH4rZhTfvq8 7hhRa+Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a81:9a05:0:b0:608:2ad5:cd28 with SMTP id r5-20020a819a05000000b006082ad5cd28mr464292ywg.4.1709319383012; Fri, 01 Mar 2024 10:56:23 -0800 (PST) Date: Fri, 1 Mar 2024 10:55:43 -0800 In-Reply-To: <20240301185559.2661241-1-irogers@google.com> Message-Id: <20240301185559.2661241-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301185559.2661241-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 04/20] perf jevents: Add tsx metric group for Intel models From: Ian Rogers To: Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792351365465296648 X-GMAIL-MSGID: 1792351365465296648 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. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/intel_metrics.py | 52 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py index 81879e68da96..3d80b555fac9 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, +from metric import (d_ratio, has_event, max, CheckPmu, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, LoadEvents, Metric, MetricGroup, MetricRef, Select) import argparse import json import math import os +from typing import Optional parser = argparse.ArgumentParser(description="Intel perf json generator") parser.add_argument("-metricgroups", help="Generate metricgroups data", action='store_true') @@ -80,10 +81,59 @@ def Smi() -> MetricGroup: ], description = 'System Management Interrupt metrics') +def Tsx() -> Optional[MetricGroup]: + pmu = "cpu_core" if CheckPmu("cpu_core") else "cpu" + cycles = Event('cycles') + cycles_in_tx = Event(f'{pmu}/cycles\-t/') + cycles_in_tx_cp = 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 = Event("RTM_RETIRED.START") + transaction_start = Event(f'{pmu}/tx\-start/') + except: + return None + + elision_start = 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 = Event("HLE_RETIRED.START") + elision_start = 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 transactions.', + 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 number 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 number of elisions.', + Select(cycles_in_tx / elision_start, + has_event(elision_start), + 0), + "cycles / elision") if elision_start else None, + ], description="Breakdown of transactional memory statistics") + + all_metrics = MetricGroup("", [ Idle(), Rapl(), Smi(), + Tsx(), ]) if args.metricgroups: