From 70b1d1682bcb6bb58d98d9479431d1dc7bfc0bc2 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Wed, 17 Aug 2022 15:33:18 +0900 Subject: [PATCH] resource: process-group: Handle the case that target cannot support taskstats all attributes in PROCESS_GROUP resource require taskstats, all attributes are mark to unsupported when the target does not support taskstats. Change-Id: I21a36949e34e7cf3fb050694b1cbddd31e954247 Signed-off-by: Dongwoo Lee --- src/resource/resource-process-group.c | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/resource/resource-process-group.c b/src/resource/resource-process-group.c index 0ee9d90..f0a9a4d 100644 --- a/src/resource/resource-process-group.c +++ b/src/resource/resource-process-group.c @@ -51,6 +51,7 @@ struct process_group_context { static u_int64_t total_memory; static long jiffy; +static int taskstat_support = -1; static int process_group_get_pid_list(struct resource *res, const struct resource_attribute *attr, @@ -239,10 +240,16 @@ static int process_group_get_disk_attrs(struct resource *res, return 0; } +static bool process_group_check_taskstat_support(struct resource *resource, + const struct resource_attribute *attr) +{ + return !!taskstat_support; +} + static bool process_group_check_gpu_support(struct resource *resource, const struct resource_attribute *attr) { - return kernel_check_gpu_support(); + return !!taskstat_support && kernel_check_gpu_support(); } static const struct resource_attribute process_group_attrs[] = { @@ -252,7 +259,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_ARRAY, .ops = { .get = process_group_get_pid_list, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_NAME_LIST", @@ -260,7 +267,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_ARRAY, .ops = { .get = process_group_get_name_list, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_CPU_UTIL", @@ -268,7 +275,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_DOUBLE, .ops = { .get = process_group_get_cpu_util, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_DISK_READ_PER_SEC", @@ -276,7 +283,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_DOUBLE, .ops = { .get = process_group_get_disk_attrs, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC", @@ -284,7 +291,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_DOUBLE, .ops = { .get = process_group_get_disk_attrs, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_VIRT", @@ -292,7 +299,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_UINT64, .ops = { .get = process_group_get_mem, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_RSS", @@ -300,7 +307,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_UINT64, .ops = { .get = process_group_get_mem, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_PSS", @@ -308,7 +315,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_UINT64, .ops = { .get = process_group_get_mem, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_SWAP", @@ -316,7 +323,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_UINT64, .ops = { .get = process_group_get_mem, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_SWAP_PSS", @@ -324,7 +331,7 @@ static const struct resource_attribute process_group_attrs[] = { .type = DATA_TYPE_UINT64, .ops = { .get = process_group_get_mem, - .is_supported = resource_attr_supported_always, + .is_supported = process_group_check_taskstat_support, }, }, { .name = "PROCESS_GROUP_ATTR_MEM_GPU", @@ -355,7 +362,7 @@ static int process_group_setup_root_pid(struct resource *res, target_pid = (int)(intptr_t)data; - if (target_pid < 0) { + if (target_pid < 0 || !taskstat_support) { ctx->pid = -1; return 0; } @@ -519,6 +526,9 @@ static int process_group_prepare_update(struct resource *res) if (!ctx) return -EINVAL; + if (!taskstat_support) + return 0; + task_dir = opendir(PROC_DIR_PATH); if (!task_dir) return -ESRCH; @@ -644,6 +654,9 @@ static int process_group_init(struct resource *res) struct process_group_context *ctx; int ret; + if (taskstat_support < 0) + taskstat_support = (int)kernel_check_taskstat_support(); + if (jiffy == 0) { /* get system USER_HZ at once */ jiffy = sysconf(_SC_CLK_TCK); -- 2.7.4