From patchwork Fri Mar 1 18:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp83322dyc; Fri, 1 Mar 2024 10:49:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbWiDlvTpK8d2hlQhIHdAc/qQtBkkkqLuuONRsinEuAwR7U7dtnFhNP+0mHLuhdOsZkDIfmHI0pD8tCCcK9wOO3vEbSw== X-Google-Smtp-Source: AGHT+IFuEtTRCCR3VSSbkl9VFUddtzXzYsPatqx97rzcUzPULwLU6DvvKxU3SEGSXRaiAe0BpE1l X-Received: by 2002:a17:906:34c6:b0:a3e:f79e:ce56 with SMTP id h6-20020a17090634c600b00a3ef79ece56mr1740755ejb.45.1709318965904; Fri, 01 Mar 2024 10:49:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709318965; cv=pass; d=google.com; s=arc-20160816; b=ERhHPPDXBRO/RPd38pxZz2zwxukMIN/oyYI5ziCuF7RzbVTfJ+ZltLI8xxOUfwvTn6 B2Cho2lfT2MtT5nBF2B1jLUc5vUdV7FmrwU7vem/GFh3wyZrdQjvTJYmZ3txG0nDzEta UII4G3ojkhQQ7OYnOCUTZL9iLk5ikkIdoAfporKVs3jtac/eOicIz47b90txzgnD2PzE 3OZGAkxywX4tFtEN6aycVYl5x19iAhwToqFQ+HfcgViFtd4TrD+Uk4LCUX796jr9bp3q XTzS1tgVpIqwve6mwD8EorGK1UL3BrI9SkR8ct9biudze/sQRRQoeYonEiXj3NYV8+cI JrQQ== 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=gcc/qUxyeEjzpXo98Okf44ySOQGx/p2IAM001Az25yY=; fh=e2K4ORCWwRvrWujysehHBbmLotlNvmXtw++YjgMskls=; b=pCbS2EHJCUyaaDDgg1sMt7tDUyQ3+5D8eL99Hay8VVERAnwkGC855d6xVDSCeeHll5 BTI46+xRzeDSXn79WanJanR4V3kxc62xXfTkPsRhFLmyykgyCRFhQsx+nbSK1j6kCjjT FMLD7/hVmpntqKL1jrehCvnrAVJgAkRVAlLSAON4m5gjLPYlC/w/9OtQSBXZGWNTnb5A X4LOKluvQKhWHNenhd8l0LDiLOr9NZmlky0wR+R4MYwO87mc7DwbWT1+/uA3z+rO6Bwv P+eeHUiBpIf+RRO3ImNlTZX07FUSouoD5fCQBXttuILkDH4/P/oUPNg3/iLPo3vf4K3g QeAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=awb4jSZ3; 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-88942-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88942-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 sa19-20020a1709076d1300b00a43bf12748asi773873ejc.537.2024.03.01.10.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:49:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88942-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=awb4jSZ3; 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-88942-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88942-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 5CFCB1F25E56 for ; Fri, 1 Mar 2024 18:49:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E50C3C469; Fri, 1 Mar 2024 18:48:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="awb4jSZ3" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 E6D643B194 for ; Fri, 1 Mar 2024 18:47:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318880; cv=none; b=TCmk6zjdxR4oxuJlf02Pk47LT3t+Am11tEBU/rDmtPH2SdLWwGOHF4WAA86aJvqieURqnP7A+V7MmDDUMTSrYN1MAnRpE/UKeomQSlUMklUUfya26Q64S/P6AmyrNlaoHl8QesBDR4QJy1BeaS2iX93DXhEZ6Yu5KapNTR0v6ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318880; c=relaxed/simple; bh=+avI6OXSebapAM2pF6TaSl95UtS1MYUkS9EvCqrF/LU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=t6OLIM/MgRevY7k+gI4qQ7MwyNnjAvaVxQ9ntAX+OfX2SC4+3dyPy45ut484XDPrzGw5KV1wqk7L8eyxdDv8Buk7QvXdH2yHix2/ES7czuOluF7YgBW4aT5ItF1HBqdsNJERRgSoHu90tED+e57w4ZS3hfZDbe1XlTwVhzPVLRs= 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=awb4jSZ3; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b269686aso3600397276.1 for ; Fri, 01 Mar 2024 10:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709318878; x=1709923678; 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=gcc/qUxyeEjzpXo98Okf44ySOQGx/p2IAM001Az25yY=; b=awb4jSZ3qKGejA5dbO4I1dDLUhX2A4dEiNDwODlpM2rsclpB9N1Wpnrv5uNhGfjmrL C+MhNWFWMF5Ch6eQNVjLfBouAUUNisEgzmwmV8bniLCz6c4I3WD+vTC8KsSdMK8qBN8n blESTGOeek7w9oCKIw2RRNbrJQUy5Oxr4Z8kE0d0eVX+HLXfAJs3U4T7p4A/a84y2cho 9wyvqV0hoTU4A19+WjGl5RJJEr/TF5dZi06UUyYqM8nswmGAYOHbSu8XCiovpGtp5gxR dkgendH7iG1ufBofpsT0ChkSksRS0AFUVKaSKJYK1ETe9cH0wQfZC3HeAjxWsL1ZFCTe hdEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709318878; x=1709923678; 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=gcc/qUxyeEjzpXo98Okf44ySOQGx/p2IAM001Az25yY=; b=IR5n5lIttG4oYBP+zARRTs3ykWsrtiKf34R6Qj95ZmBov2aaJUNXBUZYw/fQfH/HOX BwtPm5N3A2/gebYzrbnseSYYluuDREn+ZIi//ri/1/FuvzCUMsh2EogClZAj5mqmzKxP /bCe/hP0kSewXI+1y0TWlNrmPoez03mKvRXzRiIatsYmTJ4dgjDj2wTGol7G/8GxWAaT dLVvzFGLMaJFL1HbmN8I85TWCoA4a/xza//k++Fzp4h6/cetpItOMx2FHojM77rfntou 5sjITi93WPwUE+Pugy21fkxSjrO1zQW+J2x9A43jOh2vSW9t0ProYWhhlGc6iFppkEvz VYzA== X-Forwarded-Encrypted: i=1; AJvYcCVf6VZGpVs5/4ScQzgBSknsq/S4iYCRZHZCpl/81dRkmKQxXW+c6K9UpQ1Kwu1HhTi+X+vBsd2j+AUYXZ6OWmA/Pm+/gE+BYFlgkbSn X-Gm-Message-State: AOJu0YwlRLAfo52GRHsRrXqoSR3rjdtK5e2CDAcB99VYNlrys35HZDnX 0MGlHFgpeIweLJ2hn6O55RxkeYCrfQZjUmhNzpIiedk/ZWUn3NC3JA1UuDhO2HL87VCDM7EKB9V dEdvVfw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:6902:188f:b0:dc6:b768:2994 with SMTP id cj15-20020a056902188f00b00dc6b7682994mr108005ybb.0.1709318878023; Fri, 01 Mar 2024 10:47:58 -0800 (PST) Date: Fri, 1 Mar 2024 10:47:30 -0800 In-Reply-To: <20240301184737.2660108-1-irogers@google.com> Message-Id: <20240301184737.2660108-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: <20240301184737.2660108-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 05/12] perf jevents: Add software prefetch (swpf) metric group for AMD From: Ian Rogers To: Sandipan Das , Ravi Bangoria , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , John Garry , Kan Liang , Jing Zhang , Thomas Richter , James Clark , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792350844349440345 X-GMAIL-MSGID: 1792350844349440345 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 | 95 ++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py index f8d5ba2861ee..52451bcb4bbf 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -125,6 +125,100 @@ def AmdBr(): description="breakdown of retired branch instructions") +def AmdSwpf() -> Optional[MetricGroup]: + """Returns a MetricGroup representing AMD software prefetch metrics.""" + if zen_model <= 1: + return None + + swp_ld = Event("ls_dispatch.ld_dispatch") + swp_t0 = Event("ls_pref_instr_disp.prefetch") + swp_w = Event("ls_pref_instr_disp.prefetch_w") # Missing on Zen1 + swp_nt = Event("ls_pref_instr_disp.prefetch_nta") + swp_mab = Event("ls_inef_sw_pref.mab_mch_cnt") + swp_l2 = 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 = 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 = 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 = 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 = 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 = swp_t0 + swp_w + swp_nt + good_pf = swp_l2 + swp_lc + swp_lm + swp_rc + swp_rm + bad_pf = max(all_pf - good_pf, 0) + + loc_pf = swp_l2 + swp_lc + swp_lm + rem_pf = swp_rc + swp_rm + + req_pend = max(0, bad_pf - swp_mab) + + r1 = d_ratio(ins, all_pf) + r2 = d_ratio(swp_ld, all_pf) + r3 = d_ratio(swp_t0, interval_sec) + r4 = d_ratio(swp_w, interval_sec) + r5 = d_ratio(swp_nt, interval_sec) + overview = 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", r3, + "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 = d_ratio(swp_mab, all_pf) + r2 = d_ratio(req_pend, all_pf) + usefulness_bad = 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, "100%"), + ]) + + r1 = d_ratio(good_pf, all_pf) + usefulness_good = MetricGroup("swpf_usefulness_good", [ + Metric("swpf_use_good_other_src", "Usefulness good other src", r1, + "100%"), + ]) + + usefulness = MetricGroup("swpf_usefulness", [ + usefulness_bad, + usefulness_good, + ]) + + r1 = d_ratio(swp_l2, good_pf) + r2 = d_ratio(swp_lc, good_pf) + r3 = d_ratio(swp_lm, good_pf) + data_src_local = 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 = d_ratio(swp_rc, good_pf) + r2 = d_ratio(swp_rm, good_pf) + data_src_remote = 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 = MetricGroup("swpf_data_src", [data_src_local, data_src_remote]) + + return MetricGroup("swpf", [overview, usefulness, data_src], + description="Sofware prefetch breakdown (CCX L3 = L3 of current thread, Loc CCX = CCX cache on some socket)") + + def AmdUpc() -> Metric: ops = Event("ex_ret_ops", "ex_ret_cops") upc = d_ratio(ops, smt_cycles) @@ -162,6 +256,7 @@ def Rapl() -> MetricGroup: all_metrics = MetricGroup("", [ AmdBr(), + AmdSwpf(), AmdUpc(), Idle(), Rapl(),