diff options
author | Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org> | 2014-05-05 22:30:02 -0600 |
---|---|---|
committer | Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org> | 2014-05-14 10:29:06 -0600 |
commit | 0a0cd2a58811bb41e38b44df6b50245d6bfdfd0c (patch) | |
tree | 866355e83427f05911e0f21ccc8cd5f0b49969f9 /libmemtrack | |
parent | 9c0fe9145565c41dd749c12f131606c71626474f (diff) | |
download | display-0a0cd2a58811bb41e38b44df6b50245d6bfdfd0c.tar.gz |
libmemtrack: Use kgsl memory flag to determine usermapped buffers
Instead of using useraddr from kgsl memory allocations to be
matched against proc/<pid>/smaps file to be used to determine
usermapping of a buffer, use the newly added flag which directly
indicates whether a given gpubuffer entry is usermapped or
not. The flag is the last character in the "flags" field.
CRs-fixed: 634962
Change-Id: I1f82f7a2ff207eb780f1938a3b1347451b1e3d77
Diffstat (limited to 'libmemtrack')
-rw-r--r-- | libmemtrack/kgsl.c | 62 |
1 files changed, 13 insertions, 49 deletions
diff --git a/libmemtrack/kgsl.c b/libmemtrack/kgsl.c index 6dd4e27a..61940436 100644 --- a/libmemtrack/kgsl.c +++ b/libmemtrack/kgsl.c @@ -47,7 +47,6 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, size_t allocated_records = min(*num_records, ARRAY_SIZE(record_templates)); int i; FILE *fp; - FILE *smaps_fp = NULL; char line[1024]; char tmp[128]; size_t accounted_size = 0; @@ -70,19 +69,14 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, return -errno; } - if (type == MEMTRACK_TYPE_GL) { - snprintf(tmp, sizeof(tmp), "/proc/%d/smaps", pid); - smaps_fp = fopen(tmp, "r"); - if (smaps_fp == NULL) { - fclose(fp); - return -errno; - } - } - + /* Go through each line of <pid>/mem file and for every entry of type "gpumem" + * check if the gpubuffer entry is usermapped or not. If the entry is usermapped + * count the entry as accounted else count the entry as unaccounted. + */ while (1) { - unsigned long uaddr; unsigned long size; char line_type[7]; + char flags[7]; int ret; if (fgets(line, sizeof(line), fp) == NULL) { @@ -91,49 +85,21 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, /* Format: * gpuaddr useraddr size id flags type usage sglen - * 545ba000 545ba000 4096 1 ----p gpumem arraybuffer 1 + * 545ba000 545ba000 4096 1 ----pY gpumem arraybuffer 1 */ - ret = sscanf(line, "%*x %lx %lu %*d %*s %6s %*s %*d\n", - &uaddr, &size, line_type); + ret = sscanf(line, "%*x %*lx %lu %*d %6s %6s %*s %*d\n", + &size, flags, line_type); if (ret != 3) { continue; } if (type == MEMTRACK_TYPE_GL && strcmp(line_type, "gpumem") == 0) { - bool accounted = false; - /* - * We need to cross reference the user address against smaps, - * luckily both are sorted. - */ - while (smaps_addr <= uaddr) { - unsigned long start; - unsigned long end; - unsigned long smaps_size; - - if (fgets(line, sizeof(line), smaps_fp) == NULL) { - break; - } - - if (sscanf(line, "%8lx-%8lx", &start, &end) == 2) { - smaps_addr = start; - continue; - } - - if (smaps_addr != uaddr) { - continue; - } - - if (sscanf(line, "Rss: %lu kB", &smaps_size) == 1) { - if (smaps_size) { - accounted = true; - accounted_size += size; - break; - } - } - } - if (!accounted) { + + if (flags[6] == 'Y') + accounted_size += size; + else unaccounted_size += size; - } + } else if (type == MEMTRACK_TYPE_GRAPHICS && strcmp(line_type, "ion") == 0) { unaccounted_size += size; } @@ -146,8 +112,6 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, records[1].size_in_bytes = unaccounted_size; } - if (smaps_fp) - fclose(smaps_fp); fclose(fp); return 0; |