Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4700228rdb; Tue, 12 Dec 2023 07:07:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj76xkBr+N+eRY7sn9vkjqVIBsi6vMDQDRZGpyrhtHR8nM+XRo+fCBMYEUeU9cZkECk4sv X-Received: by 2002:a17:902:ec89:b0:1d0:aa79:6ef5 with SMTP id x9-20020a170902ec8900b001d0aa796ef5mr2894784plg.123.1702393632675; Tue, 12 Dec 2023 07:07:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702393632; cv=none; d=google.com; s=arc-20160816; b=xMDN/g/oSFZA02rHWX3BoaN2KPr6fiL8lXxcG6W8Fj+JSYNUnKAz+gnY+zee+mAD6I iQTdPP9FQrs/3JLSTH7ynHvI7FIpoNji46BqwrF558bEaTEFmbwWwI45/s0vVfbC3oVe uS75e+gcZ8GP6VeHXHe9SSJxC+h0kVimtBsl2eG3MsC1kXQnKmHT3iOKnoYr9PBoJOpa NZL7hSV7EkQWyMfRRDw5HdqIxdVWz+05dD73SBjPP4En/RoHdIw2451Kn1AF0nTFTVc5 NO7pBmw/jWQko5FLM7QUIyDWtxioe2ZdCq3j0K79kPBgTexpJoGVw6nc3Gz/dI5MpqYN BbKg== 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=dqlAaEK4AfutzoJDtRhcMe8xhH4CQz9XdyriMVkMPbA=; fh=5EP3x1uDWWBI9dywppNETb2J5CyUqdqYJErdwPGhe68=; b=HXjmqNDrcMGD4YWD+rmvPbPV33EG7UUblgicpkyag8XkP5d0Dc1kXz3EV1avYg/Fyz 9Jj0IVG0OL2eJQkiio8Yzkt0TDHcp29j36vQiNVq//ueJuzItoNFVrBVyGbCO4BVQnhR ZRjxqkdIJGEAf6yEFkXVe6pdsBBfdDdg7O7OcMlEb3zMd97R7GvYR2WkuPxrOKd++dzz T1SdYXIrinRBcE4VgCKUisk2qiMEWPexUbG6iaRfVFGH6IgqkxxVDX5x7mcC29fG8Qd0 f/jErCiIwtAgUxpH1g0eKhUgGQdWrIgx3DmFTvnJwJ+WmNcA0Dw8tRXkmElglWlJLF8j 8cmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ba8-20020a170902720800b001d033061b35si7977918plb.49.2023.12.12.07.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 07:07:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id B04EE80A5311; Tue, 12 Dec 2023 07:07:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376461AbjLLPGo (ORCPT + 99 others); Tue, 12 Dec 2023 10:06:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346667AbjLLPGn (ORCPT ); Tue, 12 Dec 2023 10:06:43 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F367BE3; Tue, 12 Dec 2023 07:06:48 -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 ED55C143D; Tue, 12 Dec 2023 07:07:34 -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 B9F9B3F738; Tue, 12 Dec 2023 07:06:43 -0800 (PST) Message-ID: <94e3745c-8c2b-bdf3-f331-1cbe56574d48@arm.com> Date: Tue, 12 Dec 2023 15:06:39 +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 06/14] libperf cpumap: Add any, empty and min helpers Content-Language: en-US To: Ian Rogers References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-7-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-7-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 07:07:01 -0800 (PST) On 29/11/2023 06:02, Ian Rogers wrote: > Additional helpers to better replace > perf_cpu_map__has_any_cpu_or_is_empty. > > Signed-off-by: Ian Rogers > --- > tools/lib/perf/cpumap.c | 27 +++++++++++++++++++++++++++ > tools/lib/perf/include/perf/cpumap.h | 16 ++++++++++++++++ > tools/lib/perf/libperf.map | 4 ++++ > 3 files changed, 47 insertions(+) > > diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c > index 49fc98e16514..7403819da8fd 100644 > --- a/tools/lib/perf/cpumap.c > +++ b/tools/lib/perf/cpumap.c > @@ -316,6 +316,19 @@ bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map) > return map ? __perf_cpu_map__cpu(map, 0).cpu == -1 : true; > } > > +bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map) > +{ > + if (!map) > + return true; > + > + return __perf_cpu_map__nr(map) == 1 && __perf_cpu_map__cpu(map, 0).cpu == -1; > +} I'm struggling to understand the relevance of the difference between has_any and is_any I see that there is a slight difference, but could it not be refactored out so we only need one? Do you ever get an 'any' map that has more than 1 entry? It's quite a subtle difference that is_any returns false if the first one is 'any' but then there are subsequent entries. Whereas has_any would return true. I'm not sure if future readers would be able to appreciate that. I see has_any is only used twice, both on evlist->all_cpus. Is there something about that member that means it could have a map that has an 'any' mixed with CPUs? Wouldn't that have the same result as a normal 'any' anyway? > + > +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) > +{ > + return map == NULL; > +} > + > int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu) > { > int low, high; > @@ -372,6 +385,20 @@ bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map) > return map && __perf_cpu_map__cpu(map, 0).cpu == -1; > } > > +struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map) > +{ > + struct perf_cpu cpu, result = { > + .cpu = -1 > + }; > + int idx; > + > + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { > + result = cpu; > + break; > + } > + return result; > +} > + > struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) > { > struct perf_cpu result = { > diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h > index dbe0a7352b64..523e4348fc96 100644 > --- a/tools/lib/perf/include/perf/cpumap.h > +++ b/tools/lib/perf/include/perf/cpumap.h > @@ -50,6 +50,22 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); > * perf_cpu_map__has_any_cpu_or_is_empty - is map either empty or has the "any CPU"/dummy value. > */ > LIBPERF_API bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map); > +/** > + * perf_cpu_map__is_any_cpu_or_is_empty - is map either empty or the "any CPU"/dummy value. > + */ > +LIBPERF_API bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map); > +/** > + * perf_cpu_map__is_empty - does the map contain no values and it doesn't > + * contain the special "any CPU"/dummy value. > + */ > +LIBPERF_API bool perf_cpu_map__is_empty(const struct perf_cpu_map *map); > +/** > + * perf_cpu_map__min - the minimum CPU value or -1 if empty or just the "any CPU"/dummy value. > + */ > +LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map); > +/** > + * perf_cpu_map__max - the maximum CPU value or -1 if empty or just the "any CPU"/dummy value. > + */ > LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map); > LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu); > LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, > diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map > index 10b3f3722642..2aa79b696032 100644 > --- a/tools/lib/perf/libperf.map > +++ b/tools/lib/perf/libperf.map > @@ -10,6 +10,10 @@ LIBPERF_0.0.1 { > perf_cpu_map__nr; > perf_cpu_map__cpu; > perf_cpu_map__has_any_cpu_or_is_empty; > + perf_cpu_map__is_any_cpu_or_is_empty; > + perf_cpu_map__is_empty; > + perf_cpu_map__has_any_cpu; > + perf_cpu_map__min; > perf_cpu_map__max; > perf_cpu_map__has; > perf_thread_map__new_array;