From patchwork Thu Feb 29 00:15:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp88299dyb; Wed, 28 Feb 2024 16:17:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXTFx7aeqoec40jPH5X92uxNx2DY1roBnrlLRwNh8dPkdnYzroOi+sxHpGdxLFSRN9N1ocJxdLAdosSg+RiYnQ8LmQQDA== X-Google-Smtp-Source: AGHT+IGdZaQp0iCBadj5yfvRrr68GSdpapqPFJJ0HDnEJimJLAYVLVmu/bJTFTG3FHy6m16OexVn X-Received: by 2002:a17:902:e885:b0:1dc:8b82:7f72 with SMTP id w5-20020a170902e88500b001dc8b827f72mr466627plg.16.1709165841646; Wed, 28 Feb 2024 16:17:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709165841; cv=pass; d=google.com; s=arc-20160816; b=eX4dy/X3uVeRC3609Ujutf0gK1G+mdjCyL6cCyXfoBn2TiUlNt7OAMq1Fi3F+UomFP tc/vf7YPL/xIQlpKn8PMg6wQrSy8IPq79QBTZbhD/7lSmMGN6IO6ydLQrNckWwJsK7Wv 2Y6qk8+0aODQfs8J5/9gLG+dVYSvp/b4vjdg8Q0lVtK/tb3phzyCmqDTkax7oGtgf95x 23WY8tj6F801ueJU2XnOJa8MY+uTAee7XfYgpUNQIrMONYRNu+qddFqiBxoQPG43fggU C8u/PVBk0nHQ7+pcG6vPc/HHih/V0Txvacaq8cCZbzvUCJxaHJEXT0l8QxBCy+otMrSa Eefw== 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=hQtTdiI/nTqSSUrb6KdWlrm22MYHiZGt9frOm0Mdj0Y=; b=nh8rJ4TFXYwE95HufTKP2lzaLH26XQia0+wux7CTbdRua4E3x++Nl5R5IOU567sh2n 5wTN+7fugMMQleeTLSWFo69CnEpbiswQ+ZuW8HtMulk58rkBrczeEr9M1tmMkDt2qand tpyMK9PCcGfkFheI+pR/bLfFXKpYbdizWly0K2kaWkuVZfKx9nNnnZSc1CqAzBNPHTpT p13ZsqB7x15y1MYTap1E4Xa1zMfrnBfjjnnDwSrFEHj/tnuuQavx+1t+Lr1+FfzmdMWw ZBvuVMz/nqKkc864sz7z3FZ3waZpcEzSAGKVzrBXHU2X7pH5s1/pRJTvBE6HQ4W65wFc +VhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=itbrC+ka; 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-85881-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85881-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p5-20020a170902780500b001db3613aacbsi88182pll.617.2024.02.28.16.17.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:17:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85881-ouuuleilei=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=@google.com header.s=20230601 header.b=itbrC+ka; 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-85881-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85881-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 400D5B22DB5 for ; Thu, 29 Feb 2024 00:17:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4172443AA4; Thu, 29 Feb 2024 00:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="itbrC+ka" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 0D1092E413 for ; Thu, 29 Feb 2024 00:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165754; cv=none; b=NVhZZcLCv2fWeIjThuggb22ZvmVDMJjSZunMf/INOhUQFH81vveDb95FQVRTu1HdOvBNe67rQ1+DJtSk6qmZPvslUuomDOwP63wKcYekPCZwoVNnEzarhrMQ7D2adPXLCLuiiq3R4d7c+8yn/wKN87dmA1xrILz3Ipo2tBMO7pA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709165754; c=relaxed/simple; bh=YIxmuBzBhglh4md55W8onI4xgQ9tn1Wuzd6FPGsaM/I=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=NftwCEHWfNz47cQv5q7DOadD7osuXRhLxzdatnKZMHL7pbmVdyg/Gw5q5Dn19EekohGbKQLa7Jdh1msLkWmntbxFHOWBmg5GKh+n4X0bdwI0KSNOx4EdKEo/HRzm9KRgbxOJLNsNBgqvmUWDZQqWRwsTsLbTJf2OZRfBjJETd3Y= 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=itbrC+ka; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc746178515so523492276.2 for ; Wed, 28 Feb 2024 16:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709165752; x=1709770552; 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=itbrC+kadF0E0a++Y7xmZz1cYtR15CWYJY/LNUWqrWSGp28vZHT001p0uYPR7TtDKJ yvWTjYegglb1tE5fxsquytXvCWvSscnBrbsrxOP5kIM5gH/VE9rLQ1EupJl8fjvxmEmV BkkQPw0qEWX8bqzXJjR+M4lMi5JjDE2FD2kFawXr+PofoItzFUaQc1asUs18PMFS2JFd t/abkxWwc2J09D2FPVzmu0qTGQ7lj87RRQQKMzJPChHQ73fA4iYv5JMC3O9PW56V+PEv 39Td476tW0+sJQCMCKzJ1plkEfHDPfuf+ILbrr+SHw2F34Q7GlZ5zKVRjSXk4TgqpVL8 JqUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709165752; x=1709770552; 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=l9W4kWVzSmMtlny3cVkN9bnUkEqD9aLiUgZFGxI42zm3YH0+TsABI/R9kY4av4/S9K US1O8mMICAb6Y04c5BzZmPe381xQpSKtu+GAkGmiOX3/QQA6pLS0yPjk8rulm0PgA/d6 OnJnjTz3n2OT2uzxKjMFb5/8jV6qBoqcqInAeUeMC4ox/HI+7MlwdC8oibJJpOS4Lq9d x1+aSCnA60LwZd3JPg6IfShzJxgSjGlvX5X6TQ40ExvJNHb2D8i5R3ZajYJQtirba+Rr WhGtNa7IVjDlmSBm/pW5bkATowyjEK4KzQrglNf9y7fitPVloS0NLZ77lw57eCTBioHl mveQ== X-Forwarded-Encrypted: i=1; AJvYcCUniVobn2C7TEvuzO4qfazCmfVr9tFTfrSu47r992uJ3OzqlKMC+qCmoM7+uQrCJweYdJ/Sbt1k0pZn9S5w2BRJk2XOQVvpJOpPSuly X-Gm-Message-State: AOJu0Yw4bIFMHbw0ZzvA9oVbHPpYmvbNCyWSciC8MOjgIMgfhXoHhyCc K+HotsklaCdum0KjH+rbYb2KZ4rTx0BmwId6EEwWAD1src5kjTvpWl+R20aGMteAUp1nQqHDxjq b5hFaLA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a05:6902:722:b0:dcd:b431:7f5b with SMTP id l2-20020a056902072200b00dcdb4317f5bmr210121ybt.0.1709165752053; Wed, 28 Feb 2024 16:15:52 -0800 (PST) Date: Wed, 28 Feb 2024 16:15:28 -0800 In-Reply-To: <20240229001537.4158049-1-irogers@google.com> Message-Id: <20240229001537.4158049-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: <20240229001537.4158049-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 04/13] 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: 1792190281645661715 X-GMAIL-MSGID: 1792190281645661715 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(),