Skip to contentSkip to conversation

perf tests: Fix Convert perf time to TSC test for hybrid

PATCH Applied Adrian Hunter 3 participants 6 messages Jul 13, 2022 – Jul 17, 2022 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf tests: Fix Convert perf time to TSC test for hybrid

Hi

Here are a couple more minor non-urgent fixes.

Adrian Hunter (2):
perf tests: Stop Convert perf time to TSC test opening events twice perf tests: Fix Convert perf time to TSC test for hybrid

 tools/perf/tests/perf-time-to-tsc.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/2 perf tests: Stop Convert perf time to TSC test opening events twice

Do not call evlist__open() twice.

Fixes 5bb017d4b97a ("perf test: Fix error message for test case 71 on s390, where it is not supported")
---
 tools/perf/tests/perf-time-to-tsc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/tests/perf-time-to-tsc.c +6 -3
index 4ad0dfbc8b21..8d6d60173693 100644
@@ -123,11 +123,14 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 		evsel->core.attr.enable_on_exec = 0;
 	}
 
-	if (evlist__open(evlist) == -ENOENT) {
-		err = TEST_SKIP;
+	ret = evlist__open(evlist);
+	if (ret < 0) {
+		if (ret == -ENOENT)
+			err = TEST_SKIP;
+		else
+			pr_debug("evlist__open() failed\n");
 		goto out_err;
 	}
-	CHECK__(evlist__open(evlist));
 
 	CHECK__(evlist__mmap(evlist, UINT_MAX));
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] perf tests: Stop Convert perf time to TSC test opening events twice

Quoted 13 lines · Adrian Hunter

Do not call evlist__open() twice.

Fixes 5bb017d4b97a ("perf test: Fix error message for test case 71 on s390, where it is not supported")
 tools/perf/tests/perf-time-to-tsc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/tests/perf-time-to-tsc.c +0 -0
index 4ad0dfbc8b21..8d6d60173693 100644
@@ -123,11 +123,14 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 		evsel->core.attr.enable_on_exec = 0;

tools/perf/tests/perf-time-to-tsc.c static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su · line 131

Quoted 10 lines
tools/perf/tests/perf-time-to-tsc.c +6 -2
 	}
 
