Commit fc204fb0 authored by Tomáš Peterka's avatar Tomáš Peterka

Remove moved PIDs to exclusive CPUs from the request file

parent fab6f2fc
......@@ -317,11 +317,6 @@ class CGroupManager(Manager):
We expect PIDs which require own CPU to be found in ~instance/.slapos-cpu-exclusive
"""
request_pid_set = set() # gather requests from all instances
for request_file in glob.iglob(os.path.join(self.instance_root, '*', CGroupManager.cpu_exclusive_file)):
with open(request_file, "rt") as fi:
request_pid_set.update(map(int, fi.read().split()))
cpu_list = self._cpu_list()
generic_cpu = cpu_list[0]
exclusive_cpu_list = cpu_list[1:]
......@@ -339,12 +334,19 @@ class CGroupManager(Manager):
with open(os.path.join(self.cpuset_path, "cpu" + str(exclusive_cpu), "tasks"), "rt") as fi:
exclusive_pid_set.update(map(int, fi.read().split()))
for request in request_pid_set:
if request in exclusive_pid_set:
continue # already exclusive
if request not in running_pid_set:
continue # stale PID which is not running anywhere
self._move_to_exclusive_cpu(request)
for request_file in glob.iglob(os.path.join(self.instance_root, '*', CGroupManager.cpu_exclusive_file)):
with open(request_file, "rt") as fi:
# take such PIDs which are either really running or are not already exclusive
request_pid_list = [int(pid) for pid in fi.read().split()
if int(pid) in running_pid_set or int(pid) not in exclusive_pid_set]
with open(request_file, "wt") as fo:
fo.write("") # empty file (we will write back only PIDs which weren't moved)
for request_pid in request_pid_list:
assigned_cpu = self._move_to_exclusive_cpu(request_pid)
if assigned_cpu < 0:
# if no exclusive CPU was assigned - write the PID back and try other time
with open(request_file, "at") as fo:
fo.write(str(request_pid) + "\n")
def prepare_cpu_space(self):
"""Move all PIDs from the pool of all CPUs into the first exclusive CPU."""
......
......@@ -189,7 +189,7 @@ class CGroupManagerMock(slapos.format.CGroupManager):
cpuset_path = "/tmp/cpuset/"
task_write_mode = "at" # append insted of write tasks PIDs for the tests
def allowed(self):
def is_allowed(self):
"""Always allowed."""
return True
......@@ -734,14 +734,16 @@ class TestComputerWithCGroup(SlapformatMixin):
file_write("", os.path.join(CGroupManagerMock.cpuset_path, "tasks"))
# test moving tasks from generic core to private core
# request PID 1001 to be moved to its private CPU
file_write("1001\n",
os.path.join(self.computer.partition_list[0].path,
CGroupManagerMock.cpu_exclusive_file))
request_file_path = os.path.join(self.computer.partition_list[0].path,
CGroupManagerMock.cpu_exclusive_file)
file_write("1001\n", request_file_path)
# let format do the moving
self.computer.update()
# test if the moving suceeded into any provate CPUS (id>0)
self.assertTrue(any("1001" in file_content(exclusive_task)
self.assertTrue(any("1001" in file_content(exclusive_task)
for exclusive_task in glob.glob(os.path.join(CGroupManagerMock.cpuset_path, "cpu[1-9]", "tasks"))))
# slapformat should remove successfully moved PIDs from the .slapos-cpu-exclusive file
self.assertEqual("", file_content(request_file_path).strip())
class TestPartition(SlapformatMixin):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment