Skip to content

Commit a3c0ce0

Browse files
committed
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. Signed-off-by: Cyril Hrubis <[email protected]>
1 parent cb65bc1 commit a3c0ce0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

testcases/kernel/syscalls/perf_event_open/perf_event_open02.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The -v flag makes it print out the values of each counter.
6464
#include <sys/prctl.h>
6565
#include <sys/types.h>
6666
#include <linux/types.h>
67+
#include <sched.h>
6768

6869
#if HAVE_PERF_EVENT_ATTR
6970
# include <linux/perf_event.h>
@@ -286,6 +287,12 @@ static void verify(void)
286287
unsigned long long vtsum = 0, vhsum = 0;
287288
int i;
288289
double ratio;
290+
struct sched_param sparam = {.sched_priority = 1};
291+
292+
if (sched_setscheduler(0, SCHED_FIFO, &sparam)) {
293+
tst_brkm(TBROK | TERRNO, cleanup,
294+
"sched_setscheduler(0, SCHED_FIFO, ...) failed");
295+
}
289296

290297
if (prctl(PR_TASK_PERF_EVENTS_ENABLE) == -1) {
291298
tst_brkm(TBROK | TERRNO, cleanup,
@@ -299,6 +306,12 @@ static void verify(void)
299306
"prctl(PR_TASK_PERF_EVENTS_DISABLE) failed");
300307
}
301308

309+
sparam.sched_priority = 0;
310+
if (sched_setscheduler(0, SCHED_OTHER, &sparam)) {
311+
tst_brkm(TBROK | TERRNO, cleanup,
312+
"sched_setscheduler(0, SCHED_OTHER, ...) failed");
313+
}
314+
302315
if (read(tsk0, &vt0, sizeof(vt0)) != sizeof(vt0)) {
303316
tst_brkm(TBROK | TERRNO, cleanup,
304317
"error reading task clock counter");

0 commit comments

Comments
 (0)