util: kernel: Check whether adding cpu e/u/stime for TGID taskstat
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 26 Jul 2022 05:03:13 +0000 (14:03 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 27 Jul 2022 08:24:28 +0000 (17:24 +0900)
There are difference with information on TGID taskstat among kernel
version, because e/u/stime for TGID taskstat is only summarized after
commit in mainline linux 8c733420bdd5 ("taskstats: add e/u/stime for TGID command")
is applied.
So, now check TGID taskstat has zero value for e/u/stime at the
initialization, and, if so, those time is calculated by adding values
in PID taskstats.

Change-Id: I8916e754465102a6643aefb8937e763fc5d1ee7a
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/util/kernel.c

index 0a64734..d9b1d19 100644 (file)
@@ -29,6 +29,7 @@
 #include <util/gpu-mem.h>
 
 static int have_smaps_rollup;
+static bool need_tgid_taskstat_add_time;
 static struct gpu_mem_node *gpu_mem_node;
 
 static int __get_cpu_num(char *path)
@@ -401,6 +402,12 @@ int kernel_get_thread_group_taskstats(struct taskstats *stats, pid_t tgid, bool
                        memcpy(stats->ac_comm, pid_stats.ac_comm, strlen(pid_stats.ac_comm) + 1);
                }
 
+               if (need_tgid_taskstat_add_time) {
+                       stats->ac_etime += pid_stats.ac_etime;
+                       stats->ac_utime += pid_stats.ac_utime;
+                       stats->ac_stime += pid_stats.ac_stime;
+               }
+
                stats->virtmem += pid_stats.virtmem;
                stats->coremem += pid_stats.coremem;
                stats->read_bytes += pid_stats.read_bytes;
@@ -500,6 +507,12 @@ bool kernel_check_gpu_support(void)
 
 static void __CONSTRUCTOR__ kernel_init(void)
 {
+       struct taskstats self;
+
        have_smaps_rollup = !access("/proc/self/smaps_rollup", R_OK);
        gpu_mem_node = get_system_gpu_mem_node();
+
+       kernel_get_thread_group_taskstats(&self, getpid(), false);
+       if (self.ac_etime == 0)
+               need_tgid_taskstat_add_time = true;
 }