From mboxrd@z Thu Jan 1 00:00:00 1970 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 71CE6C77B7C for ; Fri, 26 May 2023 21:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244135AbjEZVyk (ORCPT ); Fri, 26 May 2023 17:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243840AbjEZVy3 (ORCPT ); Fri, 26 May 2023 17:54:29 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBCE1B0 for ; Fri, 26 May 2023 14:54:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bac6a453dd5so1641482276.2 for ; Fri, 26 May 2023 14:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138063; x=1687730063; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=Qwu/cGmcgGyAZcdMWJypusk9brpC8zbYxPdkwt9cWJxryrN+wWqFuUogdM/q+inaa3 X5CMwBG9pJsw8mJbgbYfB1YQAMRQXotN9Takvp+xsVfHlPCHVViaSXv2SoyszMDBacrk dnJQHYm60Hu7PUfcLwgd5sYlI3Awm7IuD6VS3ZNkzQyiH5jPefFnAHa5Rqpm2jbo+dMy Y8Df0g22q7KcE5U7lt3p7eQInc+bGhBFC3kSKBmlqnb7WKQnshPIw3QMtpZsklI8r4Da 1JZR8hAERpXiq/1x0G4WEi0rbKcb+3Y+1YDBdnSB4OtOFQi8OXVVITYzrnr2JS9jc6FW EtuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138063; x=1687730063; 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=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=CWL8ZNlk9+CcPIscUX+XHKPd7Yl8gr4UgLwoH5pmQVxWulzNMzImlWYr7R1xOtBrbf BAHgefp/RLQQirKszVqUcjJouhMY9KuQ9UVNfNvhqG/Ek4DdF/cxzndlnI4n/aCDyZQZ zotvZbD7F39fIrpsm3NjWXEaRxu6oypBWwXbRxoBWeHEN0RGMkjS7AM7hh4xAKVlCB1G wC0c0d3PW7Re11AFHYyMoYLbjTOiqBK0/9EM5GRgej1TUfo11f1Xd6vprE0OrsDApNsj mKhFXwByAIHdAsurX7pBOUOpTYGs22MkS8B3klkai7BGhqivUKSIptCcY0D5tFumvMxC +eDQ== X-Gm-Message-State: AC+VfDyY3s4bHmHD/sGKnsys4isrEnJVBkaNuWBtcC5T7xISj41wFyFE aPI4hb2jDeJbYtgUZUbduSKl3eGzBllw X-Google-Smtp-Source: ACHHUZ7CPihlLsasw3b/sk86pIxYuwPTU/q0jnG123S0JRRNIklKIp43J/hfdTdzCRVbqzvIRy7dBEtJSqtd X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:4582:0:b0:ba8:4b22:4e8a with SMTP id s124-20020a254582000000b00ba84b224e8amr1753266yba.0.1685138063197; Fri, 26 May 2023 14:54:23 -0700 (PDT) Date: Fri, 26 May 2023 14:53:39 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-5-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 Content-Type: text/plain; charset="UTF-8" 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 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 *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 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 { 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); @@ -25,11 +28,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 From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E64BDC7EE2F for ; Fri, 26 May 2023 23:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=u+IpFXEoV7o2Q/oaRtQlULXhT3mp0RNH20l5K4sJ2SA=; b=X8dLY8nzyujq2V dcCWPZ30HdyPtLR/6VcIvM56f6Q84idM6mevCqO9JhDLAZpp86jkYWIJoGa8BxAJOyKIc65rfapQF S4VwnYfFuyIcG66d4PiWjILSdJqqmVo1w/C7CZTGOBMV4ppPOYUr/YkuPiOnZYIM3cz58C+ppf9Pn nBRbQpqMqh36gEagL6uJccfBnUajMkH7sT64u5tOLYhlSkalVGxsEFkgQHeHFwDRO0z18ODc92GdU ICBNWJOjLTQeACa2sURwVHa0JX7nN1DPaq5Qs3xY0SAln2GFl9NuyAs1dA7zzYDZH8117NXNsvexo rJ/LdIfq6fE8O3fvcLtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2gVC-004Eoh-1N; Fri, 26 May 2023 23:05:42 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fOC-0042xT-1B for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:54:25 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8337a578dso1650770276.1 for ; Fri, 26 May 2023 14:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138063; x=1687730063; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=Qwu/cGmcgGyAZcdMWJypusk9brpC8zbYxPdkwt9cWJxryrN+wWqFuUogdM/q+inaa3 X5CMwBG9pJsw8mJbgbYfB1YQAMRQXotN9Takvp+xsVfHlPCHVViaSXv2SoyszMDBacrk dnJQHYm60Hu7PUfcLwgd5sYlI3Awm7IuD6VS3ZNkzQyiH5jPefFnAHa5Rqpm2jbo+dMy Y8Df0g22q7KcE5U7lt3p7eQInc+bGhBFC3kSKBmlqnb7WKQnshPIw3QMtpZsklI8r4Da 1JZR8hAERpXiq/1x0G4WEi0rbKcb+3Y+1YDBdnSB4OtOFQi8OXVVITYzrnr2JS9jc6FW EtuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138063; x=1687730063; 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=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=FHuyeYYz/fM2l5REQZL8P39K+WNnc/hMoUYr6CNyjTkI7TiUULBM6sgPQDcksKrcqH vz1bUqVPg0tiZr82eiLufSay7nvfM3IxLi3H96dRnhlsLo6fsWaXXLGazVKEEH6ddPzp pYxCqznI1z/yHM3n044EnTrHG9UCewiw24+kvc3VJpNSYttVzpnDwkjK/O31RZ3Bi/CJ 9Na5mJPYhxbBNu1M6W6l9DZqrBphIi8RdoJueQ31q1XRYpiKk/MExHhZN1h/oqWrkNKx t7EzxPjSav9ZLaw6Ol1vmkb89sdln43Tvt7WKZDUImzlHjSVr1FZWGRM4H1uidETBEzg bQvg== X-Gm-Message-State: AC+VfDxgkJs0pxvLH2p4G1rNM/+jblmO2yznxQJgIQCI6ZdZxW236SbI VSQ+eLlhyZH8XkBn1LlDT+ZIRy/taelg X-Google-Smtp-Source: ACHHUZ7CPihlLsasw3b/sk86pIxYuwPTU/q0jnG123S0JRRNIklKIp43J/hfdTdzCRVbqzvIRy7dBEtJSqtd X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:4582:0:b0:ba8:4b22:4e8a with SMTP id s124-20020a254582000000b00ba84b224e8amr1753266yba.0.1685138063197; Fri, 26 May 2023 14:54:23 -0700 (PDT) Date: Fri, 26 May 2023 14:53:39 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-5-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_145424_427678_30B220A7 X-CRM114-Status: GOOD ( 17.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 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 *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 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 { 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); @@ -25,11 +28,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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel