From nobody Fri Nov 29 00:37:45 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 E52CB157E61 for ; Thu, 26 Sep 2024 17:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727372482; cv=none; b=IXK3TwvpL3alp2ESqQgfmX5ZXxxkl/LDjFh9qY9ipOLkIvDSbVVMeXHHhwfpY1nmDNdJI9rFo785inqjvHA3QWInDhuStPt2VM/XZb9SEVeezN7o8iPfUzF2qjLdSkjZ85F0HcJmiaeFqNy3IFehnMNyi21VzxY3QdgOPqxlqyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727372482; c=relaxed/simple; bh=+1OOOQq/7T2AxXkQtO1l2r+mYOpA+0yX1aQLS5Yn528=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MFaj6Y11st59fWq/GBypnqv78E4OWr4Ir6rSTO/Vzuh7bsAsKArkfxt4gMQJ1aMQ+HY4/HXISWm7zbPDtxcnZO6jyGeHeTV4n8VzKuoKwMnJJtQwUZpfzBhmzZjHkyQ2t3tK4QI6X3VZ+BIweh9jqeRdOqxykSS2jzk6TSYXTyU= 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=YXsUTOkH; arc=none smtp.client-ip=209.85.128.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="YXsUTOkH" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e211e439a3so24076777b3.3 for ; Thu, 26 Sep 2024 10:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727372480; x=1727977280; 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=8y8hrMO9b7uKPcL5T7E492/AY92K2G63R8Dxaci+iWE=; b=YXsUTOkHjHropBl/xBlCvUmmeybg5yu92WDMY+ztjK36GHIusCzyvaIFw5brgeXGMd h/6rvxBLn+fH0SExsO2KnvfpP1dOres/Nu2Er1f4EKCObwMZNqjsI23EFP9U/N0fDsO/ 1MrA8woj9pqtRxJAXSkcJXe/YesoT4XbIDxgn5csvpRQnUiYTmea4rdpeMkQKxt/O7+w hxgANCzhEo3LDQbbHfRzm1fEpCwinCqzsCk6ixCDf2Hxf09atVHrsjZUrteo88OEksgq SOszh6XQA3pwjTx4FTxsjGp2OL0Zqd8D4iJZms9qXILjqtbgBgGk+0elA0pYXrj/akm5 UXvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727372480; x=1727977280; 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=8y8hrMO9b7uKPcL5T7E492/AY92K2G63R8Dxaci+iWE=; b=ow0hGG7Z+9lmq31ZhV+0lWYPoqRM7DwuM7H/yTyRvmjbjtAPTVENoebN0MyaoFsoyF x0IVFuzVuKxnqx0/3xUx9mxu9KtAeST0Nh3DEly4bKWy07qFe8j+Rz7/Rcfq7iPPStj7 DWi6D0sLgvu5gllQY87GV5sxbzRO+iSg1hbdNLt0K6RtNI2988drAqIiZ6xYGNnilTDU 1V3/0vRfzqimrPivoSchHTAbQ5nq1Sv5X3FPCxIQgQhAVDK0V0EGB1VhWgsOUv750gQg H4mCvufSYnjhzv5mUJdZgnVVl8zn4NdcYEtP/Gc1DyR75wFDGBoGBywsC9oViQ+J8gRC kgLA== X-Forwarded-Encrypted: i=1; AJvYcCXQdQEXI375+u3srBmSkIb11pN6mCfyBoS7/n7xU6XsY3DwkxMld+dsg7Vsjxbg/h356SLR4FOzgpn9xH8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4COBLAVMWvzeqlq7c9agAP2fi8DY8Dmhu7O1WqmKOckaURQq5 ZdwDLRXiMdTPoY5xxNUKPneJPkIkuZt3wWbW+Tusgx4VbyTHB5bKbBpEehs5jz4QQe98sbgjcHE gXbZKXw== X-Google-Smtp-Source: AGHT+IGj4rNAuC+79Es9WcTdDXE8dVT6ABG7ejCxksxTMzXGbhSwXc15CkX5WtriS1hrzfAsDa80WM6/M2HC X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8872:3585:18ed:a056]) (user=irogers job=sendgmr) by 2002:a05:690c:d8c:b0:6b1:8b74:978a with SMTP id 00721157ae682-6e2475a7f4emr45537b3.4.1727372479896; Thu, 26 Sep 2024 10:41:19 -0700 (PDT) Date: Thu, 26 Sep 2024 10:40:54 -0700 In-Reply-To: <20240926174101.406874-1-irogers@google.com> Message-Id: <20240926174101.406874-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240926174101.406874-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v4 05/12] perf jevents: Add software prefetch (swpf) metric group for AMD 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 , John Garry , Jing Zhang , Sandipan Das , Benjamin Gray , 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" Add metrics that give the utility of software prefetches on zen2, zen3 and zen4. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/amd_metrics.py | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/a= md_metrics.py index 90545d4862a6..05a16e748d2e 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -120,6 +120,101 @@ def AmdBr(): description=3D"breakdown of retired branch instructio= ns") =20 =20 +def AmdSwpf() -> Optional[MetricGroup]: + """Returns a MetricGroup representing AMD software prefetch metrics.""" + global _zen_model + if _zen_model <=3D 1: + return None + + swp_ld =3D Event("ls_dispatch.ld_dispatch") + swp_t0 =3D Event("ls_pref_instr_disp.prefetch") + swp_w =3D Event("ls_pref_instr_disp.prefetch_w") # Missing on Zen1 + swp_nt =3D Event("ls_pref_instr_disp.prefetch_nta") + swp_mab =3D Event("ls_inef_sw_pref.mab_mch_cnt") + swp_l2 =3D Event("ls_sw_pf_dc_fills.local_l2", + "ls_sw_pf_dc_fills.lcl_l2", + "ls_sw_pf_dc_fill.ls_mabresp_lcl_l2") + swp_lc =3D Event("ls_sw_pf_dc_fills.local_ccx", + "ls_sw_pf_dc_fills.int_cache", + "ls_sw_pf_dc_fill.ls_mabresp_lcl_cache") + swp_lm =3D Event("ls_sw_pf_dc_fills.dram_io_near", + "ls_sw_pf_dc_fills.mem_io_local", + "ls_sw_pf_dc_fill.ls_mabresp_lcl_dram") + swp_rc =3D Event("ls_sw_pf_dc_fills.far_cache", + "ls_sw_pf_dc_fills.ext_cache_remote", + "ls_sw_pf_dc_fill.ls_mabresp_rmt_cache") + swp_rm =3D Event("ls_sw_pf_dc_fills.dram_io_far", + "ls_sw_pf_dc_fills.mem_io_remote", + "ls_sw_pf_dc_fill.ls_mabresp_rmt_dram") + + # All the swpf that were satisfied beyond L1D are good. + all_pf =3D swp_t0 + swp_w + swp_nt + good_pf =3D swp_l2 + swp_lc + swp_lm + swp_rc + swp_rm + bad_pf =3D max(all_pf - good_pf, 0) + + loc_pf =3D swp_l2 + swp_lc + swp_lm + rem_pf =3D swp_rc + swp_rm + + req_pend =3D max(0, bad_pf - swp_mab) + + r1 =3D d_ratio(ins, all_pf) + r2 =3D d_ratio(swp_ld, all_pf) + r3 =3D d_ratio(swp_t0, interval_sec) + r4 =3D d_ratio(swp_w, interval_sec) + r5 =3D d_ratio(swp_nt, interval_sec) + overview =3D MetricGroup("swpf_overview", [ + Metric("swpf_ov_insn_bt_swpf", "Insn between SWPF", r1, "insns"), + Metric("swpf_ov_loads_bt_swpf", "Loads between SWPF", r2, "loads"), + Metric("swpf_ov_rate_prefetch_t0_t1_t2", "Rate prefetch TO_T1_T2", r= 3, + "insns/sec"), + Metric("swpf_ov_rate_prefetch_w", "Rate prefetch W", r4, "insns/sec"= ), + Metric("swpf_ov_rate_preftech_nta", "Rate prefetch NTA", r5, "insns/= sec"), + ]) + + r1 =3D d_ratio(swp_mab, all_pf) + r2 =3D d_ratio(req_pend, all_pf) + usefulness_bad =3D MetricGroup("swpf_usefulness_bad", [ + Metric("swpf_use_bad_hit_l1", "Usefulness bad hit L1", r1, "100%"), + Metric("swpf_use_bad_req_pend", "Usefulness bad req pending", r2, "1= 00%"), + ]) + + r1 =3D d_ratio(good_pf, all_pf) + usefulness_good =3D MetricGroup("swpf_usefulness_good", [ + Metric("swpf_use_good_other_src", "Usefulness good other src", r1, + "100%"), + ]) + + usefulness =3D MetricGroup("swpf_usefulness", [ + usefulness_bad, + usefulness_good, + ]) + + r1 =3D d_ratio(swp_l2, good_pf) + r2 =3D d_ratio(swp_lc, good_pf) + r3 =3D d_ratio(swp_lm, good_pf) + data_src_local =3D MetricGroup("swpf_data_src_local", [ + Metric("swpf_data_src_local_l2", "Data source local l2", r1, "100%"), + Metric("swpf_data_src_local_ccx_l3_loc_ccx", + "Data source local ccx l3 loc ccx", r2, "100%"), + Metric("swpf_data_src_local_memory_or_io", + "Data source local memory or IO", r3, "100%"), + ]) + + r1 =3D d_ratio(swp_rc, good_pf) + r2 =3D d_ratio(swp_rm, good_pf) + data_src_remote =3D MetricGroup("swpf_data_src_remote", [ + Metric("swpf_data_src_remote_cache", "Data source remote cache", r1, + "100%"), + Metric("swpf_data_src_remote_memory_or_io", + "Data source remote memory or IO", r2, "100%"), + ]) + + data_src =3D MetricGroup("swpf_data_src", [data_src_local, data_src_remo= te]) + + return MetricGroup("swpf", [overview, usefulness, data_src], + description=3D"Software prefetch breakdown (CCX L3 = =3D L3 of current thread, Loc CCX =3D CCX cache on some socket)") + + def AmdUpc() -> Metric: ops =3D Event("ex_ret_ops", "ex_ret_cops") upc =3D d_ratio(ops, smt_cycles) @@ -183,6 +278,7 @@ def main() -> None: =20 all_metrics =3D MetricGroup("", [ AmdBr(), + AmdSwpf(), AmdUpc(), Idle(), Rapl(), --=20 2.46.1.824.gd892dcdcdd-goog