Files
DroidDeck/tools/tests/test_kgsl_busy.py
T
The412Banner 06be2c5fe8 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).
2026-11-01 22:44:00 +00:00

36 lines
1.4 KiB
Python

"""Exercise the HUD's kgsl memstore busy sampling and counter layout (app/src/main/cpp/gpuclock)."""
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)
self.assertIn('PASS: kgsl memstore contexts', result.stdout)
self.assertIn('PASS: kgsl counter layout', result.stdout)
if __name__ == '__main__':
unittest.main()