perf test: Test more sysfs events

Parse events for all PMUs, and not just cpu, in test "Parsing of all
PMU events from sysfs".

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ahmad Yasin <ahmad.yasin@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Samantha Alt <samantha.alt@intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230502223851.2234828-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2023-05-02 15:38:17 -07:00 committed by Arnaldo Carvalho de Melo
parent cde61c6052
commit 5a52817e38

View file

@ -7,6 +7,7 @@
#include "debug.h"
#include "pmu.h"
#include "pmu-hybrid.h"
#include "pmus.h"
#include <dirent.h>
#include <errno.h>
#include "fncache.h"
@ -558,7 +559,8 @@ static int test__checkevent_pmu_events(struct evlist *evlist)
struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == 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 evlist *evlist)
/* cpu/pmu-event/u*/
evsel = evsel__next(evsel);
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == 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)
static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{
struct stat st;
char path[PATH_MAX];
struct dirent *ent;
DIR *dir;
int ret;
struct perf_pmu *pmu;
int ret = TEST_OK;
if (!test_pmu())
return TEST_SKIP;
if (list_empty(&pmus))
perf_pmu__scan(NULL);
snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
sysfs__mountpoint());
perf_pmus__for_each_pmu(pmu) {
struct stat st;
char path[PATH_MAX];
struct dirent *ent;
DIR *dir;
int err;
ret = stat(path, &st);
if (ret) {
pr_debug("omitting PMU cpu events tests: %s\n", path);
return TEST_OK;
}
snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
sysfs__mountpoint(), pmu->name);
dir = opendir(path);
if (!dir) {
pr_debug("can't open pmu event dir: %s\n", path);
return TEST_FAIL;
}
ret = TEST_OK;
while ((ent = readdir(dir))) {
struct evlist_test e = { .name = NULL, };
char name[2 * NAME_MAX + 1 + 12 + 3];
int test_ret;
/* Names containing . are special and cannot be used directly */
if (strchr(ent->d_name, '.'))
err = stat(path, &st);
if (err) {
pr_debug("skipping PMU %s events tests: %s\n", pmu->name, path);
continue;
snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
e.name = name;
e.check = test__checkevent_pmu_events;
test_ret = test_event(&e);
if (test_ret != TEST_OK) {
pr_debug("Test PMU event failed for '%s'", name);
ret = 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, '-'))
dir = opendir(path);
if (!dir) {
pr_debug("can't open pmu event dir: %s\n", path);
ret = combine_test_results(ret, TEST_SKIP);
continue;
snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
e.name = name;
e.check = test__checkevent_pmu_events_mix;
test_ret = test_event(&e);
if (test_ret != TEST_OK) {
pr_debug("Test PMU event failed for '%s'", name);
ret = combine_test_results(ret, test_ret);
}
}
closedir(dir);
while ((ent = readdir(dir))) {
struct evlist_test e = { .name = NULL, };
char name[2 * NAME_MAX + 1 + 12 + 3];
int test_ret;
/* Names containing . are special and cannot be used directly */
if (strchr(ent->d_name, '.'))
continue;
snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
e.name = name;
e.check = test__checkevent_pmu_events;
test_ret = test_event(&e);
if (test_ret != TEST_OK) {
pr_debug("Test PMU event failed for '%s'", name);
ret = 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=%s/u",
ent->d_name, pmu->name, ent->d_name);
e.name = name;
e.check = test__checkevent_pmu_events_mix;
test_ret = test_event(&e);
if (test_ret != TEST_OK) {
pr_debug("Test PMU event failed for '%s'", name);
ret = combine_test_results(ret, test_ret);
}
}
closedir(dir);
}
return ret;
}