]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: add support to replace idle_thread of systemd scope
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 24 May 2023 11:39:15 +0000 (11:39 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 15 Jun 2023 19:27:52 +0000 (13:27 -0600)
Allow replacing the default idle_thread during process creation into a
cgroup using cgexec by introducing replace_id flag, that when unset
(default) has no effect on the process created into systemd scope
cgroup, when set replaces the default idle_thread with the process
being created.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
tests/ftests/cgroup.py
tests/ftests/process.py

index bfc3ac0136f6b7d1b530de973ded46e2383d77a3..23ef9ca91d676626cdded8a8a81f4009c2a3f9c9 100644 (file)
@@ -969,7 +969,7 @@ class Cgroup(object):
     # exec is a keyword in python, so let's name this function cgexec
     @staticmethod
     def cgexec(config, controller, cgname, cmdline, sticky=False,
-               cghelp=False,  ignore_systemd=False):
+               cghelp=False,  ignore_systemd=False, replace_idle=False):
         """cgexec equivalent method
         """
         cmd = list()
@@ -981,6 +981,9 @@ class Cgroup(object):
         if (ignore_systemd):
             cmd.append('-b')
 
+        if (replace_idle):
+            cmd.append('-r')
+
         cmd.append('-g')
         cmd.append('{}:{}'.format(controller, cgname))
 
index 97aa1734028e3b7e723a91495fcff1648ba2c290..b2cdcf6e9422525c060744ce8fb113f2fd5907ec 100644 (file)
@@ -51,14 +51,16 @@ class Process(object):
             pass
 
     @staticmethod
-    def __cgexec_infinite_loop(config, controller, cgname, sleep_time=1, ignore_systemd=False):
+    def __cgexec_infinite_loop(config, controller, cgname, sleep_time=1,
+                               ignore_systemd=False, replace_idle=False):
         cmd = ["/usr/bin/perl",
                "-e",
                "'while(1){{sleep({})}};'".format(sleep_time)
                ]
 
         try:
-            Cgroup.cgexec(config, controller, cgname, cmd, ignore_systemd=ignore_systemd)
+            Cgroup.cgexec(config, controller, cgname, cmd, ignore_systemd=ignore_systemd,
+                          replace_idle=replace_idle)
         except RunError:
             # When this process is killed, it will throw a run error.
             # Ignore it.
@@ -113,7 +115,7 @@ class Process(object):
 
     # Create a simple process in the requested cgroup
     def create_process_in_cgroup(self, config, controller, cgname,
-                                 cgclassify=True, ignore_systemd=False):
+                                 cgclassify=True, ignore_systemd=False, replace_idle=False):
         if cgclassify:
             child_pid = self.create_process(config)
             Cgroup.classify(config, controller, cgname, child_pid, ignore_systemd=ignore_systemd)
@@ -126,7 +128,8 @@ class Process(object):
             sleep_time = len(self.children) + 1
 
             p = mp.Process(target=Process.__cgexec_infinite_loop,
-                           args=(config, controller, cgname, sleep_time, ignore_systemd, ))
+                           args=(config, controller, cgname, sleep_time, ignore_systemd,
+                                 replace_idle, ))
             p.start()
 
             self.children.append(p)