util: kernel: Add check whether taskstats is supported 63/279763/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 17 Aug 2022 06:31:53 +0000 (15:31 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 17 Aug 2022 08:49:31 +0000 (17:49 +0900)
Since taskstats has various version by kernel, handling it should be
taken by considering versions. However, some task accounting is not
supported by older kernel, we should check whether it is supported or
not. This adds check procedure into constructor.

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

index 12ae6e9..a1d13d9 100644 (file)
@@ -69,4 +69,5 @@ int kernel_get_thread_group_taskstats(struct taskstats *stats, pid_t tgid, bool
 int
 kernel_get_thread_group_map_info(struct proc_map_info *map_info, pid_t tgid, bool include_gpu_mem);
 bool kernel_check_gpu_support(void);
+bool kernel_check_taskstat_support(void);
 #endif
index 0baaf4a..40fd869 100644 (file)
@@ -31,6 +31,7 @@
 static int have_smaps_rollup;
 static bool need_tgid_taskstat_add_time;
 static struct gpu_mem_node *gpu_mem_node;
+static bool taskstat_support;
 
 static int __get_cpu_num(char *path)
 {
@@ -501,14 +502,25 @@ bool kernel_check_gpu_support(void)
        return !!gpu_mem_node;
 }
 
+bool kernel_check_taskstat_support(void)
+{
+       return taskstat_support;
+}
+
 static void __CONSTRUCTOR__ kernel_init(void)
 {
        struct taskstats self;
+       int ret;
 
        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);
+       ret = kernel_get_thread_group_taskstats(&self, getpid(), false);
+       if (ret < 0) {
+               _I("taskstat is not supported.\n");
+               return;
+       }
+       taskstat_support = true;
        if (self.ac_etime == 0)
                need_tgid_taskstat_add_time = true;
 }