fix(hud): GPU clock and load without root on Adreno 8xx and hardware-scheduled kernels (#1981)

On phones where Android blocks the GPU's sysfs files for apps, the HUD
reads the GPU without root (#1969). On Adreno 8xx that showed no GPU
clock and only the partial load from Vulkan timing (OnePlus 13, Adreno
830, reported by iamTooShaar).

- GPU clock: the clock job used the Adreno 6xx/7xx registers. The
  register layout is now picked from the KGSL chip id: on 8xx
  CP_ALWAYS_ON_COUNTER is 0x8e7 and the RBBM cycle countable is 1.
  Unknown later generations read nothing.
- GPU load: hardware-scheduled kgsl kernels (every 8xx, and some 7xx
  such as the AYANEO Pocket FIT's) never write the memstore ringbuffer
  timestamps. When those stay 0, the reader samples the contexts' own
  memstore entries (every context that has submitted work, up to 64,
  contexts with new or running work first).
- HUD diagnostics report: a "GPU readers without root" line with the
  reason each reader works or fails, "none" instead of "null", and the
  per-core CPU % source named honestly.

Tested: iamTooShaar's OnePlus 13 shows GPU clock and load with the PR
test build (06be2c5). Pocket FIT standalone build of the final readers
against the kernel's sysfs numbers: idle 1-2 % vs 3-4 %, GPU job loop
25-29 % vs 28-30 %, clock 1050 MHz vs 1050 MHz. The review fixes after
the test build were not tested on the OnePlus 13.
This commit is contained in:
The412Banner authored and GitHub committed 2026-11-02 10:07:26 +00:00
1 parent 313b6a59d2
commit 55da0afd06
13 files changed
+299 -29

No files matched your search

+57
View File
@@ -3,6 +3,7 @@
#include <string.h>
#include "kgsl_busy.h"
#include "kgsl_layout.h"
#define ENTRIES 819
@@ -52,5 +53,61 @@ int main(void) {
assert(moved == 0);
puts("PASS: kgsl memstore busy");
// Hardware-scheduled kernels: ringbuffer entries stay 0, contexts carry the stamps.
memset(memstore, 0, sizeof(memstore));
static uint32_t seen[ENTRIES], ctx_last[ENTRIES];
int live[KGSL_BUSY_MAX_LIVE];
stamp(3, 50, 50);
stamp(9, 21, 20);
stamp(first - 1, 4, 4);
int count = kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE);
assert(count == 3 && live[0] == 3 && live[1] == 9 && live[2] == first - 1);
moved = 0;
assert(kgsl_busy_sample_contexts(memstore, live, count, ctx_last, &moved) == 1);
assert(moved == 1 && ctx_last[9] == 21);
// Busy or newly started contexts come first; idle ones that have run work stay in the list.
stamp(9, 21, 21);
stamp(5, 2, 1);
count = kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE);
assert(count == 4 && live[0] == 5 && live[1] == 3 && live[2] == 9 && live[3] == first - 1);
moved = 0;
assert(kgsl_busy_sample_contexts(memstore, live, count, ctx_last, &moved) == 1);
assert(moved == 1);
moved = 0;
assert(kgsl_busy_sample_contexts(memstore, live, count, ctx_last, &moved) == 1);
assert(moved == 0);
stamp(5, 2, 2);
assert(kgsl_busy_sample_contexts(memstore, live, count, ctx_last, &moved) == 0);
// Entry 0 (global) and the ringbuffer entries are not contexts; the live list is capped.
memset(memstore, 0, sizeof(memstore));
memset(seen, 0, sizeof(seen));
stamp(0, 8, 7);
stamp(first, 8, 7);
assert(kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE) == 0);
for (int id = 1; id <= KGSL_BUSY_MAX_LIVE + 10; id++) stamp(id, 1, 1);
assert(kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE) == KGSL_BUSY_MAX_LIVE);
assert(kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE) == KGSL_BUSY_MAX_LIVE);
stamp(KGSL_BUSY_MAX_LIVE + 5, 2, 1);
assert(kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE) == KGSL_BUSY_MAX_LIVE);
assert(live[0] == KGSL_BUSY_MAX_LIVE + 5);
stamp(KGSL_BUSY_MAX_LIVE + 5, 0, 0);
count = kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE);
count = kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE);
for (int i = 0; i < count; i++) assert(live[i] != KGSL_BUSY_MAX_LIVE + 5);
puts("PASS: kgsl memstore contexts");
assert(kgsl_layout_for(0x44050001u) == &KGSL_LAYOUT_A8XX); // Adreno 830
assert(kgsl_layout_for(0x44030a20u) == &KGSL_LAYOUT_A8XX); // Adreno 829
assert(kgsl_layout_for(0x43020100u) == &KGSL_LAYOUT_A7XX); // Adreno 722
assert(kgsl_layout_for(0x43050a01u) == &KGSL_LAYOUT_A7XX); // Adreno 740
assert(kgsl_layout_for(0x07010000u) == &KGSL_LAYOUT_A7XX); // Adreno 710
assert(kgsl_layout_for(0x06030001u) == &KGSL_LAYOUT_A7XX); // Adreno 630
assert(kgsl_layout_for(0x45000000u) == NULL);
assert(KGSL_LAYOUT_A8XX.always_on == 0x8e7u && KGSL_LAYOUT_A8XX.cycles == 1u);
assert(KGSL_LAYOUT_A7XX.always_on == 0x980u && KGSL_LAYOUT_A7XX.cycles == 0u);
puts("PASS: kgsl counter layout");
return 0;
}
+3 -1
View File
@@ -1,4 +1,4 @@
"""Exercise the HUD's kgsl memstore busy sampling (app/src/main/cpp/gpuclock/kgsl_busy.h)."""
"""Exercise the HUD's kgsl memstore busy sampling and counter layout (app/src/main/cpp/gpuclock)."""
import os
from pathlib import Path
import shutil
@@ -27,6 +27,8 @@ class KgslBusyTest(unittest.TestCase):
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)
self.assertIn('PASS: kgsl memstore contexts', result.stdout)
self.assertIn('PASS: kgsl counter layout', result.stdout)
if __name__ == '__main__':