Skip to contentSkip to conversation

syscalls/perf_event_open02: Fix failures

RFC PATCH New Cyril Hrubis 1 participant 4 messages Apr 24, 2018 – May 14, 2018

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 syscalls/perf_event_open02: Fix failures

The testcase was failing randomly, it could be reproduced easily when the machine is under load. To reproduce the issue just run a few dd if=/dev/zero of=/dev/null to saturate your CPUs.

It has been sugessted that the reason for the failure are rounding errors caused by a frequent preemption. I haven't got a definitive answer from kernel devs for this but it's true that changing the process pritority to realtime SCHED_FIFO for the measurement does fix the issue.

So we either delete the test or apply this patch.

---
 .../kernel/syscalls/perf_event_open/perf_event_open02.c     | 13 +++++++++++++
 1 file changed, 13 insertions(+)
testcases/kernel/syscalls/perf_event_open/perf_event_open02.c +13 -0
index 13a17948a..0590ffb43 100644
@@ -64,6 +64,7 @@ The -v flag makes it print out the values of each counter.
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <linux/types.h>
+#include <sched.h>
 
 #if HAVE_PERF_EVENT_ATTR
 # include <linux/perf_event.h>
@@ -286,6 +287,12 @@ static void verify(void)
 	unsigned long long vtsum = 0, vhsum = 0;
 	int i;
 	double ratio;
+	struct sched_param sparam = {.sched_priority = 1};
+
+	if (sched_setscheduler(0, SCHED_FIFO, &sparam)) {
+		tst_brkm(TBROK | TERRNO, cleanup,
+			 "sched_setscheduler(0, SCHED_FIFO, ...) failed");
+	}
 
 	if (prctl(PR_TASK_PERF_EVENTS_ENABLE) == -1) {
 		tst_brkm(TBROK | TERRNO, cleanup,
@@ -299,6 +306,12 @@ static void verify(void)
 			 "prctl(PR_TASK_PERF_EVENTS_DISABLE) failed");
 	}
 
+	sparam.sched_priority = 0;
+	if (sched_setscheduler(0, SCHED_OTHER, &sparam)) {
+		tst_brkm(TBROK | TERRNO, cleanup,
+			 "sched_setscheduler(0, SCHED_OTHER, ...) failed");
+	}
+
 	if (read(tsk0, &vt0, sizeof(vt0)) != sizeof(vt0)) {
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "error reading task clock counter");
Signature · 1 line
2.13.6
#1 lore raw

RFC PATCH 1/1 syscalls/perf_event_open02: Fix failures

Hi!

Quoted 10 lines

The testcase was failing randomly, it could be reproduced easily when the machine is under load. To reproduce the issue just run a few dd if=/dev/zero of=/dev/null to saturate your CPUs.

It has been sugessted that the reason for the failure are rounding errors caused by a frequent preemption. I haven't got a definitive answer from kernel devs for this but it's true that changing the process pritority to realtime SCHED_FIFO for the measurement does fix the issue.

So we either delete the test or apply this patch.

Any comments for this patch?

I would like to have this sorted out before the release...

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

RFC PATCH 1/1 syscalls/perf_event_open02: Fix failures

Hi!

Quoted 9 lines
Quoted 9 lines

The testcase was failing randomly, it could be reproduced easily when the machine is under load. To reproduce the issue just run a few dd if=/dev/zero of=/dev/null to saturate your CPUs.

It has been sugessted that the reason for the failure are rounding errors caused by a frequent preemption. I haven't got a definitive answer from kernel devs for this but it's true that changing the process pritority to realtime SCHED_FIFO for the measurement does fix the issue.

Quoted 5 lines
Quoted 1 line

So we either delete the test or apply this patch.

Any comments for this patch?

I would like to have this sorted out before the release...

Since nobody commented I will apply this next week, if you are againts this patch, or want to ack it, speak up now :-).

Signature · 2 lines
Cyril Hrubis
[email protected]