Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f403b562 authored by Kalesh Singh's avatar Kalesh Singh Committed by Gerrit Code Review
Browse files

Merge "Provide an interface to query dmabuf GPU allocations"

parents cefc4f68 1a8d198b
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -2583,6 +2583,13 @@ public final class Debug
     */
     */
    public static native long getIonPoolsSizeKb();
    public static native long getIonPoolsSizeKb();


    /**
     * Return GPU DMA buffer usage in kB or -1 on error.
     *
     * @hide
     */
    public static native long getGpuDmaBufUsageKb();

    /**
    /**
     * Return DMA-BUF memory mapped by processes in kB.
     * Return DMA-BUF memory mapped by processes in kB.
     * Notes:
     * Notes:
+1 −0
Original line number Original line Diff line number Diff line
@@ -206,6 +206,7 @@ cc_library_shared {
            ],
            ],


            shared_libs: [
            shared_libs: [
                "android.hardware.memtrack-unstable-ndk_platform",
                "libandroidicu",
                "libandroidicu",
                "libbpf_android",
                "libbpf_android",
                "libnetdbpf",
                "libnetdbpf",
+29 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
#include <string>
#include <string>
#include <vector>
#include <vector>


#include <aidl/android/hardware/memtrack/DeviceInfo.h>
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <bionic/malloc.h>
#include <bionic/malloc.h>
#include <debuggerd/client.h>
#include <debuggerd/client.h>
@@ -45,6 +46,7 @@
#include "jni.h"
#include "jni.h"
#include <dmabufinfo/dmabuf_sysfs_stats.h>
#include <dmabufinfo/dmabuf_sysfs_stats.h>
#include <dmabufinfo/dmabufinfo.h>
#include <dmabufinfo/dmabufinfo.h>
#include <dmabufinfo/dmabuf_sysfs_stats.h>
#include <meminfo/procmeminfo.h>
#include <meminfo/procmeminfo.h>
#include <meminfo/sysmeminfo.h>
#include <meminfo/sysmeminfo.h>
#include <memtrack/memtrack.h>
#include <memtrack/memtrack.h>
@@ -846,6 +848,31 @@ static jlong android_os_Debug_getDmabufHeapPoolsSizeKb(JNIEnv* env, jobject claz
    return poolsSizeKb;
    return poolsSizeKb;
}
}


static jlong android_os_Debug_getGpuDmaBufUsageKb(JNIEnv* env, jobject clazz) {
    std::vector<aidl::android::hardware::memtrack::DeviceInfo> gpu_device_info;
    if (!memtrack_gpu_device_info(&gpu_device_info)) {
        return -1;
    }

    dmabufinfo::DmabufSysfsStats stats;
    if (!GetDmabufSysfsStats(&stats)) {
        return -1;
    }

    jlong sizeKb = 0;
    const auto& importer_stats = stats.importer_info();
    for (const auto& dev_info : gpu_device_info) {
        const auto& importer_info = importer_stats.find(dev_info.name);
        if (importer_info == importer_stats.end()) {
            continue;
        }

        sizeKb += importer_info->second.size;
    }

    return sizeKb;
}

static jlong android_os_Debug_getDmabufMappedSizeKb(JNIEnv* env, jobject clazz) {
static jlong android_os_Debug_getDmabufMappedSizeKb(JNIEnv* env, jobject clazz) {
    jlong dmabufPss = 0;
    jlong dmabufPss = 0;
    std::vector<dmabufinfo::DmaBuffer> dmabufs;
    std::vector<dmabufinfo::DmaBuffer> dmabufs;
@@ -954,6 +981,8 @@ static const JNINativeMethod gMethods[] = {
            (void*)android_os_Debug_getIonHeapsSizeKb },
            (void*)android_os_Debug_getIonHeapsSizeKb },
    { "getDmabufTotalExportedKb", "()J",
    { "getDmabufTotalExportedKb", "()J",
            (void*)android_os_Debug_getDmabufTotalExportedKb },
            (void*)android_os_Debug_getDmabufTotalExportedKb },
    { "getGpuDmaBufUsageKb", "()J",
            (void*)android_os_Debug_getGpuDmaBufUsageKb },
    { "getIonPoolsSizeKb", "()J",
    { "getIonPoolsSizeKb", "()J",
            (void*)android_os_Debug_getIonPoolsSizeKb },
            (void*)android_os_Debug_getIonPoolsSizeKb },
    { "getDmabufMappedSizeKb", "()J",
    { "getDmabufMappedSizeKb", "()J",
+29 −4
Original line number Original line Diff line number Diff line
@@ -13756,8 +13756,20 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            }
            final long gpuUsage = Debug.getGpuTotalUsageKb();
            final long gpuUsage = Debug.getGpuTotalUsageKb();
            if (gpuUsage >= 0) {
            if (gpuUsage >= 0) {
                final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb();
                if (gpuDmaBufUsage >= 0) {
                    final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage;
                    pw.print("      GPU: ");
                    pw.print(stringifyKBSize(gpuUsage));
                    pw.print(" (");
                    pw.print(stringifyKBSize(gpuDmaBufUsage));
                    pw.print(" dmabuf + ");
                    pw.print(stringifyKBSize(gpuPrivateUsage));
                    pw.println(" private)");
                } else {
                    pw.print("      GPU: "); pw.println(stringifyKBSize(gpuUsage));
                    pw.print("      GPU: "); pw.println(stringifyKBSize(gpuUsage));
                }
                }
            }
            /*
            /*
             * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of
             * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of
@@ -14586,10 +14598,23 @@ public class ActivityManagerService extends IActivityManager.Stub
        final long gpuUsage = Debug.getGpuTotalUsageKb();
        final long gpuUsage = Debug.getGpuTotalUsageKb();
        if (gpuUsage >= 0) {
        if (gpuUsage >= 0) {
            final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb();
            if (gpuDmaBufUsage >= 0) {
                final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage;
                memInfoBuilder.append("      GPU: ");
                memInfoBuilder.append(stringifyKBSize(gpuUsage));
                memInfoBuilder.append(" (");
                memInfoBuilder.append(stringifyKBSize(gpuDmaBufUsage));
                memInfoBuilder.append(" dmabuf + ");
                memInfoBuilder.append(stringifyKBSize(gpuPrivateUsage));
                memInfoBuilder.append(" private)\n");
            } else {
                memInfoBuilder.append("       GPU: ");
                memInfoBuilder.append("       GPU: ");
                memInfoBuilder.append(stringifyKBSize(gpuUsage));
                memInfoBuilder.append(stringifyKBSize(gpuUsage));
                memInfoBuilder.append("\n");
                memInfoBuilder.append("\n");
            }
            }
        }
        memInfoBuilder.append("  Used RAM: ");
        memInfoBuilder.append("  Used RAM: ");
        memInfoBuilder.append(stringifyKBSize(
        memInfoBuilder.append(stringifyKBSize(
                                  totalPss - cachedPss + kernelUsed));
                                  totalPss - cachedPss + kernelUsed));