From db11c3bad1d717fc80421953c6b67e68485f3854 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 26 Jul 2022 14:03:13 +0900 Subject: [PATCH] util: kernel: Check whether adding cpu e/u/stime for TGID taskstat 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 --- src/util/kernel.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/kernel.c b/src/util/kernel.c index 0a64734..d9b1d19 100644 --- a/src/util/kernel.c +++ b/src/util/kernel.c @@ -29,6 +29,7 @@ #include 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; } -- 2.7.4