Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4367012rdh; Tue, 28 Nov 2023 22:03:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBolNeqsuiwlTxlz4he/MdQF9h6bEtHgb8IAfbXWzDoxa+9PeBP3e4dLeZRZ8rMft0i+KV X-Received: by 2002:a05:6a20:9757:b0:189:bf74:19ce with SMTP id hs23-20020a056a20975700b00189bf7419cemr15688422pzc.4.1701237784324; Tue, 28 Nov 2023 22:03:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701237784; cv=none; d=google.com; s=arc-20160816; b=eKpY7PF26k4TIqP0n5qSNG+fyZVhN3y/jh3Z4/FMa60MSgZxpSVN2swLepoZWmfTFS 1LiST6lvMqMzWAIx1vkPIrXumj2SPP0FXMunro7LcIqPU5nvgjOkg/5/Tvw7BWr/z6sq IH3z6UCSdhmQ5Bj2T3MZmVI8b0mBEMNqpnqxLWH4EDOKSsR4UIZN8tIfjsqzDn2XwkiB a0aSxfmU3ebPgmBoU3GRYcMOxyqPHa5GxG0VJF9jH6i1sQ5ioHFOz/usp8Vwuh/8/2RD +lNFywUlL05tIO6oWgYlvCpZ1A28XLYop8l5Y7x0yO2SlUDiP3jXQMcxY0Kt6Zyj3VKm CJ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=oKpplEK/d17CHcbqAj9G9D9QvSt6Rl/kdbFVrBTbVJE=; fh=uYKNI4aCUAMYZ/8oQVBIse94GgoxWIIZr1zaTbrWG7c=; b=dpbraSO80nkjMl8J0YomSR/7tMuEpupd/6+wsId1KVi02fRIl458Dqk6AgqwP5kt95 BiPAanKMLJib8k1c2d+x6iT4j8hZ092jdUyObJKq3CT1pFJwkn/9pi0V/Irmxu9fLcga FHXwaUmDzXjWqyyBHEM1DdV+ff6GO5fAMT6uAOiXjL31lBryRnEn55BYImKbRtd2XQe/ hhMIaHSRox87ZwVTarK9e1v+i9Y3R7ma1Y2wen0DZ0DHInljGW3KheZPsKYQoM4hO+g3 +uxJcLAqgVGoEun5ZszlZs8eBkXaBUaBzUZbEePWBBqap6RAjO5SBAeVbdS7GXMoJiuP 3pdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="r8F3/jBS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x12-20020a17090a9dcc00b00283a1123a02si650731pjv.96.2023.11.28.22.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:03:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="r8F3/jBS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 506EC808E57A; Tue, 28 Nov 2023 22:03:00 -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 S1377007AbjK2GCi (ORCPT + 99 others); Wed, 29 Nov 2023 01:02:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234942AbjK2GCc (ORCPT ); Wed, 29 Nov 2023 01:02:32 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36AB81BD0 for ; Tue, 28 Nov 2023 22:02:30 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d032ab478fso47665257b3.0 for ; Tue, 28 Nov 2023 22:02:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701237749; x=1701842549; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oKpplEK/d17CHcbqAj9G9D9QvSt6Rl/kdbFVrBTbVJE=; b=r8F3/jBSyyKMVrpC9Hj8PeyFnViEY4aP9iji/6hoW8nwhIQ2Y5C+IygZ3PS3AsmkXp UJ+YGJ+HYj3zd4bF9BNnW4PVCqdQfZgbm2iP3HngZR5Fk5AagGgCvOmmhR/uU4/g8uRR Pp647zAa4QbJ0uB7CPO6cn0EsqAykWQn+H98jGOQp6qzU5zo+aXYA1k31BkGPvPviYBb Gr5LvP46omEIi1m97hCtcpjXoRnwRKsX3R8dfYU+fEHcei1rFx+jQdwBOpJwIogD2sI4 sJ561UJus7eNwWlSwCpjPEezoLYxhBkreEWTHVVjpLK8jODMfQ94TJ+zz3n2XMfRGgpg ZpGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701237749; x=1701842549; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oKpplEK/d17CHcbqAj9G9D9QvSt6Rl/kdbFVrBTbVJE=; b=Oujn7tqGhEr6zpe0NJ5wwd5Xq4+sEzF3GXAcz1MmEKlfXy8lrcC96e7u7BZQ6VIZX8 YjKU1RYlnV6ymqmIFhsux3qo3XuGS3rThEpKmXEXG3O6OIbJP7QtDVqK0/9Cp2SvLTYI 7T6H0c2errWBYhFyZgx80sE2uSRISkeoOSaZ22NGLOCEYBScJBDzEdS4xPD/eNHyL99b yrDM1GzZQY4b6OD7EsutqPU/Uo9ZV8i+PwZyYrNe+qZ3bZDU5wMdvbPiqnjvyFQ3R6/w JKYd7hqu3uHzInuE2FaQxvODvJMW55LEmKzphhVcLt6TIPuEOEtEZTGkPLivjQh/9c2K jbfQ== X-Gm-Message-State: AOJu0YzCqMr8tWUyFO56nmxpOXhFjBKQx+viMZAFxUkr4YVRfnaKj0KO PSFXfCY7/4cp17WhiCdM0MIL7UN0eE4s X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:763b:80fa:23ca:96f8]) (user=irogers job=sendgmr) by 2002:a05:690c:fd3:b0:5cc:41c1:606 with SMTP id dg19-20020a05690c0fd300b005cc41c10606mr691036ywb.6.1701237749390; Tue, 28 Nov 2023 22:02:29 -0800 (PST) Date: Tue, 28 Nov 2023 22:02:03 -0800 In-Reply-To: <20231129060211.1890454-1-irogers@google.com> Message-Id: <20231129060211.1890454-7-irogers@google.com> Mime-Version: 1.0 References: <20231129060211.1890454-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v1 06/14] libperf cpumap: Add any, empty and min helpers From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , 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" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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, 28 Nov 2023 22:03:00 -0800 (PST) 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; +} + 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; -- 2.43.0.rc1.413.gea7ed67945-goog