From nobody Fri Dec 19 20:54:14 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 567A51A304A for ; Wed, 8 Jan 2025 05:34:49 +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=1736314490; cv=none; b=eI7Z3bI7+8ODvNsaTkafzPlrwwx5wDvjIErKiEf71mTDJ9vr1x1E8iVm2GxG2SXwIOOI5EUdB/wSbVCZU9jO3F4koGMDAhYjLtclRJphtDqwX01MGPu3spYrtnA5DcBN2mh8dhRseupOhAVww+rm8W/iDUI8N59igg0ZT9mqix4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736314490; c=relaxed/simple; bh=FH6pJMsaJgeqK7UUNBqCQ6T9Rv/2s4i52g3/jbl+dxU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gvS4Ncc7rmmck0UXQJB57vpHymM24oln9GNXo6XfqVRnraj6JWANi9SuL24r/XXfX5taDbxsCqQOHzGpH/hL/43rA283/zH4K2lSqQjagEjcLDUBu3sHDBD9wqrsR2mGfutIJUXotqSCMU7LJ9ByWM2dHG5GCyWXzymTwf9go7U= 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=aC7P5dJ7; 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="aC7P5dJ7" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e4bed6c9151so34045512276.0 for ; Tue, 07 Jan 2025 21:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736314488; x=1736919288; 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=t23J7xHrW+6du/GAso1cLjFOTcnn40e4CEJt2KBpcE4=; b=aC7P5dJ7mQKkVoU4wWK3kuu05K+XaulFPBYq0yMG0mM5jAVgeVJ5QZIwW5Ui3Ii+vc 5kKIgyVrCfL9ZzEAFnmaREl2Qd6ua8TLCVUBmcER0hTLy79erAmdILAXspzcXMyWVZ6z Ce8e+nDYT3swEFr0eCp3UiM0eRI2aXHLL6R5kT+WZZnqVBeAdpoCDO3ikQreIjtC2DBL og0aIS27W0ulM9oL4EjwtRkBqXcdIOXtlZl3BYk5PxH6CWpawXuL+Jc9qq6adj4ZATpA dPGHhsL4uODF2MIQSeAzdiQRI8E0jXoXyiSeMFWVsC1Wk05FeTKac2BqOiGzDBUVBPa4 oFKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736314488; x=1736919288; 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=t23J7xHrW+6du/GAso1cLjFOTcnn40e4CEJt2KBpcE4=; b=RGjYAMd0caMZYhGSotr3EAL5ueCdMu1Cly+0J6Oa1GmF0NLUVTk39nmDyVXoPcM07m GBvSJmNVm2SgnLfqUsG56BPVA4CoiFWDHJLl4Z4cycRoEXqnAOMZ/x64Krt8gu3n6iZy wXtAcrImqSwsrMsO23ibOqHUgl8V9EcJJU/WcFh0VRb/WPhHYyYI6VzyZ96VY0QfYfhr QyQw6cFvTBVgLa60XqbcpPYBUEwPj+3wykFzPesGoshr/T3pgRXy8epoSmxTma/CtIHY kCXaDYXwTFIsPGCqVpnip99GziKI07tD8uAx7Q1txL0MRkbL8hlT12dgLyevs/mUi2b8 oTyA== X-Forwarded-Encrypted: i=1; AJvYcCVOLbjadpy9LL7fN4iK4LuZWyXDsIqn5Y+xPVysssdlWNpkfqlC1clkA4L7I/KtS2wvq8HcSkTXUic0GE8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzrs2dUplF0uucUdDHvevBg3Vkw/ytoo4O/vhew8GWpFYDaX9o7 Hg6flkuIlyxKraojIeYPUdW1LBOZA4+Dfqm0+kj/lFXZdWstGU+guLxabMjTgt4mrh05m34lbCs M6EiXpg== X-Google-Smtp-Source: AGHT+IGfud90+1PaGtUI5JAJlfl3512z8vfPSPhC61W7tJfmD1UNBvEijqmfYY9XQy9B8gM2/qNunvu08Lxp X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a25:2b43:0:b0:e2b:d0e9:130f with SMTP id 3f1490d57ef6-e54efbf428cmr3266276.0.1736314488295; Tue, 07 Jan 2025 21:34:48 -0800 (PST) Date: Tue, 7 Jan 2025 21:34:26 -0800 In-Reply-To: <20250108053428.1724490-1-irogers@google.com> Message-Id: <20250108053428.1724490-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: <20250108053428.1724490-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 2/4] perf stat: Use counter cpumask to skip zero values 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 , Leo Yan , Yoshihiro Furudera , Weilin Wang , Andi Kleen , James Clark , Dominique Martinet , 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" When a counter is 0 it may or may not be skipped. For uncore counters it is common they are only valid on 1 logical CPU and all other CPUs should be skipped. The PMU's cpumask was used for the skip calculation, but that cpumask may not reflect user overrides. Similarly a counter on a core PMU may explicitly not request a CPU be gathered. If the counter on this CPU's value is 0 then the counter should be skipped as it wasn't requested. Switch from using the PMU cpumask to that associated with the evsel to support these cases. Avoid potential crash with --per-thread mode where config->aggr_get_id is NULL. Add some examples for the tool event 0 counter skipping. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ba79f73e1cf5..32badf623267 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1042,8 +1042,16 @@ static bool should_skip_zero_counter(struct perf_sta= t_config *config, return true; =20 /* - * Many tool events are only gathered on the first index, skip other - * zero values. + * In per-thread mode the aggr_map and aggr_get_id functions may be + * NULL, assume all 0 values should be output in that case. + */ + if (!config->aggr_map || !config->aggr_get_id) + return false; + + /* + * Tool events may be gathered on all logical CPUs, for example + * system_time, but for many the first index is the only one used, for + * example num_cores. Don't skip for the first index. */ if (evsel__is_tool(counter)) { struct aggr_cpu_id own_id =3D @@ -1051,15 +1059,12 @@ static bool should_skip_zero_counter(struct perf_st= at_config *config, =20 return !aggr_cpu_id__equal(id, &own_id); } - /* - * Skip value 0 when it's an uncore event and the given aggr id - * does not belong to the PMU cpumask. + * Skip value 0 when the counter's cpumask doesn't match the given aggr + * id. */ - if (!counter->pmu || !counter->pmu->is_uncore) - return false; =20 - perf_cpu_map__for_each_cpu(cpu, idx, counter->pmu->cpus) { + perf_cpu_map__for_each_cpu(cpu, idx, counter->core.cpus) { struct aggr_cpu_id own_id =3D config->aggr_get_id(config, cpu); =20 if (aggr_cpu_id__equal(id, &own_id)) --=20 2.47.1.613.gc27f4b7a9f-goog