From nobody Mon Dec 15 22:26:46 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 16BFC222587 for ; Tue, 14 Jan 2025 23:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736896425; cv=none; b=mQRHpwAGdyDxbA7ejTK06tZYOvW4FfTOeTlauompXxyFDT2FGZefG0FjoRr9XcrwCtO6PbmfREi0XySGhZNTg8f7veVK5x0718ywXFDLAu2X79bRmB6uhoiOZtW68DND8jVW1+qUA4GogCDqHSLJYkI1+vwOuInirFVXPAYCqX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736896425; c=relaxed/simple; bh=TK5jsPUddoVqcWXgIyzdTH/6UP97uh46LEr347Po1cA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=AlLz1H4btz7yyH1YIZUsdHihJG67toh3TZjHnOE8tbkEDSA9eCPGXmvPiPwFFXCO4+vWk5BP5FzNgyqErHZvjYDuwCW7BoY0H6Qt95G+w1yfTJeUgmMrO1poQdh1dNhHpR2mZhbbl6LaW2HH1pqSSTtsiNavu5jxsAPvKGTrFjc= 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=1ER2/FXL; arc=none smtp.client-ip=209.85.219.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1ER2/FXL" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e54d9b54500so14025743276.3 for ; Tue, 14 Jan 2025 15:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736896422; x=1737501222; 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=N1xjM3wphMNYu1Ks6TVH7fA4hJ036I4dNmv6CTOW45Q=; b=1ER2/FXL/7UCxzaN40Ds9MA0VVhLmxOF9U3yhHXxo9UVSLwzb9CGOvoTMJXeqT0/69 XE8bIYFcAkVewOnOn1U8QV0k3l9lttW4VeN6SkULz854PJ0GDJWN9jT4tE2g49W5/ryx 84JRrNtX6ozGWiF6uW1pINvxN/YQVU1gt+4+FZFb9I3iTreq4NKzycEy25d4NbhvBgR5 GJJKyJq3jIqhBn9mHcPfBfARQVIApC2Y/RI+QJgwucbHYze/aha84EjIz1wpxGpGiyYC 9X/RDG3wXN/RUWXuUjFiQzgQW4f6sAysfMIQZvJhL6XZeItw/JyQYNii65ZhabO/YLFr QAIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896422; x=1737501222; 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=N1xjM3wphMNYu1Ks6TVH7fA4hJ036I4dNmv6CTOW45Q=; b=bZz5FN2Psf4HH5PTHUMcmehEUG4GejWVA+7cYW4G85Ffk4O5NF5GqJ5v9is7eIDJq6 n4GuuoETOx3mvpdo8BnEjROwcPJew/s9WXsVkHiNrBJMBxGT/pexZtr4g4CNXJEqRS/8 XmVRMRorfjoHVvrPj4SSag/d/LAoGKS7jb13nI9mbaspvz1oEj+tSakGMRJJd4eeUruO O0bc4KvEpTyIPUddOgR5coQYP4neCuGPbHJSXq9CRRSShZbyi1XQcoApMbYIBoLTB/fQ dP1Ibo58sO13r8yWsIJNnA50yxrBzcdFsOOgKV+jsfbp35sZtvzZoHG5xSu9Fp2D1JYs 8lEA== X-Forwarded-Encrypted: i=1; AJvYcCUj/2IpGUMAzJMDkdqGjMDTe9ddO6IicT0rd5+hU8rCrJWnYC5Ch5/pZD7GBEGRyubvhm1JHEdOMpGA5cI=@vger.kernel.org X-Gm-Message-State: AOJu0YzSj/sYrVhatSC+z/S9LqMzWxTi/23/C0hO/cnRW8Hm17v5h/eH pZA0uePZCbzfnpzec8uN7d3wRWpsgsYb/g+cLpDfdlkrrjiHGm2O2TWP9MLd1f1kv3sbTqV6QdD 1OiXSKA== X-Google-Smtp-Source: AGHT+IE6vfJevlH8r7yu7Dpu1i9qXKvuoPLqRHx5pq+3+JCv3a3eukT2BmKSixvpexe5/MBkmW1GzX281wQl X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:b3e8:96da:3fa1:5494]) (user=irogers job=sendgmr) by 2002:a25:c7d4:0:b0:e57:3e87:8c17 with SMTP id 3f1490d57ef6-e573e878d01mr27597276.5.1736896422209; Tue, 14 Jan 2025 15:13:42 -0800 (PST) Date: Tue, 14 Jan 2025 15:13:31 -0800 In-Reply-To: <20250114231332.13419-1-irogers@google.com> Message-Id: <20250114231332.13419-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250114231332.13419-1-irogers@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Subject: [PATCH v1 3/4] perf stat: Don't merge counters purely on name 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 , James Clark , Ze Gao , Weilin Wang , Jean-Philippe Romain , Junhao He , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Counter merging was added in commit 942c5593393d ("perf stat: Add perf_stat_merge_counters()"), however, it merges events with the same name on different PMUs regardless of whether the different PMUs are actually of the same type (ie they differ only in the suffix on the PMU). For hwmon events there may be a temp1 event on every PMU, but the PMU names are all unique and don't differ just by a suffix. The merging is over eager and will merge all the hwmon counters together meaning an aggregated and very large temp1 value is shown. The same would be true for say cache events and memory controller events where the PMUs differ but the event names are the same. Fix the problem by correctly saying two PMUs alias when they differ only by suffix. Note, there is an overlap with evsel's merged_stat with aggregation and the evsel's metric_leader where aggregation happens for metrics. Fixes: 942c5593393d ("perf stat: Add perf_stat_merge_counters()") Signed-off-by: Ian Rogers --- tools/perf/util/stat.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 7c2ccdcc3fdb..cfdb6d55df9b 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -535,7 +535,10 @@ static int evsel__merge_aggr_counters(struct evsel *ev= sel, struct evsel *alias) =20 return 0; } -/* events should have the same name, scale, unit, cgroup but on different = PMUs */ +/* + * Events should have the same name, scale, unit, cgroup but on different = core + * PMUs or on different but matching uncore PMUs. + */ static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b) { if (strcmp(evsel__name(evsel_a), evsel__name(evsel_b))) @@ -553,7 +556,13 @@ static bool evsel__is_alias(struct evsel *evsel_a, str= uct evsel *evsel_b) if (evsel__is_clock(evsel_a) !=3D evsel__is_clock(evsel_b)) return false; =20 - return evsel_a->pmu !=3D evsel_b->pmu; + if (evsel_a->pmu =3D=3D evsel_b->pmu || evsel_a->pmu =3D=3D NULL || evsel= _b->pmu =3D=3D NULL) + return false; + + if (evsel_a->pmu->is_core) + return evsel_b->pmu->is_core; + + return pmu__name_match(evsel_a->pmu, evsel_b->pmu->name); } =20 static void evsel__merge_aliases(struct evsel *evsel) --=20 2.48.0.rc2.279.g1de40edade-goog