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
This commit is contained in:
@@ -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));
|
size_t allocated_records = min(*num_records, ARRAY_SIZE(record_templates));
|
||||||
int i;
|
int i;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
FILE *smaps_fp = NULL;
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
char tmp[128];
|
char tmp[128];
|
||||||
size_t accounted_size = 0;
|
size_t accounted_size = 0;
|
||||||
@@ -70,19 +69,14 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type,
|
|||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == MEMTRACK_TYPE_GL) {
|
/* Go through each line of <pid>/mem file and for every entry of type "gpumem"
|
||||||
snprintf(tmp, sizeof(tmp), "/proc/%d/smaps", pid);
|
* check if the gpubuffer entry is usermapped or not. If the entry is usermapped
|
||||||
smaps_fp = fopen(tmp, "r");
|
* count the entry as accounted else count the entry as unaccounted.
|
||||||
if (smaps_fp == NULL) {
|
*/
|
||||||
fclose(fp);
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned long uaddr;
|
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
char line_type[7];
|
char line_type[7];
|
||||||
|
char flags[7];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (fgets(line, sizeof(line), fp) == NULL) {
|
if (fgets(line, sizeof(line), fp) == NULL) {
|
||||||
@@ -91,49 +85,21 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type,
|
|||||||
|
|
||||||
/* Format:
|
/* Format:
|
||||||
* gpuaddr useraddr size id flags type usage sglen
|
* 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",
|
ret = sscanf(line, "%*x %*lx %lu %*d %6s %6s %*s %*d\n",
|
||||||
&uaddr, &size, line_type);
|
&size, flags, line_type);
|
||||||
if (ret != 3) {
|
if (ret != 3) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == MEMTRACK_TYPE_GL && strcmp(line_type, "gpumem") == 0) {
|
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) {
|
if (flags[6] == 'Y')
|
||||||
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;
|
accounted_size += size;
|
||||||
break;
|
else
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!accounted) {
|
|
||||||
unaccounted_size += size;
|
unaccounted_size += size;
|
||||||
}
|
|
||||||
} else if (type == MEMTRACK_TYPE_GRAPHICS && strcmp(line_type, "ion") == 0) {
|
} else if (type == MEMTRACK_TYPE_GRAPHICS && strcmp(line_type, "ion") == 0) {
|
||||||
unaccounted_size += size;
|
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;
|
records[1].size_in_bytes = unaccounted_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (smaps_fp)
|
|
||||||
fclose(smaps_fp);
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user