From patchwork Wed Feb 21 07:07:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 203966 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp877180dyc; Tue, 20 Feb 2024 23:09:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXsbftwBevkTt/oOU9YDNIBqPWCDFg1Yxw9whg86YTr7zlw2Jv3G7dRdz8Nh9BMePwKXR44ifYmqtQccg9qiw1u21UkMA== X-Google-Smtp-Source: AGHT+IHnbA/pa8LI76uvWd4V3tbsNxi9OtJVlcBhZso0ekFTrhHVseSmy+hxkUoS/kz4DeydV7P5 X-Received: by 2002:a17:902:b788:b0:1db:e089:7474 with SMTP id e8-20020a170902b78800b001dbe0897474mr9755442pls.66.1708499340801; Tue, 20 Feb 2024 23:09:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708499340; cv=pass; d=google.com; s=arc-20160816; b=PqLTCSsSHuOKwpMEbbVcUxS8jd57THC6lJEMN3DNxjnOCraqfTBSObyq1Eaa79MLDW elCMXcaLfaPBevK7fOayx5Tk6XmjinA/0uhKpommDj9N4674psQFjl6ehCX/4lS+BlUi 9k8Gh+DCIK9QgKQEcbdfL0qMNsCRbOy1MRpeQVjGm+st3ut9UOzTR/NZsxvrHLN/fN85 72T+z0ZUy6ZmoxD22fNTrj4pm9ntVcWLepnLklsoq6mMcneF91qZsyCc6ON2j6jZ71tb 3AB77QTpnT+RYe78FnADFM33qWmhODWi3pAhIYeBrJQb/eGF16JV/4nRz1fDLaDvFEL1 bHeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=tjKYmJzQl8F9/gAiKS0z/bm1yBfw+nAatzaAOGPVP0k=; fh=GgUcv5u5jAJwD1jWUBd4QOEp3w7D+H6nARvmTbtwefw=; b=Ojm3etnXnvp9/SGYO5ppIXAul8PJV8jzQJ4UwFgvN2s7QjoJIXZTnTQRHqEaZtoUJV n5Qk5rKMXDR2rxVuaGBbE729MFBCO5lwytoYctjPS0mfIARwuI8FmCsziDJbB61J7B5v 3M7EHRKPtCIXXlcHGfjspJQBElHExfVDRNmAZmH5KKBzNhpa+r809Idr15RzWaVnUbnc 7s8x9+yb3nCDxeZ3noy1XuwKHEM5HiSPqSaghtLMVVZGHhzOBHyjNF2sVKrG0wM97dez 0ODSIRQ3gz+5o0otWPLLTkCfjMBo21NPgUbaYDUls3ZrRRqQzJXb+ZZ1D7wvykGmWNAI 78YA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="XrF/1n7d"; 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-74185-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74185-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 b19-20020a170902ed1300b001db71681d44si7540081pld.187.2024.02.20.23.09.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:09:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74185-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="XrF/1n7d"; 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-74185-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74185-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 AA927B255C6 for ; Wed, 21 Feb 2024 07:08:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A494C3AC10; Wed, 21 Feb 2024 07:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XrF/1n7d" 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 ECD3C3A8E3 for ; Wed, 21 Feb 2024 07:07:57 +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=1708499279; cv=none; b=h3NomfiOeRQpS9Bmbqy9ylH7O5GAsuvYs3kJeTpJU5+zRW4fYrwU0QnCv3fh/mGyyGPYm4/KscnZjlwgKKvMRPYk2X4Mp02tbylE78TU819IpwpRCZnP0ZdM7Qt/h/1LY8CKp+DelLO4f2wbMIflZYRLw+NCmBSSOcnqNO5IIxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499279; c=relaxed/simple; bh=Vctcg2i0KcfuRuGiF34q8FKyaNU+WFLIoo1taHhTiGA=; h=Date:Message-Id:Mime-Version:Subject:From:To:Cc:Content-Type; b=JihDLXVvDbTBcXCjybdctB2HJpxCtoT0gOsAdzw+3jAQgDb13e2g7V8LN2G/++O0jiGRu6QFWXstumXuvaMTNtIen3m4qmo7adAea8OXDMueF/rDY/y/RJt+4+FMOo9IW5uXljROVQACD8a654RInCyhtjMZSARXrIHXjonlsgE= 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=XrF/1n7d; 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-602dae507caso103810417b3.0 for ; Tue, 20 Feb 2024 23:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708499277; x=1709104077; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=tjKYmJzQl8F9/gAiKS0z/bm1yBfw+nAatzaAOGPVP0k=; b=XrF/1n7dOXKAH5wwlFadyQT+L3Z6MR53hW/PKAjj+2En2vZI9bzH9ynIoY3vETgytt TG3qmFQPUux+TK0yo1csf/5DvXHXFFEPzh4ptDxH4PRAvosOb6LZwE543X/I+mFb+ZVz NsV8Qp5M0pQTczBSMiuMoVKTxpoXfUsVCQYVFNHFLlX8sBYQDv/w6qdzYj+VmUevsyjh 6ho48hzhNE93SRUqEodChE7Gc8ltK+QAX9MuBMjHvr0hUCQ1dquctIgKsP0Lz35teJ0V 0TL97/tQ3IAH46OU5ruNnB1T7PPMAuUEhI7QVSxYgUCKrbIAZjLgZYg12GAl+USPGaOX wGPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708499277; x=1709104077; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tjKYmJzQl8F9/gAiKS0z/bm1yBfw+nAatzaAOGPVP0k=; b=n2NFfRfdRcQl9bdGqfV+eUZNHrB29pyx9YI+hHipyIw2I3tMKAx5kSTkpjkl7ysYqP L+jAC5HxSrIu1u0Q74fwE46yLFEWuIjdluJJXrS7Urn1JgjE0SveWNcq+dhqEogCK3N1 lrYi2QSFxU1gwRtvEGmcwqew0j1qB9xkIqVnu//xUz4T/njZF8DbFbiHMsfoUcbtgSbD lQvsDQCZBm46taN9qzolD7mwArAihzL6yAr6UdoFaIn1klPnzgEEYLPMZeLgEp2p+N2F JMatdqeip6dxADqWgZX6ALHySSnzH0YbTIjGmh/hK4J/3K1C+TqMmUT22dgaAvU00uXU inlg== X-Forwarded-Encrypted: i=1; AJvYcCV21/erLd9wt5qur70JSBmTyf7yqQM4HcBj9Jd9UHGGRQyL7F0Uwz1Kx6LJmPUd/a+u0vBrGOTGL1G+c6uyScOdkL62VT9Ob8nNsGnQ X-Gm-Message-State: AOJu0YwSUXupJeYU5M65r6gd4h4sxcrMF8Ld7dhAaHAZ6QLEJN63xJfM /MW6Cj/wrvoxz7/ssuLS3eA376Ji0iCnSrgVrNRzUkF8DfDJDMxaW3gUx1rsWqPXPBI6GO63e+7 O9DXPaQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3c02:f882:5876:b7ab]) (user=irogers job=sendgmr) by 2002:a0d:d9c6:0:b0:608:77cd:bbfd with SMTP id b189-20020a0dd9c6000000b0060877cdbbfdmr485456ywe.1.1708499276945; Tue, 20 Feb 2024 23:07:56 -0800 (PST) Date: Tue, 20 Feb 2024 23:07:52 -0800 Message-Id: <20240221070754.4163916-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Subject: [PATCH v3 1/3] perf stat: Pass fewer metric arguments From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Kajol Jain , John Garry , Kaige Ye , K Prateek Nayak , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791489945751536387 X-GMAIL-MSGID: 1791491404706629228 Pass metric_expr and evsel rather than specific variables from the struct, thereby reducing the number of arguments. This will enable later fixes. To reduce the size of the diff, local variables are added to match the previous parameter names. This isn't done in the case of "name" as evsel->name is more intention revealing. A whitespace issue is also addressed. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- v3 is a rebase fixing a merge conflict with 6d6be5eb45b4 ("perf metric: Don't remove scale from counts") --- tools/perf/util/stat-shadow.c | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index cf573ff3fa84..10b452792037 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -355,11 +355,12 @@ static void print_nsecs(struct perf_stat_config *config, print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0); } -static int prepare_metric(struct evsel **metric_events, - struct metric_ref *metric_refs, +static int prepare_metric(const struct metric_expr *mexp, struct expr_parse_ctx *pctx, int aggr_idx) { + struct evsel * const *metric_events = mexp->metric_events; + struct metric_ref *metric_refs = mexp->metric_refs; int i; for (i = 0; metric_events[i]; i++) { @@ -403,7 +404,7 @@ static int prepare_metric(struct evsel **metric_events, if (!aggr) break; - if (!metric_events[i]->supported) { + if (!metric_events[i]->supported) { /* * Not supported events will have a count of 0, * which can be confusing in a @@ -436,18 +437,18 @@ static int prepare_metric(struct evsel **metric_events, } static void generic_metric(struct perf_stat_config *config, - const char *metric_expr, - const char *metric_threshold, - struct evsel **metric_events, - struct metric_ref *metric_refs, - char *name, - const char *metric_name, - const char *metric_unit, - int runtime, + struct metric_expr *mexp, + struct evsel *evsel, int aggr_idx, struct perf_stat_output_ctx *out) { print_metric_t print_metric = out->print_metric; + const char *metric_name = mexp->metric_name; + const char *metric_expr = mexp->metric_expr; + const char *metric_threshold = mexp->metric_threshold; + const char *metric_unit = mexp->metric_unit; + struct evsel * const *metric_events = mexp->metric_events; + int runtime = mexp->runtime; struct expr_parse_ctx *pctx; double ratio, scale, threshold; int i; @@ -462,7 +463,7 @@ static void generic_metric(struct perf_stat_config *config, pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list); pctx->sctx.runtime = runtime; pctx->sctx.system_wide = config->system_wide; - i = prepare_metric(metric_events, metric_refs, pctx, aggr_idx); + i = prepare_metric(mexp, pctx, aggr_idx); if (i < 0) { expr__ctx_free(pctx); return; @@ -497,18 +498,18 @@ static void generic_metric(struct perf_stat_config *config, print_metric(config, ctxp, color, "%8.2f", metric_name ? metric_name : - out->force_header ? name : "", + out->force_header ? evsel->name : "", ratio); } } else { print_metric(config, ctxp, color, /*unit=*/NULL, out->force_header ? - (metric_name ? metric_name : name) : "", 0); + (metric_name ?: evsel->name) : "", 0); } } else { print_metric(config, ctxp, color, /*unit=*/NULL, out->force_header ? - (metric_name ? metric_name : name) : "", 0); + (metric_name ?: evsel->name) : "", 0); } expr__ctx_free(pctx); @@ -523,7 +524,7 @@ double test_generic_metric(struct metric_expr *mexp, int aggr_idx) if (!pctx) return NAN; - if (prepare_metric(mexp->metric_events, mexp->metric_refs, pctx, aggr_idx) < 0) + if (prepare_metric(mexp, pctx, aggr_idx) < 0) goto out; if (expr__parse(&ratio, pctx, mexp->metric_expr)) @@ -625,10 +626,7 @@ void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *config, if ((*num)++ > 0) out->new_line(config, ctxp); - generic_metric(config, mexp->metric_expr, mexp->metric_threshold, - mexp->metric_events, mexp->metric_refs, evsel->name, - mexp->metric_name, mexp->metric_unit, mexp->runtime, - aggr_idx, out); + generic_metric(config, mexp, evsel, aggr_idx, out); } return NULL; From patchwork Wed Feb 21 07:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 203967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp877345dyc; Tue, 20 Feb 2024 23:09:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVosISjWDDMXc4PsIcTa0qXWNb57cfotX9muFYHIn2n+IGjeCSXSMpyuzvtgavtvc/wNDglNkiJBjzCVE3WcB1sIggCcw== X-Google-Smtp-Source: AGHT+IGgXPcq2zWoiNBF4OMB8mNQvzn42+s8Wi86XBxyhiDMia6HqzkJJw/S6kqsYtDz8HBZmJ9c X-Received: by 2002:aa7:c44d:0:b0:564:7bed:b866 with SMTP id n13-20020aa7c44d000000b005647bedb866mr5256944edr.23.1708499369167; Tue, 20 Feb 2024 23:09:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708499369; cv=pass; d=google.com; s=arc-20160816; b=cbtZ5TkkBG/BeVO6tWS5yVLS9OIQWAoA9/owrDxRBiJVNafIE0LILU10qrB6g9gJXI Ym2IS+YT9W0+CsuhuXahhqYysNiJIykTEtndEgcXCAl1Zzo3wzx71RYTLihAERQuD83X Ms1NhKu56GtJKpMoQotd9dGNKModSpREmO06htejz2xoY9G9KVwavuYEbrT05o5dp5Rk HCoeKXJF+svHgD+kl5j2XUIScr0W7rcRlwbgN43TZi/FKLPsjICeW4EqjpmOrMzcOZBG vV9ue7CFXTF0sg2Nir4Jf1Y2A+DzjQAw0cGTEG16ucmJghnNPLc28mOoaEF9scHkHE/T 6wTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=IvthopvNRdGOZJq8hSaBpJ0dA5xV4FM2S9eVhI67i9I=; fh=ePUA6EUIBSh1UE7akljWvkifw0ZXw4UtzKX1XqQj5p4=; b=qVU/D0UV1y7iOVYn7RJWzexLWQgi216MSWiUDsCbS+6iw2uBAZ9awXKRVUgW5I90oK y58zQDoXiT71jZ9m7Saq/ic7uiMMqx++ByjvmkUw81uM2tZL+bYYqc73LI/PYGrMtGT0 TIK/OTW2wop6Med6wumgOdkJoKqsqavt3P99hWJrTciVshNImxOlQuektZzlLI/Pa0b3 XLmBkQA3x7qwsmiKUF9b8517IiRanlui90pF10mCxxx3CMektWfJM9+ATK37xoAdnJgI g3/m4x3Di4vK5w868XKuruvv7+Ntj9SBZCn0sTqLgoUiEtOr3FhR5dEOUJ+3MKm4ytjt WA1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ivxFwb4d; 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-74186-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74186-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 11-20020a508e4b000000b0056475b2dd0asi2535261edx.496.2024.02.20.23.09.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:09:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74186-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=ivxFwb4d; 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-74186-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74186-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 9B9161F219FC for ; Wed, 21 Feb 2024 07:09:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FB743B297; Wed, 21 Feb 2024 07:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ivxFwb4d" 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 1FD183A278 for ; Wed, 21 Feb 2024 07:07:59 +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=1708499281; cv=none; b=rLNY6onRoMBVOgjOEcSJ3eD2ZK/7x74anIb/1jim8BAbVD2JF1yX0zJK7ynBz8P6xoeyZ8wWZlL5wDNWiaLPNUBK4LrJ8A7/9+oIvoShM2nP4TxC36WbBUmyxQRhSAo+Iw80S/uuznHG4PYwvW5eI2Fy5YOFX9vY74Sb+B6WUA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499281; c=relaxed/simple; bh=p2BFm98alOENnWqviYTCy9ucqswGbAxkTLrhYtaIgqA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=mjhQ01175RDZGuKgDY1MIWR+uKwkvHU+Kir/ZCbiobo6JcGnAP1HBtuOLiqXaFRijAblDCARCQ52sRdjiskQyPl46Jslr42qftLUW7p62N7ymjrxpT0HF2N0SAb4Vb7vaHrkN6/3GDJNYGy+J6MQ2yoNRDRVhY+pUtvGX9cGCvI= 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=ivxFwb4d; 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-dcbfe1a42a4so740209276.2 for ; Tue, 20 Feb 2024 23:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708499279; x=1709104079; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IvthopvNRdGOZJq8hSaBpJ0dA5xV4FM2S9eVhI67i9I=; b=ivxFwb4dUdthYRCAv6vIqtbS+I1zglAjh6vcwZEQydEK+G/49kJp1miwXOxlIS2BGU kNeKEoIrRU9ZiZRAVtpTmJf8dyBeyDWKr50vG8ryA4nTg/z4bhokaHC6bjvMVplNnmZb CW4KpDQtrXQlAl5l1hVOGOhJR6+6LxuZzFJJ+TPJ7QCw0O6gwWdDsmnfAgCHjdrMZuFJ CAo31h090xJU2OQmBIEX0Cwgea3FBpske+LoAf5LTonpjqSVIdiV7Bt3JEdOVQhaPFje fTRDEZk20SPhSo8bO719au+nLEVhoiC9lu2k+HLmAvQpN9qGyotkNpzDhQkFshdYo8Ze KtGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708499279; x=1709104079; h=cc: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=IvthopvNRdGOZJq8hSaBpJ0dA5xV4FM2S9eVhI67i9I=; b=wHwdYo4pfd31hVhczed3NJWkQa2Lz3HqZCbybJcdgdWk3r3P26gc3hj7YIiQBEuJif n8tUWU9x+pW/VIJseG4FusfuslW91cKLsTQvYcJHqB01RfkafY4i79n5SRS+QUZXSzxe i59FURRStcdbyx83ANmsmhHztmcnoP0+IXjYCel/dhdzbBFoTgbzga7cavUX58a/0YOm hJIZMmdB5uU1qoTbs6bgNmzTGXpfG04ZhyXpRmvKBa2O8FOd70aPb7IQpRzU/ZzByvC9 APNnl6Iv2+uHZ8tYTNjSVLZvszUucxIGfgHvuOpVOSKkBMPQhZR/gFKbj4H4xHyxWnf2 twnQ== X-Forwarded-Encrypted: i=1; AJvYcCWmcFRXtr1FBq0NGLdzjx9bmCNKG1Y3B5fjQrl+4/IPDuStspdWemzXuWsBt10NTgh1w03L/LSZ+azv3T/T4GnUP9ZGqOgYrn0s+585 X-Gm-Message-State: AOJu0Yya8GLF2Fl7Vxt/lELBiiqHqI/W0wkDyOueCzlVCar+Zp5pN7pT 4sKpB+in+zsLc7mvsRJH/XGCWBSo34lX6uFy8hYmKRd9EfhRLFuXYYmIVo72wmKH/kWgAjVtcyd 9hQL62Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3c02:f882:5876:b7ab]) (user=irogers job=sendgmr) by 2002:a05:6902:18ce:b0:dbd:b165:441 with SMTP id ck14-20020a05690218ce00b00dbdb1650441mr4691108ybb.0.1708499279254; Tue, 20 Feb 2024 23:07:59 -0800 (PST) Date: Tue, 20 Feb 2024 23:07:53 -0800 In-Reply-To: <20240221070754.4163916-1-irogers@google.com> Message-Id: <20240221070754.4163916-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221070754.4163916-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Subject: [PATCH v3 2/3] perf metrics: Compute unmerged uncore metrics individually From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Kajol Jain , John Garry , Kaige Ye , K Prateek Nayak , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791491434727230448 X-GMAIL-MSGID: 1791491434727230448 When merging counts from multiple uncore PMUs the metric is only computed for the metric leader. When merging/aggregation is disabled, prior to this patch just the leader's metric would be computed. Fix this by computing the metric for each PMU. On a SkylakeX: Before: ``` $ perf stat -A -M memory_bandwidth_total -a sleep 1 Performance counter stats for 'system wide': CPU0 82,217 UNC_M_CAS_COUNT.RD [uncore_imc_0] # 9.2 MB/s memory_bandwidth_total CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_0] # 0.0 MB/s memory_bandwidth_total CPU0 61,395 UNC_M_CAS_COUNT.WR [uncore_imc_0] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_0] CPU0 0 UNC_M_CAS_COUNT.RD [uncore_imc_1] CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_1] CPU0 0 UNC_M_CAS_COUNT.WR [uncore_imc_1] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_1] CPU0 81,570 UNC_M_CAS_COUNT.RD [uncore_imc_2] CPU18 113,886 UNC_M_CAS_COUNT.RD [uncore_imc_2] CPU0 62,330 UNC_M_CAS_COUNT.WR [uncore_imc_2] CPU18 66,942 UNC_M_CAS_COUNT.WR [uncore_imc_2] CPU0 75,489 UNC_M_CAS_COUNT.RD [uncore_imc_3] CPU18 27,958 UNC_M_CAS_COUNT.RD [uncore_imc_3] CPU0 55,864 UNC_M_CAS_COUNT.WR [uncore_imc_3] CPU18 38,727 UNC_M_CAS_COUNT.WR [uncore_imc_3] CPU0 0 UNC_M_CAS_COUNT.RD [uncore_imc_4] CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_4] CPU0 0 UNC_M_CAS_COUNT.WR [uncore_imc_4] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_4] CPU0 75,423 UNC_M_CAS_COUNT.RD [uncore_imc_5] CPU18 104,527 UNC_M_CAS_COUNT.RD [uncore_imc_5] CPU0 57,596 UNC_M_CAS_COUNT.WR [uncore_imc_5] CPU18 56,777 UNC_M_CAS_COUNT.WR [uncore_imc_5] CPU0 1,003,440,851 ns duration_time 1.003440851 seconds time elapsed ``` After: ``` $ perf stat -A -M memory_bandwidth_total -a sleep 1 Performance counter stats for 'system wide': CPU0 88,968 UNC_M_CAS_COUNT.RD [uncore_imc_0] # 9.5 MB/s memory_bandwidth_total CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_0] # 0.0 MB/s memory_bandwidth_total CPU0 59,498 UNC_M_CAS_COUNT.WR [uncore_imc_0] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_0] CPU0 0 UNC_M_CAS_COUNT.RD [uncore_imc_1] # 0.0 MB/s memory_bandwidth_total CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_1] # 0.0 MB/s memory_bandwidth_total CPU0 0 UNC_M_CAS_COUNT.WR [uncore_imc_1] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_1] CPU0 88,635 UNC_M_CAS_COUNT.RD [uncore_imc_2] # 9.5 MB/s memory_bandwidth_total CPU18 117,975 UNC_M_CAS_COUNT.RD [uncore_imc_2] # 11.5 MB/s memory_bandwidth_total CPU0 60,829 UNC_M_CAS_COUNT.WR [uncore_imc_2] CPU18 62,105 UNC_M_CAS_COUNT.WR [uncore_imc_2] CPU0 82,238 UNC_M_CAS_COUNT.RD [uncore_imc_3] # 8.7 MB/s memory_bandwidth_total CPU18 22,906 UNC_M_CAS_COUNT.RD [uncore_imc_3] # 3.6 MB/s memory_bandwidth_total CPU0 53,959 UNC_M_CAS_COUNT.WR [uncore_imc_3] CPU18 32,990 UNC_M_CAS_COUNT.WR [uncore_imc_3] CPU0 0 UNC_M_CAS_COUNT.RD [uncore_imc_4] # 0.0 MB/s memory_bandwidth_total CPU18 0 UNC_M_CAS_COUNT.RD [uncore_imc_4] # 0.0 MB/s memory_bandwidth_total CPU0 0 UNC_M_CAS_COUNT.WR [uncore_imc_4] CPU18 0 UNC_M_CAS_COUNT.WR [uncore_imc_4] CPU0 83,595 UNC_M_CAS_COUNT.RD [uncore_imc_5] # 8.9 MB/s memory_bandwidth_total CPU18 110,151 UNC_M_CAS_COUNT.RD [uncore_imc_5] # 10.5 MB/s memory_bandwidth_total CPU0 56,540 UNC_M_CAS_COUNT.WR [uncore_imc_5] CPU18 53,816 UNC_M_CAS_COUNT.WR [uncore_imc_5] CPU0 1,003,353,416 ns duration_time ``` Signed-off-by: Ian Rogers | Acked-by: Namhyung Kim --- tools/perf/util/metricgroup.c | 2 ++ tools/perf/util/stat-shadow.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 966cca5a3e88..b24a1c177a80 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -44,6 +44,8 @@ struct metric_event *metricgroup__lookup(struct rblist *metric_events, if (!metric_events) return NULL; + if (evsel->metric_leader) + me.evsel = evsel->metric_leader; nd = rblist__find(metric_events, &me); if (nd) return container_of(nd, struct metric_event, nd); diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 10b452792037..3466aa952442 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -356,6 +356,7 @@ static void print_nsecs(struct perf_stat_config *config, } static int prepare_metric(const struct metric_expr *mexp, + const struct evsel *evsel, struct expr_parse_ctx *pctx, int aggr_idx) { @@ -399,8 +400,29 @@ static int prepare_metric(const struct metric_expr *mexp, source_count = 1; } else { struct perf_stat_evsel *ps = metric_events[i]->stats; - struct perf_stat_aggr *aggr = &ps->aggr[aggr_idx]; + struct perf_stat_aggr *aggr; + /* + * If there are multiple uncore PMUs and we're not + * reading the leader's stats, determine the stats for + * the appropriate uncore PMU. + */ + if (evsel && evsel->metric_leader && + evsel->pmu != evsel->metric_leader->pmu && + mexp->metric_events[i]->pmu == evsel->metric_leader->pmu) { + struct evsel *pos; + + evlist__for_each_entry(evsel->evlist, pos) { + if (pos->pmu != evsel->pmu) + continue; + if (pos->metric_leader != mexp->metric_events[i]) + continue; + ps = pos->stats; + source_count = 1; + break; + } + } + aggr = &ps->aggr[aggr_idx]; if (!aggr) break; @@ -416,7 +438,8 @@ static int prepare_metric(const struct metric_expr *mexp, source_count = 0; } else { val = aggr->counts.val; - source_count = evsel__source_count(metric_events[i]); + if (!source_count) + source_count = evsel__source_count(metric_events[i]); } } n = strdup(evsel__metric_id(metric_events[i])); @@ -463,7 +486,7 @@ static void generic_metric(struct perf_stat_config *config, pctx->sctx.user_requested_cpu_list = strdup(config->user_requested_cpu_list); pctx->sctx.runtime = runtime; pctx->sctx.system_wide = config->system_wide; - i = prepare_metric(mexp, pctx, aggr_idx); + i = prepare_metric(mexp, evsel, pctx, aggr_idx); if (i < 0) { expr__ctx_free(pctx); return; @@ -524,7 +547,7 @@ double test_generic_metric(struct metric_expr *mexp, int aggr_idx) if (!pctx) return NAN; - if (prepare_metric(mexp, pctx, aggr_idx) < 0) + if (prepare_metric(mexp, /*evsel=*/NULL, pctx, aggr_idx) < 0) goto out; if (expr__parse(&ratio, pctx, mexp->metric_expr)) From patchwork Wed Feb 21 07:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 203968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp877374dyc; Tue, 20 Feb 2024 23:09:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWuKmSujKcind0dKMQ1bwcx4fIUsPOD1DzXJpyIw3fzfx+EdTjh2K0tc3EV8MgbEQmU6pXynyDdWjvM1ZC7WH5CkyVn+Q== X-Google-Smtp-Source: AGHT+IGhB4cER1G586BH1lUqyytME75NVYh0MWENhoQCEr1cAyguvRIZQhi3koGSNTA8At4Mq+Jn X-Received: by 2002:ae9:e203:0:b0:787:76dc:652e with SMTP id c3-20020ae9e203000000b0078776dc652emr3732616qkc.33.1708499372896; Tue, 20 Feb 2024 23:09:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708499372; cv=pass; d=google.com; s=arc-20160816; b=xOLi/xwLukWCs7+R7y0+MkNp8o/cGfPck2/ohWqAc4VZ+xoxV/BLtaf4l0KMInubgI DYMNMrZMXtCV9Mm+LKKI219QxSupWSujn7vomAkR9SGgaeamNvKwISpKV7vYmYChZfOU j4NXPYH5uBIHAW4DusBGAYUWhLxm2BWIAFG/IxJfMGOdqtk7S9X7AB9xltUcsgDA44eQ LkIrXO4wmlmXfy5UvVXhdESDUQMPSyWZBXQixWAhci+UW4ZX+GxKQOKfhwj+lLngqFsj Aag6cDFFVu7kYsrtTl23JVljji6AWuQt7CUGp4Vit6+DaMc+lEcXY/lfifIcmuK7YNoT 3WcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=DfVuTk7FcAUa184IhDAbJwuMC16l/TIzHOCMWidcT2s=; fh=9QShks5HPkM9CtQ8Vea8Z7pMZ+FAjG4Yi+FXd0eVyUc=; b=DMIzpAOZtxkGLax0BApbI5jCwWBxT8y/+Hc+wNTmVOIqZ9SYrrCX0z///CDTrufAT9 nd/p3IpFQ7s4vJAYjyUwzMNrdd14LkDB6JkHVCRjLEA+OUgwVDaydbvv38W8aRXjlsOz Zpg5cDv1zmeOhiq2miR0bkzBoe0UCdTxiJTbgas2r9MqXrEBxjK50TygFNnfeIQtZaV9 b4eEW33ExKHfYsG9jeqlYmaJOZw0HREA38RcZdEvNd2quQvf7exIQuVHMu0Bw+3/jJZ4 l8ffVFKY8PlhpozEIKStQ102wpNbAwSiJmJCn1QM1aC1BmEPEspj5oCEaV7oJeI6tSQL C9YA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u5WMWwiS; 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-74187-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74187-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pa10-20020a05620a830a00b007874f43dd5dsi9587022qkn.445.2024.02.20.23.09.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:09:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74187-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u5WMWwiS; 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-74187-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74187-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AD7651C22F83 for ; Wed, 21 Feb 2024 07:09:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B86A3B781; Wed, 21 Feb 2024 07:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u5WMWwiS" 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 1ADAA3A8F5 for ; Wed, 21 Feb 2024 07:08:01 +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=1708499283; cv=none; b=YH4/5ntWLtqbyW5ROkHJ7RK9kRhw94f3ZzoDUJztvUO3/9U/rzeRTCTNL7S5rolhIHSpcGFDMTjsn6slLU7tpv1b1o/J29oc2GmcD5ktOWBVvdMKFxIYQcCySsIa291aT6qp8aoIzOKebDLxXDpr8Z6yfDv7m5VAmwDcAVu2O+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499283; c=relaxed/simple; bh=VTnFedSHbWRXdPeVX5bVM50OyRSGy300r/pvDJawCfs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=dUmFoBO7ZhKQTiwyalHiBkSWvC9dEMu9FkKSQYKYWzMlYgRvCYJfoEFyzkoxcYReiYBADplcnqHj0TcPtBD2hFrtvWXZFs3CaCUxq0CyzFpepfvxmfzsxYNShbsbCB3vTQz1KbVR99bx4D/CKmK+HBI6rHAwVnIYiVdJmW9Ib0U= 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=u5WMWwiS; 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-dc64f63d768so10934471276.2 for ; Tue, 20 Feb 2024 23:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708499281; x=1709104081; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DfVuTk7FcAUa184IhDAbJwuMC16l/TIzHOCMWidcT2s=; b=u5WMWwiSuRnVlwYVjkghy8yD3+KyPndGBwJfXJ3oKw/BulP7ut1YfR1R9vuMafZ1V2 fGzEfiA49uhG7VmObQzrcbNRYV13emTfYeZ6SSqiqxtNG22tvRMAl5n5UK6gR6qSvFtg Pq0kPTpxlRn4r4r7y/pV9Det5kO0rnCLFh8Yf7JHDxKI+Kwj7yxWWgOn/ent8eAN3l8Y Cy6WZ5Fr6+JOShEM9A0G507i6PxF1PHmYKLBjZDbTNuTwgCk9fpbMcxZN9iMPAJJp0JW y5CaPMzksKBcWYfZXzL8be9GlSwiESvNCzd28wVz9uUSc+nrIibcuBGlyclG6EVfYPo3 w3fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708499281; x=1709104081; h=cc: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=DfVuTk7FcAUa184IhDAbJwuMC16l/TIzHOCMWidcT2s=; b=Y6qkiu+AGSg1Uk8u1aZ6encGMjkV6gYtaFArTMy7hegexDKjRg6YcbVbfDrZ4Y6xpJ 3NHXY7fTtHKMbnr3/ASVYLXvjzXCSpMVHG4EjGRVKFjsHF0+1gRTKr+osNupLuY+rgFF AtHfG16tP8rZwNf5/buvEmeGaZEbA2OyhJ5c+IjHNY5coLgbpGu5C9rF6cJH5D03Ps4G 5nR75g5Yb+ldZs0SpxCpd0B0QkQzBpQhFs2yz7C4lLR5EtguCiQHCcr+sSDV3jWdJuwe CMVdD/5rTPvA1/UP4sBaRhoK5X/VM15IkhXewUb1SG40w/Ni++LiBHUEkdXk2aSvvweW wpVQ== X-Forwarded-Encrypted: i=1; AJvYcCWlvbpQ7w44aoN1t8vx77My+wc2p/u4BmQRuaAxNd0kZWZA0XtKjPQxPy0CuZvJ3H515FxoUuMbnU+3FcB/bRH8Ah5xsH5FU7qgHiKK X-Gm-Message-State: AOJu0YyHHD1zxxtka8GaFmjI8/R5KvPMVRYOTz2JqvXxWpdoc17vA2yV awOviGGtNOZtLS6pdBjD7ozy2CUWehk2Bm+qPCnZfQWUuanSUV7og9FHLENqsw529dkzZn27o9O l5/VnCQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3c02:f882:5876:b7ab]) (user=irogers job=sendgmr) by 2002:a05:6902:98b:b0:dc6:ff2b:7e1b with SMTP id bv11-20020a056902098b00b00dc6ff2b7e1bmr5058563ybb.4.1708499281168; Tue, 20 Feb 2024 23:08:01 -0800 (PST) Date: Tue, 20 Feb 2024 23:07:54 -0800 In-Reply-To: <20240221070754.4163916-1-irogers@google.com> Message-Id: <20240221070754.4163916-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240221070754.4163916-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Subject: [PATCH v3 3/3] perf stat: Fix metric-only aggregation index From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Kajol Jain , John Garry , Kaige Ye , K Prateek Nayak , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791491438341430693 X-GMAIL-MSGID: 1791491438341430693 Aggregation index was being computed using the evsel's cpumap which may have a different (typically the same or fewer) entries. Before: ``` $ perf stat --metric-only -A -M memory_bandwidth_total -a sleep 1 Performance counter stats for 'system wide': MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total CPU0 12.8 0.0 12.9 12.7 0.0 12.6 CPU1 1.007806367 seconds time elapsed ``` After: ``` $ perf stat --metric-only -A -M memory_bandwidth_total -a sleep 1 Performance counter stats for 'system wide': MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total CPU0 15.4 0.0 15.3 15.0 0.0 14.9 CPU18 0.0 0.0 13.5 5.2 0.0 11.9 1.007858736 seconds time elapsed ``` Signed-off-by: Ian Rogers | Acked-by: Namhyung Kim --- tools/perf/util/stat-display.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ae37395f90c0..bfc1d705f437 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1137,11 +1137,16 @@ static void print_no_aggr_metric(struct perf_stat_config *config, u64 ena, run, val; double uval; struct perf_stat_evsel *ps = counter->stats; - int aggr_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); + int aggr_idx = 0; - if (aggr_idx < 0) + if (!perf_cpu_map__has(evsel__cpus(counter), cpu)) continue; + cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) { + if (config->aggr_map->map[aggr_idx].cpu.cpu == cpu.cpu) + break; + } + os->evsel = counter; os->id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); if (first) {