-	if (evlist__open(evlist) == -ENOENT) {
-		err = TEST_SKIP;
+	ret = evlist__open(evlist);
+	if (ret < 0) {
+		if (ret == -ENOENT)
+			err = TEST_SKIP;
+		else
+			pr_debug("evlist__open() failed\n");

The error message for the evlist__open is slightly different with the old one, "evlist__open(evlist) failed!". Not sure if anyone care about it.

Thanks,
Kan

Quoted 6 lines
tools/perf/tests/perf-time-to-tsc.c +0 -1
 		goto out_err;
 	}
-	CHECK__(evlist__open(evlist));
 
 	CHECK__(evlist__mmap(evlist, UINT_MAX));
 
author reviewer
#3 lore raw

PATCH 2/2 perf tests: Fix Convert perf time to TSC test for hybrid

In reply to Adrian Hunter

The test does not always correctly determine the number of events for hybrids, nor allow for more than 1 evsel when parsing.

Fix by iterating the events actually created and getting the correct evsel for the events processed.

Fixes d9da6f70eb23 ("perf tests: Support 'Convert perf time to TSC' test for hybrid")
---
 tools/perf/tests/perf-time-to-tsc.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
tools/perf/tests/perf-time-to-tsc.c +4 -14
index 8d6d60173693..7c7d20fc503a 100644
@@ -20,8 +20,6 @@
 #include "tsc.h"
 #include "mmap.h"
 #include "tests.h"
-#include "pmu.h"
-#include "pmu-hybrid.h"
 
 /*
  * Except x86_64/i386 and Arm64, other archs don't support TSC in perf.  Just
@@ -106,18 +104,8 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 
 	evlist__config(evlist, &opts, NULL);
 
-	evsel = evlist__first(evlist);
-
-	evsel->core.attr.comm = 1;
-	evsel->core.attr.disabled = 1;
-	evsel->core.attr.enable_on_exec = 0;
-
-	/*
-	 * For hybrid "cycles:u", it creates two events.
-	 * Init the second evsel here.
-	 */
-	if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom")) {
-		evsel = evsel__next(evsel);
+	/* For hybrid "cycles:u", it creates two events */
+	evlist__for_each_entry(evlist, evsel) {
 		evsel->core.attr.comm = 1;
 		evsel->core.attr.disabled = 1;
 		evsel->core.attr.enable_on_exec = 0;
@@ -170,10 +158,12 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 				goto next_event;
 
 			if (strcmp(event->comm.comm, comm1) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm1_time = sample.time;
 			}
 			if (strcmp(event->comm.comm, comm2) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm2_time = sample.time;
 			}
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#4 lore raw
Quoted 6 lines · Adrian Hunter

The test does not always correctly determine the number of events for hybrids, nor allow for more than 1 evsel when parsing.

Fix by iterating the events actually created and getting the correct evsel for the events processed.

Yes, we cannot always assume there are two events for hybrid.

Quoted 2 lines
Fixes d9da6f70eb23 ("perf tests: Support 'Convert perf time to TSC' test for hybrid")

Thanks,
Kan

Quoted 51 lines
---
 tools/perf/tests/perf-time-to-tsc.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
tools/perf/tests/perf-time-to-tsc.c +4 -14
index 8d6d60173693..7c7d20fc503a 100644
@@ -20,8 +20,6 @@
 #include "tsc.h"
 #include "mmap.h"
 #include "tests.h"
-#include "pmu.h"
-#include "pmu-hybrid.h"
 
 /*
  * Except x86_64/i386 and Arm64, other archs don't support TSC in perf.  Just
@@ -106,18 +104,8 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 
 	evlist__config(evlist, &opts, NULL);
 
-	evsel = evlist__first(evlist);
-
-	evsel->core.attr.comm = 1;
-	evsel->core.attr.disabled = 1;
-	evsel->core.attr.enable_on_exec = 0;
-
-	/*
-	 * For hybrid "cycles:u", it creates two events.
-	 * Init the second evsel here.
-	 */
-	if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom")) {
-		evsel = evsel__next(evsel);
+	/* For hybrid "cycles:u", it creates two events */
+	evlist__for_each_entry(evlist, evsel) {
 		evsel->core.attr.comm = 1;
 		evsel->core.attr.disabled = 1;
 		evsel->core.attr.enable_on_exec = 0;
@@ -170,10 +158,12 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 				goto next_event;
 
 			if (strcmp(event->comm.comm, comm1) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm1_time = sample.time;
 			}
 			if (strcmp(event->comm.comm, comm2) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm2_time = sample.time;
 			}
maintainer Applied
#5 lore raw

Em Wed, Jul 13, 2022 at 09:05:21AM -0400, Liang, Kan escreveu:

Quoted 10 lines · Adrian Hunter
Quoted 6 lines

The test does not always correctly determine the number of events for hybrids, nor allow for more than 1 evsel when parsing.

Fix by iterating the events actually created and getting the correct evsel for the events processed.

Quoted 7 lines

Yes, we cannot always assume there are two events for hybrid.

Quoted 2 lines
Fixes d9da6f70eb23 ("perf tests: Support 'Convert perf time to TSC' test for hybrid")

Thanks, applied.

- Arnaldo

Quoted 53 lines

Thanks,
Kan

Quoted 51 lines
---
 tools/perf/tests/perf-time-to-tsc.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
tools/perf/tests/perf-time-to-tsc.c +4 -14
index 8d6d60173693..7c7d20fc503a 100644
@@ -20,8 +20,6 @@
 #include "tsc.h"
 #include "mmap.h"
 #include "tests.h"
-#include "pmu.h"
-#include "pmu-hybrid.h"
 
 /*
  * Except x86_64/i386 and Arm64, other archs don't support TSC in perf.  Just
@@ -106,18 +104,8 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 
 	evlist__config(evlist, &opts, NULL);
 
-	evsel = evlist__first(evlist);
-
-	evsel->core.attr.comm = 1;
-	evsel->core.attr.disabled = 1;
-	evsel->core.attr.enable_on_exec = 0;
-
-	/*
-	 * For hybrid "cycles:u", it creates two events.
-	 * Init the second evsel here.
-	 */
-	if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom")) {
-		evsel = evsel__next(evsel);
+	/* For hybrid "cycles:u", it creates two events */
+	evlist__for_each_entry(evlist, evsel) {
 		evsel->core.attr.comm = 1;
 		evsel->core.attr.disabled = 1;
 		evsel->core.attr.enable_on_exec = 0;
@@ -170,10 +158,12 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
 				goto next_event;
 
 			if (strcmp(event->comm.comm, comm1) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm1_time = sample.time;
 			}
 			if (strcmp(event->comm.comm, comm2) == 0) {
+				CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
 				CHECK__(evsel__parse_sample(evsel, event, &sample));
 				comm2_time = sample.time;
 			}
Signature · 1 line
- Arnaldo