From nobody Mon Feb 9 05:59:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95B30C77B7C for ; Wed, 24 May 2023 22:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236848AbjEXWTG (ORCPT ); Wed, 24 May 2023 18:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236660AbjEXWSs (ORCPT ); Wed, 24 May 2023 18:18:48 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AA4194 for ; Wed, 24 May 2023 15:18:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-556011695d1so28678687b3.1 for ; Wed, 24 May 2023 15:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966724; x=1687558724; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=L9hyOxVMtag083U3DrBABQpzrKUd2k9oDsc9+XJnAEA=; b=LtpxsdvrVIHpyYlb3xLC8sqG58Bzm9j5cBtRTcbu3rsLbnqcZy2LpSxSNxzA50XG5w /AUONv2Gk38DiQ/sYYuLmGBrZ/dzL4pyU88PhOjIqusuhk7jVExQGDVPzetaywcYi+Un wlZ8DlLrDhrD5XMNTk6j7Y8NGCryNgqHWNZXjk3X79vkNmKHzrZ1avClFhIeEuor36PF wbHuvGb3DpL5LShCo/zH9iD455YuPM9wYpj4zAl6NMTsAZMedl+TUr0q6YbTi/3QCBUV 5Bb5M5U55AZMpwbXdhswy+/+aqWe3ropFnOYFQj4k/s1Y7okZgYYUlSi/pGomDTdRQJB Q/ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966724; x=1687558724; 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=L9hyOxVMtag083U3DrBABQpzrKUd2k9oDsc9+XJnAEA=; b=gVkDD7xVSWFCfZG4fkqyigu40WEgbnrm+nG5IWV8ZpWPa18vzN6zKrKqD9QrvsEfXW hXg8cH97I70cccwDvI+7pEhVk288RUuBksy2qFvKWRqPsudZwBmyXKqevxpVEmaCLpBv gBDVTgme9W80DH4sFUBz0HzX+6oxcrsoxOeoE+PBwp8tBuACciG8/aRHszkn+GMbzCtj L/Mv8XI3A9axdzBlt+CPVQawCjKpUgUFgFvnRzTk8I2snAlaVes4hP9+/Thy6GQ3y5b7 q7gx3wWh7DZ0H/F3s+kA1dIN/WhmVvbhllBbmAz+SIiOWltzwa8xN6YmY9FffS/Bcz9m RRSw== X-Gm-Message-State: AC+VfDzsZZzdXKdH7xSMvLnwYLCBO5YzzsqgjPGp8VpUZHEWxblB6inq d6z4GuIaYv7ecM1sBJfztl4g17eaGrU/ X-Google-Smtp-Source: ACHHUZ4A9xBsf2NqNhBKrjOga52LfeOavCka+IP0c2dGDJ+fOrU4kiCHN5RkZ7kCcC0QXT4WglaRezW0Dn7i X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ad57:0:b0:561:be13:2fd3 with SMTP id l23-20020a81ad57000000b00561be132fd3mr11098955ywk.1.1684966723958; Wed, 24 May 2023 15:18:43 -0700 (PDT) Date: Wed, 24 May 2023 15:18:00 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-5-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 04/35] libperf cpumap: Add "any CPU"/dummy test function From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is common in the code currently to test a map for "empty" when in fact the "any CPU"/dummy value of -1 is being sought. Add a new function to enable this and document the behavior of two other functions. The term "any CPU" comes from perf_event_open, where the value is consumed, but it is more typical in the code to see this value/map referred to as the dummy value. This could be misleading due to the dummy event and also dummy not being intention revealing, so it is hoped to migrate the code to referring to this as "any CPU". Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 5 +++++ tools/lib/perf/include/perf/cpumap.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 48595a3ad69c..7c8237a9e902 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -342,6 +342,11 @@ bool perf_cpu_map__equal(const struct perf_cpu_map *lh= s, const struct perf_cpu_m return true; } =20 +bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map) +{ + return map && perf_cpu_map__cpu(map, 0).cpu =3D=3D -1; +} + 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/include/= perf/cpumap.h index d0ae9552f8e2..3b7c965a17f2 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -13,6 +13,9 @@ struct perf_cpu { =20 struct perf_cpu_map; =20 +/** + * perf_cpu_map__dummy_new - a map with a singular "any CPU"/dummy -1 valu= e. + */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); @@ -25,11 +28,18 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersec= t(struct perf_cpu_map *or LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *c= pus, int idx); LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); +/** + * perf_cpu_map__empty - is map either empty or the "any CPU"/dummy value. + */ LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *m= ap); 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, const struct perf_cpu_map *rhs); +/** + * perf_cpu_map__any_cpu - Does the map contain the "any CPU"/dummy -1 val= ue? + */ +LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); =20 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) =3D 0, (cpu) =3D perf_cpu_map__cpu(cpus, idx); \ --=20 2.40.1.698.g37aff9b760-goog