Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4711095rdb; Tue, 12 Dec 2023 07:21:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKlzZZmwQW8f/VAq+4TM/bTaP931opSfwtHFiqbT2wQHlVpvsvPqu36aYaBe1pMjvbOhZa X-Received: by 2002:a92:d686:0:b0:35d:5995:1d74 with SMTP id p6-20020a92d686000000b0035d59951d74mr7721410iln.57.1702394470642; Tue, 12 Dec 2023 07:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702394470; cv=none; d=google.com; s=arc-20160816; b=dyVVQuIzyJhBTmIsawguq+PP9pnomCm3pAtNcAgK/JK3wfMNa/06X89BaBsgGcVqsc BUgTikzoNBUUQvD+naKwP+Al/idDmW8ac5ubQTrwOpyRNaxVR3V/yECmhjzWT9UrMUlk Id16RC05lc8Q3EN8Sn8wMOh8tcAtKMk2K3jzWJBOcezi5WtpueXKYcKNnaxAl6l71psT s/HZRj47Tm+lnN/BW5iOwmsSjrFgrzM75oWt29sJANNOj0CE+vUHgCXeee+2x5+WemBs G6zmm7rr5tctNIuauYV/fJNYeUWgtunIqPqg/uRFbUq0U8zsY/jzjoC7/DJb7IvyxE8S Yoag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=6KW7XwNu3gbHV9TEepFHJOjzEsLY1SYwTK3IfeaQ/14=; fh=5EP3x1uDWWBI9dywppNETb2J5CyUqdqYJErdwPGhe68=; b=bnrlhIAQVuMbQeZx4OB8uX9MkNGUgQSt+CLzS+QuDcrP95uC75iy+qmE8lQMMpNZFE oOGrgIIjcfuz5bmFiWRTzkL3646GLBxDLrcW8beo3Idf89QRT+s6gHZ2rglseWTsH1E5 kgPUM+g5DRfqSMTd4zMJ3ct/1KQvtrG0eSR1jWnpKfi2/xhKk7k9ZZq68dDFYxdhVFy+ UKwvvcPrxsULTEAvHm05tb/E9kzQEWgawy4lClTrPCf27w77lOQYIybL8pfEUV0ZhGY3 Jj5S0B3lV9q085DsUZG6HEcll76/2niG6uTFumBq6EguqYwfa+r0kPKy0ryLZUSLUrNm daCg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j4-20020a654304000000b005c661efffd0si7741459pgq.754.2023.12.12.07.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 07:21:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2C84080A532E; Tue, 12 Dec 2023 07:21:08 -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 S1376638AbjLLPUx (ORCPT + 99 others); Tue, 12 Dec 2023 10:20:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376634AbjLLPUw (ORCPT ); Tue, 12 Dec 2023 10:20:52 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6F4BDB; Tue, 12 Dec 2023 07:20:56 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A4B6143D; Tue, 12 Dec 2023 07:21:42 -0800 (PST) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 457B53F738; Tue, 12 Dec 2023 07:20:51 -0800 (PST) Message-ID: <0e1ca950-b5a4-1e08-8696-4e3e12e21b19@arm.com> Date: Tue, 12 Dec 2023 15:20:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v1 14/14] libperf cpumap: Document perf_cpu_map__nr's behavior Content-Language: en-US To: Ian Rogers References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-15-irogers@google.com> 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 From: James Clark In-Reply-To: <20231129060211.1890454-15-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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, 12 Dec 2023 07:21:08 -0800 (PST) On 29/11/2023 06:02, Ian Rogers wrote: > 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. Hmmm... I'm not sure whether to laugh or cry at that API. Reviewed-by: James Clark > + */ > 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.