Files
DroidDeck/tools/gpuload/src/gpuload_busy.h
T
The412Banner 8cb5c2168e 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.
2026-11-01 20:22:51 +00:00

23 lines
1.2 KiB
C

// Busy-time bookkeeping shared by VK_LAYER_DROIDDECK_gpu_load and DroidDeck's compositor, kept free of Vulkan so it
// can be tested on its own.
#ifndef DROIDDECK_GPULOAD_BUSY_H
#define DROIDDECK_GPULOAD_BUSY_H
#include <stdint.h>
// GPU ticks between the timestamp written before a batch and the one written after it. Batches on one queue run one
// after the other, so these add up without overlap. Ticks are never compared across batches: on Adreno the always-on
// counter behind the timestamps restarts when the GPU powers down between batches (seen on the Retroid Pocket Duo).
// Anything backwards or longer than max_ticks is a bogus pair and counts as nothing.
static inline uint64_t gpuload_interval(uint64_t start, uint64_t end, uint64_t max_ticks) {
return end > start && end - start <= max_ticks ? end - start : 0;
}
// A timestamp query slot is reused once its end is available; until the GPU runs the slot's reset again the
// query still shows the previous end, so a result equal to the last one harvested is the old one.
static inline int gpuload_result_is_new(uint64_t start_avail, uint64_t end_avail, uint64_t end, uint64_t last_end) {
return start_avail && end_avail && end != last_end;
}
#endif