From nobody Thu Dec 18 22:15:22 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 D5B62C19F20 for ; Tue, 2 May 2023 22:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbjEBWlB (ORCPT ); Tue, 2 May 2023 18:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbjEBWk5 (ORCPT ); Tue, 2 May 2023 18:40:57 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E13E358E for ; Tue, 2 May 2023 15:40:25 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-552f2f940edso84337997b3.0 for ; Tue, 02 May 2023 15:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683067222; x=1685659222; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2hc6sYqaX/JTEzA/WD5PdQqzvPbvzN/Ao//5MFid2Dk=; b=cPM/XeaYqW8ATEh2et7lHdr0dAMzZNIm5WbuxFf8j8j45I0GkN69BbdrMqfbvtTjFz /rwgkYHSWC2gH7+pVPv4Tep2Zl1i4ofTcxJWGu21WQU5f2n+npUt3CnreJzRJfB0Vuuc DRLXb+f4x0X3cZe4SFAa3gfzN7lHKQU0gtpHFQOZ3H2Ald2QdjFk/xpj2qKEhrAn+EoH kt7DdfJLOuiwhz9l+SqgE85rpt5CJDQtCeQYyHkr7RX09hbO0RTSaiXsSo6u3mg3oXkJ bWUtBTofyZCuUyzSy8IIZZWqd6+PoU69fjDSZ/yuISJ9duzO3QAhqmVIFpUU3eFVgrp9 cOCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683067222; x=1685659222; 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=2hc6sYqaX/JTEzA/WD5PdQqzvPbvzN/Ao//5MFid2Dk=; b=XhsPtfRnYhVfaqAHWS/qiHv0DLxwC9HmA2RKJ1l6mwsKXY3fu+9Kllg9UkU3YUy2Mc Ixc5Y2cgZcFVXpsEQ2/Mke13NgGbugD3sY9t62A4F5Lg3xtLLHwSFo72pKvWrMpZ1XTo vGQcfAgqSErOEfka/Kuzl2n19tJ1qu/KDU34e6R0tpmrnYdNKe3vRO3mXznuhjDrjiTR /JPTEMac9K8e9ZJy7zPp7Tv9Dqx7+q9QmjvKroe8idmxSky6HwDVYLUmBGYsXNwzvMsj iREEKBrcWh6anE3i7NlAbYzw/X+IJDni3bP0Voh9/E2Vz8+Yv+tmyl6YniHFc6Z48auZ MlSA== X-Gm-Message-State: AC+VfDyCnWy/hxUEvATpSCeqo6wBxVB1VhY9JkYj064UdSNQJXD8Bc+r LHn+Zp7Mt0m6lk2pkKxKcblEPt976puR X-Google-Smtp-Source: ACHHUZ6aqJfkF1DqLqV5dk0PcZwobR7Cpms4xHZeUifk8XAn1c6w2Zms4SRaNZSJKKQ3uNmdCClNiXbd+SuL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:e70c:446b:d23b:982e]) (user=irogers job=sendgmr) by 2002:a81:a8c4:0:b0:556:edb1:1fb0 with SMTP id f187-20020a81a8c4000000b00556edb11fb0mr11609056ywh.10.1683067222531; Tue, 02 May 2023 15:40:22 -0700 (PDT) Date: Tue, 2 May 2023 15:38:17 -0700 In-Reply-To: <20230502223851.2234828-1-irogers@google.com> Message-Id: <20230502223851.2234828-11-irogers@google.com> Mime-Version: 1.0 References: <20230502223851.2234828-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v4 10/44] perf test: Test more sysfs events 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" Parse events for all PMUs, and not just cpu, in test "Parsing of all PMU events from sysfs". Signed-off-by: Ian Rogers --- tools/perf/tests/parse-events.c | 129 ++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 58 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 8068cfd89b84..3721a2182f45 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -7,6 +7,7 @@ #include "debug.h" #include "pmu.h" #include "pmu-hybrid.h" +#include "pmus.h" #include #include #include "fncache.h" @@ -558,7 +559,8 @@ static int test__checkevent_pmu_events(struct evlist *e= vlist) struct evsel *evsel =3D evlist__first(evlist); =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 type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type = || + strcmp(evsel->pmu_name, "cpu")); TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", @@ -590,7 +592,8 @@ static int test__checkevent_pmu_events_mix(struct evlis= t *evlist) /* cpu/pmu-event/u*/ evsel =3D evsel__next(evsel); TEST_ASSERT_VAL("wrong number of entries", 2 =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 type", PERF_TYPE_RAW =3D=3D evsel->core.attr.type = || + strcmp(evsel->pmu_name, "cpu")); TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", @@ -2225,74 +2228,84 @@ static int test_pmu(void) =20 static int test__pmu_events(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) { - struct stat st; - char path[PATH_MAX]; - struct dirent *ent; - DIR *dir; - int ret; - - if (!test_pmu()) - return TEST_SKIP; + struct perf_pmu *pmu; + int ret =3D TEST_OK; =20 - snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/", - sysfs__mountpoint()); + if (list_empty(&pmus)) + perf_pmu__scan(NULL); =20 - ret =3D stat(path, &st); - if (ret) { - pr_debug("omitting PMU cpu events tests: %s\n", path); - return TEST_OK; - } + perf_pmus__for_each_pmu(pmu) { + struct stat st; + char path[PATH_MAX]; + struct dirent *ent; + DIR *dir; + int err; =20 - dir =3D opendir(path); - if (!dir) { - pr_debug("can't open pmu event dir: %s\n", path); - return TEST_FAIL; - } + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/", + sysfs__mountpoint(), pmu->name); =20 - ret =3D TEST_OK; - while ((ent =3D readdir(dir))) { - struct evlist_test e =3D { .name =3D NULL, }; - char name[2 * NAME_MAX + 1 + 12 + 3]; - int test_ret; + err =3D stat(path, &st); + if (err) { + pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path); + continue; + } =20 - /* Names containing . are special and cannot be used directly */ - if (strchr(ent->d_name, '.')) + dir =3D opendir(path); + if (!dir) { + pr_debug("can't open pmu event dir: %s\n", path); + ret =3D combine_test_results(ret, TEST_SKIP); continue; + } =20 - snprintf(name, sizeof(name), "cpu/event=3D%s/u", ent->d_name); + while ((ent =3D readdir(dir))) { + struct evlist_test e =3D { .name =3D NULL, }; + char name[2 * NAME_MAX + 1 + 12 + 3]; + int test_ret; =20 - e.name =3D name; - e.check =3D test__checkevent_pmu_events; + /* Names containing . are special and cannot be used directly */ + if (strchr(ent->d_name, '.')) + continue; =20 - test_ret =3D test_event(&e); - if (test_ret !=3D TEST_OK) { - pr_debug("Test PMU event failed for '%s'", name); - ret =3D combine_test_results(ret, test_ret); - } - /* - * Names containing '-' are recognized as prefixes and suffixes - * due to '-' being a legacy PMU separator. This fails when the - * prefix or suffix collides with an existing legacy token. For - * example, branch-brs has a prefix (branch) that collides with - * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix - * isn't expected after this. As event names in the config - * slashes are allowed a '-' in the name we check this works - * above. - */ - if (strchr(ent->d_name, '-')) - continue; + snprintf(name, sizeof(name), "%s/event=3D%s/u", pmu->name, ent->d_name); =20 - snprintf(name, sizeof(name), "%s:u,cpu/event=3D%s/u", ent->d_name, ent->= d_name); - e.name =3D name; - e.check =3D test__checkevent_pmu_events_mix; - test_ret =3D test_event(&e); - if (test_ret !=3D TEST_OK) { - pr_debug("Test PMU event failed for '%s'", name); - ret =3D combine_test_results(ret, test_ret); + e.name =3D name; + e.check =3D test__checkevent_pmu_events; + + test_ret =3D test_event(&e); + if (test_ret !=3D TEST_OK) { + pr_debug("Test PMU event failed for '%s'", name); + ret =3D combine_test_results(ret, test_ret); + } + + if (!is_pmu_core(pmu->name)) + continue; + + /* + * Names containing '-' are recognized as prefixes and suffixes + * due to '-' being a legacy PMU separator. This fails when the + * prefix or suffix collides with an existing legacy token. For + * example, branch-brs has a prefix (branch) that collides with + * a PE_NAME_CACHE_TYPE token causing a parse error as a suffix + * isn't expected after this. As event names in the config + * slashes are allowed a '-' in the name we check this works + * above. + */ + if (strchr(ent->d_name, '-')) + continue; + + snprintf(name, sizeof(name), "%s:u,%s/event=3D%s/u", + ent->d_name, pmu->name, ent->d_name); + e.name =3D name; + e.check =3D test__checkevent_pmu_events_mix; + test_ret =3D test_event(&e); + if (test_ret !=3D TEST_OK) { + pr_debug("Test PMU event failed for '%s'", name); + ret =3D combine_test_results(ret, test_ret); + } } - } =20 - closedir(dir); + closedir(dir); + } return ret; } =20 --=20 2.40.1.495.gc816e09b53d-goog