[PATCH] Support 3D memory usage value for Mali midgard GPU Driver 30/215630/1 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix accepted/tizen/5.5/unified/20191031.022202 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090051 accepted/tizen/5.5/unified/wearable/hotfix/20201027.112740 accepted/tizen/unified/20191014.062508 submit/tizen/20191014.011158 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 submit/tizen_5.5_wearable_hotfix/20201026.184304 tizen_5.5.m2_release
authorMinyoung, Song <minyoung.song@samsung.com>
Tue, 16 Jan 2018 07:09:16 +0000 (16:09 +0900)
committerSungguk Na <sungguk.na@samsung.com>
Wed, 24 Jul 2019 01:17:15 +0000 (10:17 +0900)
The usage of 3D memory is differ from GPU series
In case of Mali utgard, it comes from smaps of process
In case of Mali midgard, it comes form specific debug node

Change-Id: Iaef54537d107f49763ef8f8508c6787a73851a81
Signed-off-by: Minyoung, Song <minyoung.song@samsung.com>
memps.c

diff --git a/memps.c b/memps.c
index 8a7e9af..46b2217 100644 (file)
--- a/memps.c
+++ b/memps.c
@@ -35,6 +35,7 @@
 #define STR_SGX_PATH   "/dev/pvrsrvkm"
 #define STR_3D_PATH1   "/dev/mali"
 #define STR_3D_PATH2   "/dev/kgsl-3d0"
+#define STR_3D_UNIFIED_PATH "/usr/bin/gpu_mem_info"
 #define STR_DRM_PATH1  "/drm mm object (deleted)"
 #define STR_DRM_PATH2  "/dev/dri/card0"
 #define MEMCG_PATH     "/sys/fs/cgroup/memory"
@@ -114,6 +115,7 @@ struct geminfo {
 
 static int sum;
 static int verbos;
+static int use_gpu_mem_info = 0;
 
 /* reads file contents into memory */
 static char* cread(const char* path)
@@ -727,6 +729,28 @@ static void init_trib_mapinfo(trib_mapinfo *tmi)
        tmi->gem_mmap = 0;
 }
 
+unsigned int get_graphic_3d_meminfo(unsigned int tgid)
+{
+       char command[256], buf[256];
+       char *tmp[2];
+       unsigned int size = 0;
+       int tid, ret;
+       FILE *p_gpu;
+
+       snprintf(command, sizeof(command), "%s %d", STR_3D_UNIFIED_PATH, tgid);
+       p_gpu = popen(command, "r");
+       if (p_gpu) {
+               fgets(buf, 256, p_gpu);
+               ret = sscanf(buf, "%d %ms %d %ms", &tid, &tmp[0], &size, &tmp[1]);
+               if (ret == 4) {
+                       free(tmp[0]);
+                       free(tmp[1]);
+               }
+               pclose(p_gpu);
+       }
+       return size;
+}
+
 static int
 get_trib_mapinfo(unsigned int tgid, mapinfo *milist,
                 geminfo *gilist, trib_mapinfo *result)
@@ -740,10 +764,14 @@ get_trib_mapinfo(unsigned int tgid, mapinfo *milist,
                return -EINVAL;
 
        init_trib_mapinfo(result);
+
+       if (use_gpu_mem_info)
+               result->graphic_3d = get_graphic_3d_meminfo(tgid);
+
        for (mi = milist; mi;) {
-               if (strstr(mi->name, STR_SGX_PATH)) {
+               if (!use_gpu_mem_info && strstr(mi->name, STR_SGX_PATH)) {
                        result->graphic_3d += mi->pss;
-               } else if (strstr(mi->name, STR_3D_PATH1) ||
+               } else if (!use_gpu_mem_info && strstr(mi->name, STR_3D_PATH1) ||
                        strstr(mi->name, STR_3D_PATH2)) {
                        result->graphic_3d += mi->size;
                } else if (mi->rss != 0 && mi->pss == 0
@@ -990,6 +1018,9 @@ static int show_map_all_new(int output_type, char *output_path)
                return 0;
        }
 
+       use_gpu_mem_info = (!access(STR_3D_UNIFIED_PATH, F_OK | X_OK)) ? 1 : 0;
+       errno = 0;
+
        pDir = opendir("/proc");
        if (pDir == NULL) {
                fprintf(stderr, "cannot read directory /proc.\n");