Skip to contentSkip to conversation

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

PATCH Superseded Athira Rajeev 6 participants 9 messages Sep 7, 2023 – Sep 27, 2023 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

 tools/perf/tests/parse-events.c | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/perf/tests/parse-events.c +38 -0
index 658fb9599d95..1ecaeceb69f8 100644
@@ -2514,9 +2514,14 @@ 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];
+		char *buf = NULL;
+		FILE *file;
 		struct dirent *ent;
+		size_t len = 0;
 		DIR *dir;
 		int err;
+		int n;
 
 		snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
 			sysfs__mountpoint(), pmu->name);
@@ -2538,11 +2543,44 @@ 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;
+			bool is_event_parameterized = 0;
 
 			/* Names containing . are special and cannot be used directly */
 			if (strchr(ent->d_name, '.'))
 				continue;
 
+			/* exclude parametrized ones (name contains '?') */
+			n = snprintf(pmu_event, sizeof(pmu_event), "%s%s", path, ent->d_name);
+			if (n >= PATH_MAX) {
+				pr_err("pmu event name crossed PATH_MAX(%d) size\n", PATH_MAX);
+				continue;
+			}
+
+			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, '?'))
+				is_event_parameterized = 1;
+
+			free(buf);
+			buf = NULL;
+			fclose(file);
+
+			if (is_event_parameterized == 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
reviewer Tested-by on v2 1/1
#1 lore raw
Quoted 16 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 4 lines

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

Thanks,
Ian

Quoted 77 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

 tools/perf/tests/parse-events.c | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/perf/tests/parse-events.c +38 -1
index 658fb9599d95..1ecaeceb69f8 100644
@@ -2514,9 +2514,14 @@ 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];
+               char *buf = NULL;
+               FILE *file;
                struct dirent *ent;
+               size_t len = 0;
                DIR *dir;
                int err;
+               int n;
 
                snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
                        sysfs__mountpoint(), pmu->name);
@@ -2538,11 +2543,44 @@ 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;
+                       bool is_event_parameterized = 0;
 
                        /* Names containing . are special and cannot be used directly */
                        if (strchr(ent->d_name, '.'))
                                continue;
 
+                       /* exclude parametrized ones (name contains '?') */
+                       n = snprintf(pmu_event, sizeof(pmu_event), "%s%s", path, ent->d_name);
+                       if (n >= PATH_MAX) {
+                               pr_err("pmu event name crossed PATH_MAX(%d) size\n", PATH_MAX);
+                               continue;
+                       }
+
+                       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, '?'))
+                               is_event_parameterized = 1;
+
+                       free(buf);
+                       buf = NULL;
+                       fclose(file);
+
+                       if (is_event_parameterized == 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

Tested-by on v2 1/1
#2 lore raw
In reply to Athira Rajeev
Quoted 22 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".

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

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

#3 lore raw
Quoted 35 lines · Sachin Sant
Quoted 23 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".

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

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

Quoted 8 lines

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

Hi Sachin, Ian

Thanks for testing the patch

Athira

#4 lore raw
Quoted 44 lines · Athira Rajeev
Quoted 41 lines · Sachin Sant
Quoted 23 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".

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

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

Quoted 7 lines
Quoted 3 lines

- Sachin

Hi Sachin, Ian

Thanks for testing the patch

Hi Arnaldo

Can you please check and pull this if it looks good to go .

Thanks
Athira

Quoted 4 lines

Athira

#5 lore raw
Quoted 50 lines · Athira Rajeev
Quoted 3 lines

On 08-Sep-2023, at 7:48 PM, Athira Rajeev <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines · Sachin Sant
Quoted 4 lines

On 07-Sep-2023, at 10:29 PM, Athira Rajeev <

Quoted 37 lines · [email protected]> wrote:
Quoted 36 lines
Quoted 19 lines

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.

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

Quoted 8 lines
Quoted 3 lines

Hi Sachin, Ian

Thanks for testing the patch

Hi Arnaldo

Can you please check and pull this if it looks good to go .

Namhyung, can you please take a look?

I'll be back home next week, now at Kernel Recipes in Paris.

- Arnaldo

Quoted 9 lines

Thanks
Athira

Quoted 4 lines

Athira

maintainer
#6 lore raw

Hello,

Quoted 55 lines · Arnaldo Carvalho de Melo
Quoted 51 lines · Athira Rajeev
Quoted 51 lines · Athira Rajeev
Quoted 36 lines · Sachin Sant
Quoted 23 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".

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

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

Quoted 8 lines

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

- Sachin

Hi Sachin, Ian

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks for testing the patch

Hi Arnaldo

Can you please check and pull this if it looks good to go .

Namhyung, can you please take a look?

Yep sure. I think it needs to close the file when getline() fails.

Athira, can you please send v3 with that?

Thanks,
Namhyung

#7 lore raw
Quoted 67 lines · Namhyung Kim

Hello,

Quoted 59 lines · Arnaldo Carvalho de Melo
Quoted 55 lines · Athira Rajeev
Quoted 45 lines · Athira Rajeev
Quoted 41 lines · Sachin Sant
Quoted 23 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".

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

Quoted 8 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

The patch fixes the reported issue.

6.2: Parsing of all PMU events from sysfs : Ok
6.3: Parsing of given PMU events from sysfs : Ok

Quoted 7 lines
Quoted 3 lines

- Sachin

Hi Sachin, Ian

Thanks for testing the patch

Hi Arnaldo

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Can you please check and pull this if it looks good to go .

Namhyung, can you please take a look?

Yep sure. I think it needs to close the file when getline() fails.

Athira, can you please send v3 with that?

Sure, I will post V3 with this change

Athira

Quoted 3 lines

Thanks,
Namhyung

Reviewed-by on v2 1/1
#8 lore raw
In reply to Athira Rajeev
Quoted 15 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 2 lines

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

Patch looks good to me.

Thanks,
Kajol Jain

Quoted 76 lines

---
Changelog:
v1 -> v2:
Addressed review comments from Ian. Updated size of pmu event name variable and changed bool name which is used to skip the test.

 tools/perf/tests/parse-events.c | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/perf/tests/parse-events.c +38 -0
index 658fb9599d95..1ecaeceb69f8 100644
@@ -2514,9 +2514,14 @@ 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];
+		char *buf = NULL;
+		FILE *file;
 		struct dirent *ent;
+		size_t len = 0;
 		DIR *dir;
 		int err;
+		int n;
 
 		snprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/events/",
 			sysfs__mountpoint(), pmu->name);
@@ -2538,11 +2543,44 @@ 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;
+			bool is_event_parameterized = 0;
 
 			/* Names containing . are special and cannot be used directly */
 			if (strchr(ent->d_name, '.'))
 				continue;
 
+			/* exclude parametrized ones (name contains '?') */
+			n = snprintf(pmu_event, sizeof(pmu_event), "%s%s", path, ent->d_name);
+			if (n >= PATH_MAX) {
+				pr_err("pmu event name crossed PATH_MAX(%d) size\n", PATH_MAX);
+				continue;
+			}
+
+			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, '?'))
+				is_event_parameterized = 1;
+
+			free(buf);
+			buf = NULL;
+			fclose(file);
+
+			if (is_event_parameterized == 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;