From 9d24d32fd342a1acbfaa9a08b4575a767bba01da Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 6 Mar 2024 07:25:17 +0530 Subject: [PATCH] api: add helper to move threads into cgroup (v1) Introduce a new helper cgroup_attach_task_tid(), which will be used to move threads into a cgroup for legacy/hybrid controllers running setup in cgroup v1 mode. The core of the helper is craved out of cgroup_attach_task_pid(), now both cgroup_attach_task_pid() and cgroup_attach_task() calls cgroup_attach_task_tid() in turn. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/api.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/api.c b/src/api.c index e8b97523..383bbe93 100644 --- a/src/api.c +++ b/src/api.c @@ -2012,16 +2012,7 @@ err: return ret; } -/** - * cgroup_attach_task_pid is used to assign tasks to a cgroup. - * struct cgroup *cgroup: The cgroup to assign the thread to. - * pid_t tid: The thread to be assigned to the cgroup. - * - * returns 0 on success. - * returns ECGROUPNOTOWNER if the caller does not have access to the cgroup. - * returns ECGROUPNOTALLOWED for other causes of failure. - */ -int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) +static int cgroup_attach_task_tid(struct cgroup *cgroup, pid_t tid) { char path[FILENAME_MAX] = {0}; char *controller_name; @@ -2086,6 +2077,20 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) return 0; } +/** + * cgroup_attach_task_pid is used to assign tasks to a cgroup. + * struct cgroup *cgroup: The cgroup to assign the thread to. + * pid_t tid: The thread to be assigned to the cgroup. + * + * returns 0 on success. + * returns ECGROUPNOTOWNER if the caller does not have access to the cgroup. + * returns ECGROUPNOTALLOWED for other causes of failure. + */ +int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) +{ + return cgroup_attach_task_tid(cgroup, tid); +} + /** * cgroup_attach_task is used to attach the current thread to a cgroup. * struct cgroup *cgroup: The cgroup to assign the current thread to. @@ -2095,11 +2100,8 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) int cgroup_attach_task(struct cgroup *cgroup) { pid_t tid = cg_gettid(); - int error; - - error = cgroup_attach_task_pid(cgroup, tid); - return error; + return cgroup_attach_task_tid(cgroup, tid); } /** -- 2.47.2