From nobody Fri Dec 19 03:46:21 2025 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 AD596C83F2F for ; Thu, 31 Aug 2023 15:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245398AbjHaPRL (ORCPT ); Thu, 31 Aug 2023 11:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243723AbjHaPRK (ORCPT ); Thu, 31 Aug 2023 11:17:10 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E85C6E50; Thu, 31 Aug 2023 08:17:07 -0700 (PDT) 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 F3AA0C15; Thu, 31 Aug 2023 08:17:46 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5470D3F64C; Thu, 31 Aug 2023 08:17:04 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Jing Zhang , Haixin Yu , Kajol Jain , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Miguel Ojeda , Liam Howlett , Chen Zhongjin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/7] perf test: Check result of has_event(cycles) test Date: Thu, 31 Aug 2023 16:16:12 +0100 Message-Id: <20230831151632.124985-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the function always returns 0, so even when the has_event() test fails, the test still passes. Fix it by returning ret instead. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/expr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 81229fa4f1e9..39be7f3b3a53 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -263,7 +263,7 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u =20 expr__ctx_free(ctx); =20 - return 0; + return ret; } =20 DEFINE_SUITE("Simple expression parser", expr); --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 7C64DC83F2E for ; Thu, 31 Aug 2023 15:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345101AbjHaPR3 (ORCPT ); Thu, 31 Aug 2023 11:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243723AbjHaPR2 (ORCPT ); Thu, 31 Aug 2023 11:17:28 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38ED8E5B; Thu, 31 Aug 2023 08:17:25 -0700 (PDT) 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 4165DC15; Thu, 31 Aug 2023 08:18:04 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 73D813F64C; Thu, 31 Aug 2023 08:17:21 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kajol Jain , Haixin Yu , Jing Zhang , Ravi Bangoria , Madhavan Srinivasan , Kan Liang , Yang Jihong , Eduard Zingerman , Liam Howlett , Chen Zhongjin , Miguel Ojeda , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/7] perf jevents: Remove unused keyword Date: Thu, 31 Aug 2023 16:16:13 +0100 Message-Id: <20230831151632.124985-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 'cpuid_not_more_than' was the working title of the new 'strcmp_cpuid_str' keyword and was accidentally left in. It was never used so tidying it up has no effect. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/pmu-events/metric.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric= .py index 0e9ec65d92ae..1bbb89102901 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -558,8 +558,7 @@ def ParsePerfJson(orig: str) -> Expression: # Convert accidentally converted scientific notation constants back py =3D re.sub(r'([0-9]+)Event\(r"(e[0-9]+)"\)', r'\1\2', py) # Convert all the known keywords back from events to just the keyword - keywords =3D ['if', 'else', 'min', 'max', 'd_ratio', 'source_count', 'ha= s_event', 'strcmp_cpuid_str', - 'cpuid_not_more_than'] + keywords =3D ['if', 'else', 'min', 'max', 'd_ratio', 'source_count', 'ha= s_event', 'strcmp_cpuid_str'] for kw in keywords: py =3D re.sub(rf'Event\(r"{kw}"\)', kw, py) try: --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 C1829C83F10 for ; Thu, 31 Aug 2023 15:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbjHaPRu (ORCPT ); Thu, 31 Aug 2023 11:17:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345302AbjHaPRs (ORCPT ); Thu, 31 Aug 2023 11:17:48 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C4379E50; Thu, 31 Aug 2023 08:17:42 -0700 (PDT) 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 CFB33C15; Thu, 31 Aug 2023 08:18:21 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 09F5C3F64C; Thu, 31 Aug 2023 08:17:38 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Jing Zhang , Haixin Yu , Kajol Jain , Madhavan Srinivasan , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Miguel Ojeda , Chen Zhongjin , Liam Howlett , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/7] perf util: Add a function for replacing characters in a string Date: Thu, 31 Aug 2023 16:16:14 +0100 Message-Id: <20230831151632.124985-4-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It finds all occurrences of a single character and replaces them with a multi character string. This will be used in a test in a following commit. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + tools/perf/tests/util.c | 30 +++++++++++++++++++++ tools/perf/util/string.c | 48 +++++++++++++++++++++++++++++++++ tools/perf/util/string2.h | 1 + 6 files changed, 82 insertions(+) create mode 100644 tools/perf/tests/util.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 63d5e6d5f165..2b45ffa462a6 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -66,6 +66,7 @@ perf-y +=3D dlfilter-test.o perf-y +=3D sigtrap.o perf-y +=3D event_groups.o perf-y +=3D symbols.o +perf-y +=3D util.o =20 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) perf-$(CONFIG_DWARF_UNWIND) +=3D dwarf-unwind.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 0ad18cf6dd22..cb6f1dd00dc4 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -123,6 +123,7 @@ static struct test_suite *generic_tests[] =3D { &suite__sigtrap, &suite__event_groups, &suite__symbols, + &suite__util, NULL, }; =20 diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index f33cfc3c19a4..b394f3ac2d66 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -145,6 +145,7 @@ DECLARE_SUITE(dlfilter); DECLARE_SUITE(sigtrap); DECLARE_SUITE(event_groups); DECLARE_SUITE(symbols); +DECLARE_SUITE(util); =20 /* * PowerPC and S390 do not support creation of instruction breakpoints usi= ng the diff --git a/tools/perf/tests/util.c b/tools/perf/tests/util.c new file mode 100644 index 000000000000..43e66a620b83 --- /dev/null +++ b/tools/perf/tests/util.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "tests.h" +#include "util/debug.h" + +#include +#include +#include + +static int test_strreplace(char find, const char *s, const char *replace, = const char *expected) +{ + char *new =3D strreplace_chars(find, s, replace); + int ret =3D strcmp(new, expected); + + free(new); + return ret =3D=3D 0; +} + +static int test__util(struct test_suite *t __maybe_unused, int subtest __m= aybe_unused) +{ + TEST_ASSERT_VAL("empty string", test_strreplace(' ', "", "123", "")); + TEST_ASSERT_VAL("no match", test_strreplace('5', "123", "4", "123")); + TEST_ASSERT_VAL("replace 1", test_strreplace('3', "123", "4", "124")); + TEST_ASSERT_VAL("replace 2", test_strreplace('a', "abcabc", "ef", "efbcef= bc")); + TEST_ASSERT_VAL("replace long", test_strreplace('a', "abcabc", "longlong", + "longlongbclonglongbc")); + + return 0; +} + +DEFINE_SUITE("util", util); diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index cf05b0b56c57..6410a683183e 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -301,3 +301,51 @@ unsigned int hex(char c) return c - 'a' + 10; return c - 'A' + 10; } + + +/* + * Replace all occurrences of character 'find' in string s with string 're= place' + * + * The new string could be longer so a new string is returned which must + * be freed. + */ +char *strreplace_chars(char find, const char *s, const char *replace) +{ + int replace_len =3D strlen(replace); + char *new_s, *to; + const char *loc =3D strchr(s, find); + const char *from =3D s; + int num =3D 0; + + /* Count occurrences */ + while (loc) { + loc =3D strchr(loc + 1, find); + num++; + } + + /* Allocate enough space for replacements and reset first location */ + new_s =3D malloc(strlen(s) + (num * (replace_len - 1) + 1)); + if (!new_s) + return NULL; + loc =3D strchr(s, find); + to =3D new_s; + + while (loc) { + /* Copy original string up to found char and update positions */ + memcpy(to, from, 1 + loc - from); + to +=3D loc - from; + from =3D loc + 1; + + /* Copy replacement string and update positions */ + memcpy(to, replace, replace_len); + to +=3D replace_len; + + /* Find next occurrence or end of string */ + loc =3D strchr(from, find); + } + + /* Copy any remaining chars + null */ + strcpy(to, from); + + return new_s; +} diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h index 56c30fef9682..920488099214 100644 --- a/tools/perf/util/string2.h +++ b/tools/perf/util/string2.h @@ -39,5 +39,6 @@ char *strpbrk_esc(char *str, const char *stopset); char *strdup_esc(const char *str); =20 unsigned int hex(char c); +char *strreplace_chars(char find, const char *s, const char *replace); =20 #endif /* PERF_STRING_H */ --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 4F192C83F2F for ; Thu, 31 Aug 2023 15:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346262AbjHaPSE (ORCPT ); Thu, 31 Aug 2023 11:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233904AbjHaPSD (ORCPT ); Thu, 31 Aug 2023 11:18:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3AE2EE55; Thu, 31 Aug 2023 08:18:00 -0700 (PDT) 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 3D0CDC15; Thu, 31 Aug 2023 08:18:39 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 77AC53F64C; Thu, 31 Aug 2023 08:17:56 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kajol Jain , Jing Zhang , Haixin Yu , Madhavan Srinivasan , Kan Liang , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Chen Zhongjin , Liam Howlett , Miguel Ojeda , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/7] perf test: Add a test for strcmp_cpuid_str() expression Date: Thu, 31 Aug 2023 16:16:15 +0100 Message-Id: <20230831151632.124985-5-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Test that the new expression builtin returns a match when the current escaped CPU ID is given, and that it doesn't match when "0x0" is given. The CPU ID in test__expr() has to be changed to perf_pmu__getcpuid() which returns the CPU ID string, rather than the raw CPU ID that get_cpuid() returns because that can't be used with strcmp_cpuid_str(). It doesn't affect the is_intel test because both versions contain "Intel". Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/tests/expr.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 39be7f3b3a53..78544092ef0c 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -9,6 +9,7 @@ #include #include #include +#include #include =20 static int test_ids_union(void) @@ -74,10 +75,13 @@ static int test__expr(struct test_suite *t __maybe_unus= ed, int subtest __maybe_u int ret; struct expr_parse_ctx *ctx; bool is_intel =3D false; - char buf[128]; + char strcmp_cpuid_buf[256]; + struct perf_pmu *pmu =3D pmu__find_core_pmu(); + char *cpuid =3D perf_pmu__getcpuid(pmu); + char *escaped_cpuid1, *escaped_cpuid2; =20 - if (!get_cpuid(buf, sizeof(buf))) - is_intel =3D strstr(buf, "Intel") !=3D NULL; + TEST_ASSERT_VAL("get_cpuid", cpuid); + is_intel =3D strstr(cpuid, "Intel") !=3D NULL; =20 TEST_ASSERT_EQUAL("ids_union", test_ids_union(), 0); =20 @@ -257,9 +261,28 @@ static int test__expr(struct test_suite *t __maybe_unu= sed, int subtest __maybe_u TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) =3D=3D 1); TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_pt= r)); =20 + + /* Test no cpuid match */ + ret =3D test(ctx, "strcmp_cpuid_str(0x0)", 0); + + /* + * Test cpuid match with current cpuid. Special chars have to be + * escaped. + */ + escaped_cpuid1 =3D strreplace_chars('-', cpuid, "\\-"); + free(cpuid); + escaped_cpuid2 =3D strreplace_chars(',', escaped_cpuid1, "\\,"); + free(escaped_cpuid1); + escaped_cpuid1 =3D strreplace_chars('=3D', escaped_cpuid2, "\\=3D"); + free(escaped_cpuid2); + scnprintf(strcmp_cpuid_buf, sizeof(strcmp_cpuid_buf), + "strcmp_cpuid_str(%s)", escaped_cpuid1); + free(escaped_cpuid1); + ret |=3D test(ctx, strcmp_cpuid_buf, 1); + /* has_event returns 1 when an event exists. */ expr__add_id_val(ctx, strdup("cycles"), 2); - ret =3D test(ctx, "has_event(cycles)", 1); + ret |=3D test(ctx, "has_event(cycles)", 1); =20 expr__ctx_free(ctx); =20 --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 D9E07C83F2F for ; Thu, 31 Aug 2023 15:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346511AbjHaPSX (ORCPT ); Thu, 31 Aug 2023 11:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243146AbjHaPSW (ORCPT ); Thu, 31 Aug 2023 11:18:22 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6ECA7E6A; Thu, 31 Aug 2023 08:18:17 -0700 (PDT) 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 7A90AC15; Thu, 31 Aug 2023 08:18:56 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C726D3F64C; Thu, 31 Aug 2023 08:18:13 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Jing Zhang , Haixin Yu , Kajol Jain , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Chen Zhongjin , Miguel Ojeda , Liam Howlett , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/7] perf pmu: Move pmu__find_core_pmu() to pmus.c Date: Thu, 31 Aug 2023 16:16:16 +0100 Message-Id: <20230831151632.124985-6-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" pmu__find_core_pmu() more logically belongs in pmus.c because it iterates over all PMUs, so move it to pmus.c At the same time rename it to perf_pmus__find_core_pmu() to match the naming convention in this file. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 6 +++--- tools/perf/tests/expr.c | 2 +- tools/perf/util/expr.c | 2 +- tools/perf/util/pmu.c | 17 ----------------- tools/perf/util/pmu.h | 2 +- tools/perf/util/pmus.c | 18 ++++++++++++++++++ 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 615084eb88d8..3d9330feebd2 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -10,7 +10,7 @@ =20 const struct pmu_metrics_table *pmu_metrics_table__find(void) { - struct perf_pmu *pmu =3D pmu__find_core_pmu(); + struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); =20 if (pmu) return perf_pmu__find_metrics_table(pmu); @@ -20,7 +20,7 @@ const struct pmu_metrics_table *pmu_metrics_table__find(v= oid) =20 const struct pmu_events_table *pmu_events_table__find(void) { - struct perf_pmu *pmu =3D pmu__find_core_pmu(); + struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); =20 if (pmu) return perf_pmu__find_events_table(pmu); @@ -32,7 +32,7 @@ double perf_pmu__cpu_slots_per_cycle(void) { char path[PATH_MAX]; unsigned long long slots =3D 0; - struct perf_pmu *pmu =3D pmu__find_core_pmu(); + struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); =20 if (pmu) { perf_pmu__pathname_scnprintf(path, sizeof(path), diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 78544092ef0c..e3aa9d4fcf3a 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -76,7 +76,7 @@ static int test__expr(struct test_suite *t __maybe_unused= , int subtest __maybe_u struct expr_parse_ctx *ctx; bool is_intel =3D false; char strcmp_cpuid_buf[256]; - struct perf_pmu *pmu =3D pmu__find_core_pmu(); + struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); char *cpuid =3D perf_pmu__getcpuid(pmu); char *escaped_cpuid1, *escaped_cpuid2; =20 diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 4488f306de78..7be23b3ac082 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -509,7 +509,7 @@ double expr__strcmp_cpuid_str(const struct expr_parse_c= tx *ctx __maybe_unused, bool compute_ids __maybe_unused, const char *test_id) { double ret; - struct perf_pmu *pmu =3D pmu__find_core_pmu(); + struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); char *cpuid =3D perf_pmu__getcpuid(pmu); =20 if (!cpuid) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 152cda84f273..8213e26783a1 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2049,20 +2049,3 @@ void perf_pmu__delete(struct perf_pmu *pmu) zfree(&pmu->id); free(pmu); } - -struct perf_pmu *pmu__find_core_pmu(void) -{ - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmus__scan_core(pmu))) { - /* - * The cpumap should cover all CPUs. Otherwise, some CPUs may - * not support some events or have different event IDs. - */ - if (RC_CHK_ACCESS(pmu->cpus)->nr !=3D cpu__max_cpu().cpu) - return NULL; - - return pmu; - } - return NULL; -} diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 6a4e170c61d6..45079f26abf6 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -264,6 +264,6 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_na= me, const char *filename, struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name); struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *c= ore_pmus); void perf_pmu__delete(struct perf_pmu *pmu); -struct perf_pmu *pmu__find_core_pmu(void); +struct perf_pmu *perf_pmus__find_core_pmu(void); =20 #endif /* __PMU_H */ diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6631367c756f..032ce57d2b8e 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -10,6 +10,7 @@ #include #include #include +#include "cpumap.h" #include "debug.h" #include "evsel.h" #include "pmus.h" @@ -592,3 +593,20 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *e= vsel) } return pmu; } + +struct perf_pmu *perf_pmus__find_core_pmu(void) +{ + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmus__scan_core(pmu))) { + /* + * The cpumap should cover all CPUs. Otherwise, some CPUs may + * not support some events or have different event IDs. + */ + if (RC_CHK_ACCESS(pmu->cpus)->nr !=3D cpu__max_cpu().cpu) + return NULL; + + return pmu; + } + return NULL; +} --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 17894C83F10 for ; Thu, 31 Aug 2023 15:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346512AbjHaPSs (ORCPT ); Thu, 31 Aug 2023 11:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236867AbjHaPSs (ORCPT ); Thu, 31 Aug 2023 11:18:48 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9FA04E72; Thu, 31 Aug 2023 08:18:34 -0700 (PDT) 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 A8449C15; Thu, 31 Aug 2023 08:19:13 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0835D3F64C; Thu, 31 Aug 2023 08:18:30 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Jing Zhang , Haixin Yu , Kajol Jain , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Liam Howlett , Miguel Ojeda , Chen Zhongjin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/7] perf pmus: Simplify perf_pmus__find_core_pmu() Date: Thu, 31 Aug 2023 16:16:17 +0100 Message-Id: <20230831151632.124985-7-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the while loop always either exits on the first iteration with a core PMU, or exits with NULL on heterogeneous systems or when not all CPUs are online. Both of the latter behaviors are undesirable for platforms other than Arm so simplify it to always return the first core PMU, or NULL if none exist. This behavior was depended on by the Arm version of pmu_metrics_table__find(), so the logic has been moved there instead. Suggested-by: Ian Rogers Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 8 +++++++- tools/perf/util/pmus.c | 14 +------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 3d9330feebd2..3099f5f448ba 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -10,8 +10,14 @@ =20 const struct pmu_metrics_table *pmu_metrics_table__find(void) { - struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); + struct perf_pmu *pmu; + + /* Metrics aren't currently supported on heterogeneous Arm systems */ + if (perf_pmus__num_core_pmus() > 1) + return NULL; =20 + /* Doesn't matter which one here because they'll all be the same */ + pmu =3D perf_pmus__find_core_pmu(); if (pmu) return perf_pmu__find_metrics_table(pmu); =20 diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 032ce57d2b8e..5ae41644ccda 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -596,17 +596,5 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *e= vsel) =20 struct perf_pmu *perf_pmus__find_core_pmu(void) { - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmus__scan_core(pmu))) { - /* - * The cpumap should cover all CPUs. Otherwise, some CPUs may - * not support some events or have different event IDs. - */ - if (RC_CHK_ACCESS(pmu->cpus)->nr !=3D cpu__max_cpu().cpu) - return NULL; - - return pmu; - } - return NULL; + return perf_pmus__scan_core(NULL); } --=20 2.34.1 From nobody Fri Dec 19 03:46:21 2025 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 35768C83F32 for ; Thu, 31 Aug 2023 15:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346518AbjHaPTC (ORCPT ); Thu, 31 Aug 2023 11:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236867AbjHaPTB (ORCPT ); Thu, 31 Aug 2023 11:19:01 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86EDCE74; Thu, 31 Aug 2023 08:18:52 -0700 (PDT) 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 92EC9C15; Thu, 31 Aug 2023 08:19:31 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 529BA3F64C; Thu, 31 Aug 2023 08:18:48 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Jing Zhang , Haixin Yu , Kajol Jain , Madhavan Srinivasan , Ravi Bangoria , Yang Jihong , Eduard Zingerman , Miguel Ojeda , Liam Howlett , Chen Zhongjin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 7/7] perf pmu: Remove unused function Date: Thu, 31 Aug 2023 16:16:18 +0100 Message-Id: <20230831151632.124985-8-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831151632.124985-1-james.clark@arm.com> References: <20230831151632.124985-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" pmu_events_table__find() is no longer used so remove it and its Arm specific version. Signed-off-by: James Clark Reviewed-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 10 ---------- tools/perf/util/pmu.c | 5 ----- tools/perf/util/pmu.h | 1 - 3 files changed, 16 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 3099f5f448ba..2a4eab2d160e 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -24,16 +24,6 @@ const struct pmu_metrics_table *pmu_metrics_table__find(= void) return NULL; } =20 -const struct pmu_events_table *pmu_events_table__find(void) -{ - struct perf_pmu *pmu =3D perf_pmus__find_core_pmu(); - - if (pmu) - return perf_pmu__find_events_table(pmu); - - return NULL; -} - double perf_pmu__cpu_slots_per_cycle(void) { char path[PATH_MAX]; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8213e26783a1..f9d8525eec64 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -775,11 +775,6 @@ char *perf_pmu__getcpuid(struct perf_pmu *pmu) return cpuid; } =20 -__weak const struct pmu_events_table *pmu_events_table__find(void) -{ - return perf_pmu__find_events_table(NULL); -} - __weak const struct pmu_metrics_table *pmu_metrics_table__find(void) { return perf_pmu__find_metrics_table(NULL); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 45079f26abf6..4b9386534d2a 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -238,7 +238,6 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table); =20 char *perf_pmu__getcpuid(struct perf_pmu *pmu); -const struct pmu_events_table *pmu_events_table__find(void); const struct pmu_metrics_table *pmu_metrics_table__find(void); =20 int perf_pmu__convert_scale(const char *scale, char **end, double *sval); --=20 2.34.1