diff mbox series

perf_event_open02: set process as RT during Setup stage

Message ID 20250227184907.392133-1-edliaw@google.com
State New
Headers show
Series perf_event_open02: set process as RT during Setup stage | expand

Commit Message

Edward Liaw Feb. 27, 2025, 6:49 p.m. UTC
From: "kuan-ying.zhu" <kuan-ying.zhu@mediatek.com>

Move the action of set the task RT from the Verify stage to the Setup
stage. Avoid potential risks of task migration due to scheduler policy.

Signed-off-by: kuan-ying.zhu <kuan-ying.zhu@mediatek.com>
Signed-off-by: Edward Liaw <edliaw@google.com>
---
 .../syscalls/perf_event_open/perf_event_open02.c    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Cyril Hrubis March 18, 2025, 11:19 a.m. UTC | #1
Hi!
> Move the action of set the task RT from the Verify stage to the Setup
> stage. Avoid potential risks of task migration due to scheduler policy.

What exactly goes wrong if we switch to the realtime policy later? I
see that we do bench_work(500) at the start of the setup. That may mean
that we may get different estimate on how many loops we do per second,
but that would only mean that the test would run for shorter time.

We also do bind_to_current_cpu() just after that, the task shouldn't be
migrated after that.

The actual change looks reasonable, however the patch description should
tell why we need to do this change.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
index 7306ecf51..7b3305a52 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
@@ -198,6 +198,12 @@  static void setup(void)
 {
 	int i;
 	struct perf_event_attr tsk_event, hw_event;
+	struct sched_param sparam = {.sched_priority = 1};
+
+	if (sched_setscheduler(0, SCHED_FIFO, &sparam)) {
+		tst_brk(TBROK | TERRNO,
+			"sched_setscheduler(0, SCHED_FIFO, ...) failed");
+	}
 
 	for (i = 0; i < MAX_CTRS; i++) {
 		hwfd[i] = -1;
@@ -271,12 +277,7 @@  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_brk(TBROK | TERRNO,
-			"sched_setscheduler(0, SCHED_FIFO, ...) failed");
-	}
+	struct sched_param sparam = {.sched_priority = 0};
 
 	all_counters_set(PR_TASK_PERF_EVENTS_ENABLE);
 	do_work(8);