Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4654133rdb; Tue, 12 Dec 2023 06:01:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtsXmheoCTEIBHwRRf7Dh5qbF3w63Lb2Xxi+vQIR4chPtv/QA9/CyTmctq9cPqIupNwQ7q X-Received: by 2002:a17:90a:5787:b0:286:742e:47b8 with SMTP id g7-20020a17090a578700b00286742e47b8mr4786743pji.3.1702389678483; Tue, 12 Dec 2023 06:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702389678; cv=none; d=google.com; s=arc-20160816; b=zy9m3+URmy9hNg9qnFK9PgjwFur/ebRjoADJKZQAaT0CZOSS+2AtE4Nhelhff+kNDm gbe4gJDvotAqILH20Otjy4wC+SY/uo8SPuSB7k9h+0OBUVa5bXIu+UMjF/TMUxy7AvwU HQkA4H3Nb2NPcbBLziYStQKV/9x8JEqmyAXxf4+cOI+y9+ZUKPGN7+0lhWuYgjQ7DBal GWwfZoszqV61fo0vQMorXu0RSs9SxO183nlqZ8vZxjRlATidIRgt13GsV23IZMEtiN61 DUtb3y5hC6UlUbGpb5gwSAFbgWXApT04v0iEXs2KjiFASSUhFGRhcWEplIZFs8ikVahh CT/w== 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=VqHeYd+LaPDlS43quea80p0hx2TTK5Al4rgxyZmi4qM=; fh=5EP3x1uDWWBI9dywppNETb2J5CyUqdqYJErdwPGhe68=; b=Amio95Ybh/fYJcGIIlhKqQB2Xx/bshovRKwKIz3X2vKeJJiBpHrrABvrVCswzXSuCm Zw9rld+TTzYvRShjwk1EZTHCWD3l0WG7uxuEy04k0cNd9SdGC5caMwr2ZwXKGC/6SNvo Z3PR7dV/RFggtrWl0ltn92RghvPD64UkSAEzY38qyuZNhWVRy+q0kJvdU4L2CrcuuP5t 6cmphK/jxzafq361FCkSkC4Yqn7Z9/4aT78cjxipXfMQ8xYhi/TWrGsu1X344uw/pwrE rzXTmLDr+5mkVTEgvLzsb99Sz80RtTzIdX4tL5mOiLsj9VI8Xtv9S7XVSzImAhcWY40J J5Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l9-20020a17090a49c900b00286da82b44esi963620pjm.182.2023.12.12.06.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:01:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 50628803B36D; Tue, 12 Dec 2023 06:01:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376377AbjLLOA7 (ORCPT + 99 others); Tue, 12 Dec 2023 09:00:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376341AbjLLOA6 (ORCPT ); Tue, 12 Dec 2023 09:00:58 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C620B3; Tue, 12 Dec 2023 06:01:04 -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 9232D143D; Tue, 12 Dec 2023 06:01:50 -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 39A933F738; Tue, 12 Dec 2023 06:00:59 -0800 (PST) Message-ID: <63d7fe55-719e-43f8-531c-eb7fa30c473a@arm.com> Date: Tue, 12 Dec 2023 14:00:55 +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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 06:01:15 -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; > +} > + > +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) > +{ > + return map == NULL; > +} > + Maybe it doesn't currently happen, but it seems a bit weird that the 'new' function can create a map of length 0 which would return empty == false here. Could we either make this check also return true for maps with length 0, or prevent the new function from returning a map of 0 length? > 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;