mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
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.
78 lines
3.8 KiB
C
78 lines
3.8 KiB
C
#ifndef DROIDDECK_KGSL_BUSY_H
|
|
#define DROIDDECK_KGSL_BUSY_H
|
|
// kgsl lets any client map its memstore read-only (KGSL_PROP_DEVICE_SHADOW). The CP writes a ringbuffer's
|
|
// start-of-pipe timestamp there before each submission's command buffers and its end-of-pipe timestamp after them
|
|
// (adreno_gen7_ringbuffer.c gen7_ringbuffer_addcmds), so start != end means that ringbuffer has work on the GPU.
|
|
// Ringbuffer entries start at KGSL_MEMSTORE_MAX: entries - 2 - 4 levels, or entries - 1 - 4 on kernels without the
|
|
// LPAC slot. Entries - 6 .. entries - 2 cover both; a context entry in that range follows the same start/end rule.
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#define KGSL_BUSY_ENTRY_WORDS 10
|
|
#define KGSL_BUSY_SOP 0
|
|
#define KGSL_BUSY_EOP 2
|
|
#define KGSL_BUSY_SLOTS 5
|
|
|
|
static inline int kgsl_busy_first_slot(size_t bytes) {
|
|
size_t entries = bytes / (KGSL_BUSY_ENTRY_WORDS * sizeof(uint32_t));
|
|
return entries < 8 ? -1 : (int)(entries - 6);
|
|
}
|
|
|
|
// 1 when a watched slot has a submission between its start and end timestamps. *moved is set when a start
|
|
// timestamp differs from last[], which then holds the new ones.
|
|
static inline int kgsl_busy_sample(const volatile uint32_t *memstore, int first, uint32_t last[KGSL_BUSY_SLOTS], int *moved) {
|
|
int busy = 0;
|
|
for (int i = 0; i < KGSL_BUSY_SLOTS; i++) {
|
|
const volatile uint32_t *entry = memstore + (size_t)(first + i) * KGSL_BUSY_ENTRY_WORDS;
|
|
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
|
if (sop != eop) busy = 1;
|
|
if (sop != last[i]) {
|
|
*moved = 1;
|
|
last[i] = sop;
|
|
}
|
|
}
|
|
return busy;
|
|
}
|
|
|
|
// Hardware-scheduled kernels (every gen8 GPU and some gen7 ones: .gpudev = *_hwsched_gpudev in adreno-gpulist.h)
|
|
// leave the ringbuffer entries at 0. The GMU firmware writes each context's own entry instead
|
|
// (gen8_hwsched_hfi.c send_context_pointers). Context ids run from 1 below the ringbuffer entries, lowest free first,
|
|
// and kgsl zeroes an entry when its context is created or destroyed.
|
|
#define KGSL_BUSY_MAX_LIVE 64
|
|
|
|
// Collects the contexts to sample: every entry below first with a non-zero start stamp (kgsl zeroes an entry when its
|
|
// context is created or destroyed). Entries whose start stamp changed since the previous scan (seen[]) or that are
|
|
// busy now come first, so the max_live cap only drops idle ones. Returns how many ids went into live[].
|
|
static inline int kgsl_busy_scan_contexts(const volatile uint32_t *memstore, int first, uint32_t *seen, int *live, int max_live) {
|
|
int n = 0, idle = 0;
|
|
int idle_ids[KGSL_BUSY_MAX_LIVE];
|
|
for (int id = 1; id < first; id++) {
|
|
const volatile uint32_t *entry = memstore + (size_t)id * KGSL_BUSY_ENTRY_WORDS;
|
|
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
|
int changed = sop != seen[id];
|
|
seen[id] = sop;
|
|
if ((changed || sop != eop) && n < max_live) live[n++] = id;
|
|
else if (sop != 0 && idle < KGSL_BUSY_MAX_LIVE) idle_ids[idle++] = id;
|
|
}
|
|
for (int i = 0; i < idle && n < max_live; i++) live[n++] = idle_ids[i];
|
|
return n;
|
|
}
|
|
|
|
// 1 when a live context has a submission between its start and end timestamps. *moved is set when a start
|
|
// timestamp differs from last[] (indexed by context id), which then holds the new ones.
|
|
static inline int kgsl_busy_sample_contexts(const volatile uint32_t *memstore, const int *live, int count, uint32_t *last, int *moved) {
|
|
int busy = 0;
|
|
for (int i = 0; i < count; i++) {
|
|
const volatile uint32_t *entry = memstore + (size_t)live[i] * KGSL_BUSY_ENTRY_WORDS;
|
|
uint32_t sop = entry[KGSL_BUSY_SOP], eop = entry[KGSL_BUSY_EOP];
|
|
if (sop != eop) busy = 1;
|
|
if (sop != last[live[i]]) {
|
|
*moved = 1;
|
|
last[live[i]] = sop;
|
|
}
|
|
}
|
|
return busy;
|
|
}
|
|
|
|
#endif
|