resource: process-group: Add PROCESS_GROUP_ATTR_MEM_GPU attribute 95/276595/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 20 Jun 2022 11:16:27 +0000 (20:16 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 29 Jun 2022 10:21:06 +0000 (19:21 +0900)
Change-Id: If047337cb4efd57ae19fcfbf3a89be95542b7e84
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
lib/resource-monitor/resource-monitor.h
src/resource/resource-process-group.c

index 2d52243..bf5d57f 100644 (file)
@@ -140,6 +140,7 @@ extern "C" {
 #define PROCESS_GROUP_ATTR_MEM_PSS             BIT(7)  /* DATA_TYPE_UINT64 */
 #define PROCESS_GROUP_ATTR_MEM_SWAP            BIT(8)  /* DATA_TYPE_UINT64 */
 #define PROCESS_GROUP_ATTR_MEM_SWAP_PSS                BIT(9)  /* DATA_TYPE_UINT64 */
+#define PROCESS_GROUP_ATTR_MEM_GPU             BIT(10) /* DATA_TYPE_UINT64 */
 
 #define PROCESS_GROUP_CTRL_ROOT_PID            BIT(0)
 
index 7520194..f126d60 100644 (file)
@@ -44,6 +44,7 @@ struct process_group_context {
                u_int64_t mem_pss;
                u_int64_t mem_swap;
                u_int64_t mem_swap_pss;
+               u_int64_t mem_gpu;
        } info;
        u_int64_t prev_total_time;
 };
@@ -191,6 +192,9 @@ static int process_group_get_mem(const struct resource *res,
        case PROCESS_GROUP_ATTR_MEM_SWAP_PSS:
                *mem = ctx->info.mem_swap_pss;
                break;
+       case PROCESS_GROUP_ATTR_MEM_GPU:
+               *mem = ctx->info.mem_gpu;
+               break;
        default:
                return -EINVAL;
        }
@@ -307,6 +311,14 @@ static const struct resource_attribute process_group_attrs[] = {
                        .get = process_group_get_mem,
                        .is_supported = resource_attr_supported_always,
                },
+       }, {
+               .name   = "PROCESS_GROUP_ATTR_MEM_GPU",
+               .id     = PROCESS_GROUP_ATTR_MEM_GPU,
+               .type   = DATA_TYPE_UINT64,
+               .ops    = {
+                       .get = process_group_get_mem,
+                       .is_supported = resource_attr_supported_always,
+               },
        },
 };
 
@@ -384,7 +396,7 @@ static u_int64_t get_total_cpu_time(void)
        return total_time;
 }
 
-static int update_aggr_taskstats(struct process_group_context *ctx)
+static int update_aggr_taskstats(struct process_group_context *ctx, struct resource *res)
 {
        struct process_info_node *node;
        struct taskstats *prev, *curr;
@@ -396,6 +408,7 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
        gpointer key, value;
        pid_t pid;
        int ret;
+       bool include_gpu_mem = is_resource_attr_interested(res, PROCESS_GROUP_ATTR_MEM_GPU);
 
        memset(&ctx->info, 0, sizeof(ctx->info));
 
@@ -430,7 +443,7 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
                        continue;
                }
 
-               ret = kernel_get_thread_group_map_info(&map_info, pid, false);
+               ret = kernel_get_thread_group_map_info(&map_info, pid, include_gpu_mem);
                if (ret < 0) {
                        free(curr);
                        g_hash_table_iter_remove(&iter);
@@ -459,6 +472,9 @@ static int update_aggr_taskstats(struct process_group_context *ctx)
                ctx->info.mem_swap += (u_int64_t)map_info.swap * 1024;
                ctx->info.mem_swap_pss += (u_int64_t)map_info.swap_pss * 1024;
 
+               if (include_gpu_mem)
+                       ctx->info.mem_gpu += (u_int64_t)map_info.gpu_mem * 1024;
+
                free(prev);
                node->prev = curr;
        }
@@ -588,7 +604,7 @@ static int process_group_prepare_update(struct resource *res)
                        }
                }
 
-               ret = update_aggr_taskstats(ctx);
+               ret = update_aggr_taskstats(ctx, res);
                if (ret < 0) {
                        ret = -EINVAL;
                        goto out_free_hash;