Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4885880rdb; Tue, 12 Dec 2023 12:03:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeNUMF2DdhjsIne6oSyW4y6n5i8jzcLiksJhq6Yxo9HHZ6MoHRYpc1M5rweH8J2npstBMA X-Received: by 2002:a05:6870:c10c:b0:1fb:747:7d04 with SMTP id f12-20020a056870c10c00b001fb07477d04mr8561687oad.2.1702411393021; Tue, 12 Dec 2023 12:03:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702411392; cv=none; d=google.com; s=arc-20160816; b=Bm01d4CFo+B1q1JCAMrs3UxtAwbcE/+oh0oUWneqg4DpAsLm1AxSh99Goi75xTpEho xZ1EmYYefzUhRafmatps+ZqOHctufx6gz8jUCZZ5MJg5Nbs9xo5OxFy1gqiOA+7xwDcC cn1h2fPa45zbGevMziBEh0os/ZOYEx1wv7Jsx0lA7aWt6Uvuaeq3ReQYH0RxG53iqfxv e3QC10g6qvSyEcLP0DXP6Bab+re/yPIfVM/8meRmFVH9vzoo+GgjWie9QXZGXJVqhctU UCtb1CEZkfPgJsfDP3jjqPylIg98KxwWa5SopMJGzHvfW6uJmZzcKCtnxUUILp7fnPBR fn4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Bv1+Mtk2Gb5EiPRPIvE+IzzrHt4kY36IyFcki/03XAg=; fh=cbSbzzQTNzL0KNAuE9cxfEu5x6TvDttt6j2jrzuXqlE=; b=y9YqJqp39l3JDC4/3w4m6QxiV8tv7r4FfoZdVXp7jif8XmLFQQ00QKZh8DcYptnFsx KMxynMEd8ZjluOb9wsorWofqAPy2OuC+fxJZ29gDqH0DBigUQp2RyWoJn+0+Wm+Unzk8 kRbMJ3qQfX+bBbqnpHRnjCcOD3ctVUoIUnYQxKSC5t6hIwc/VupcFe50rB2i38IROeWv Yz/ucco1IiTYQ1GPTsfrJo03ZuNYHwVdk69ZroKhZ9SYB5kOfQx5zoAYj9pej8LFFuO+ TRAHiWKn+QTenpE2IFCuc8estW6g0XoYqBhplC/C9LjODzes1fntibzJ/RcrWgVhNBX2 nnqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zMnWj8Xh; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t4-20020a656084000000b005c21d7d1114si8209372pgu.818.2023.12.12.12.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 12:03:12 -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; dkim=pass header.i=@google.com header.s=20230601 header.b=zMnWj8Xh; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B59068047476; Tue, 12 Dec 2023 12:03:11 -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 S1376781AbjLLUDC (ORCPT + 99 others); Tue, 12 Dec 2023 15:03:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjLLUDA (ORCPT ); Tue, 12 Dec 2023 15:03:00 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 333ADB7 for ; Tue, 12 Dec 2023 12:03:06 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-551d5cd1c42so2441a12.0 for ; Tue, 12 Dec 2023 12:03:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702411384; x=1703016184; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Bv1+Mtk2Gb5EiPRPIvE+IzzrHt4kY36IyFcki/03XAg=; b=zMnWj8XhLMYtIWUzrVfUFw1V40ASR+nE/TEu1+mMnvXF6w0Tm3h0WG3Fu62WhqMLNn AKcd4Bk2Z5Wontkn5TniSMfooYhR8b7s3z5FApYJX/ZyNg/am3lWmEtY8fY8xhtw1TPg TjViyhOqjyAejoa2oZOkTi+8if4XWHBZ4nNRv/3gXvKV+r7OQW0tkqkj1t7DkfEDoRPv R/mNPSHbdqfbH894ku7wqn/0jFpHkSm0iCb7NhbRbOb8KMseBZ4BiOrMyPuTbF5gLjWX 2m11eIrM90jtI+fZpqS2xzcyrlUqDKLzi+ufrktfk92qR+l9MiBCTlcbxOJG97BoZGlw oizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702411384; x=1703016184; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bv1+Mtk2Gb5EiPRPIvE+IzzrHt4kY36IyFcki/03XAg=; b=ZstJWpldBbvNctm68GopcHySfU0VxAYqVWsMFHyi3YwFKSx/WaHxMDd79g6po9kvHR b5wMSqEoU/h8MivSJqPKsxIRzznCX8PimhDdneB+YMz2POlu8+hHS2zBVhqQ4WsjCBHM OfyudzZy+PH0zJNGXUiRj9xh6SWnftgWUwEps+uFJZvIn6rJLYu1hHfevR7zQr3Y9K9I z6Y9AVyG6Cvl1fqd10VNVIbpN4V4MHhvUQyv4h+Qvmi+qOjenGgzw1WHAzboj/SuiBhh wukT9Y6DaoGoP8/FSi4ueIDRvvv0d8J/s2n42rda2vF9IEG+jfTS5+xBt0nNLipGEUhO 4U8w== X-Gm-Message-State: AOJu0YzNF7FAWCPCbsxk/Xa/Jfk31WkUL24KuWQDfJE3vGwR8sxHWUmh /9iQ6AQ1k0mDQ/7wbuAVH3TTtTek+s7hwC5c7EwUnQ== X-Received: by 2002:a50:d7c3:0:b0:54a:ee8b:7a99 with SMTP id m3-20020a50d7c3000000b0054aee8b7a99mr392000edj.0.1702411384344; Tue, 12 Dec 2023 12:03:04 -0800 (PST) MIME-Version: 1.0 References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-7-irogers@google.com> <63d7fe55-719e-43f8-531c-eb7fa30c473a@arm.com> In-Reply-To: <63d7fe55-719e-43f8-531c-eb7fa30c473a@arm.com> From: Ian Rogers Date: Tue, 12 Dec 2023 12:02:52 -0800 Message-ID: Subject: Re: [PATCH v1 06/14] libperf cpumap: Add any, empty and min helpers To: James Clark 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 12:03:11 -0800 (PST) On Tue, Dec 12, 2023 at 6:01=E2=80=AFAM James Clark w= rote: > > > > 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 s= truct perf_cpu_map *map) > > return map ? __perf_cpu_map__cpu(map, 0).cpu =3D=3D -1 : true; > > } > > > > +bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *m= ap) > > +{ > > + if (!map) > > + return true; > > + > > + return __perf_cpu_map__nr(map) =3D=3D 1 && __perf_cpu_map__cpu(ma= p, 0).cpu =3D=3D -1; > > +} > > + > > +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) > > +{ > > + return map =3D=3D 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 =3D= =3D > 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? We can add an assert or return NULL for size 0 in alloc. I think I prefer the return NULL option. It should never happen but it feels the right defensive thing to do. Thanks, Ian > > 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_c= pu_map *map) > > return map && __perf_cpu_map__cpu(map, 0).cpu =3D=3D -1; > > } > > > > +struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map) > > +{ > > + struct perf_cpu cpu, result =3D { > > + .cpu =3D -1 > > + }; > > + int idx; > > + > > + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { > > + result =3D cpu; > > + break; > > + } > > + return result; > > +} > > + > > struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) > > { > > struct perf_cpu result =3D { > > diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/incl= ude/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_c= pu_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 pe= rf_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 per= f_cpu_map *map); > > +/** > > + * perf_cpu_map__is_empty - does the map contain no values and it does= n'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 th= e "any CPU"/dummy value. > > + */ > > +LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_ma= p *map); > > +/** > > + * perf_cpu_map__max - the maximum CPU value or -1 if empty or just th= e "any CPU"/dummy value. > > + */ > > LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_ma= p *map); > > LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, str= uct 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;