fix(hud): GPU clock and load without root on Adreno 8xx

Adreno 8xx phones (OnePlus 13, Adreno 830) showed no GPU clock and only
the partial Vulkan-timing GPU load, where kgsl sysfs is blocked:

- The cycle-counter job read the A6xx/A7xx registers. On A8xx
  CP_ALWAYS_ON_COUNTER is 0x8e7, not 0x980 (gen8_reg.h, Mesa a6xx.xml),
  RBBM countable 0 is NEVER_COUNT (cycles are countable 1, Mesa
  a8xx_perfcntrs.xml), and CP protection leaves 0x000-0x3a3 readable
  (gen8_0_0_protected_regs). The layout is now picked from the KGSL chip
  id (top byte 0x44 on every A8xx); unknown later generations read nothing.
- Every gen8 GPU runs the hardware scheduler, which never writes the
  memstore ringbuffer stamps; the GMU writes each context's own entry
  (gen8_hwsched_hfi.c send_context_pointers). Where the ringbuffer
  entries are all 0 the reader now watches the contexts that submit work
  (rescanned every 200 samples, at most 64).
- The HUD diagnostics report says why each no-root GPU reader works or
  not, prints "none" instead of "null" for missing values, and labels the
  per-core CPU numbers as a clock estimate when /proc/stat is unreadable.

Kernel facts checked in the OnePlus SM8750 kgsl source
(LineageOS/android_kernel_oneplus_sm8750-modules @e05c031c).
This commit is contained in:
The412Banner committed 2026-11-01 22:44:00 +00:00
1 parent e30e722f8b
commit 06be2c5fe8
13 files changed
+274 -24

No files matched your search

+49
View File
@@ -3,6 +3,7 @@
#include <string.h>
#include "kgsl_busy.h"
#include "kgsl_layout.h"
#define ENTRIES 819
@@ -52,5 +53,53 @@ 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);
// Idle and unchanged since the last scan: dropped. Busy or newly started: kept.
stamp(9, 21, 21);
stamp(5, 2, 1);
count = kgsl_busy_scan_contexts(memstore, first, seen, live, KGSL_BUSY_MAX_LIVE);
assert(count == 1 && live[0] == 5);
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);
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__':