Skip to contentSkip to conversation

perf test: Fix parse-events tests to skip parametrized events

PATCH Superseded Athira Rajeev 3 participants 5 messages Aug 7, 2023 – Sep 7, 2023 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf test: Fix parse-events tests to skip parametrized events

Testcase "Parsing of all PMU events from sysfs" parse events for all PMUs, and not just cpu. In case of powerpc, the PowerVM environment supports events from hv_24x7 and hv_gpci PMU which is of example format like below:

- hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
- hv_gpci/event,partition_id=?/

The value for "?" needs to be filled in depending on system configuration. It is better to skip these parametrized events in this test as it is done in:
'commit b50d691e50e6 ("perf test: Fix "all PMU test" to skip parametrized events")' which handled a simialr instance with "all PMU test".

Fix parse-events test to skip parametrized events since it needs proper setup of the parameters.

---
 tools/perf/tests/parse-events.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
tools/perf/tests/parse-events.c +32 -0
index b2f82847e4c3..605373c7d005 100644
@@ -2504,7 +2504,11 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
 	while ((pmu = perf_pmus__scan(pmu)) != NULL) {
 		struct stat st;
 		char path[PATH_MAX];
+		char pmu_event[PATH_MAX + 256];
+		char *buf = NULL;
+		FILE *file;
 		struct dirent *ent;
+		size_t len = 0;
 		DIR *dir;
 		int err;
 
@@ -2528,11 +2532,39 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
 			struct evlist_test e = { .name = NULL, };
 			char name[2 * NAME_MAX + 1 + 12 + 3];
 			int test_ret;
+			int skip = 0;
 
 			/* Names containing . are special and cannot be used directly */
 			if (strchr(ent->d_name, '.'))
 				continue;
 
+			/* exclude parametrized ones (name contains '?') */
+			snprintf(pmu_event, PATH_MAX + 256, "%s%s", path, ent->d_name);
+			file = fopen(pmu_event, "r");
+			if (!file) {
+				pr_debug("can't open pmu event file for '%s'\n", ent->d_name);
+				ret = combine_test_results(ret, TEST_FAIL);
+				continue;
+			}
+
+			if (getline(&buf, &len, file) < 0) {
+				pr_debug(" pmu event: %s is a null event\n", ent->d_name);
+				ret = combine_test_results(ret, TEST_FAIL);
+				continue;
+			}
+
+			if (strchr(buf, '?'))
+				skip = 1;
+
+			free(buf);
+			buf = NULL;
+			fclose(file);
+
+			if (skip == 1) {
+				pr_debug("skipping parametrized PMU event: %s which contains ?\n", pmu_event);
+				continue;
+			}
+
 			snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
 
 			e.name  = name;
Signature · 1 line
2.31.1
Tested-by on v1 1/1
#1 lore raw
Quoted 19 lines · Athira Rajeev

Testcase "Parsing of all PMU events from sysfs" parse events for all PMUs, and not just cpu. In case of powerpc, the PowerVM environment supports events from hv_24x7 and hv_gpci PMU which is of example format like below:

- hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
- hv_gpci/event,partition_id=?/

The value for "?" needs to be filled in depending on system configuration. It is better to skip these parametrized events in this test as it is done in:
'commit b50d691e50e6 ("perf test: Fix "all PMU test" to skip parametrized events")' which handled a simialr instance with "all PMU test".

Quoted 5 lines

Fix parse-events test to skip parametrized events since it needs proper setup of the parameters.

—

Thanks Athira for the fix. With this fix applied the reported problem Is fixed.

6.1: Test event parsing : Ok
6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

#2 lore raw
Quoted 32 lines · Sachin Sant
Quoted 20 lines · Athira Rajeev

Testcase "Parsing of all PMU events from sysfs" parse events for all PMUs, and not just cpu. In case of powerpc, the PowerVM environment supports events from hv_24x7 and hv_gpci PMU which is of example format like below:

- hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
- hv_gpci/event,partition_id=?/

The value for "?" needs to be filled in depending on system configuration. It is better to skip these parametrized events in this test as it is done in:
'commit b50d691e50e6 ("perf test: Fix "all PMU test" to skip parametrized events")' which handled a simialr instance with "all PMU test".

Quoted 5 lines

Fix parse-events test to skip parametrized events since it needs proper setup of the parameters.

—

Thanks Athira for the fix. With this fix applied the reported problem Is fixed.

Quoted 7 lines

6.1: Test event parsing : Ok
6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

Hi All,

Looking for review comments on this patch

Thanks
Athira

reviewer
#3 lore raw
In reply to Athira Rajeev
Quoted 9 lines · Athira Rajeev

Testcase "Parsing of all PMU events from sysfs" parse events for all PMUs, and not just cpu. In case of powerpc, the PowerVM environment supports events from hv_24x7 and hv_gpci PMU which is of example format like below:

- hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
- hv_gpci/event,partition_id=?/

Quoted 6 lines

The value for "?" needs to be filled in depending on system configuration. It is better to skip these parametrized events in this test as it is done in:
'commit b50d691e50e6 ("perf test: Fix "all PMU test" to skip parametrized events")' which handled a simialr instance with "all PMU test".

I'd say this is different, the "?" is really ugly. On other architectures the problem is solved by having >1 PMU, domain and core can be meta-data associated with the PMU. If we want to aggregate based on domain and core in the perf tool, it will need a different way of solving the problem for Power. Skipping the test is just pushing this problem down the road.

Quoted 13 lines

Fix parse-events test to skip parametrized events since it needs proper setup of the parameters.

---
 tools/perf/tests/parse-events.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
tools/perf/tests/parse-events.c +0 -0
index b2f82847e4c3..605373c7d005 100644

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2507

Quoted 4 lines
tools/perf/tests/parse-events.c +1 -0
@@ -2504,7 +2504,11 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
        while ((pmu = perf_pmus__scan(pmu)) != NULL) {
                struct stat st;
                char path[PATH_MAX];
+               char pmu_event[PATH_MAX + 256];

By definition paths can't be longer than PATH_MAX.

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2535

Quoted 12 lines
tools/perf/tests/parse-events.c +4 -0
+               char *buf = NULL;
+               FILE *file;
                struct dirent *ent;
+               size_t len = 0;
                DIR *dir;
                int err;
 
@@ -2528,11 +2532,39 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
                        struct evlist_test e = { .name = NULL, };
                        char name[2 * NAME_MAX + 1 + 12 + 3];
                        int test_ret;
+                       int skip = 0;

Prefer a boolean. Prefer is_event_parameterized over skip to make variable name more intention revealing.

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2542

Quoted 7 lines
tools/perf/tests/parse-events.c +2 -0
                        /* Names containing . are special and cannot be used directly */
                        if (strchr(ent->d_name, '.'))
                                continue;
 
+                       /* exclude parametrized ones (name contains '?') */
+                       snprintf(pmu_event, PATH_MAX + 256, "%s%s", path, ent->d_name);

Use sizeof(pmu_event) rather than "PATH_MAX + 256".

Thanks,
Ian

Quoted 31 lines
tools/perf/tests/parse-events.c +25 -1
+                       file = fopen(pmu_event, "r");
+                       if (!file) {
+                               pr_debug("can't open pmu event file for '%s'\n", ent->d_name);
+                               ret = combine_test_results(ret, TEST_FAIL);
+                               continue;
+                       }
+
+                       if (getline(&buf, &len, file) < 0) {
+                               pr_debug(" pmu event: %s is a null event\n", ent->d_name);
+                               ret = combine_test_results(ret, TEST_FAIL);
+                               continue;
+                       }
+
+                       if (strchr(buf, '?'))
+                               skip = 1;
+
+                       free(buf);
+                       buf = NULL;
+                       fclose(file);
+
+                       if (skip == 1) {
+                               pr_debug("skipping parametrized PMU event: %s which contains ?\n", pmu_event);
+                               continue;
+                       }
+
                        snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
 
                        e.name  = name;
--

2.31.1

#4 lore raw
Quoted 22 lines · Ian Rogers
Quoted 9 lines · Athira Rajeev

Testcase "Parsing of all PMU events from sysfs" parse events for all PMUs, and not just cpu. In case of powerpc, the PowerVM environment supports events from hv_24x7 and hv_gpci PMU which is of example format like below:

- hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
- hv_gpci/event,partition_id=?/

Quoted 6 lines

The value for "?" needs to be filled in depending on system configuration. It is better to skip these parametrized events in this test as it is done in:
'commit b50d691e50e6 ("perf test: Fix "all PMU test" to skip parametrized events")' which handled a simialr instance with "all PMU test".

Quoted 6 lines

I'd say this is different, the "?" is really ugly. On other architectures the problem is solved by having >1 PMU, domain and core can be meta-data associated with the PMU. If we want to aggregate based on domain and core in the perf tool, it will need a different way of solving the problem for Power. Skipping the test is just pushing this problem down the road.

Hi Ian

Thanks for the comments. We will check on this for powerpc.

Quoted 9 lines
Quoted 9 lines

Fix parse-events test to skip parametrized events since it needs proper setup of the parameters.

---
tools/perf/tests/parse-events.c | 32 ++++++++++++++++++++++++++++++++

1 file changed, 32 insertions(+)
Quoted 11 lines

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2507

Quoted 9 lines
tools/perf/tests/parse-events.c +1 -0
index b2f82847e4c3..605373c7d005 100644
@@ -2504,7 +2504,11 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
       while ((pmu = perf_pmus__scan(pmu)) != NULL) {
               struct stat st;
               char path[PATH_MAX];
+               char pmu_event[PATH_MAX + 256];

By definition paths can't be longer than PATH_MAX.

Yeah, my bad. Will fix this.

Quoted 8 lines
Quoted 8 lines
tools/perf/tests/parse-events.c +3 -0
+               char *buf = NULL;
+               FILE *file;
               struct dirent *ent;
+               size_t len = 0;
               DIR *dir;
               int err;
 
Quoted 8 lines

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2535

Quoted 5 lines
tools/perf/tests/parse-events.c +1 -0
@@ -2528,11 +2532,39 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
                       struct evlist_test e = { .name = NULL, };
                       char name[2 * NAME_MAX + 1 + 12 + 3];
                       int test_ret;
+                       int skip = 0;

Prefer a boolean. Prefer is_event_parameterized over skip to make variable name more intention revealing.

Sure

Quoted 10 lines

tools/perf/tests/parse-events.c static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest · line 2542

Quoted 8 lines
tools/perf/tests/parse-events.c +2 -0
                       /* Names containing . are special and cannot be used directly */
                       if (strchr(ent->d_name, '.'))
                               continue;
 
+                       /* exclude parametrized ones (name contains '?') */
+                       snprintf(pmu_event, PATH_MAX + 256, "%s%s", path, ent->d_name);

Use sizeof(pmu_event) rather than "PATH_MAX + 256".

Will send V2 with these changes

Quoted 34 lines

Thanks,
Ian

Quoted 30 lines
tools/perf/tests/parse-events.c +25 -1
+                       file = fopen(pmu_event, "r");
+                       if (!file) {
+                               pr_debug("can't open pmu event file for '%s'\n", ent->d_name);
+                               ret = combine_test_results(ret, TEST_FAIL);
+                               continue;
+                       }
+
+                       if (getline(&buf, &len, file) < 0) {
+                               pr_debug(" pmu event: %s is a null event\n", ent->d_name);
+                               ret = combine_test_results(ret, TEST_FAIL);
+                               continue;
+                       }
+
+                       if (strchr(buf, '?'))
+                               skip = 1;
+
+                       free(buf);
+                       buf = NULL;
+                       fclose(file);
+
+                       if (skip == 1) {
+                               pr_debug("skipping parametrized PMU event: %s which contains ?\n", pmu_event);
+                               continue;
+                       }
+
                       snprintf(name, sizeof(name), "%s/event=%s/u", pmu->name, ent->d_name);
 
                       e.name  = name;
--

2.31.1