diff mbox series

[testsuite] tests/task_setscheduler: add cgroup v2 case for moving proc to root cgroup

Message ID 20240702095401.16278-1-gongruiqi1@huawei.com (mailing list archive)
State New
Delegated to: Ondrej Mosnáček
Headers show
Series [testsuite] tests/task_setscheduler: add cgroup v2 case for moving proc to root cgroup | expand

Commit Message

GONG, Ruiqi July 2, 2024, 9:54 a.m. UTC
Currently for systems that only enable cgroup v2, the test script would
fail to move the target process into the root cgroup since the cgroup v1
path is used, which therefore makes the testcase fail. Add cgroup v2
handling here so that no matter which cgroup version the CPU controller
is bound to, the target process can always be moved to the root CPU
cgroup.

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---
 tests/task_setscheduler/test | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/tests/task_setscheduler/test b/tests/task_setscheduler/test
index c2fe8c6..fa1efb1 100755
--- a/tests/task_setscheduler/test
+++ b/tests/task_setscheduler/test
@@ -20,12 +20,17 @@  vec( $rin, fileno($f), 1 ) = 1;
 select( $rin, undef, undef, 5 );
 close($f);
 
-$cgroup_cpu = "/sys/fs/cgroup/cpu/tasks";
-if ( -w $cgroup_cpu ) {
-
-    # We can only set the scheduler policy fo SCHED_{RR,FIFO} in the root
-    # cgroup so move our target process to the root cgroup.
-    open( my $fd, ">>", $cgroup_cpu );
+# We can only set the scheduler policy fo SCHED_{RR,FIFO} in the root
+# cgroup so move our target process to the root cgroup.
+$cgroup_v1_cpu = "/sys/fs/cgroup/cpu/tasks";
+if ( -w $cgroup_v1_cpu ) {
+    open( my $fd, ">>", $cgroup_v1_cpu );
+    print $fd $pid;
+    close $fd;
+}
+$cgroup_v2 = "/sys/fs/cgroup/cgroup.procs";
+if ( -w $cgroup_v2 ) {
+    open( my $fd, ">>", $cgroup_v2 );
     print $fd $pid;
     close $fd;
 }