Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp188866lqc; Thu, 29 Feb 2024 14:24:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8GTnE/bhhEeHsN+6h9ep+BYWOrT0UubsPrTU/peEJD6jRcFrxk8BU34uT3e9WtpqH3I8Oy/3xNDdbib5OTGIVsNhnYDcpnYAI3MJJXQ== X-Google-Smtp-Source: AGHT+IEUxogpAY+kB7h3gsTk+Qg9TsX6LzIDdj+X5lp2XRNNFk0zmCE1KVGEX7NSwd/Ts7nXfoGP X-Received: by 2002:a17:90b:4d8f:b0:29a:7125:11a1 with SMTP id oj15-20020a17090b4d8f00b0029a712511a1mr398469pjb.41.1709245485450; Thu, 29 Feb 2024 14:24:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709245485; cv=pass; d=google.com; s=arc-20160816; b=hIfI5zGjGb3YEBuEFrKaRsz6U5BSGrsdVs9W8wWDgX9MtFCxBQknSKco59nWQ1c0L5 A58hMlx/0eOE0DvjF8OlAm1/WCqtmOCHMbve11CqPAPctJEFMSt9DqOSe+wm9lYYybws cUx+7RuhCPjgu7Vtj13Lc4aJ2JwKX7rFdtljO6XPd6pLHSBWOiOFhWIz/+9A9njSmBUM VG1vN5RBY9zbceFCIHMSkUqfzLPhFOkbajuU/p2rP5xO+Mkxyue+Ys3ilcTEA3+r44/P pezj/JuhjyeVb96t73Jk9E1XwbjtvkphRQltIm2dvu7UCGMUarn+/OvD9Y+Le3+8vrIN nz2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=AC95sJOHserqojNV1PF/N7NvID1NylIv6WRV8BDuhdk=; fh=xwiTb8dW8FnIyS8b3h9/neqRLRhsKMpwfKiuZ0NbPVk=; b=g/v7aaKMt1mNSapZk+KOkr7xFtCXUM2ahDUaXYla8NTg3guezHeEb8Xi5HFbvl+s33 2g+kfv8UrqgteOrQBxAM1UUXVf8hlI5OEugJXzkGqVGiw2HUDAN0leCnQgikfO6aJDyK X6sMpiMMh8OSPN9VNYFcmz9gesj8HjRtsvkrDZuPoE4fJ6CxgibAaChqyM0faBJbvFsO 2G9nThxHIf+/ibWUW4fjzQm+QLIZtOtjyMcoa7G62SJjwKuBET0NN3Hhjuw0r1n9XXGW ipPFSHY/j0/1hpI9KRmZT1OEtHsxxEjtewn0l4/4DULECmSlu5q8lZroiaPEv+q67PzR TQHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Jqna82+R; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-87569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id my10-20020a17090b4c8a00b0029898ed5732si2413516pjb.86.2024.02.29.14.24.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 14:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Jqna82+R; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-87569-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7CABFB23458 for ; Thu, 29 Feb 2024 21:18:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99F5916FF48; Thu, 29 Feb 2024 21:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Jqna82+R" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECE7E16FF21; Thu, 29 Feb 2024 21:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709241475; cv=none; b=E8haD1j5Wfshv1qwlJrDmY4Kc68vhOFAauUHOXTdQQdbQkY1Fn9PE6VWB0Wgb6Il+qzYg7vDPmvz0eW060JUyjrh0zlpRlviW/xHPjTFF89gQolj3XYQpSBM54/AOIrvlaHREF+VFUg+M8lvEtgIgD8+HLoE/ECK9s2O3Ixm1aU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709241475; c=relaxed/simple; bh=48SPLz2ZW2N1t+uqG8Wjgsd5Q/oGZByKDeVhfI1fnOg=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=k3pvCePKFxsJEjzCLfmXiybuRIYCf9Oj58iYcFU0XDP+G1jISrlOguLecBfeoJU4jpElXJIzzfJbd9q2kh4Y6MZlk3sXfmaMe8crUusqhzCrsvQjdZAdjQeEH98yiGzL4tGf5dWfCUoPOPE06K8JnKmmhp5ybBOtgKw6XbEGSac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Jqna82+R; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709241474; x=1740777474; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=48SPLz2ZW2N1t+uqG8Wjgsd5Q/oGZByKDeVhfI1fnOg=; b=Jqna82+RQNQALS6hENlpc4UuRD9SxQ1F6IYcUMe/yuiNRIULbAVu5cng BvsT/2e2yIiWRrxKwtnT+0yGDwymS0nef6tpaV8YzXQ9Phm33TCC6En/l 7wEGiKprJsEXdfLJT3mxzpp8ZAzyql39/QxFeNu1xieo8JFWss46TJN0N AsxoSrJcJflvL8K1x9dhPRI4NlRgmAEWvo+tPGwJ1LWrLrj/X81XhHwET 4r5a1vadT2b7DVlBxZXej3+yk28VPF4tJK5gmHYHISQi8hM0KFIeUw2nT AOZq95qk152GRWdq8lOHBo30+jCrDtyx6JwGv46SAgNY503qI9KaG4sIa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="29175709" X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="29175709" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 13:17:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="12646048" Received: from linux.intel.com ([10.54.29.200]) by orviesa003.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 13:17:53 -0800 Received: from [10.212.85.217] (kliang2-mobl1.ccr.corp.intel.com [10.212.85.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id ADBF3580D37; Thu, 29 Feb 2024 13:17:50 -0800 (PST) Message-ID: <7ec53a59-10d7-4a85-90b7-1337a0a42815@linux.intel.com> Date: Thu, 29 Feb 2024 16:17:49 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 05/20] perf jevents: Add br metric group for branch statistics on Intel Content-Language: en-US To: Ian Rogers , 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 , Adrian Hunter , John Garry , Jing Zhang , Thomas Richter , James Clark , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian References: <20240229001806.4158429-1-irogers@google.com> <20240229001806.4158429-6-irogers@google.com> From: "Liang, Kan" In-Reply-To: <20240229001806.4158429-6-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024-02-28 7:17 p.m., Ian Rogers wrote: > 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") > > + Unnecessary empty line. Thanks, Kan > 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: