From nobody Fri Oct 3 07:42:44 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 C68B722E3FA for ; Thu, 4 Sep 2025 04:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756961586; cv=none; b=FXx7b6P7vuOAj5fjlOQTG0Y9cRXIoVEYUc9riABbO1+v6Fe3KGoIkoZP6CT/vJWWahoJr/qTp07wNfZGEKfhyur7AWXQ2VOyB1Q33EMOs/5bsrOvW+MOBYzZKn66f8lHPwXGB19H7MJcm/JTaCkI6PDrh01Eks45w/I37mYgunw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756961586; c=relaxed/simple; bh=AoaWUxeG6SEbSKI94mDI6Id1kc2OmbfzpZAJdXuOr4g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=exHb4fZyduFQ61kCNVycgad6Sc9onroLkJZrd75raV2i85O5dtzEACRsjK6gtVNt6zHMVSkEGQJCA/gC58uQ5coJcNmfH0YhyAN8I7yUEdifvr91m5Q8da3Ij+Xkm5Bba7z3tg05j2qtTNCjNQxoKOZffTo/PbOfEsLE3OBy/ks= 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=3BjZN+O9; arc=none smtp.client-ip=209.85.215.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="3BjZN+O9" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b471757d82fso406902a12.3 for ; Wed, 03 Sep 2025 21:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756961584; x=1757566384; 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=e+2liq/jPgISqfiXyP6NXv9wMG0ADdc/UnKxtWE/dLU=; b=3BjZN+O9XLozFkMbCd/NbXzshgD1o0R+nt2ZYF3/y0CuVtmj0ZA/7a9cV/pBLhejy0 DeQyUY28+Nsr1S6VlIsJWsf6OWbwCiwq941mD30mA/kffatlcTxsG5En0lPkZNdlJBpr OPNzpMpMLZdPoh6c/Pk1/qO/HdII9RRNlB5Lhab4JkztT30/Qjrbbpmv1n6e31/15EBa SOMn4AOyQMbIvyw0l5pzqs5pQwJj7WjexXZy1v4dEgpAIbyKZOte0sYKVV9vbywTpxGg GO+WEWq0GRCOuNSGVZo4UunQmW3kcYm5ZdPZwXXENfmF4FsTZLZUJYVmJxfhvdM7ErgT Lcuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756961584; x=1757566384; 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=e+2liq/jPgISqfiXyP6NXv9wMG0ADdc/UnKxtWE/dLU=; b=iybwIcRyKylMf9j6j8ClyRWXc5aDg9IayKQo7tGK/GA159PslrQZJf+YI7UmGIhkcf AA7CCCzwyYnvXOGGZvxOMVp86P9Hsib9l3q7Rmb2QFARUnrYcqBdfxsEXz++EosP8yL4 AMvlvbAuZ0PFJ6Zb6A82x4nsh33WlzLPEUlozL2FZEdSx4pnfLetU5XuiOKTopCifUOy ZlQRJWyeea113XDnmxbTnC0yhW5v+dEfuKFEwm3vUKn0mGggbIGQcSYRRzDA7Vd4WAPZ SSIvofsampXoNXNEOHEvTkZjKl0DbXUWCq/3VcntNXmFhlUFOJGpygIOFsYeGLwu5Epy 1/ug== X-Forwarded-Encrypted: i=1; AJvYcCVRU1Rbos5b9iHEdF7YRdcFPqotiFld+HUpKyxK+EbKoMdOfJ0EXacGrZGOnXePgc1oqtLyd30bj64cDrg=@vger.kernel.org X-Gm-Message-State: AOJu0YzBc69TcJY+yfzyI7vBMy+egvfu55PP8wU7FY7EM27SGCUu6cR3 aGTF/wbd8wIdaKw6N9ubI4sjcZ6LngEtKLQvypOTq9mtZAVQmhATjEUaZl6ODD76v3cCvLagZWp myQJv8X3zaQ== X-Google-Smtp-Source: AGHT+IFTyAOE9Hy8bi3NIGcO6ZowUnHoWq7+kPqnFpuQl7ebDPjGcGapy9TGDdI5xnea69E/Gh8zFLheEMiE X-Received: from plgt2.prod.google.com ([2002:a17:902:e842:b0:248:da10:4e37]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:41cd:b0:248:9348:965e with SMTP id d9443c01a7336-249448f8a41mr222643335ad.9.1756961584202; Wed, 03 Sep 2025 21:53:04 -0700 (PDT) Date: Wed, 3 Sep 2025 21:52:51 -0700 In-Reply-To: <20250904045253.1007052-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: <20250904045253.1007052-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250904045253.1007052-2-irogers@google.com> Subject: [PATCH v6 1/3] perf jevents: Add collection of topdown like metrics for arm64 From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, John Garry , Jing Zhang , Sandipan Das , Benjamin Gray , Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Metrics are created using legacy, common and recommended events. As events may be missing a TryEvent function will give None if an event is missing. To workaround missing JSON events for cortex-a53, sysfs encodings are used. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/arm64_metrics.py | 148 ++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 4 deletions(-) diff --git a/tools/perf/pmu-events/arm64_metrics.py b/tools/perf/pmu-events= /arm64_metrics.py index c9aa2d827a82..067ebbad1adf 100755 --- a/tools/perf/pmu-events/arm64_metrics.py +++ b/tools/perf/pmu-events/arm64_metrics.py @@ -1,14 +1,152 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -from metric import (JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, L= oadEvents, - MetricGroup) +from metric import (d_ratio, Event, JsonEncodeMetric, JsonEncodeMetricGrou= pDescriptions, + LoadEvents, Metric, MetricGroup) import argparse import json import os +from typing import Optional =20 # Global command line arguments. _args =3D None =20 +def Arm64Topdown() -> MetricGroup: + """Returns a MetricGroup representing ARM64 topdown like metrics.""" + def TryEvent(name: str) -> Optional[Event]: + # Skip an event if not in the json files. + try: + return Event(name) + except: + return None + # ARM models like a53 lack JSON for INST_RETIRED but have the + # architetural standard event in sysfs. Use the PMU name to identify + # the sysfs event. + pmu_name =3D f'armv8_{_args.model.replace("-", "_")}' + ins =3D Event("instructions") + ins_ret =3D Event("INST_RETIRED", f"{pmu_name}/inst_retired/") + cycles =3D Event("cycles") + stall_fe =3D TryEvent("STALL_FRONTEND") + stall_be =3D TryEvent("STALL_BACKEND") + br_ret =3D TryEvent("BR_RETIRED") + br_mp_ret =3D TryEvent("BR_MIS_PRED_RETIRED") + dtlb_walk =3D TryEvent("DTLB_WALK") + itlb_walk =3D TryEvent("ITLB_WALK") + l1d_tlb =3D TryEvent("L1D_TLB") + l1i_tlb =3D TryEvent("L1I_TLB") + l1d_refill =3D Event("L1D_CACHE_REFILL", f"{pmu_name}/l1d_cache_refill/") + l2d_refill =3D Event("L2D_CACHE_REFILL", f"{pmu_name}/l2d_cache_refill/") + l1i_refill =3D Event("L1I_CACHE_REFILL", f"{pmu_name}/l1i_cache_refill/") + l1d_access =3D Event("L1D_CACHE", f"{pmu_name}/l1d_cache/") + l2d_access =3D Event("L2D_CACHE", f"{pmu_name}/l2d_cache/") + llc_access =3D TryEvent("LL_CACHE_RD") + l1i_access =3D Event("L1I_CACHE", f"{pmu_name}/l1i_cache/") + llc_miss_rd =3D TryEvent("LL_CACHE_MISS_RD") + ase_spec =3D TryEvent("ASE_SPEC") + ld_spec =3D TryEvent("LD_SPEC") + st_spec =3D TryEvent("ST_SPEC") + vfp_spec =3D TryEvent("VFP_SPEC") + dp_spec =3D TryEvent("DP_SPEC") + br_immed_spec =3D TryEvent("BR_IMMED_SPEC") + br_indirect_spec =3D TryEvent("BR_INDIRECT_SPEC") + br_ret_spec =3D TryEvent("BR_RETURN_SPEC") + crypto_spec =3D TryEvent("CRYPTO_SPEC") + inst_spec =3D TryEvent("INST_SPEC") + + return MetricGroup("lpm_topdown", [ + MetricGroup("lpm_topdown_tl", [ + Metric("lpm_topdown_tl_ipc", "Instructions per cycle", d_ratio( + ins, cycles), "insn/cycle"), + Metric("lpm_topdown_tl_stall_fe_rate", "Frontend stalls to all c= ycles", + d_ratio(stall_fe, cycles), "100%") if stall_fe else None, + Metric("lpm_topdown_tl_stall_be_rate", "Backend stalls to all cy= cles", + d_ratio(stall_be, cycles), "100%") if stall_be else None, + ]), + MetricGroup("lpm_topdown_fe_bound", [ + MetricGroup("lpm_topdown_fe_br", [ + Metric("lpm_topdown_fe_br_mp_per_insn", + "Branch mispredicts per instruction retired", + d_ratio(br_mp_ret, ins_ret), "br/insn") if br_mp_ret = else None, + Metric("lpm_topdown_fe_br_ins_rate", + "Branches per instruction retired", d_ratio( + br_ret, ins_ret), "100%") if br_ret else None, + Metric("lpm_topdown_fe_br_mispredict", + "Branch mispredicts per branch instruction", + d_ratio(br_mp_ret, br_ret), "100%") if (br_mp_ret and= br_ret) else None, + ]), + MetricGroup("lpm_topdown_fe_itlb", [ + Metric("lpm_topdown_fe_itlb_walks", "Itlb walks per insn", + d_ratio(itlb_walk, ins_ret), "walk/insn"), + Metric("lpm_topdown_fe_itlb_walk_rate", "Itlb walks per L1I = TLB access", + d_ratio(itlb_walk, l1i_tlb) if l1i_tlb else None, "10= 0%"), + ]) if itlb_walk else None, + MetricGroup("lpm_topdown_fe_icache", [ + Metric("lpm_topdown_fe_icache_l1i_per_insn", + "L1I cache refills per instruction", + d_ratio(l1i_refill, ins_ret), "l1i/insn"), + Metric("lpm_topdown_fe_icache_l1i_miss_rate", + "L1I cache refills per L1I cache access", + d_ratio(l1i_refill, l1i_access), "100%"), + ]), + ]), + MetricGroup("lpm_topdown_be_bound", [ + MetricGroup("lpm_topdown_be_dtlb", [ + Metric("lpm_topdown_be_dtlb_walks", "Dtlb walks per instruct= ion", + d_ratio(dtlb_walk, ins_ret), "walk/insn"), + Metric("lpm_topdown_be_dtlb_walk_rate", "Dtlb walks per L1D = TLB access", + d_ratio(dtlb_walk, l1d_tlb) if l1d_tlb else None, "10= 0%"), + ]) if dtlb_walk else None, + MetricGroup("lpm_topdown_be_mix", [ + Metric("lpm_topdown_be_mix_ld", "Percentage of load instruct= ions", + d_ratio(ld_spec, inst_spec), "100%") if ld_spec else = None, + Metric("lpm_topdown_be_mix_st", "Percentage of store instruc= tions", + d_ratio(st_spec, inst_spec), "100%") if st_spec else = None, + Metric("lpm_topdown_be_mix_simd", "Percentage of SIMD instru= ctions", + d_ratio(ase_spec, inst_spec), "100%") if ase_spec els= e None, + Metric("lpm_topdown_be_mix_fp", + "Percentage of floating point instructions", + d_ratio(vfp_spec, inst_spec), "100%") if vfp_spec els= e None, + Metric("lpm_topdown_be_mix_dp", + "Percentage of data processing instructions", + d_ratio(dp_spec, inst_spec), "100%") if dp_spec else = None, + Metric("lpm_topdown_be_mix_crypto", + "Percentage of data processing instructions", + d_ratio(crypto_spec, inst_spec), "100%") if crypto_sp= ec else None, + Metric( + "lpm_topdown_be_mix_br", "Percentage of branch instructi= ons", + d_ratio(br_immed_spec + br_indirect_spec + br_ret_spec, + inst_spec), "100%") if br_immed_spec and br_indi= rect_spec and br_ret_spec else None, + ], description=3D"Breakdown of instructions by type. Counts incl= ude both useful and wasted speculative instructions" + ) if inst_spec else None, + MetricGroup("lpm_topdown_be_dcache", [ + MetricGroup("lpm_topdown_be_dcache_l1", [ + Metric("lpm_topdown_be_dcache_l1_per_insn", + "L1D cache refills per instruction", + d_ratio(l1d_refill, ins_ret), "refills/insn"), + Metric("lpm_topdown_be_dcache_l1_miss_rate", + "L1D cache refills per L1D cache access", + d_ratio(l1d_refill, l1d_access), "100%") + ]), + MetricGroup("lpm_topdown_be_dcache_l2", [ + Metric("lpm_topdown_be_dcache_l2_per_insn", + "L2D cache refills per instruction", + d_ratio(l2d_refill, ins_ret), "refills/insn"), + Metric("lpm_topdown_be_dcache_l2_miss_rate", + "L2D cache refills per L2D cache access", + d_ratio(l2d_refill, l2d_access), "100%") + ]), + MetricGroup("lpm_topdown_be_dcache_llc", [ + Metric("lpm_topdown_be_dcache_llc_per_insn", + "Last level cache misses per instruction", + d_ratio(llc_miss_rd, ins_ret), "miss/insn"), + Metric("lpm_topdown_be_dcache_llc_miss_rate", + "Last level cache misses per last level cache acc= ess", + d_ratio(llc_miss_rd, llc_access), "100%") + ]) if llc_miss_rd and llc_access else None, + ]), + ]), + ]) + + def main() -> None: global _args =20 @@ -29,11 +167,13 @@ def main() -> None: ) _args =3D parser.parse_args() =20 - all_metrics =3D MetricGroup("",[]) - directory =3D f"{_args.events_path}/arm64/{_args.vendor}/{_args.model}/" LoadEvents(directory) =20 + all_metrics =3D MetricGroup("",[ + Arm64Topdown(), + ]) + if _args.metricgroups: print(JsonEncodeMetricGroupDescriptions(all_metrics)) else: --=20 2.51.0.338.gd7d06c2dae-goog From nobody Fri Oct 3 07:42:44 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 E207F23C8AE for ; Thu, 4 Sep 2025 04:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756961588; cv=none; b=crl9c7pZQp1g/WHfOwNgdrCZaEQEDhfSaWgb0pExO0ND9QF91pOl7/GlhcPHIAFtnQtQb3/SiMPhd4BAGcDWykN4yMRkMKjYiI/unbXn0OmodePkcNyR1jl0PMras0pHSuXyZ+LG3B3OU/ioeaFO2j+xf9z2Gln8tnaiIPpuPg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756961588; c=relaxed/simple; bh=DxqALzct7pjSC7q6i3UumoTchp1X2Vgr5qrDJZaBNHU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cKVfe/6GEgcM9tKQgjqTOO61h5u2OgxAAO/n6AdPK4WmiPy0VjYZ2Ne3ojXoX7cufoq+p8zfNxG2zhYC/ijrthnz6hTlOAtc5JUlV4hfREjNGnA6N4j1WZLmb2VBnUBDfZbJyiK57efUWC/3OkMtDB+XjQW5TJJ8FBlQUMRGdX8= 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=dKjQVH6w; arc=none smtp.client-ip=209.85.214.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="dKjQVH6w" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-24cba71c71fso4993335ad.2 for ; Wed, 03 Sep 2025 21:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756961586; x=1757566386; 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=z6fcB2Hn+kdC3nY9KK6yt1lH6XCY5pViALcFk/7zZSc=; b=dKjQVH6wgmrxGkEPzq6P/LhliUoLbs564AnlFVBat1tdwy0k9u3ncFYUhDiAZsY8Ut 7DxH+1jW9Zg/oWuClMONCR25sNNr2loUsa6xPjHVYEvt01egGZEOMRaRGQOH4+lVIDED GNqQbBmByUFKLyipFhDLXEn8VSp72qUq3QXe52YTJob51rE7Ucu5xXZf3C62rdf1AfP8 f/X2yaQBrBwlgsIx2hKF4Ib1J8WLhbVqc9CTkuT14BVLvP7AIzWCSmmCjFfDVmn2mifq fhHHqrFOVBkFhSgJwHFCKXe8iDticeeUiUd/77/+dQT6i2xtEcvv3rRJmNjlSlEJoC52 7DNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756961586; x=1757566386; 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=z6fcB2Hn+kdC3nY9KK6yt1lH6XCY5pViALcFk/7zZSc=; b=UmitwnWTPdkcWqboLrIwaph+4r4qJ3PNOotkgtdSgVGvDye4+kG69b1H9qc6tmlIzU Of4KqX5kM9honzrjz1ezOherVTEszWvn6Y1lglAPFQWVS3wIpZ3P8ugk59XOb6i6yEa5 nxFAbS0hmsjkO7tlMOhAp6ADqgY2PWqR+4T9xkRSfdLVpE3ez/oc812v1uDy0cd1rgno G10sHyC4QzsWJFIDzKDTUUHICF6OmSXcY3WC74VH+lg62TFpajWlK/cXGE3JBy41d6mr NKwAYgobE+J2ODpSTNiiuWbrpSnNvb4+GD4+JuJDa7pbRVRTO1wZn90pc3uRUu/yMS7p wsJQ== X-Forwarded-Encrypted: i=1; AJvYcCUSJUuqbMWz2+cElRt8cqbRf3rC8nHCywnxlpdsHoDcYoUMHLs4Axe3NoWZrIrXnbfrfeXHUSycpZ2XJ1o=@vger.kernel.org X-Gm-Message-State: AOJu0YyX2453GTXgbqglwgamwlfLq0vIiK4tpIWMFeOJX+3JGRW3pwrA th3R5TxyJ4SNN5cQAEZXiEXzs3BAFC6/6C6n0v2eewP9JOukNnnqVvdY+Cu4o+3z4VlwGQfdlNI VZ9uO8BCDWg== X-Google-Smtp-Source: AGHT+IHGNByFi2JyIa9qM97FWwXg54d405XOJ5XY/sCItp8tCQjC6nz4qMPhTde5FarXaF7IrT7/bnriXOLQ X-Received: from plbmn8.prod.google.com ([2002:a17:903:a48:b0:24a:ad96:175]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e550:b0:24c:a417:4490 with SMTP id d9443c01a7336-24ca417470fmr53348385ad.5.1756961586201; Wed, 03 Sep 2025 21:53:06 -0700 (PDT) Date: Wed, 3 Sep 2025 21:52:52 -0700 In-Reply-To: <20250904045253.1007052-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: <20250904045253.1007052-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250904045253.1007052-3-irogers@google.com> Subject: [PATCH v6 2/3] perf jevents: Add cycles breakdown metric for arm64/AMD/Intel From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, John Garry , Jing Zhang , Sandipan Das , Benjamin Gray , Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Breakdown cycles to user, kernel and guest. Add a common_metrics.py file for such metrics. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/Build | 2 +- tools/perf/pmu-events/amd_metrics.py | 3 +++ tools/perf/pmu-events/arm64_metrics.py | 2 ++ tools/perf/pmu-events/common_metrics.py | 18 ++++++++++++++++++ tools/perf/pmu-events/intel_metrics.py | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tools/perf/pmu-events/common_metrics.py diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 366cd720659a..b2c557ad9964 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -43,7 +43,7 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) $(call rule_mkdir) $(Q)$(call echo-cmd,gen)$(PYTHON) $(LEGACY_CACHE_PY) > $@ =20 -GEN_METRIC_DEPS :=3D pmu-events/metric.py +GEN_METRIC_DEPS :=3D pmu-events/metric.py pmu-events/common_metrics.py =20 # Generate AMD Json ZENS =3D $(shell ls -d pmu-events/arch/x86/amdzen*) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/a= md_metrics.py index d971fbf40318..5dd6e7288d24 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -4,6 +4,7 @@ from metric import (d_ratio, has_event, max, Event, JsonEnc= odeMetric, JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, Metric, MetricGroup, Select) import argparse +from common_metrics import Cycles import json import math import os @@ -594,6 +595,7 @@ def AmdUpc() -> Metric: return Metric("lpm_upc", "Micro-ops retired per core cycle (higher is be= tter)", upc, "uops/cycle") =20 + def Idle() -> Metric: cyc =3D Event("msr/mperf/") tsc =3D Event("msr/tsc/") @@ -676,6 +678,7 @@ def main() -> None: AmdSwpf(), AmdUopCache(), AmdUpc(), + Cycles(), Idle(), Rapl(), UncoreL3(), diff --git a/tools/perf/pmu-events/arm64_metrics.py b/tools/perf/pmu-events= /arm64_metrics.py index 067ebbad1adf..5e9b37693a8d 100755 --- a/tools/perf/pmu-events/arm64_metrics.py +++ b/tools/perf/pmu-events/arm64_metrics.py @@ -3,6 +3,7 @@ from metric import (d_ratio, Event, JsonEncodeMetric, JsonEncodeMetricGrou= pDescriptions, LoadEvents, Metric, MetricGroup) import argparse +from common_metrics import Cycles import json import os from typing import Optional @@ -172,6 +173,7 @@ def main() -> None: =20 all_metrics =3D MetricGroup("",[ Arm64Topdown(), + Cycles(), ]) =20 if _args.metricgroups: diff --git a/tools/perf/pmu-events/common_metrics.py b/tools/perf/pmu-event= s/common_metrics.py new file mode 100644 index 000000000000..4ae3b0687a8a --- /dev/null +++ b/tools/perf/pmu-events/common_metrics.py @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +from metric import (d_ratio, Event, Metric, MetricGroup) + +def Cycles() -> MetricGroup: + cyc_k =3D Event("cpu\\-cycles:kHh") # exclude user and guest + cyc_g =3D Event("cpu\\-cycles:G") # exclude host + cyc_u =3D Event("cpu\\-cycles:uH") # exclude kernel, hypervisor and gue= st + cyc =3D cyc_k + cyc_g + cyc_u + + return MetricGroup("lpm_cycles", [ + Metric("lpm_cycles_total", "Total number of cycles", cyc, "cycles"), + Metric("lpm_cycles_user", "User cycles as a percentage of all cycles= ", + d_ratio(cyc_u, cyc), "100%"), + Metric("lpm_cycles_kernel", "Kernel cycles as a percentage of all cy= cles", + d_ratio(cyc_k, cyc), "100%"), + Metric("lpm_cycles_guest", "Hypervisor guest cycles as a percentage = of all cycles", + d_ratio(cyc_g, cyc), "100%"), + ], description =3D "cycles breakdown per privilege level (users, kernel,= guest)") diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index 36b6c4704522..463d9f056bf2 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -5,6 +5,7 @@ from metric import (d_ratio, has_event, max, source_count, = CheckPmu, Event, Literal, LoadEvents, Metric, MetricConstraint, MetricG= roup, MetricRef, Select) import argparse +from common_metrics import Cycles import json import math import os @@ -1069,6 +1070,7 @@ def main() -> None: LoadEvents(directory) =20 all_metrics =3D MetricGroup("", [ + Cycles(), Idle(), Rapl(), Smi(), --=20 2.51.0.338.gd7d06c2dae-goog From nobody Fri Oct 3 07:42:44 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 1E81A242909 for ; Thu, 4 Sep 2025 04:53:08 +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=1756961590; cv=none; b=uwE5Me6xvu0nem9l540eDUsMEm9jtqto3XvnFYummZTkaZNsCoeKHnswudSlr2MMLMydzCyGgLswKVME9mKbWVrkQBnjpVAUdw0naFYzKQA1rm6VgnyfArkMGZbF4GTF8UWWLM8qPrghyfkylgKKUwAiynsgA4b9sLZA9MJamVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756961590; c=relaxed/simple; bh=2nRqbW0WkwURucWNeXjSn7fOr+Pzwf5yXF518XDNXM4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IIiL+Nw9t/kTQ7RPyrJdJQrw3lKJlV5h3bkwfqEuNAUkQl2TWdVoHcbFjxmsgZpxIdXt8XrpgJOMQ7Flhb7Z408C4rxFEtEd5Byz6JaTox8/mRBFvHy5VfNi4fT8cx/ZZ3vUbXS84eaa9XC2wrgvQFV+pxShf9IFsgOHNSSAw3Q= 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=qnqrWyrv; 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="qnqrWyrv" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b4f93fe3831so772425a12.0 for ; Wed, 03 Sep 2025 21:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756961588; x=1757566388; 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=TtHpdxRTquFPiYRPRab1l8zsx1u08uaZD16J/LBQO3w=; b=qnqrWyrv2tPKm7zoL3dlRGiJgeFZ8SzO5KH1k3WjqxwbJCy3JWiloQPajd1g++0/Fy x7NOnQscchTAux6qZ3q3KKZjT7ylscXb4CpEY0uucwmNAzlmQi+s9eQVaqjDIAeq1a6O Qj43t0z4lV9CTYawGvsHTVRW00wPC4qT2U+3vNfSLchvrG2eQ4LpDGli/Y4q9ie+cckU aI9vT2U6BRF6Nj2QBgseU8CEoV5ecu8Gr8k0yLDy3r/nv28lHMJGCWNxis4AJmb4uCyV EB8vRLOmXtQqQgP7mzr+QwRTcKGcrkTWpSSsVj04aME7FK0V4dJbjcok/OwQv6nFquZt +pNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756961588; x=1757566388; 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=TtHpdxRTquFPiYRPRab1l8zsx1u08uaZD16J/LBQO3w=; b=c3nzxQxbNX2prbnG6CTnrhUGY8I+5bq6zS+DPTqMZK1eBvx1Jtld1oiwYzJja76XXt yFfuxrXubDyjCYtk1vvO0RxfzwHEEFUAxoxga1kURr1IOkSeXf47xEg5BsE9D0qjBcMb 2IwgAQOXrsAVhnET27mbirCEmCdZUjkpyoBNxg8YyXnkBCLfQkXIXzgkAXHw9aoMb4ku wIP0kyvjQKcK1qDYyjuBQhackv88V3AWrYzId+vKmqNrUoR0GBv21v6gyQajRTk8zK5S hyKtclIh5h6QqozozTbVuGiZ4sLiIIF8+3PYWPjzjx/Y9c7r9krCOWOWu2dNBqfscsMy vQcA== X-Forwarded-Encrypted: i=1; AJvYcCUvR0/dBuYXYVvkBvO2x1fWhjMN/cSkfffloMy2n2OcqHR3kIMdyMiN0PslCUrPxOxOrnu9UNkYUcqNvhY=@vger.kernel.org X-Gm-Message-State: AOJu0YwEhu0lRiRTRoFLVnisBvDXcyOb/2RjTlAttJ3LcXhD5/vP5TkJ PA2ixk9TYd/0r2uQYz4blrKPCdg+Kx8t41MXW70gl3nH1x4bQbtXWkuWstOo1MZskCYVO7RNJOv R9Bz9MB6W9w== X-Google-Smtp-Source: AGHT+IFfn8Z/EBKXtxnsGTFeSUhOaMoxR9/CtQzY5LIl4n+S7uUV99sy7Ex91B89Eo6PSM9JfdFgb+9St60E X-Received: from plcz17.prod.google.com ([2002:a17:903:4091:b0:24c:b394:50e4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e543:b0:24a:9b12:5248 with SMTP id d9443c01a7336-24a9b125499mr209610835ad.54.1756961588337; Wed, 03 Sep 2025 21:53:08 -0700 (PDT) Date: Wed, 3 Sep 2025 21:52:53 -0700 In-Reply-To: <20250904045253.1007052-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: <20250904045253.1007052-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.338.gd7d06c2dae-goog Message-ID: <20250904045253.1007052-4-irogers@google.com> Subject: [PATCH v6 3/3] perf jevents: Validate that all names given an Event From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, John Garry , Jing Zhang , Sandipan Das , Benjamin Gray , Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Validate they exist in a json file from one directory found from one directory above the model's json directory. This avoids broken fallback encodings being created. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/metric.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric= .py index 2029b6e28365..585454828c2f 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -11,12 +11,14 @@ from typing import Dict, List, Optional, Set, Tuple, Un= ion all_pmus =3D set() all_events =3D set() experimental_events =3D set() +all_events_all_models =3D set() =20 def LoadEvents(directory: str) -> None: """Populate a global set of all known events for the purpose of validati= ng Event names""" global all_pmus global all_events global experimental_events + global all_events_all_models all_events =3D { "context\\-switches", "cpu\\-cycles", @@ -42,6 +44,20 @@ def LoadEvents(directory: str) -> None: # The generated directory may be the same as the input, which # causes partial json files. Ignore errors. pass + all_events_all_models =3D all_events.copy() + for root, dirs, files in os.walk(directory + ".."): + for filename in files: + if filename.endswith(".json"): + try: + for x in json.load(open(f"{root}/{filename}")): + if "EventName" in x: + all_events_all_models.add(x["EventName"]) + elif "ArchStdEvent" in x: + all_events_all_models.add(x["ArchStdEvent"]) + except json.decoder.JSONDecodeError: + # The generated directory may be the same as the input, which + # causes partial json files. Ignore errors. + pass =20 =20 def CheckPmu(name: str) -> bool: @@ -64,6 +80,25 @@ def CheckEvent(name: str) -> bool: =20 return name in all_events =20 +def CheckEveryEvent(*names: str) -> None: + """Check all the events exist in at least one json file""" + global all_events_all_models + if len(all_events_all_models) =3D=3D 0: + assert len(names) =3D=3D 1, f"Cannot determine valid events in {names}" + # No events loaded so assume any event is good. + return + + for name in names: + # Remove trailing modifier. + if ':' in name: + name =3D name[:name.find(':')] + elif '/' in name: + name =3D name[:name.find('/')] + if any([name.startswith(x) for x in ['amd', 'arm', 'cpu', 'msr', 'po= wer']]): + continue + if name not in all_events_all_models: + raise Exception(f"Is {name} a named json event?") + =20 def IsExperimentalEvent(name: str) -> bool: global experimental_events @@ -403,6 +438,7 @@ class Event(Expression): =20 def __init__(self, *args: str): error =3D "" + CheckEveryEvent(*args) for name in args: if CheckEvent(name): self.name =3D _FixEscapes(name) --=20 2.51.0.338.gd7d06c2dae-goog