tools/power/turbostat: Move process to root cgroup
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Tue, 24 Jan 2023 18:39:53 +0000 (10:39 -0800)
committerZhang Rui <rui.zhang@intel.com>
Tue, 24 Oct 2023 05:38:09 +0000 (13:38 +0800)
When available CPUs are reduced via cgroup cpuset controller, turbostat
will exit with errors (For example):
get_counters: Could not migrate to CPU 0
turbostat: re-initialized with num_cpus 20
get_counters: Could not migrate to CPU 0
turbostat: re-initialized with num_cpus 20

Move the turbostat to root cgroup, which has every CPU.

Writing the value 0 to a cgroup.procs file causes the writing
process to be moved to the corresponding cgroup.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
tools/power/x86/turbostat/turbostat.c

index 0ef6fba118b1bc2e70f07bc746964b35fe8df616..fea63d9d8e02d24ee384032f5fdad67e5d6dc7d5 100644 (file)
@@ -6666,6 +6666,19 @@ void cmdline(int argc, char **argv)
 
 int main(int argc, char **argv)
 {
+       int fd, ret;
+
+       fd = open("/sys/fs/cgroup/cgroup.procs", O_WRONLY);
+       if (fd < 0)
+               goto skip_cgroup_setting;
+
+       ret = write(fd, "0\n", 2);
+       if (ret == -1)
+               perror("Can't update cgroup\n");
+
+       close(fd);
+
+skip_cgroup_setting:
        outf = stderr;
        cmdline(argc, argv);