path: root/tools/testing/selftests/cgroup/cgroup_util.c
diff options
authorMichal Koutný <mkoutny@suse.com>2019-10-04 12:57:41 +0200
committerTejun Heo <tj@kernel.org>2019-10-07 07:11:54 -0700
commit58c9f75b86f76895b9dd44f21dc1e37d0f477cc7 (patch)
tree8bf68c62b3f6973e0ccc89da290522085855e11e /tools/testing/selftests/cgroup/cgroup_util.c
parentcgroup: Optimize single thread migration (diff)
selftests: cgroup: Simplify task self migration
Simplify task migration by being oblivious about its PID during migration. This allows to easily migrate individual threads as well. This change brings no functional change and prepares grounds for thread granularity migrating tests. Signed-off-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'tools/testing/selftests/cgroup/cgroup_util.c')
1 files changed, 11 insertions, 5 deletions
diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c
index bdb69599c4bd..f6573eac1365 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/cgroup_util.c
@@ -282,10 +282,12 @@ int cg_enter(const char *cgroup, int pid)
int cg_enter_current(const char *cgroup)
- char pidbuf[64];
+ return cg_write(cgroup, "cgroup.procs", "0");
- snprintf(pidbuf, sizeof(pidbuf), "%d", getpid());
- return cg_write(cgroup, "cgroup.procs", pidbuf);
+int cg_enter_current_thread(const char *cgroup)
+ return cg_write(cgroup, "cgroup.threads", "0");
int cg_run(const char *cgroup,
@@ -410,11 +412,15 @@ int set_oom_adj_score(int pid, int score)
return 0;
-char proc_read_text(int pid, const char *item, char *buf, size_t size)
+ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size)
char path[PATH_MAX];
- snprintf(path, sizeof(path), "/proc/%d/%s", pid, item);
+ if (!pid)
+ snprintf(path, sizeof(path), "/proc/%s/%s",
+ thread ? "thread-self" : "self", item);
+ else
+ snprintf(path, sizeof(path), "/proc/%d/%s", pid, item);
return read_text(path, buf, size);