From aee45ee0bc05abd181ff16af92c599d31f9fbc7f Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Fri, 23 Oct 2020 09:31:54 -0700 Subject: [PATCH] Add total GPU usage report into dumpsys meminfo output With latest kernel changes, total GPU memory usage is reported and can be obtained via a BPF program. Create JNI interface to query it and report inside dumpsys meminfo output. Bug: 171261987 Test: dumpsys meminfo Signed-off-by: Suren Baghdasaryan Merged-In: I949a13836d5b5bc87fc43f60871b4fbf2add6480 Change-Id: I949a13836d5b5bc87fc43f60871b4fbf2add6480 --- core/java/android/os/Debug.java | 7 +++++++ core/jni/android_os_Debug.cpp | 13 +++++++++++++ .../android/server/am/ActivityManagerService.java | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 8ab734d2325e0..27dc6e0ada433 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -2575,6 +2575,13 @@ public final class Debug */ public static native long getIonMappedSizeKb(); + /** + * Return memory size in kilobytes used by GPU. + * + * @hide + */ + public static native long getGpuTotalUsageKb(); + /** * Return whether virtually-mapped kernel stacks are enabled (CONFIG_VMAP_STACK). * Note: caller needs config_gz read sepolicy permission diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 5a859aabce7b8..28fc8ede1653e 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -844,6 +844,17 @@ static jlong android_os_Debug_getIonMappedSizeKb(JNIEnv* env, jobject clazz) { return ionPss; } +static jlong android_os_Debug_getGpuTotalUsageKb(JNIEnv* env, jobject clazz) { + jlong sizeKb = -1; + uint64_t size; + + if (meminfo::ReadGpuTotalUsageKb(&size)) { + sizeKb = size; + } + + return sizeKb; +} + static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz) { static enum { @@ -912,6 +923,8 @@ static const JNINativeMethod gMethods[] = { (void*)android_os_Debug_getIonPoolsSizeKb }, { "getIonMappedSizeKb", "()J", (void*)android_os_Debug_getIonMappedSizeKb }, + { "getGpuTotalUsageKb", "()J", + (void*)android_os_Debug_getGpuTotalUsageKb }, { "isVmapStack", "()Z", (void*)android_os_Debug_isVmapStack }, }; diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index e4cdfe92ec8a0..40f24283d1b86 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13744,6 +13744,10 @@ public class ActivityManagerService extends IActivityManager.Stub // set on ION VMAs, therefore consider the entire ION heap as used kernel memory kernelUsed += ionHeap; } + final long gpuUsage = Debug.getGpuTotalUsageKb(); + if (gpuUsage >= 0) { + pw.print(" GPU: "); pw.println(stringifyKBSize(gpuUsage)); + } final long lostRAM = memInfo.getTotalSizeKb() - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() - kernelUsed - memInfo.getZramTotalSizeKb(); @@ -14552,6 +14556,12 @@ public class ActivityManagerService extends IActivityManager.Stub // set on ION VMAs, therefore consider the entire ION heap as used kernel memory kernelUsed += ionHeap; } + final long gpuUsage = Debug.getGpuTotalUsageKb(); + if (gpuUsage >= 0) { + memInfoBuilder.append(" GPU: "); + memInfoBuilder.append(stringifyKBSize(gpuUsage)); + memInfoBuilder.append("\n"); + } memInfoBuilder.append(" Used RAM: "); memInfoBuilder.append(stringifyKBSize( totalPss - cachedPss + kernelUsed));