From a7b9c03b96f647e4d3c1939fba9ac0ed78dd93fb Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 17 Aug 2022 15:31:53 +0900 Subject: [PATCH] util: kernel: Add check whether taskstats is supported 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 --- include/util/kernel.h | 1 + src/util/kernel.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/util/kernel.h b/include/util/kernel.h index 12ae6e9..a1d13d9 100644 --- a/include/util/kernel.h +++ b/include/util/kernel.h @@ -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 diff --git a/src/util/kernel.c b/src/util/kernel.c index 0baaf4a..40fd869 100644 --- a/src/util/kernel.c +++ b/src/util/kernel.c @@ -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; } -- 2.7.4