From patchwork Fri Mar 1 18:47: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: 209018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp83161dyc; Fri, 1 Mar 2024 10:49:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVq2Q0hGhSKTXPPS8eRym6d8pJGZG9WP+1x1rklXZUVMEWLnCsKy96vg3XdgF2EUz5Ero+yHbHRsB9LGHcIHEl1UUTcmQ== X-Google-Smtp-Source: AGHT+IEvbJ3riTyzb5C26ns164h+U9MHcQ88ntQHwfYlWTmp+/+kLWRUc0/vu4D+qpee9WkarGre X-Received: by 2002:a05:6830:112:b0:6e4:ca90:4526 with SMTP id i18-20020a056830011200b006e4ca904526mr2976179otp.20.1709318948325; Fri, 01 Mar 2024 10:49:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709318948; cv=pass; d=google.com; s=arc-20160816; b=uixNoFK4OU9CTUFi7PzwtAD6LZNPDD1j/DJxKxXS/ZN5KPe706+MDm4Ax3ektmHH4D mGE0KGNl7Kk7qXSP4EvancKhxDYqFgBFN4R2Tfu6zVj0s1ZmpcZ9a7SUeC+ko/EP0OHA NZISUT5U0JJcpUG+w0E1cod/a7UKqUsyQ8Q2Tdhsc2HazNLw78bz2jAepuaxUTw3Npdl n0ClIbA3je6aYK07Khpgz50iB1a5PBb52tXZlw/XnyEijGjnv97t/T3FcLzAxJA++bak EE+hi4R1fFVbbMIpjAWNdNv4gw1gpoa3iuK8x1cztIrIveumOvSPZZ73mcDl+VkCzMdg l7vg== 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=KWgiWiE03exBg0PhwlQIGByRAV21o9JQjLn06/BhBfg=; fh=R9UQ2wTcPnHGV71l8F3V55zmOE+cpNIjTnb7xjTkBqg=; b=mRo9g2I4s50vzVS5NDUbdrlIgzfFYOFo29MUXLBWppWihxE+kJkbst56v/JTduuRKq u2y0oM8HXrCRVkv2uk+QfjSUFlYz3VvXvPqqW6Xlt2ihSrMF/WJzmQYRiairfZ39QoPb a4lL2BMADfZ1+uoBQzfW8W/kByk6M22HrUzxzSL3OOgE16JxDlSWTg4UDDZ7S+Etcr8y L0aD81StGfTGVOXuT4fUDUoj86rHn0WeyunA4UyYmrE9diKIREvBol0YhvYeC9QkoSPd UktTDuFxidyshMfl0hDwWiC/8Ap03XKd3S2JB0QVBCN6SInvcQsBXggeU9WkOM6NgbYR ck4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yH3OGAUy; 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-88941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88941-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y13-20020a63180d000000b005ce016cce21si4048090pgl.191.2024.03.01.10.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:49:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yH3OGAUy; 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-88941-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88941-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1F7E7287A90 for ; Fri, 1 Mar 2024 18:49:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D47F93BB52; Fri, 1 Mar 2024 18:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yH3OGAUy" 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 B11812900 for ; Fri, 1 Mar 2024 18:47:56 +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=1709318878; cv=none; b=IpL3jwUgegvCZblOafEucULCNyzuEoLTywP23lWAvXXhJMwu3q7AM3QC++HPhq5m5fcycbTlnxOVSfRSgDPCHGFCjcGCe3+1L60u1qrt3VJ8j/O5RQRs/38/E4Bpm/oR2b8jnSjBRmuuxqX2W8YhEUU3wonkjt2RjKdKRFmtok0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709318878; c=relaxed/simple; bh=YIxmuBzBhglh4md55W8onI4xgQ9tn1Wuzd6FPGsaM/I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Gd7ouPTeAlXjDdHzIAM9xEJ4aK6XE3rjAUJyrQHw5sd/4vAEWazpEm/dXRquXwZWl5fVcB0EWyqM+Vgg93rzELdXWdEQgeALihHzG6F5DGwRBc0XqxlCfghAE3ooXLBd7Z/TieTSLJl4w08nhNem3G/PfOFgmvMZlj41rodw69Y= 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=yH3OGAUy; 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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60942936e31so43519337b3.1 for ; Fri, 01 Mar 2024 10:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709318876; x=1709923676; 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=KWgiWiE03exBg0PhwlQIGByRAV21o9JQjLn06/BhBfg=; b=yH3OGAUySB209hsYUXvNYToJJzxjq4DTKItQNGML61GQ5U64i9Cp72Sj9rX4U4WwBK YaGOxcmgNuS5hWIZUxOu2GfqZU1OiIIsLjlRcubZ3411LizS38zwv5iDL4ilRdebCB3F OjQUieCT6HZG5QhVrhUdCo+7efXaenQpeIKo/J7IaGAL3yzTnM7AQrIc7BSOhaS6nj5v bAkLr7b9T577qn7zX0gq6J3BPXR1YZmt+zGMuljCAP9Qt342Xc+HPfq2hpzFM2xlH4If ZpIwM4l4ss4ogAMiW9ezIDarxGfkrykZlUPjGhGJPTEwPbTI/Z5qblTlXdnJIRpmVuKE /9YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709318876; x=1709923676; 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=KWgiWiE03exBg0PhwlQIGByRAV21o9JQjLn06/BhBfg=; b=HWpXpuIUjpT2DdE4eUfCP3HeIdRP/chIbJA8OoeoJiyntv2mnNuSFMz1DIXuuLuJ5H c4fnP0/4y4RTm4fKuOVYBbZ7bbxkLL7q6JA9p+fxhTdOcaXoES+7rkp/QUQmuzdqa2MX JPaiaRCAtXLHXmpnfSxENOWWD+JdgsHcaC69hiKL/KhXsO5gkakMa59JbwVKC9W7eeal eSYjUM/JRK1hQzYHFpe4GuLAohk5SAmQ44+VacXFn839iq889t6tDaP0DYUwvbbY9Nod kNM3B3k7YqtO+OlhMHeRKxy78Lu+G1Tl/dl44Dqc1zSzPTC1RNUGXx0fZSybkkLscMy0 GlRw== X-Forwarded-Encrypted: i=1; AJvYcCUtdEnxt0r9gohHP0bUFq/FsUiyTNYL/mRfInbnywCOJcCIIN2sgV3PrKwBKsHwBx+T70rtvROxBFf9R5E3Q7ofjVR90e8pfy57cYQ7 X-Gm-Message-State: AOJu0YyVYsXLvVcTlmG1QYJz91pE/PJPe+hpKdkHoXIjCEQ1l/pOgZjM R/DhU8Cxpku2XI/6HoRV8dJNSw4yKpZb0dWrjKN4Wm222HP2qHW+BcC2/jXIK0PYLdkpAXLHL9u SAVUzaw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a81:9809:0:b0:609:2031:1e09 with SMTP id p9-20020a819809000000b0060920311e09mr600157ywg.6.1709318875876; Fri, 01 Mar 2024 10:47:55 -0800 (PST) Date: Fri, 1 Mar 2024 10:47:29 -0800 In-Reply-To: <20240301184737.2660108-1-irogers@google.com> Message-Id: <20240301184737.2660108-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: <20240301184737.2660108-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 04/12] perf jevents: Add br metric group for branch statistics on 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: 1792350825574862097 X-GMAIL-MSGID: 1792350825574862097 The br metric group for branches itself comprises metric groups for total, taken, conditional, fused and far metric groups using json events. The lack of conditional events on anything but zen2 means this category is lacking on zen1, zen3 and zen4. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/amd_metrics.py | 104 +++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tools/perf/pmu-events/amd_metrics.py b/tools/perf/pmu-events/amd_metrics.py index ce3d1535483a..f8d5ba2861ee 100755 --- a/tools/perf/pmu-events/amd_metrics.py +++ b/tools/perf/pmu-events/amd_metrics.py @@ -7,6 +7,7 @@ import argparse import json import math import os +from typing import Optional parser = argparse.ArgumentParser(description="AMD perf json generator") parser.add_argument("-metricgroups", help="Generate metricgroups data", action='store_true') @@ -18,10 +19,112 @@ LoadEvents(directory) zen_model = int(args.model[6:]) interval_sec = Event("duration_time") +ins = Event("instructions") cycles = Event("cycles") # Number of CPU cycles scaled for SMT. smt_cycles = Select(cycles / 2, Literal("#smt_on"), cycles) +def AmdBr(): + def Total() -> MetricGroup: + br = Event("ex_ret_brn") + br_m_all = Event("ex_ret_brn_misp") + br_clr = Event("ex_ret_msprd_brnch_instr_dir_msmtch", "ex_ret_brn_resync") + + br_r = d_ratio(br, interval_sec) + ins_r = d_ratio(ins, br) + misp_r = d_ratio(br_m_all, br) + clr_r = d_ratio(br_clr, interval_sec) + + return MetricGroup("br_total", [ + Metric("br_total_retired", + "The number of branch instructions retired per second.", br_r, + "insn/s"), + Metric( + "br_total_mispred", + "The number of branch instructions retired, of any type, that were " + "not correctly predicted as a percentage of all branch instrucions.", + misp_r, "100%"), + Metric("br_total_insn_between_branches", + "The number of instructions divided by the number of branches.", + ins_r, "insn"), + Metric("br_total_insn_fe_resteers", + "The number of resync branches per second.", clr_r, "req/s") + ]) + + def Taken() -> MetricGroup: + br = Event("ex_ret_brn_tkn") + br_m_tk = Event("ex_ret_brn_tkn_misp") + br_r = d_ratio(br, interval_sec) + ins_r = d_ratio(ins, br) + misp_r = d_ratio(br_m_tk, br) + return MetricGroup("br_taken", [ + Metric("br_taken_retired", + "The number of taken branches that were retired per second.", + br_r, "insn/s"), + Metric( + "br_taken_mispred", + "The number of retired taken branch instructions that were " + "mispredicted as a percentage of all taken branches.", misp_r, + "100%"), + Metric( + "br_taken_insn_between_branches", + "The number of instructions divided by the number of taken branches.", + ins_r, "insn"), + ]) + + def Conditional() -> Optional[MetricGroup]: + br = Event("ex_ret_cond") + br_r = d_ratio(br, interval_sec) + ins_r = d_ratio(ins, br) + + metrics = [ + Metric("br_cond_retired", "Retired conditional branch instructions.", + br_r, "insn/s"), + Metric("br_cond_insn_between_branches", + "The number of instructions divided by the number of conditional " + "branches.", ins_r, "insn"), + ] + if zen_model == 2: + br_m_cond = Event("ex_ret_cond_misp") + misp_r = d_ratio(br_m_cond, br) + metrics += [ + Metric("br_cond_mispred", + "Retired conditional branch instructions mispredicted as a " + "percentage of all conditional branches.", misp_r, "100%"), + ] + + return MetricGroup("br_cond", metrics) + + def Fused() -> MetricGroup: + br = Event("ex_ret_fused_instr", "ex_ret_fus_brnch_inst") + br_r = d_ratio(br, interval_sec) + ins_r = d_ratio(ins, br) + return MetricGroup("br_cond", [ + Metric("br_fused_retired", + "Retired fused branch instructions per second.", br_r, "insn/s"), + Metric( + "br_fused_insn_between_branches", + "The number of instructions divided by the number of fused " + "branches.", ins_r, "insn"), + ]) + + def Far() -> MetricGroup: + br = Event("ex_ret_brn_far") + br_r = d_ratio(br, interval_sec) + ins_r = d_ratio(ins, br) + return MetricGroup("br_far", [ + Metric("br_far_retired", "Retired far control transfers per second.", + br_r, "insn/s"), + Metric( + "br_far_insn_between_branches", + "The number of instructions divided by the number of far branches.", + ins_r, "insn"), + ]) + + return MetricGroup("br", [Total(), Taken(), Conditional(), Fused(), Far()], + description="breakdown of retired branch instructions") + + def AmdUpc() -> Metric: ops = Event("ex_ret_ops", "ex_ret_cops") upc = d_ratio(ops, smt_cycles) @@ -58,6 +161,7 @@ def Rapl() -> MetricGroup: description="Processor socket power consumption estimates") all_metrics = MetricGroup("", [ + AmdBr(), AmdUpc(), Idle(), Rapl(),