From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A61B5606A322 for ; Fri, 4 Dec 2026 04:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PvT9xktB; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lm2QWp1k DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=nH1fYq9KOpv+/NRLdV1/jzct92LNZx3GKk3gLWnTb6Y=; b=PvT9xktBXM5u0z JM2gfQ6gNWF7yF2c7rBrxowiA8hvJjQKCyiH3NNWYT0gUrkw+ptFM3dP2ob1Y2IEh2I7AFBY5N/Pu q5WTtJI7bBAsd8efp567pm5UH9ElZOSB/Y12a24KSGZ/t+XyXm/HCmUEP0MjbeXMBKcqDmwAfUACg a7V0ohPRGa62Uy7BCX7xCy57cscacOtcm/OLWVtdQu9A41CHPtpv+IP2Zs/oxpak9Rhhog9kY9a47 P+9eR+1VqgwDMnITbyPwnY3/gwU3xf7r04nsl2cx1VBDKH7/pP4i6MNN6e5eevHH7Xl+knJNyofIJ xIhW7Ga/oLfujSmcGX7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZKiK-0000000Gazg-3p69; Fri, 04 Dec 2026 04:16:05 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZKiE-0000000GazG-3ADB for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 04:15:58 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id E1D94605FD; Fri, 4 Dec 2026 04:15:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1808D1F000C2; Fri, 4 Dec 2026 04:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796357757; bh=nH1fYq9KOpv+/NRLdV1/jzct92LNZx3GKk3gLWnTb6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Lm2QWp1ke/qxV9ct1umQ0YVbA2krv84l3FKwziixLiuFz4kZUVEz7Uq2VzJkResz2 wIMXODthi6C1+854xHJ0bkeK0AsHWPQIEwA50R59wRKBI/K7MJRK2h1OjcI55UZR07 sRRgBSmMhtRE3EqHYjp77f/fFyBGvfhjBttRsK1S8sfairyRJvW6Y1AuiGmw+eXgjb RO8zJL1eOzMXOUP6v4HwhJUv3qCf9JYTEEfAe54CiqY3OLOlZRzrnaCExRkgOe2tly +5feA+Jbf4vIAfb/03+Q8brC8y9PFZ2fSuNBTWCveZjc5dPozuoNcjduwOnmbiQ1VN rZQi9fieASUrQ== 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.6.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case Date: Thu, 3 Dec 2026 23:15:50 -0500 Message-ID: <20261204041543.2574571-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120242-finite-impure-8f05@gregkh> References: <2026120242-finite-impure-8f05@gregkh> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 e38d859a384d2..4e0e4c3533973 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -51,6 +51,12 @@ LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); (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 ddaf38f92898f..30e57aae7f252 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3531,9 +3531,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