From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5573C4332F for ; Tue, 12 Dec 2023 13:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376348AbjLLNyZ (ORCPT ); Tue, 12 Dec 2023 08:54:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376327AbjLLNyY (ORCPT ); Tue, 12 Dec 2023 08:54:24 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9CC0283; Tue, 12 Dec 2023 05:54:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92A02143D; Tue, 12 Dec 2023 05:55:16 -0800 (PST) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 65A483F738; Tue, 12 Dec 2023 05:54:25 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 13:54:21 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v1 05/14] libperf cpumap: Add for_each_cpu that skips the "any CPU" case Content-Language: en-US To: Ian Rogers References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-6-irogers@google.com> Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=c3=a9_Almeida?= , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org From: James Clark In-Reply-To: <20231129060211.1890454-6-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/11/2023 06:02, Ian Rogers wrote: > 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. > > Signed-off-by: Ian Rogers Reviewed-by: James Clark > --- > 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 9cf361fc5edc..dbe0a7352b64 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -64,6 +64,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 8ec818568662..066f9232e947 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -3580,9 +3580,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;