From nobody Thu Dec 18 08:38:00 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 C0867C77B7C for ; Wed, 26 Apr 2023 07:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239637AbjDZHHR (ORCPT ); Wed, 26 Apr 2023 03:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239499AbjDZHG1 (ORCPT ); Wed, 26 Apr 2023 03:06:27 -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 11EF344A4 for ; Wed, 26 Apr 2023 00:05:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b92309d84c1so33260967276.1 for ; Wed, 26 Apr 2023 00:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682492704; x=1685084704; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/DyyFJ8rDDuRlbHILxuq/n1XyL8kZC4XVBz7gkkjj0g=; b=yD7jcbQ7BtJ9heAatlDomgW6pBoRf4c4a9IxQn1R9HmjAX+cV5hEbzt2ooIiX933nq C44kx9wOeM9NxV2mVcIewNEqf/cx42oRK4BX4A8b6LrOh1eteLLhyImuR0QVuOG2lAmz U9Cs04OMS8eN0amzclZoRNgD4Sqx9d9RCP6ZGFp8Joj7r86drbAkz5p8OW7G2nTHASb+ cZt4nUOEV3icNO8QusxaknZtcQAzHLzF/ialPZ0NgqYGjRKtMTl/v+r0PNo1rOA+09Tn L68Pm6MOh03BFa6Yxlj6vMt1IrSCxQm1Z6nnWlpPHd3vNPiSedEHLWKCSjcVJCZhLw1o tSvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682492704; x=1685084704; h=cc: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=/DyyFJ8rDDuRlbHILxuq/n1XyL8kZC4XVBz7gkkjj0g=; b=iavb/efj8a2Zy7b37JYVCkZujfE50ruRdOVdBGDxWbvMqPcVBQY2mA2qBuexpvzaJ2 df7va47HOIiTsRBtWn0sKRO8+95Ihd8nhdlYrSfPRjXv1OCBZv/SYJc802GW4r4vofEb qEre4wI6neJ30C7gcrb/JvlBUoxLvARPS3hV4U5C8Q68MFbqv+/WaMuXV+e8I4y5EUnW BaUFUgl/vCQ6CeeiDwqt2a4Tocnecnd1nFvP5ClWrj0aQ85dDsr5eFM5ewKDs0AnRUQf NF/SPnn+f2FXYQYC7T6+1xJw8YSrwa1W0PxOJ5jEFj0A6xVtGmXkgxAqaPTOJ1WeABZ/ V75g== X-Gm-Message-State: AC+VfDwM2Lr52J1i0zKpjVaA78TQGOZwk8f80zQo0Z6Z85zp9tJ4SRXV qsr3kluOmtyuCOG8osndktSFfOCpdf0Z X-Google-Smtp-Source: ACHHUZ6y5R6hIPDBP9JQr5OofgHsoDW8CGyVPTublNJFdV0I29Qxn3zeHGmzR+1HVeBLii4tKNgr1yqBc9xY X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:144f:e890:2b29:48d9]) (user=irogers job=sendgmr) by 2002:a81:ad0e:0:b0:54f:bf72:7fa6 with SMTP id l14-20020a81ad0e000000b0054fbf727fa6mr1003155ywh.0.1682492703869; Wed, 26 Apr 2023 00:05:03 -0700 (PDT) Date: Wed, 26 Apr 2023 00:00:39 -0700 In-Reply-To: <20230426070050.1315519-1-irogers@google.com> Message-Id: <20230426070050.1315519-30-irogers@google.com> Mime-Version: 1.0 References: <20230426070050.1315519-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v1 29/40] perf test: Fix parse-events tests for >1 core PMU From: Ian Rogers To: Arnaldo Carvalho de Melo , Kan Liang , Ahmad Yasin , Peter Zijlstra , Ingo Molnar , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Florian Fischer , Rob Herring , Zhengjun Xing , John Garry , Kajol Jain , Sumanth Korikkar , Thomas Richter , Tiezhu Yang , Ravi Bangoria , Leo Yan , Yang Jihong , James Clark , Suzuki Poulouse , Kang Minchul , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove assumptions of just 1 core PMU. Signed-off-by: Ian Rogers --- tools/perf/tests/parse-events.c | 179 +++++++++++++++++++------------- 1 file changed, 106 insertions(+), 73 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 0b8ec9b1034f..a0cd50e18ebc 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -25,6 +25,11 @@ static bool test_config(const struct evsel *evsel, __u64= expected_config) return (evsel->core.attr.config & PERF_HW_EVENT_MASK) =3D=3D expected_con= fig; } =20 +static bool test_perf_config(const struct perf_evsel *evsel, __u64 expecte= d_config) +{ + return (evsel->attr.config & PERF_HW_EVENT_MASK) =3D=3D expected_config; +} + #ifdef HAVE_LIBTRACEEVENT =20 #if defined(__s390x__) @@ -87,11 +92,27 @@ static int test__checkevent_tracepoint_multi(struct evl= ist *evlist) =20 static int test__checkevent_raw(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); + struct perf_evsel *evsel; + bool raw_type_match =3D false; =20 - TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type); - TEST_ASSERT_VAL("wrong config", test_config(evsel, 0x1a)); + TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); + + perf_evlist__for_each_evsel(&evlist->core, evsel) { + struct perf_pmu *pmu; + bool type_matched =3D false; + + TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); + perf_pmus__for_each_pmu(pmu) { + if (pmu->type =3D=3D evsel->attr.type) { + TEST_ASSERT_VAL("PMU type expected once", !type_matched); + type_matched =3D true; + if (pmu->type =3D=3D PERF_TYPE_RAW) + raw_type_match =3D true; + } + } + TEST_ASSERT_VAL("No PMU found for type", type_matched); + } + TEST_ASSERT_VAL("Raw PMU not matched", raw_type_match); return TEST_OK; } =20 @@ -107,31 +128,35 @@ static int test__checkevent_numeric(struct evlist *ev= list) =20 static int test__checkevent_symbolic_name(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); + struct perf_evsel *evsel; =20 - TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr.= type); - TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_INSTRUCT= IONS)); + TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); + + perf_evlist__for_each_evsel(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->attr.type= ); + TEST_ASSERT_VAL("wrong config", + test_perf_config(evsel, PERF_COUNT_HW_INSTRUCTIONS)); + } return TEST_OK; } =20 static int test__checkevent_symbolic_name_config(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); + struct perf_evsel *evsel; =20 - TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->core.attr.= type); - TEST_ASSERT_VAL("wrong config", test_config(evsel, PERF_COUNT_HW_CPU_CYCL= ES)); - /* - * The period value gets configured within evlist__config, - * while this test executes only parse events method. - */ - TEST_ASSERT_VAL("wrong period", - 0 =3D=3D evsel->core.attr.sample_period); - TEST_ASSERT_VAL("wrong config1", - 0 =3D=3D evsel->core.attr.config1); - TEST_ASSERT_VAL("wrong config2", - 1 =3D=3D evsel->core.attr.config2); + TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); + + perf_evlist__for_each_evsel(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->attr.type= ); + TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, PERF_COUNT_HW_CP= U_CYCLES)); + /* + * The period value gets configured within evlist__config, + * while this test executes only parse events method. + */ + TEST_ASSERT_VAL("wrong period", 0 =3D=3D evsel->attr.sample_period); + TEST_ASSERT_VAL("wrong config1", 0 =3D=3D evsel->attr.config1); + TEST_ASSERT_VAL("wrong config2", 1 =3D=3D evsel->attr.config2); + } return TEST_OK; } =20 @@ -147,11 +172,14 @@ static int test__checkevent_symbolic_alias(struct evl= ist *evlist) =20 static int test__checkevent_genhw(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); + struct perf_evsel *evsel; =20 - TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE =3D=3D evsel->core.attr.= type); - TEST_ASSERT_VAL("wrong config", test_config(evsel, 1 << 16)); + TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); + + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE =3D=3D evsel->attr.type= ); + TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 1 << 16)); + } return TEST_OK; } =20 @@ -243,17 +271,15 @@ static int test__checkevent_tracepoint_modifier(struc= t evlist *evlist) static int test__checkevent_tracepoint_multi_modifier(struct evlist *evlist) { - struct evsel *evsel; + struct perf_evsel *evsel; =20 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1); =20 - evlist__for_each_entry(evlist, evsel) { - TEST_ASSERT_VAL("wrong exclude_user", - !evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", - evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); } =20 return test__checkevent_tracepoint_multi(evlist); @@ -262,25 +288,27 @@ test__checkevent_tracepoint_multi_modifier(struct evl= ist *evlist) =20 static int test__checkevent_raw_modifier(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); - - TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); + struct perf_evsel *evsel; =20 + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); + } return test__checkevent_raw(evlist); } =20 static int test__checkevent_numeric_modifier(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); - - TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); + struct perf_evsel *evsel; =20 + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); + } return test__checkevent_numeric(evlist); } =20 @@ -298,21 +326,23 @@ static int test__checkevent_symbolic_name_modifier(st= ruct evlist *evlist) =20 static int test__checkevent_exclude_host_modifier(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); - - TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); - TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host); + struct perf_evsel *evsel; =20 + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude guest", !evsel->attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude host", evsel->attr.exclude_host); + } return test__checkevent_symbolic_name(evlist); } =20 static int test__checkevent_exclude_guest_modifier(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); - - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); - TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); - + struct perf_evsel *evsel; +=20 + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude guest", evsel->attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude host", !evsel->attr.exclude_host); + } return test__checkevent_symbolic_name(evlist); } =20 @@ -330,13 +360,14 @@ static int test__checkevent_symbolic_alias_modifier(s= truct evlist *evlist) =20 static int test__checkevent_genhw_modifier(struct evlist *evlist) { - struct evsel *evsel =3D evlist__first(evlist); - - TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip); + struct perf_evsel *evsel; =20 + perf_evlist__for_each_entry(&evlist->core, evsel) { + TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); + } return test__checkevent_genhw(evlist); } =20 @@ -466,21 +497,23 @@ static int test__checkevent_list(struct evlist *evlis= t) { struct evsel *evsel =3D evlist__first(evlist); =20 - TEST_ASSERT_VAL("wrong number of entries", 3 =3D=3D evlist->core.nr_entri= es); + TEST_ASSERT_VAL("wrong number of entries", 3 <=3D evlist->core.nr_entries= ); =20 /* r1 */ - TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type); - TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); - TEST_ASSERT_VAL("wrong config1", 0 =3D=3D evsel->core.attr.config1); - TEST_ASSERT_VAL("wrong config2", 0 =3D=3D evsel->core.attr.config2); - TEST_ASSERT_VAL("wrong config3", 0 =3D=3D evsel->core.attr.config3); - TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); - TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); - TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); + TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT !=3D evsel->core.attr.= type); + while (PERF_TYPE_TRACEPOINT !=3D evsel->core.attr.type) { + TEST_ASSERT_VAL("wrong config", test_config(evsel, 1)); + TEST_ASSERT_VAL("wrong config1", 0 =3D=3D evsel->core.attr.config1); + TEST_ASSERT_VAL("wrong config2", 0 =3D=3D evsel->core.attr.config2); + TEST_ASSERT_VAL("wrong config3", 0 =3D=3D evsel->core.attr.config3); + TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); + TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); + TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); + evsel =3D evsel__next(evsel); + } =20 /* syscalls:sys_enter_openat:k */ - evsel =3D evsel__next(evsel); TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT =3D=3D evsel->core.att= r.type); TEST_ASSERT_VAL("wrong sample_type", PERF_TP_SAMPLE_TYPE =3D=3D evsel->core.attr.sample_type); @@ -1916,7 +1949,7 @@ static int test_event(const struct evlist_test *e) e->name, ret, err.str); parse_events_error__print(&err, e->name); ret =3D TEST_FAIL; - if (strstr(err.str, "can't access trace events")) + if (err.str && strstr(err.str, "can't access trace events")) ret =3D TEST_SKIP; } else { ret =3D e->check(evlist); --=20 2.40.1.495.gc816e09b53d-goog