From nobody Sat Feb 7 18:29:17 2026 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 ED410EB64DA for ; Wed, 5 Jul 2023 08:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbjGEI1U (ORCPT ); Wed, 5 Jul 2023 04:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232056AbjGEI1J (ORCPT ); Wed, 5 Jul 2023 04:27:09 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D63E5184; Wed, 5 Jul 2023 01:27:05 -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 EFA6E169C; Wed, 5 Jul 2023 01:27:47 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EC4D73F73F; Wed, 5 Jul 2023 01:27:03 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] perf test: Fix event parsing test on Arm Date: Wed, 5 Jul 2023 09:26:51 +0100 Message-Id: <20230705082653.23566-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705082653.23566-1-james.clark@arm.com> References: <20230705082653.23566-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" The test looks for a PMU from sysfs with type =3D PERF_TYPE_RAW when opening a raw event. Arm doesn't have a real raw PMU, only core PMUs with unique types other than raw. Instead of looking for a matching PMU, just test that the event type was parsed as raw and skip the PMU search on Arm. The raw event type test should also apply to all platforms so add it outside of the ifdef. Fixes: aefde50a446b ("perf test: Fix parse-events tests for >1 core PMU") Acked-by: Ian Rogers Signed-off-by: James Clark --- tools/perf/tests/parse-events.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 133218e51ab4..21f79aa31233 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -108,10 +108,21 @@ static int test__checkevent_raw(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu =3D NULL; + struct perf_pmu *pmu __maybe_unused =3D NULL; bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); + TEST_ASSERT_VAL("event not parsed as raw type", + evsel->attr.type =3D=3D PERF_TYPE_RAW); +#if defined(__aarch64__) + /* + * Arm doesn't have a real raw type PMU in sysfs, so raw events + * would never match any PMU. However, RAW events on Arm will + * always successfully open on the first available core PMU + * so no need to test for a matching type here. + */ + type_matched =3D raw_type_match =3D true; +#else while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); @@ -120,6 +131,7 @@ static int test__checkevent_raw(struct evlist *evlist) raw_type_match =3D true; } } +#endif TEST_ASSERT_VAL("No PMU found for type", type_matched); } TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match); --=20 2.34.1 From nobody Sat Feb 7 18:29:17 2026 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 2E441EB64DD for ; Wed, 5 Jul 2023 08:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbjGEI11 (ORCPT ); Wed, 5 Jul 2023 04:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbjGEI1L (ORCPT ); Wed, 5 Jul 2023 04:27:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1DFD61712; Wed, 5 Jul 2023 01:27:08 -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 3846D169E; Wed, 5 Jul 2023 01:27:50 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 345FF3F73F; Wed, 5 Jul 2023 01:27:06 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] perf test: Fix event parsing test when PERF_PMU_CAP_EXTENDED_HW_TYPE isn't supported. Date: Wed, 5 Jul 2023 09:26:52 +0100 Message-Id: <20230705082653.23566-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705082653.23566-1-james.clark@arm.com> References: <20230705082653.23566-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" Arm has multiple PMU types for heterogeneous systems, but doesn't currently support PERF_PMU_CAP_EXTENDED_HW_TYPE. Make the tests support both scenarios so that they pass on Arm, and will still pass once PERF_PMU_CAP_EXTENDED_HW_TYPE support is added. Fixes: 27c9fcfc1e14 ("perf test: Update parse-events expectations to test f= or multiple events") Acked-by: Ian Rogers Signed-off-by: James Clark --- tools/perf/tests/parse-events.c | 86 +++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 21f79aa31233..b2f82847e4c3 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -20,6 +20,20 @@ #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) =20 +static int num_core_entries(void) +{ + /* + * If the kernel supports extended type, expect events to be + * opened once for each core PMU type. Otherwise fall back to the legacy + * behavior of opening only one event even though there are multiple + * PMUs + */ + if (perf_pmus__supports_extended_type()) + return perf_pmus__num_core_pmus(); + + return 1; +} + static bool test_config(const struct evsel *evsel, __u64 expected_config) { __u32 type =3D evsel->core.attr.type; @@ -339,7 +353,7 @@ static int test__checkevent_symbolic_name_modifier(stru= ct evlist *evlist) struct perf_evsel *evsel; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D perf_pmus__num_core_pmus()); + evlist->core.nr_entries =3D=3D num_core_entries()); =20 perf_evlist__for_each_entry(&evlist->core, evsel) { TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); @@ -842,11 +856,11 @@ static int test__group1(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (perf_pmus__num_core_pmus() * 2)); + evlist->core.nr_entries =3D=3D (num_core_entries() * 2)); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D perf_pmus__num_core_pmus()); + evlist__nr_groups(evlist) =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* instructions:k */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -885,7 +899,7 @@ static int test__group2(struct evlist *evlist) struct evsel *evsel, *leader =3D NULL; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus() + 1)); + evlist->core.nr_entries =3D=3D (2 * num_core_entries() + 1)); /* * TODO: Currently the software event won't be grouped with the hardware * event except for 1 PMU. @@ -1051,11 +1065,11 @@ static int test__group4(struct evlist *evlist __may= be_unused) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (perf_pmus__num_core_pmus() * 2)); + evlist->core.nr_entries =3D=3D (num_core_entries() * 2)); TEST_ASSERT_VAL("wrong number of groups", - perf_pmus__num_core_pmus() =3D=3D evlist__nr_groups(evlist)); + num_core_entries() =3D=3D evlist__nr_groups(evlist)); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles:u + p */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1096,11 +1110,11 @@ static int test__group5(struct evlist *evlist __may= be_unused) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (5 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (5 * num_core_entries())); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist__nr_groups(evlist) =3D=3D (2 * num_core_entries())); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles + G */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1131,7 +1145,7 @@ static int test__group5(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) =3D=3D 1); TEST_ASSERT_VAL("wrong sample_read", !evsel->sample_read); } - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles:G */ evsel =3D leader =3D evsel__next(evsel); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1161,7 +1175,7 @@ static int test__group5(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) =3D=3D 1); } - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles */ evsel =3D evsel__next(evsel); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1182,11 +1196,11 @@ static int test__group_gh1(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (2 * num_core_entries())); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D perf_pmus__num_core_pmus()); + evlist__nr_groups(evlist) =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles + :H group modifier */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1223,11 +1237,11 @@ static int test__group_gh2(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (2 * num_core_entries())); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D perf_pmus__num_core_pmus()); + evlist__nr_groups(evlist) =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles + :G group modifier */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1264,11 +1278,11 @@ static int test__group_gh3(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (2 * num_core_entries())); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D perf_pmus__num_core_pmus()); + evlist__nr_groups(evlist) =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles:G + :u group modifier */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1305,11 +1319,11 @@ static int test__group_gh4(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (2 * num_core_entries())); TEST_ASSERT_VAL("wrong number of groups", - evlist__nr_groups(evlist) =3D=3D perf_pmus__num_core_pmus()); + evlist__nr_groups(evlist) =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles:G + :uG group modifier */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1346,9 +1360,9 @@ static int test__leader_sample1(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (3 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (3 * num_core_entries())); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles - sampling group leader */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1398,9 +1412,9 @@ static int test__leader_sample2(struct evlist *evlist= __maybe_unused) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (2 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (2 * num_core_entries())); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* instructions - sampling group leader */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1437,9 +1451,9 @@ static int test__checkevent_pinned_modifier(struct ev= list *evlist) struct evsel *evsel =3D NULL; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D perf_pmus__num_core_pmus()); + evlist->core.nr_entries =3D=3D num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { evsel =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(evsel)); TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); @@ -1455,9 +1469,9 @@ static int test__pinned_group(struct evlist *evlist) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (3 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D (3 * num_core_entries())); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles - group leader */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1500,9 +1514,9 @@ static int test__exclusive_group(struct evlist *evlis= t) struct evsel *evsel =3D NULL, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (3 * perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D 3 * num_core_entries()); =20 - for (int i =3D 0; i < perf_pmus__num_core_pmus(); i++) { + for (int i =3D 0; i < num_core_entries(); i++) { /* cycles - group leader */ evsel =3D leader =3D (i =3D=3D 0 ? evlist__first(evlist) : evsel__next(e= vsel)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr= .type); @@ -1574,7 +1588,7 @@ static int test__checkevent_precise_max_modifier(stru= ct evlist *evlist) struct evsel *evsel =3D evlist__first(evlist); =20 TEST_ASSERT_VAL("wrong number of entries", - evlist->core.nr_entries =3D=3D (1 + perf_pmus__num_core_pmus())); + evlist->core.nr_entries =3D=3D 1 + num_core_entries()); TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE =3D=3D evsel->core.attr.= type); TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_SW_TASK_CLO= CK)); return TEST_OK; --=20 2.34.1