From 36ecff37878a8c9dd3f2c941a33f4d218ffe294c Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 24 May 2023 11:39:15 +0000 Subject: [PATCH] ftests: add support to replace idle_thread of systemd scope 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 Signed-off-by: Tom Hromatka --- tests/ftests/cgroup.py | 5 ++++- tests/ftests/process.py | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/ftests/cgroup.py b/tests/ftests/cgroup.py index bfc3ac01..23ef9ca9 100644 --- a/tests/ftests/cgroup.py +++ b/tests/ftests/cgroup.py @@ -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)) diff --git a/tests/ftests/process.py b/tests/ftests/process.py index 97aa1734..b2cdcf6e 100644 --- a/tests/ftests/process.py +++ b/tests/ftests/process.py @@ -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) -- 2.47.2