Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4650130rdb; Tue, 12 Dec 2023 05:54:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmXf1WCvovIxwbXLotD1X5UnSj+biIUPIvzKAx39znpb1TRDID1E+q8QjYl/LrLyBFAYh0 X-Received: by 2002:a17:902:6bc4:b0:1d0:acd7:97fa with SMTP id m4-20020a1709026bc400b001d0acd797famr6171287plt.127.1702389276283; Tue, 12 Dec 2023 05:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702389276; cv=none; d=google.com; s=arc-20160816; b=z7vnTpT1qB58I0SZyR6YwAHtoft5lRrWhjNcYYGL8+LH27e7T7TSTtYV3eBPWx2ocw uAHJWGP2KOHZV2jfoIzaFk8pUVVmz3xUt9Vm+09hbguIqfV7VGNf9PuVO+EAZ1FVVExz HLGELJHU538ACPeiwF7FP3N6jnuf0xsk7ezgNA1NhrOGpsiA3lbMaXx4B2pb8igyWIkM yGjKWDAbzT30fAWNCkVECVzVDNvYYdWF8fSOI/e+KTKSG5PUsWV2CPw7mEpItYxsnEXj rpIQjR9VoIwF7nXowQbV4taTcvbGNbDerBNBQSOov6hXKZMrLbdTno9Gu1exFFy/r9/2 o3pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=adyC00tEYo82sp5D5NqQpwkqMvr9NGySbv77V4pWXIg=; fh=5EP3x1uDWWBI9dywppNETb2J5CyUqdqYJErdwPGhe68=; b=p6UPv11hd1RsDEPO0qGCfDRSJXOIi1Og7ElnQNv8Cg9c3iKJhbDfWf/q7S+I7CTM5o DzUzaPfwX3O/MB5guibS8khVfdTnZtmdFVM18cLBkff+GfiAkFzxWeZMRpSe/Y25qx4a fiof+Hgp+DHk7oXR6ZWdBLjbv4iMrLwhYC4dL4SNuVfVLrwaGBCwLR9WmaI/+fwVSSNP n/+ActybnlxZLmH8xqgu6vr+z31w3tN9Qbuoez5jFvVoDdhj2zveG5HHJJbPLSdIuvZs /gDFw7nmgw9AsiS2IJc02gukGU3cSlbgnqP4bLy1iDaz4GD2pNZzrHIOLek20woIpxdx n6fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n2-20020a170902d2c200b001c3411c9b83si21774plc.454.2023.12.12.05.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A4945806A133; Tue, 12 Dec 2023 05:54:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376341AbjLLNyZ (ORCPT + 99 others); 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 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:54:34 -0800 (PST) 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;