From patchwork Thu Feb 29 00:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp88318dyb; Wed, 28 Feb 2024 16:17:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVAN1ut1sMBQ6UsETdkq4WG71evu3OUZ13aIDnXDs5jszvyXKa83jddkeFjT3dLco3vjBQTaCrxbM7TwfIE/NSFbuUGIQ== X-Google-Smtp-Source: AGHT+IEDfHVrcp2PY4IzF7k382BNBYUW7n4splJJmxXIYq5Na30jyfFy/EA6lsJGrZKDkXNO44nf X-Received: by 2002:a05:6512:3ba7:b0:512:f307:71b0 with SMTP id g39-20020a0565123ba700b00512f30771b0mr358954lfv.7.1709165844143; Wed, 28 Feb 2024 16:17:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709165844; cv=pass; d=google.com; s=arc-20160816; b=Zdw0JMmzwnGyXqWiAjCmjlxZ0haNpbBpuoXrfN+ykdFRvyvEfaxbAgwZVkOtMeT8fH m6hTVtVZCjUIAfXDatWc+ukLIUnxt7PM9JuVzyyzZIx2kNlPQa+v9v78djjxG+fBUm3D 7hDwB5lIwQnItFFW2yQMqHe3jz3hv46Wv/df0sJ/t65AgZ5coSFwde6+PFk/iyv/oNZB uAn2poHKl/2cWgzwEnH7lBAeJnPi5pdCqd3Y3I8Np7oXvblloDDRTng4SqGE8JqZc4No aiB0irCHZ5wgokRLBZt1n+ZOiR5Z3AcfrvxWabIvFkL88VLWXrE7kxMAppbFt3HsY8YK okcw== 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=s1e1l94WWHXveLjgnGSPJ/09xrypH26f4oBCMC/IJzY=; b=ZP4iDBXX8wV6WQp22KA3sPXgByQAQDAYF5vRqTdjic2WtAyJ7V3+vXxYIJ2NKr0NxN pLgZzLVTpubCZDZNNotWZY1NVUf3N+BTCMosjUkjJBIgb3Uou2swDek/X61/mfe69dgP DXOqb4wQh94+Vasio+QGpGUwUOMX+38H/NFEU7eff3MFJQVLz+jV5yGUotW5j2XxlTYE 2RBdEc8FfHj+CkBB2DrzOtMuD975//uchhgNCm0XU9c9txXH+P9JWX56LxTgfxsUASuO 87+s7eXG036ui+ACBL2/uKGCPn8gqGiybyb3WDowHsf2PfYICCsNWiC+JjR3dtTJ3Ci7 bHEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zXCkv7Gq; 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-85882-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85882-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u9-20020a50d509000000b0056577684470si50964edi.246.2024.02.28.16.17.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:17:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85882-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zXCkv7Gq; 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-85882-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85882-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 8FD841F21A45 for ; Thu, 29 Feb 2024 00:17:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D67F44366; Thu, 29 Feb 2024 00:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zXCkv7Gq" 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 35DE338F97 for ; Thu, 29 Feb 2024 00:15:54 +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=1709165756; cv=none; b=mzqu+DzwDY+mumyuJ9pUGJ+Wuq1fW7+93bVRQXQk/3pLadpwytxB13Gc9BkrEtQ4tfOt1vkSjkvd0p+Jw+BFH2zeeUL3uIZ8GU8raODY14iIiARGeEI+Vei9GPBlpLUXs97cldkhDVoJqQxoIA8QsgJk5iYHhGMvt+okEme04ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165756; c=relaxed/simple; bh=+avI6OXSebapAM2pF6TaSl95UtS1MYUkS9EvCqrF/LU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JSrUCLn/rJRCGVsWJNgWLuxB/30Ixspj3CAgnwoKHJyGO1jba1RkpZxrbT6bPfyf/ieoOFHxL0fErMhLRB7GE2HrAcYLT8sTBXhWqYy/vUkkgOWxuMRVeanrOx+5B2hX+k4ecaxcYEnxAaPzo5bRRZaavWedTQBc9+03STDjEFM= 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=zXCkv7Gq; 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-6087ffdac8cso5032977b3.2 for ; Wed, 28 Feb 2024 16:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709165754; x=1709770554; 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=zXCkv7GqQ7CeFtzE+jD4qIVcNbHuzq/Z+4gyLc1ocsHbWafSu4WXtTgXto4j1hPp3E vQ7EDv0ov2d9MWC5JNkZ6gbzlIPACBRk4715FLXGXO0ZLtmMSeQu608SpLnaQ9gU9zmd mN0s7yAvkwxoM9AHn1GOApy8mD/G15lsUurvaj7qKpCWjkwmwZgBoSg2BArArIE2+VbY 7zBFXWJ2VoobY6NcjDxEKEWbroxifxoQqedE05Q0DABzwzcm02eLsZSd8/3IaEVx1HWj f/Llslt1umtEsJAc8pyPoDPrp/PR9Mid8wMOsu0qnnUTgQUJe+9+YtC78SeOV227GVia Z/Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709165754; x=1709770554; 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=tkVgd986hx3t4sHc3TvWkUBhiQbG0pCMYRT6r0hyIALAFC4Akaqf+4pNRy8XlJ+aLu xO8voIx+5fQ5n126U6tjYDwkcWRypPcajhgVtUDVoi/52DoaoA4nhducr1nGqKpd2Oqp 7OGrM1A8R+HMOjpa4JENce5iShDyFfdz9Ht87GMpbAC+lSAUhz6rUmWFbqvw1Lk9ia4g j469D0Rf91KtYhaFVmvvygGg/Kb+1xPYzgfqAsEv98LdhJTthh/E8AvkDSYrdJ4aCgVh NIoDbnxiXWDSpwkWDUFbaveKIMXvqWzVeFD4Lw944QL+m3m+c+2pkgVNYWnEj7pQGLYb vjew== X-Forwarded-Encrypted: i=1; AJvYcCWXlIV12qDKmAAl+65dOdvcZ3IGdQK6ZJ/dDAHasxu5XtKGP/RxjxjsiOi5RXX/dnL8/0Z98V8cvOA/IoIml3KG8G5yIvCxTlHdkpZW X-Gm-Message-State: AOJu0YyZxYS9topEdGV4eIeJiWJfIutcfkz/IrjfoCiRWBKV/Pwr3DZ6 qSugnJBsU1OY8Iq/Lc8H3MJkdaqNVha4KEw59kJjT3okEt3YQkJ06+bhL0vTbxuCgVsdHxbKMRm Jwwg9SQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a05:6902:100a:b0:dc6:e5e9:f3af with SMTP id w10-20020a056902100a00b00dc6e5e9f3afmr192114ybt.9.1709165754237; Wed, 28 Feb 2024 16:15:54 -0800 (PST) Date: Wed, 28 Feb 2024 16:15:29 -0800 In-Reply-To: <20240229001537.4158049-1-irogers@google.com> Message-Id: <20240229001537.4158049-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: <20240229001537.4158049-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 05/13] 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: 1792190284119331846 X-GMAIL-MSGID: 1792190284119331846 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(),