Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp477300rwd; Sat, 27 May 2023 00:42:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MBCKWTIirmLGu8bzfZWR5KHS5lSQvT36PflBgA/F9139Qb9WTyqUSpdMspKa2relny6rD X-Received: by 2002:a05:6a20:840e:b0:10f:5fc:695e with SMTP id c14-20020a056a20840e00b0010f05fc695emr2548684pzd.7.1685173323781; Sat, 27 May 2023 00:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685173323; cv=none; d=google.com; s=arc-20160816; b=gKVzw1paGYVmm2voFioUW3V6RozkstJsLZQ2vtaniYBp4V7Q9JY4FNslpwAFIVgsZo VGMF6ko4QDxjivzbZvjVhEz/azDFHxOsRxQMfbTwTHdtoGao5iuKFh2NJq1D6QF2++Vf MP1g1fu4O7fBNNkdX1Mda0mWTalFmlujHGApS6cgBT0xnOlrmUTj3de7WyX3iU/V4vjB HndyPQTkYzU99kUeC0ai/h6CM/wAbk26AO3OJInM7jTFWYzny+BulMzUMrp0hmO22/eZ FNU8Yu6IAO+F4MPG3sh/HwyRaglkCl5LTlItHcmTmWIBXt7Fe2rIObQ9xUhnIwY1MZJD Dhgw== 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=h/IfzR0PqTlQjshfXa1Gk+Wb9K4Bgq3zLGbFa1hs2Y0=; b=bdERZDzTD8rDHUQNcFA/yE3k504yAy9iJ0j/sFDviAg9ahh0FhzXGBcOOJIZBVij+W BhmBHWkZkJ7uBX9+t4aWbNuxnU9O5y+E7cfcOO7k/Fsv6FMbEuLOhQcvuBCwyqsJRL52 TbiaVrPsTm+rcKTQrkfXxBLJYXMNRowi47rxoAXc7q0SOM3p3qHh9lQL6nTruVO89abi lFQi/3rkHYyke/8cHnrtj2B9eU0IeO1BDc9ALRLfJsdX8h6V13x5pLiOYhuueQyNeMnV DRqNGcSMjzVRXql+7m4c+NpV8A92DdjvQ1NG7r4J0qIA0KMQqCIjGeBT6odiYePuvH6l 5Kgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="uv/J/j69"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020aa79a4b000000b00626007418c3si2518727pfj.289.2023.05.27.00.41.49; Sat, 27 May 2023 00:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="uv/J/j69"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbjE0HWr (ORCPT + 99 others); Sat, 27 May 2023 03:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbjE0HWl (ORCPT ); Sat, 27 May 2023 03:22:41 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5177213A for ; Sat, 27 May 2023 00:22:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bad475920a8so1165528276.1 for ; Sat, 27 May 2023 00:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685172159; x=1687764159; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=h/IfzR0PqTlQjshfXa1Gk+Wb9K4Bgq3zLGbFa1hs2Y0=; b=uv/J/j690VyP3Vt8AeocE8BDGK93yzo4ik+vLkbLL6lR94OjspqqjeFZ5S+D5Jxr9A DNQYqLa+7rTD3UJxJFn/LfenDBwFoHgd91XRaJXPShrvCgEWCoxD/V+KBS5+a8rdK5pY yi55i5UjKsWgbkbfV4Ru6wvUjiQC3wOy/vHfONVDQajAJW4Rj1JgPK2lCp0H8k9SatAY AXBaMn2h+tqFDCzM4Xn5wsDqYTLCkGr8UstLqHZZI+4UKhmUo3DR2DQQ34PVba5ZTi7q vVvCk1gzwNcJRRTS8aPGVQqksnFjP9/Byl4R0ppWxr+VG/vDm/jF52VrtIf1JNiCSszG P4pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685172159; x=1687764159; 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=h/IfzR0PqTlQjshfXa1Gk+Wb9K4Bgq3zLGbFa1hs2Y0=; b=J8YXs1Zqzl0uvxxdv3RoUytzeq6VBrPbq0/NZZc6o0fbENmaCKcUPQm+Wz1ZsAk/bR jf4XHWYSYyjDv6b7Bah6HqS8LkVhF/98Sihmh/BjqZAuiDuhL4quEwJuYt57+uIi0f78 hX3YhoR2a9S7UZPuThXTKlADyzR9AMkxZBEhthXXh45Fribh4oL3SyFTc1TKnfwmVj1V vRjpK3F4uWnibR5qcJgJGWgKpv3FLlZjkAmQW9vUnxgiNXnkOdV4rzzA/lgPeBNocKLs 6Fm0jLPv86jKNXB0IgdvOqRsQvmLZ1+JKXTrd5NNuHXOmUAq/7HMWaScC1EQPlU/FWmd 7TRA== X-Gm-Message-State: AC+VfDztkP8DYz7I46kfKHcr5TjhYIkrCoyPWWYqrqte4eVrTgbVlZ4i 5nAzwSy+91KsIfXlI+CQHPnsWJ6OepiI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:b31c:0:b0:b94:6989:7fa6 with SMTP id l28-20020a25b31c000000b00b9469897fa6mr841825ybj.4.1685172159462; Sat, 27 May 2023 00:22:39 -0700 (PDT) Date: Sat, 27 May 2023 00:21:39 -0700 In-Reply-To: <20230527072210.2900565-1-irogers@google.com> Message-Id: <20230527072210.2900565-4-irogers@google.com> Mime-Version: 1.0 References: <20230527072210.2900565-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v5 03/34] 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Kan Liang --- 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 98d7cb24a158..2a5a29217374 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -356,6 +356,11 @@ bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, const struct perf_cpu_m return true; } +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__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 cedfc26d944e..e38d859a384d 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -18,6 +18,9 @@ struct perf_cache { struct perf_cpu_map; +/** + * perf_cpu_map__dummy_new - a map with a singular "any CPU"/dummy -1 value. + */ 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); @@ -30,11 +33,18 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(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 *cpus, 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 *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, const struct perf_cpu_map *rhs); +/** + * perf_cpu_map__any_cpu - Does the map contain the "any CPU"/dummy -1 value? + */ +LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ -- 2.41.0.rc0.172.g3f132b7071-goog