Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4367266rdh; Tue, 28 Nov 2023 22:03:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+0wgV4mTwnWogs5tAE1stlTsR6DvGtT6yS5FwV3aTSp9TgnqW+k3P8LkJ+a6rRVG3ePPu X-Received: by 2002:a05:6a21:164f:b0:187:97fc:6c56 with SMTP id no15-20020a056a21164f00b0018797fc6c56mr18428283pzb.49.1701237813945; Tue, 28 Nov 2023 22:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701237813; cv=none; d=google.com; s=arc-20160816; b=ihKY8kTGkFzZLq9cHYFus7VH1HiKyrtlL5OHb9j/FuR9LTJEAnbdN5M+LT6B4cC01m lYybeBzN86UwZ1IsM9TVWX24YMDIGqsv+OwMlqGKKjXESpP++WURku5I6fQgKETe3j53 8ny5Ox+3jizQhIUu52g3S7g9AX+/+bSA00RB9h5kGmuTwOB3Etr8Y3l7PzPQ9NxOE0S5 Lag3c0C6ZY44jw6PUwbc+MplzmS9bZ+xzBs3UWXab+UIjCzfriF2ccYuAMpOqpJ0Z4CF lAMv3i+zd1TiQkBjKELNY/HrnPKjNHLlNoYKrXR5SnAfSdjVMW22eoADjgqpOWwYAo4m Wucg== 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=gdtDmuZlpO8R+sCZuGq6XIuCqB6n5MWFW+Mek7m4zb4=; fh=uYKNI4aCUAMYZ/8oQVBIse94GgoxWIIZr1zaTbrWG7c=; b=lp3KRMgE51zZajsbOXtLaNPeF6ATusIvtAfaB+lutGxCPADJoRZgRtf6vOW1H6NysN Jmzdb+2ABNre4SJswKH0rnd9y56Z9B/W6QRNVUggqEG3adeEh7/RIOv/MKeo1oGKQSIW eEuTttouBkvMj8qS/5Gqd1xTq/QkXg74sr7PpS4pJGE2TzTK8CxQgLpKe5qfksynb+sD i5+Xb+JiAr+5NwHA/8gMI+jNB9NL5qfCvQa94cIaRr8yi3Zlw0FqeFMbm6JqnWk5mxmP 5wrrk1w8T5M1hKeAAR4fm3V2eu3HzvoGDWN0enCDxrmuBWZG5be4iBlIsz4PG8kmz/e5 bgaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gotxKEv8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ix21-20020a170902f81500b001cf5d324819si12444569plb.154.2023.11.28.22.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gotxKEv8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id F31DE80465D8; Tue, 28 Nov 2023 22:03:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377001AbjK2GDH (ORCPT + 99 others); Wed, 29 Nov 2023 01:03:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377032AbjK2GCm (ORCPT ); Wed, 29 Nov 2023 01:02:42 -0500 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 0732419BF for ; Tue, 28 Nov 2023 22:02:49 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5ccf44b0423so84980867b3.0 for ; Tue, 28 Nov 2023 22:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701237768; x=1701842568; 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=gdtDmuZlpO8R+sCZuGq6XIuCqB6n5MWFW+Mek7m4zb4=; b=gotxKEv80wkHKfwOnrYUFZ1P/QiffG8FS3MtPA9e9ms22h6ijUbW+/gk/3Zc3rYqX0 eZz+enL5hNKX61jBBi0F1WtSYodUp0KpUX0MiQqCsSrT/qXGNmklX1bKK2dXW1i/3Guh MM7V904BCR9zGFc5AfXVYQ5S73yHjMZy5c+XG61hU70H/MmXc3WWwh8KYVR4SjJ0Syni Rn5Hs4cyevaUfF4b13San60VPFuoeKeaYqYnr/RLHSErNHnx9jmQPu6EDahzQGId4VAh azirywDrQQrMois+BFSzJlyIygMrwJDTghbRccfFE9s6SSQCoVEgWC2fXFTexinuJ6R2 1OiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701237768; x=1701842568; 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=gdtDmuZlpO8R+sCZuGq6XIuCqB6n5MWFW+Mek7m4zb4=; b=BLwSjT4lGLlFyTMtkS27MltMa1Yzl3Kr3WCWXTGOYu2DHxxJkDdmw/weRm3tDmSLRk SiwPcUgyt0zdO493N+opi39iawr9ubXlDcCrXxirq/QIGvaX9oc0VPOjizJYrjFCu/qI SZrn639al8+q4aP/TLJ5GWvAtvHK3r0Wk1Vd0/26OuQCjKH1Ii33Q6z/NOjOmvbGssDc XbXixhf5qbHdxZibse0XB/ep09hzJlm1YvC2kVl4qspQj1yYXp2PjMNH7pNDsWNPxXKN iHdLvv25CNRjj1bFEMGxp67lp89tFQ62R/hMpv+hjo+1+zyhiY/QX5e/2WbTC7UEUZQV x5sQ== X-Gm-Message-State: AOJu0Yyxmc/chmJppg0ictwX++nJfSV8Br4eUPWKhtgFf9CduJF0INqj ebctHFvYrne+yPy3FR4y5WGs0nlIlPmh X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:763b:80fa:23ca:96f8]) (user=irogers job=sendgmr) by 2002:a05:690c:fcd:b0:5ca:fef:82a4 with SMTP id dg13-20020a05690c0fcd00b005ca0fef82a4mr623872ywb.4.1701237768039; Tue, 28 Nov 2023 22:02:48 -0800 (PST) Date: Tue, 28 Nov 2023 22:02:11 -0800 In-Reply-To: <20231129060211.1890454-1-irogers@google.com> Message-Id: <20231129060211.1890454-15-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 14/14] libperf cpumap: Document perf_cpu_map__nr's behavior 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 28 Nov 2023 22:03:31 -0800 (PST) perf_cpu_map__nr's behavior around an empty CPU map is strange as it returns that there is 1 CPU. Changing code that may rely on this behavior is hard, we can at least document the behavior. Signed-off-by: Ian Rogers --- tools/lib/perf/include/perf/cpumap.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 523e4348fc96..90457d17fb2f 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -44,7 +44,18 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, struct perf_cpu_map *other); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); +/** + * perf_cpu_map__cpu - get the CPU value at the given index. Returns -1 if index + * is invalid. + */ LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); +/** + * perf_cpu_map__nr - for an empty map returns 1, as perf_cpu_map__cpu returns a + * cpu of -1 for an invalid index, this makes an empty map + * look like it contains the "any CPU"/dummy value. Otherwise + * the result is the number CPUs in the map plus one if the + * "any CPU"/dummy value is present. + */ 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. -- 2.43.0.rc1.413.gea7ed67945-goog