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

Commit 33204a0b authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

GPU Memory: add errno to error log messages

This change also adopts the new program retrieval api.

Bug: 170674916
Test: build
Change-Id: I51a58e5730b170bf6b6db0f02792b007a69181e0
parent 5338559c
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -43,18 +43,21 @@ void GpuMem::initialize() {
    // Make sure bpf programs are loaded
    bpf::waitForProgsLoaded();

    int fd = bpf::bpfFdGet(kGpuMemTotalProgPath, BPF_F_RDONLY);
    errno = 0;
    int fd = bpf::retrieveProgram(kGpuMemTotalProgPath);
    if (fd < 0) {
        ALOGE("Failed to retrieve pinned program from %s", kGpuMemTotalProgPath);
        ALOGE("Failed to retrieve pinned program from %s [%d(%s)]", kGpuMemTotalProgPath, errno,
              strerror(errno));
        return;
    }

    // Attach the program to the tracepoint, and the tracepoint is automatically enabled here.
    errno = 0;
    int count = 0;
    while (bpf_attach_tracepoint(fd, kGpuMemTraceGroup, kGpuMemTotalTracepoint) < 0) {
        if (++count > kGpuWaitTimeout) {
            ALOGE("Failed to attach bpf program to %s/%s tracepoint", kGpuMemTraceGroup,
                  kGpuMemTotalTracepoint);
            ALOGE("Failed to attach bpf program to %s/%s tracepoint [%d(%s)]", kGpuMemTraceGroup,
                  kGpuMemTotalTracepoint, errno, strerror(errno));
            return;
        }
        // Retry until GPU driver loaded or timeout.
@@ -62,9 +65,11 @@ void GpuMem::initialize() {
    }

    // Use the read-only wrapper BpfMapRO to properly retrieve the read-only map.
    errno = 0;
    auto map = bpf::BpfMapRO<uint64_t, uint64_t>(kGpuMemTotalMapPath);
    if (!map.isValid()) {
        ALOGE("Failed to create bpf map from %s", kGpuMemTotalMapPath);
        ALOGE("Failed to create bpf map from %s [%d(%s)]", kGpuMemTotalMapPath, errno,
              strerror(errno));
        return;
    }
    setGpuMemTotalMap(map);