feat(hud): GPU load and clock without root where Android blocks kgsl (#1969)

On some Adreno devices (the Retroid Pocket Duo) SELinux hides kgsl's sysfs
nodes from apps, so the HUD showed no GPU % and no GPU clock. Devices whose
nodes are readable keep using them; nothing changes there or on GPUs
without kgsl.

Where the nodes are blocked:

- GPU %: a native reader maps kgsl's memstore read-only (any kgsl client
  may) and samples the ringbuffer start/end timestamps once a millisecond
  while a HUD is shown. That covers all GPU work, Android's own
  composition included.
- Backup for GPU %: an implicit Vulkan layer in the guest
  (tools/gpuload) and the compositor time their own GPU work with
  timestamp queries. It runs until the memstore stamps are seen moving,
  and for the whole session if they never move.
- GPU clock: a small GPU job of our own reads the always-on and RBBM
  cycle counters (libgpuclock).

The HUD diagnostics export lists which source each GPU value came from.
tools/gpuload/build.sh takes the Vulkan headers from build_local.sh's NDK
first and keeps NDK paths with spaces intact.
This commit is contained in:
The412Banner authored and GitHub committed 2026-11-01 20:22:51 +00:00
1 parent 6cd844ea51
commit 8cb5c2168e
30 files changed
+1891 -10

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "kgsl_busy.h"
#define ENTRIES 819
static uint32_t memstore[ENTRIES * KGSL_BUSY_ENTRY_WORDS];
static void stamp(int entry, uint32_t sop, uint32_t eop) {
memstore[entry * KGSL_BUSY_ENTRY_WORDS + KGSL_BUSY_SOP] = sop;
memstore[entry * KGSL_BUSY_ENTRY_WORDS + KGSL_BUSY_EOP] = eop;
}
int main(void) {
assert(kgsl_busy_first_slot(8 * 4096) == 813);
assert(kgsl_busy_first_slot(8 * 16384) == 3270);
assert(kgsl_busy_first_slot(7 * 40) == -1);
int first = kgsl_busy_first_slot(sizeof(memstore));
uint32_t last[KGSL_BUSY_SLOTS] = {0};
int moved = 0;
stamp(first, 100, 100);
stamp(first + 2, 7, 7);
assert(kgsl_busy_sample(memstore, first, last, &moved) == 0);
assert(moved == 1 && last[0] == 100 && last[2] == 7);
moved = 0;
assert(kgsl_busy_sample(memstore, first, last, &moved) == 0);
assert(moved == 0);
stamp(first + 2, 8, 7);
assert(kgsl_busy_sample(memstore, first, last, &moved) == 1);
assert(moved == 1);
moved = 0;
stamp(first + 2, 8, 8);
assert(kgsl_busy_sample(memstore, first, last, &moved) == 0);
assert(moved == 0);
stamp(first + 4, 3, 2);
assert(kgsl_busy_sample(memstore, first, last, &moved) == 1);
memset(memstore, 0, sizeof(memstore));
stamp(first - 1, 5, 4);
stamp(first + KGSL_BUSY_SLOTS, 9, 8);
memset(last, 0, sizeof(last));
moved = 0;
assert(kgsl_busy_sample(memstore, first, last, &moved) == 0);
assert(moved == 0);
puts("PASS: kgsl memstore busy");
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
"""Exercise the HUD's kgsl memstore busy sampling (app/src/main/cpp/gpuclock/kgsl_busy.h)."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
REPO = Path(__file__).resolve().parents[2]
class KgslBusyTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which(os.environ.get('CC', 'cc'))
if compiler is None:
raise unittest.SkipTest('A host C compiler is required')
cls.temp = tempfile.TemporaryDirectory(prefix='droiddeck-kgsl-busy-')
cls.addClassCleanup(cls.temp.cleanup)
cls.binary = Path(cls.temp.name) / 'kgsl-busy-test'
subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', '-Werror',
'-I', str(REPO / 'app/src/main/cpp/gpuclock'),
str(REPO / 'tools/tests/kgsl_busy_harness.c'), '-o', str(cls.binary)],
check=True, capture_output=True, text=True)
def test_ringbuffer_slots_and_busy_rule(self):
result = subprocess.run([str(self.binary)], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn('PASS: kgsl memstore busy', result.stdout)
if __name__ == '__main__':
unittest.main()