From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796358077; b=e5avBAqMPd9lmeAlTGWr0XzsZo/cXs2GbXIaVpDeuplW0JbcwJse5OSarb1Ek+TvVBMH NTZl2K7A1uokFpIQ8T39RuIzxlI/HVL9b0eQmqvow4GGA6FUU+fsCSIjOacn/OBUDbuKH TXev7xDS+UK6YOuUo6BtU6MBI4aspxCsMbOLxesJubQ0CI9trpu0AOZL+u9l0J/Z96Jzb OracVqZTQeDP6k2wxY0kbdTtHsiHNITbaa/TaSMXPUtUs7TJPUyGzJ+PeK+M9UMCOybIh WKWVeYIjDFdQsCGlhe/kKY8dLAJ2Dp1lF1SjQDZH/NUzBusdLL4SE4MoHlsJCU27wvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358077; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=qYpCEPzi72AfomYVVHc10my4R/1yrjPTZ7L66kCac84=; b=KixuHfWnNwBsctxPME61KdfnyUG6kwDPymH4vjuEKI2suTIhwfaENwtunPNybRy+LUdk 1ufO/WtrV2573BrB476snygzwecLtO4VPbTBuIpVT9AyOanR5KG7/BT2Bs7I4iWI1aAiA 4DWRZTyEtaxpJSvetea99JX59osWksZbYrR7qb3bytJ+W2Qa9gacgaU+Ptp2Zdq78zQBW AI0HYrszr1jIXwGysqqc2xvmii+gm1+Y0iAmEXMePj7wbR9m9BDG8ER7/CEp7euxiK5Ma eO+i8znYQO0ZsZAlaKD38j9MQ1TMZuuvy9Z0di52epLV4eEa/T3oGIEJBQ4rYkWGViA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l3Rgx9Gf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4013606A32F; Fri, 4 Dec 2026 04:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l3Rgx9Gf Received: by smtp.kernel.org (Postfix) with ESMTPSA id B68361F00897; Fri, 4 Dec 2026 04:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358077; bh=qYpCEPzi72AfomYVVHc10my4R/1yrjPTZ7L66kCac84=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l3Rgx9Gfl47gypaO4ptsHHIFK+E1z/mVk1tjhatct2017jy7O2y44fHyLW+rJGkwN iTFwd6nFQ9ZRdFzI2iNOobL/cqpPEsGEDlccdDvB1XPXoKjZtmesueonvZgCgOV7JI v3q6BoNGCO/M6HgqJaqTUnPYZqs0HhG3gsHJ6KVtyO3QP9aUAnDQG1DfoPs4zJAPOB rpPMCjCdv6ab1lTUZUHhUem487jirUALDLIR48SNcCGx7/M98or6ObUC8a8d3pY3+r 8XLBUSWJsVpdwGrSjrSxMKBkbV81r6fd/lCmKFBRpAaIljGadOyROoPE0REqkw/zFz 5n6WTzAO8AohQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Ian Rogers , James Clark , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Athira Jajeev , Atish Patra , Changbin Du , Darren Hart , Davidlohr Bueso , Huacai Chen , Ingo Molnar , Jiri Olsa , John Garry , K Prateek Nayak , Kajol Jain , Kan Liang , Leo Yan , Mark Rutland , Mike Leach , Namhyung Kim , Nick Desaulniers , Paolo Bonzini , Paran Lee , Peter Zijlstra , Ravi Bangoria , Sandipan Das , Sean Christopherson , "Steinar H. Gunderson" , Suzuki Poulouse , Thomas Gleixner , Will Deacon , Yang Jihong , Yang Li , Yanteng Si , bpf@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case Date: Thu, 3 Dec 2026 23:21:10 -0500 Message-ID: <20261204042102.2586131-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120243-tricking-diabetes-c833@gregkh> References: <2026120243-tricking-diabetes-c833@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Ian Rogers [ Upstream commit 5805c82513c444333efb086017be8d666336858a ] When iterating CPUs in a CPU map it is often desirable to skip the "any CPU" (aka dummy) case. Add a helper for this and use in builtin-record. Reviewed-by: James Clark Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexandre Ghiti Cc: Andrew Jones Cc: André Almeida Cc: Athira Jajeev Cc: Atish Patra Cc: Changbin Du Cc: Darren Hart Cc: Davidlohr Bueso Cc: Huacai Chen Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: K Prateek Nayak Cc: Kajol Jain Cc: Kan Liang Cc: Leo Yan Cc: Mark Rutland Cc: Mike Leach Cc: Namhyung Kim Cc: Nick Desaulniers Cc: Paolo Bonzini Cc: Paran Lee Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sandipan Das Cc: Sean Christopherson Cc: Steinar H. Gunderson Cc: Suzuki Poulouse Cc: Thomas Gleixner Cc: Will Deacon Cc: Yang Jihong Cc: Yang Li Cc: Yanteng Si Cc: bpf@vger.kernel.org Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20231129060211.1890454-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Stable-dep-of: 82b4a28e7588 ("perf record: Reject CPU indices equal to the mask size") Signed-off-by: Sasha Levin --- tools/lib/perf/include/perf/cpumap.h | 6 ++++++ tools/perf/builtin-record.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 03aceb72a783c..60c4e05470102 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -31,6 +31,12 @@ LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_c (idx) < perf_cpu_map__nr(cpus); \ (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx)) +#define perf_cpu_map__for_each_cpu_skip_any(_cpu, idx, cpus) \ + for ((idx) = 0, (_cpu) = perf_cpu_map__cpu(cpus, idx); \ + (idx) < perf_cpu_map__nr(cpus); \ + (idx)++, (_cpu) = perf_cpu_map__cpu(cpus, idx)) \ + if ((_cpu).cpu != -1) + #define perf_cpu_map__for_each_idx(idx, cpus) \ for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index fa2a066005ad0..eac672d02e94b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3545,9 +3545,7 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp if (cpu_map__is_dummy(cpus)) return 0; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu.cpu == -1) - continue; + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) { /* Return ENODEV is input cpu is greater than max cpu */ if ((unsigned long)cpu.cpu > mask->nbits) return -ENODEV; -- 2.53.0