Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp169146rbe; Wed, 28 Feb 2024 16:20:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU070kFg0C0UUOfwaZyNIcOEox56l9kXwgp3RDS1tS2ZzN33Xk3OISr6/h4Of8f0DChna5182CaxxNXjYccgT8q6LIVDncgNNyudsivKA== X-Google-Smtp-Source: AGHT+IG1YqDK7pGUnMaLlCFfmUkjccg8l3L28+g0aAupFZh8C5WmG0fNO9IzHAB8u87+Nt8hHAtj X-Received: by 2002:a17:906:3d9:b0:a3e:ea61:5b5f with SMTP id c25-20020a17090603d900b00a3eea615b5fmr284270eja.54.1709166030396; Wed, 28 Feb 2024 16:20:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709166030; cv=pass; d=google.com; s=arc-20160816; b=TfnHKe7hGm8+dOmmEkZK7WZHJ8N1vqnPuSS7CxCRAFMZXjpiR1EGvtwk+phwKsG4DG OhqZrwzUkN1l60ckd9UZ/RDbPPXCKv07Q2W4NKNM7AiIPGhvmCEcw1vyWnsnlO7eOGPM A1JoA8L7289SswMPDIAxWVS3DQTK6ySGL3UyvAIlmgkyeR1+6t9zOckcYsDOnsAavIjz r1UgFCTjm81bgkWV2Q4E7RhKi+Hj1rlX94Fdi1UEEx2bpmPozEFffqsYQY5uovwSfHyh OaJMHuWdoRPLAXY9LM5+qh5xfT7C1EhnOz22DJGkfM8WM6/aTcTdpWOY5Kw28rnCVVyl /5WA== 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=FFlMx+oNasYCjHbkgyCsRQrkyODw2CbaRmUxLrBz57E=; fh=gTkc+nY8rurh8pTeVCxGCaloCmhI0b9CUjpTPcu91Fc=; b=izo9fh4ONEhmYoWk4xTFMxAhV6vzr7d/SVNjfBNzlt8AQDysY6vWFe3b3IYHm2COL0 6BMUYtM0ky7R4ZaGpuKVqqMxialsFCciNMJdxFpgR9g4V/Qus6NFo9CCnOW1zkLF6NTf Ksbb9ldqSMszlYNoGyLObCggHG6Qfa9kAKkcTxhd5a6xjGfGZM1YHRWi5vIHYUff8Ow4 RtdoC7CEFwAacwqtq0rS+vJIyh3naLxnTH3JIResuqoDdnqqN4OzpxZiMSx9hehkyjcA ZMtPdQ28tO2JtPq4jFd4TFcdRHf97k7/ljUyopxULmxM5MFQITcTBC7BgWhRcDOaFDq2 kyVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Dq/cFuI9"; 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-85897-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z10-20020a170906270a00b00a4436eea7d2si51464ejc.919.2024.02.28.16.20.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:20:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85897-linux.lists.archive=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="Dq/cFuI9"; 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-85897-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85897-linux.lists.archive=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 BC4341F22480 for ; Thu, 29 Feb 2024 00:20:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B1E44596D; Thu, 29 Feb 2024 00:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dq/cFuI9" 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 5AB2D42A8C for ; Thu, 29 Feb 2024 00:18:36 +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=1709165918; cv=none; b=NUX25ArFumhksiDVitD/pVF4DDPIksIUJ0qJpG4NYvEp212e1LWBkrv+kcwfjiY3FKST8GlsArd7Ijnf2BZa3Xjq+Jc8lMdlqqRVFFuF2m41dQseglV4QCnyvzv9v5vAZ/vI3uIMkUICwsPeyOs2Y++noLSDNU3vQUvYtDqnDjY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165918; c=relaxed/simple; bh=lh38C2ZP3x0TtmsYtzGGwnk35I03kkxZ3DF9a2lkNs8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=vB6mvWELGcoeeJZAjTX8OLIBa6TQ8SsAey89C+j3rNsDMSAldDO7rEvykt2OToxFX8qqfZYrXww8crm1upTdkRgHMRyeQ18/QLmv8erTfOPNscP6QuqZN0tsr07RNMoQWScQZQFoF9BZDlbbYwiSXjszqff0m9EIhPaUlAkCmV0= 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=Dq/cFuI9; 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-607c9677a91so5912027b3.2 for ; Wed, 28 Feb 2024 16:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709165915; x=1709770715; 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=FFlMx+oNasYCjHbkgyCsRQrkyODw2CbaRmUxLrBz57E=; b=Dq/cFuI9y/evbZOWtKeVWlsfNbNE9w3FhYKZadsSug9L9f0TjF580XkGR40LmE7jZc jwxCSzBX/J0tMtW2NMxy7iUZVkQo/CMiT7S3+xMngLxNQc4k2dfE5pu95Y3fH/Te4Ev9 wmojcVo4zt+NZtwWllb+suCNpJ8SlMbCincehbrfdCXuuXsvDBXGp6CMPERNE32SRzpz wqXxj3tgYkbZ3T+9hiZo14PyocJ4BSjD2Krt2+RwViQdVkPK6W/xRv4h0uWD5hHYcVei MwLm3GuZUiS5SfufhahY/INLH44vbuJGluD8cnoK44IsxEcDqBmvGsT7GOERkX/Ec5as V86Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709165915; x=1709770715; 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=FFlMx+oNasYCjHbkgyCsRQrkyODw2CbaRmUxLrBz57E=; b=cgpJnbjX+QfqQsOMSPdfw3aKr3VOp0KOcEZnpFofsPKu2m8HOcoBfXL7xRJsZeUlIK EBglAGy/I110Yqtpog9vXTREo7IMXYUvtrIbuIeJONdCRxA6+JkaHsHb/HU4s8lm+cuF LQtXeQBihz6tehncYpoggXyVWPOO9uf0NGmVUkF4LuZPllvzRxHywIvrVBevUKu3TrQn QL0a3w/m1Rn9LNkc9x8HQ4J1+cJRZnLfunJDI/crItn99GmBak5LEdjZk8ELkQXgTge5 KleM1jRmNW9wu7KXf8H4tJRE3MwZrlwdxldLZuSi9RArIwkt5j6+c8g+pkDPY93fdUn6 YBSw== X-Forwarded-Encrypted: i=1; AJvYcCWrdiCPc/taFlFXP5XSqZdxZ3gS72ePlCBiMMZTqJo+T8Tga/te8TFulphoWHctLpKeeHJwJuA6ZTRfvrH3BN1bVUFzQO7KXMg2Qc2I X-Gm-Message-State: AOJu0YwYZeZqbmJ7N4v+F+6VWfY/1gcZn2j8AOne6AUg02l53tipQpXy C3hpqfcD/oulVJH0y9iDqAY6Dp1Gw9UbfPMOZPB2lN0/SBVHRfsPxltAsfSceJ1eUjqhTTlxgQA 3r/Zu/w== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a81:9849:0:b0:609:3c46:1889 with SMTP id p70-20020a819849000000b006093c461889mr145864ywg.7.1709165915657; Wed, 28 Feb 2024 16:18:35 -0800 (PST) Date: Wed, 28 Feb 2024 16:17:50 -0800 In-Reply-To: <20240229001806.4158429-1-irogers@google.com> Message-Id: <20240229001806.4158429-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: <20240229001806.4158429-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 05/20] perf jevents: Add br metric group for branch statistics on Intel From: Ian Rogers To: Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Andi Kleen , 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 Content-Type: text/plain; charset="UTF-8" The br metric group for branches itself comprises metric groups for total, taken, conditional, fused and far metric groups using json events. Condtional taken and not taken metrics are specific to Icelake and later generations, so a model to generation look up is added. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/intel_metrics.py | 139 +++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events/intel_metrics.py index 1096accea2aa..bee5da19d19d 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -19,6 +19,7 @@ LoadEvents(directory) interval_sec = Event("duration_time") + def Idle() -> Metric: cyc = Event("msr/mperf/") tsc = Event("msr/tsc/") @@ -127,11 +128,149 @@ def Tsx() -> Optional[MetricGroup]: return MetricGroup('transaction', metrics) +def IntelBr(): + ins = Event("instructions") + + def Total() -> MetricGroup: + br_all = Event ("BR_INST_RETIRED.ALL_BRANCHES", "BR_INST_RETIRED.ANY") + br_m_all = Event("BR_MISP_RETIRED.ALL_BRANCHES", + "BR_INST_RETIRED.MISPRED", + "BR_MISP_EXEC.ANY") + br_clr = None + try: + br_clr = Event("BACLEARS.ANY", "BACLEARS.ALL") + except: + pass + + br_r = d_ratio(br_all, interval_sec) + ins_r = d_ratio(ins, br_all) + misp_r = d_ratio(br_m_all, br_all) + clr_r = d_ratio(br_clr, interval_sec) if br_clr else None + + 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" + ) if clr_r else None + ]) + + def Taken() -> MetricGroup: + br_all = Event("BR_INST_RETIRED.ALL_BRANCHES", "BR_INST_RETIRED.ANY") + br_m_tk = None + try: + br_m_tk = Event("BR_MISP_RETIRED.NEAR_TAKEN", + "BR_MISP_RETIRED.TAKEN_JCC", + "BR_INST_RETIRED.MISPRED_TAKEN") + except: + pass + br_r = d_ratio(br_all, interval_sec) + ins_r = d_ratio(ins, br_all) + misp_r = d_ratio(br_m_tk, br_all) if br_m_tk else None + 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%") if misp_r else None, + Metric( + "br_taken_insn_between_branches", + "The number of instructions divided by the number of taken branches.", + ins_r, "insn"), + ]) + + def Conditional() -> Optional[MetricGroup]: + try: + br_cond = Event("BR_INST_RETIRED.COND", + "BR_INST_RETIRED.CONDITIONAL", + "BR_INST_RETIRED.TAKEN_JCC") + br_m_cond = Event("BR_MISP_RETIRED.COND", + "BR_MISP_RETIRED.CONDITIONAL", + "BR_MISP_RETIRED.TAKEN_JCC") + except: + return None + + br_cond_nt = None + br_m_cond_nt = None + try: + br_cond_nt = Event("BR_INST_RETIRED.COND_NTAKEN") + br_m_cond_nt = Event("BR_MISP_RETIRED.COND_NTAKEN") + except: + pass + br_r = d_ratio(br_cond, interval_sec) + ins_r = d_ratio(ins, br_cond) + misp_r = d_ratio(br_m_cond, br_cond) + taken_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"), + Metric("br_cond_mispred", + "Retired conditional branch instructions mispredicted as a " + "percentage of all conditional branches.", misp_r, "100%"), + ] + if not br_m_cond_nt: + return MetricGroup("br_cond", taken_metrics) + + br_r = d_ratio(br_cond_nt, interval_sec) + ins_r = d_ratio(ins, br_cond_nt) + misp_r = d_ratio(br_m_cond_nt, br_cond_nt) + + not_taken_metrics = [ + Metric("br_cond_retired", "Retired conditional not taken branch instructions.", + br_r, "insn/s"), + Metric("br_cond_insn_between_branches", + "The number of instructions divided by the number of not taken conditional " + "branches.", ins_r, "insn"), + Metric("br_cond_mispred", + "Retired not taken conditional branch instructions mispredicted as a " + "percentage of all not taken conditional branches.", misp_r, "100%"), + ] + return MetricGroup("br_cond", [ + MetricGroup("br_cond_nt", not_taken_metrics), + MetricGroup("br_cond_tkn", taken_metrics), + ]) + + def Far() -> Optional[MetricGroup]: + try: + br_far = Event("BR_INST_RETIRED.FAR_BRANCH") + except: + return None + + br_r = d_ratio(br_far, interval_sec) + ins_r = d_ratio(ins, br_far) + 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(), Far()], + description="breakdown of retired branch instructions") + + all_metrics = MetricGroup("", [ Idle(), Rapl(), Smi(), Tsx(), + IntelBr(), ]) if args.metricgroups: -- 2.44.0.278.ge034bb2e1d-goog