Add GPU_FOREIGN_UTIL_PCT: game detection via per-process GPU 3D-engine usage
Reads the same PDH counters as Task Manager (\GPU Engine(*)\Utilization Percentage, locale-independent via PdhAddEnglishCounterW), which cover graphics work under WDDM — games are caught without an exe list and the offender is named. Windows-only; a missing or failing counter disables the path with one log line. dwm (the desktop compositor) joins the default ignore list.
This commit is contained in:
@@ -34,8 +34,8 @@ Each consumer is enabled by setting its URL (`OLLAMA_URL`, `COMFY_URL`) and
|
||||
disabled by leaving it empty — at least one is required. With only Ollama
|
||||
the proxy is a pass-through (no image jobs can arrive); with only ComfyUI
|
||||
the Ollama unload/warm steps are skipped. A third, URL-less consumer —
|
||||
detection of foreign GPU holders such as games — is enabled by `GAME_PROCS`
|
||||
and/or `GPU_FOREIGN_VRAM_MB` (see below).
|
||||
detection of foreign GPU holders such as games — is enabled by `GAME_PROCS`,
|
||||
`GPU_FOREIGN_VRAM_MB` and/or `GPU_FOREIGN_UTIL_PCT` (see below).
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -64,7 +64,8 @@ override file values. Invalid values fail at startup.
|
||||
| `COMFY_START_TIMEOUT` | `2m` | Max wait for the managed ComfyUI to come up |
|
||||
| `GAME_PROCS` | _(empty = disabled)_ | Process names (comma-separated); while any runs, the GPU counts as held: requests wait, Ollama unloads, managed ComfyUI stops |
|
||||
| `GPU_FOREIGN_VRAM_MB` | `0` (disabled) | Also treat the GPU as held when a non-ignored process uses more VRAM than this (needs nvidia-smi) |
|
||||
| `GPU_IGNORE_PROCS` | `ollama,ollama app,ollama_llama_server,python,pythonw` | Process names never counted as foreign GPU users |
|
||||
| `GPU_FOREIGN_UTIL_PCT` | `0` (disabled) | Also treat the GPU as held when a non-ignored process uses more than this percent of the GPU 3D engine (Windows PDH counters — what Task Manager shows; catches games without an exe list) |
|
||||
| `GPU_IGNORE_PROCS` | `ollama,ollama app,ollama_llama_server,python,pythonw,dwm` | Process names never counted as foreign GPU users |
|
||||
| `GAME_POLL_INTERVAL` | `15s` | How often game/VRAM detection runs (don't go below ~10s — nvidia-smi polls keep the GPU awake) |
|
||||
| `LOGLEVEL` | `warn` | `info` logs every request (colored arrows in text mode), `debug` adds lock transitions. `LOG_LEVEL` works as an alias |
|
||||
| `LOG_FORMAT` | `text` | `json` for structured JSON logs |
|
||||
@@ -148,20 +149,25 @@ adds a `BindPaths=` to the systemd unit on Linux. Re-run it after changing
|
||||
Want to game on the same GPU without Ollama/ComfyUI squatting on the VRAM?
|
||||
gpu-turnstile can watch for foreign GPU holders and, while one is active,
|
||||
make LLM/image requests wait (or 503, per `LLM_BUSY_MODE`), unload Ollama's
|
||||
models and stop the managed ComfyUI so the game gets the memory. Two
|
||||
models and stop the managed ComfyUI so the game gets the memory. Three
|
||||
detection paths, each optional, polled every `GAME_POLL_INTERVAL` (15s):
|
||||
|
||||
```
|
||||
GAME_PROCS=cyberpunk2077.exe,bg3.exe # the reliable way on Windows
|
||||
GPU_FOREIGN_UTIL_PCT=30 # zero-config on Windows: any non-ignored
|
||||
# process using >30% of the GPU 3D engine
|
||||
GAME_PROCS=cyberpunk2077.exe,bg3.exe # explicit exe watch list
|
||||
GPU_FOREIGN_VRAM_MB=1024 # catch-all via nvidia-smi
|
||||
```
|
||||
|
||||
`GAME_PROCS` matches running process names (case-insensitive, `.exe`
|
||||
optional). `GPU_FOREIGN_VRAM_MB` asks nvidia-smi which processes hold GPU
|
||||
memory and treats anything not in `GPU_IGNORE_PROCS` above the threshold as
|
||||
foreign — handy as a catch-all, but note that under Windows' WDDM driver
|
||||
graphics-only games may not show up in nvidia-smi's per-process list, so
|
||||
name your games in `GAME_PROCS` there; on Linux both paths work. When the
|
||||
`GPU_FOREIGN_UTIL_PCT` reads the same per-process GPU engine counters as
|
||||
Task Manager (PDH), which cover graphics work under Windows' WDDM driver —
|
||||
so games show up without naming them, and the offender is named in the log
|
||||
and monitor. Windows-only. `GAME_PROCS` matches running process names
|
||||
(case-insensitive, `.exe` optional). `GPU_FOREIGN_VRAM_MB` asks nvidia-smi
|
||||
which processes hold GPU memory and treats anything not in
|
||||
`GPU_IGNORE_PROCS` above the threshold as foreign — handy as a catch-all on
|
||||
Linux, but under WDDM graphics-only games may not show up in nvidia-smi's
|
||||
per-process list, so on Windows prefer `GPU_FOREIGN_UTIL_PCT`. When the
|
||||
game exits, requests resume automatically.
|
||||
|
||||
## Build and run
|
||||
|
||||
Reference in New Issue
Block a user