]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
src/python: add attach_threads option to attach()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 11 Mar 2024 03:37:19 +0000 (09:07 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 20 Mar 2024 20:40:45 +0000 (14:40 -0600)
Add support to move all threads by writing a tid into cgroups
cgroup.procs for the cgroup v1 controller, when attach_threads option in
the attach() is set, by default its false.  When set, it calls
cgroup_attach_thread_tid().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/python/cgroup.pxd.m4
src/python/libcgroup.pyx.m4

index 29ace69aec2670b843917b8564b6b0a0478f694b..0ab34c6dde8f4a13834c6094e633211a5c70442d 100644 (file)
@@ -133,4 +133,6 @@ cdef extern from "libcgroup.h":
 
     bool cgroup_is_systemd_enabled()
 
+    int cgroup_attach_thread_tid(cgroup * cgroup, pid_t tid)
+
 # vim: set et ts=4 sw=4:
index 6b5da587331f1d58492de8f5906f4b05f8841392..faf9c94eeae00999a7a70d7432d7f0fe3bc742c9 100644 (file)
@@ -470,12 +470,14 @@ cdef class Cgroup:
         if ret is not 0:
             raise RuntimeError("cgroup_delete_cgroup failed: {}".`format'(ret))
 
-    def attach(self, pid=None, root_cgroup=False):
+    def attach(self, pid=None, root_cgroup=False, attach_threads=False):
         """Attach a process to a cgroup
 
         Arguments:
         pid - pid to be attached.  If none, then the current pid is attached
         root_cgroup - if True, then the pid will be attached to the root cgroup
+        attach_threads - if True, pid will be written in cgroup.procs (v1)
+
 
         Description:
         Attach a process to a cgroup
@@ -486,10 +488,16 @@ cdef class Cgroup:
             else:
                 ret = cgroup.cgroup_attach_task(self._cgp)
         else:
-            if root_cgroup:
-                ret = cgroup.cgroup_attach_task_pid(NULL, pid)
+            if attach_threads:
+                if root_cgroup:
+                    ret = cgroup.cgroup_attach_thread_tid(NULL, pid)
+                else:
+                    ret = cgroup.cgroup_attach_thread_tid(self._cgp, pid)
             else:
-                ret = cgroup.cgroup_attach_task_pid(self._cgp, pid)
+                if root_cgroup:
+                    ret = cgroup.cgroup_attach_task_pid(NULL, pid)
+                else:
+                    ret = cgroup.cgroup_attach_task_pid(self._cgp, pid)
 
         if ret is not 0:
             raise RuntimeError("cgroup_attach_task failed: {}".`format'(ret))