From patchwork Tue Feb 6 04:31:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 197171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1316340dyb; Mon, 5 Feb 2024 20:32:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHqWODLQlu56+EMx7IH1bTRK9v0H7KUXI/009BJTw3bStdfhIGqqwJuWo/sXouXgo/dAdS X-Received: by 2002:a17:90a:c20a:b0:296:ca18:b3db with SMTP id e10-20020a17090ac20a00b00296ca18b3dbmr328642pjt.0.1707193967839; Mon, 05 Feb 2024 20:32:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707193967; cv=pass; d=google.com; s=arc-20160816; b=PVgJ5APUTcmVolhXXA5stMuRgebKPl3t7EnNRkHxOu2+1nOzamuU3cV5Z+BUfJuWlb /U2ndFPYr711AyHSeqBAf1oZwWoChSSRSXQc31Fa/nFdln61rdNNq5UJS6pGOy6TeJ52 4fTfbacpUxKPXuqCRJJSxLGUaXb4in0iqHFNFGZ9sCXeXy1buOihSAQ2mkajYLgNaWd3 rzyIXIVe+e0oW6uVnAsjaqyrIM8tSIHWlPe8uf9P0OW/uEVtFx+amjLb2OFAQX2NROnC W0hcK8TiOVXjVQwix8LzquiglRB/shTHsqRvvsBfdOnOGKUe+uXSUXhlZzInhns39mrF l7Kg== 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=mZUpnex2KPkifzX16ZZpXLaFgVrYfXozd164M4YKBC4=; fh=04lEFPG5fM2eyoRbHOV80HV1fqpZOtVQVffrOohO4lk=; b=imtHYmxXz7iEEyViL7GbxbF/gvXRlzEpjbFvf56dEU5jQY2YrbXJhw/D8PoMNdNS1p A/bNyJweboDcPVzz0M1jmueeqaIcYzM8/+QZDJhK5AicDz5hAOWR+EwvNJCT9E2K6QFP zi/zTwxP2i1mWQbAaWPP3cQyrmQm3ndxCilthoDHxUXEDhlqCj0VGscIK+jOT/6Fbg2w Yux12Ma3Rm5h7BJ8u6nuFC4yy76MAxbGYjXZ+NOIZf2fZzyCHjJS6aX/eBexV9uLtm+W h0lIA82+7Uy9w8f1jS/sO/t3OGHFxHQRZeDKZseMyGvWdGTCBRPiARBSBIFWHmi2cotD jCXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=k+F9p+Uz; 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-54301-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54301-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUBqluIc0bfIpisLtSiakBxzod1QaRaebbwLf0gc/y6KziSVSizv3ml8sTpBAjvVG3Zo8hru5HTwUNKZCqC/njIdyJOtA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h24-20020a17090acf1800b00296a5bf4d4dsi461373pju.92.2024.02.05.20.32.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 20:32:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54301-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=k+F9p+Uz; 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-54301-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54301-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 978CE2840A5 for ; Tue, 6 Feb 2024 04:32:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12A707C082; Tue, 6 Feb 2024 04:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k+F9p+Uz" 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 2B3F97765E for ; Tue, 6 Feb 2024 04:32:09 +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=1707193930; cv=none; b=Yw93TXeFLUdgvdLRPWt5hahIvA/ocBck+5rQsRNGDW+GJUZkwtsxoYQjsRm+DpgGfz8FrxjoHWD2yMuE0U5BxPZ5shELyQqibI8NJojbx+VkpatKVUfmDUTiDvsV2M0jQ0NfNaQE75/09pe65BWVSXW4Q7Cfz8Jneamdg81ZZGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707193930; c=relaxed/simple; bh=H4Ot/tbzdD7mTU5prpB/Q+DedtdUrPrliS8HXaRvhm4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=r2TpWJWz3JzBqc2q9pdyL/0oOeRmWgi5cNO7aOQrxPuLrpRkYwDIrWpMNpUELfvUZ2tcFYzZDqwS+G3VoE7bjL/Nu64OphUZCT2Qv4gulJALc6y29yZtuR7qMsfDYFHnFIw8J7nMRwFE3maW4dzjt9T4sS+W6zZmJhNvc4iqxtc= 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=k+F9p+Uz; 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-dc6df2b2d1aso6168291276.1 for ; Mon, 05 Feb 2024 20:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707193928; x=1707798728; 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=mZUpnex2KPkifzX16ZZpXLaFgVrYfXozd164M4YKBC4=; b=k+F9p+Uz0w+cbOpW+KJkZ4I7dev6JX4AjMXrg3G7EieyTwOxfHRoXJSNEJTGoDe42v YRoi1BeADQplKbiwY0XNnyNVE8JPYZryZ711mTSYNS50R3ZC00X7A4gfpOwjKGNM1Y1f 1NMl3cfCg/H/ivA+cZAOn/g+i+8kgCzua2iHN7FZB43k/vNO6hYgnweLGDSE0U5FdMJP GbkiQaG2HbbQzQQCwafGW44JzXHcXW2uTzpWu/7JegaTQS5b3Q0Sbvf7qjrrHBPlqrlY BBp2Kgo8GYCg6h22r02Haa78goXeESpkOsjLDLRnSQZYCATzLcgMuHL/qh/QwLv5ECwh vLgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707193928; x=1707798728; 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=mZUpnex2KPkifzX16ZZpXLaFgVrYfXozd164M4YKBC4=; b=Zz5xYA7ycnZuOHzVr+IXsnvp+x/01acG0Si565Fb7pDR5+ULQNz2hFrbQQqwkQt11k AzGw4RNhsOgNLgJFmAoi9rdVTrKO8OKl9+UWEP7VVy1PFNZ9vPqWB4rcAWqZWkXybLNP GaONDZYuux/9u7wWBNU1KL2avzwnsuU96tQYewXzheg51M4J6MXODBTVCycq8Ynd0bi6 3FDQSxLRj1oxQhmRtlV+C4F9SPjZW43/OqfdUbWgJBRWyQlba/UyARbh430t8zeB85f/ eoaP6lpoUDzx4UJK0OMTHFLXA/fCrpgINuVla5MDLRo2t1nm9TdsahtQ6loXaqjr46yh Qx6w== X-Gm-Message-State: AOJu0YzTCpxc9gIot1CbDpxiGMAIK2eHwrYTGwxMhx7/1bz4t58ZLzyy WlKkkSg3AiAPzBYQk6inYFb1Zt3ilFm5TGQGcwRGo/1JqrdAW2+oabFgRXOkX10aG/wxuejgPSq dThAqOQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:326b:71bb:e465:6f39]) (user=irogers job=sendgmr) by 2002:a05:6902:240f:b0:dc6:4bf5:5a74 with SMTP id dr15-20020a056902240f00b00dc64bf55a74mr21509ybb.11.1707193928212; Mon, 05 Feb 2024 20:32:08 -0800 (PST) Date: Mon, 5 Feb 2024 20:31:58 -0800 In-Reply-To: <20240206043159.2539981-1-irogers@google.com> Message-Id: <20240206043159.2539981-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: <20240206043159.2539981-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v2 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: 1790122621988852011 X-GMAIL-MSGID: 1790122621988852011 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 --- 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 ca3e0404f187..c33ffee837ca 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 b3a25659b9e6..c745337f50a4 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; @@ -421,7 +443,8 @@ static int prepare_metric(const struct metric_expr *mexp, * metric. */ val = aggr->counts.val * (1.0 / metric_events[i]->scale); - 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])); @@ -468,7 +491,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; @@ -529,7 +552,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))