From 42b73c4098e95c0cc8c97a83d0da68d0239ea7f6 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 27 Oct 2026 12:33:45 +0300 Subject: [PATCH] Note what each 2026-10 frame time fix needs on a Linux host: the SleepThread spin is for the Windows timer only, the file I/O moved off the game and render threads is portable with fsync in place of FlushFileBuffers, the slow-present profiler is Windows-only Co-Authored-By: Claude Opus 5.5 --- docs/backlog.md | 16 ++++++++++++++++ runtime/kernel.c | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/backlog.md b/docs/backlog.md index c7f42677..188d5d95 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -161,6 +161,22 @@ Each platform item gets a written design first, agreed with the maintainer. the mirrored and texture-bound pages after each sync and mark them in the fault handler (Ryujinx), uploading pools the game rewrites every frame whole instead of tracking them. Soft-dirty (`/proc/self/clear_refs`) is process-wide and slow, a last resort. Under Proton the Windows build already works: Wine emulates both. + Frame time fixes of 2026-10 (merge 2b1e295) and what each needs on Linux: + - Short SleepThread spins (`kernel.c` `sleep_ns`, `SLEEP_SPIN_NS`): Windows-only cause, the high-resolution + waitable timer wakes 0.3-0.5 ms late. `clock_nanosleep` wakes within the timer slack (50 us default, + `prctl(PR_SET_TIMERSLACK)` lowers it): spin below that or not at all, and measure with `TOTK_TRACE=sched` + ("sleep asked / took"). + - Background save Commit (`fs_host.c`), pipeline cache autosave thread (`vk_pipeline.c`), shader record writes + outside the lookup lock (`gfx_shader.c`), `.use` masks read at start: portable as written; they keep file I/O + and flushes off the game and render threads, which any OS needs. On Linux the Commit's FlushFileBuffers become + `fsync` of each file and directory, and the renames `rename()` plus an `fsync` of the parent. + - Recording copy index by 64 KiB block (`nvn_api_cmd.c`), world clock input (`frame_rate.c`, `input_win.c`): + portable logic, no OS calls. + - Slow-present profiler (`prof_win.c`, `TOTK_PROFILE_SLOW`): Windows-only (SuspendThread, GetThreadContext, + QueryThreadCycleTime, RtlVirtualUnwind). On Linux use `perf record -g` or a `SIGPROF` sampler; `tstall` has no + direct equivalent. + - VMA block allocation on the render thread (`vk_texture.c` `create_tex`, 8-11 ms per 256 MiB block on AMD + Windows): measure again on RADV before working around it. 36. **Steam Deck**: RADV offers Vulkan 1.3 and `VK_EXT_external_memory_host`; 4 Zen 2 cores, so expect 30-40 fps. 37. **Launcher**: one exe for Windows and Linux, SDL3 and Dear ImGui (SavageWindRecomp `runtime/ui/launcher.mm`), with Play, Settings, Game files and Quit. Settings that need a restart go there, and it is the recovery path when a diff --git a/runtime/kernel.c b/runtime/kernel.c index 23c61766..ea94cfa2 100644 --- a/runtime/kernel.c +++ b/runtime/kernel.c @@ -1333,7 +1333,8 @@ void kern_run_on_guest_main(void (*fn)(Cpu *c)) { // The high-resolution waitable timer ends a wait 0.3-0.5 ms late at best: the SDK's 20 us polling sleeps (main thread // and job workers, about 1.5 per frame each) took 460-515 us. Sleeps up to SLEEP_SPIN_NS spin on the performance -// counter instead; the virtual core is already given up. +// counter instead; the virtual core is already given up. Linux: clock_nanosleep wakes within about 50 us (timer slack), +// so a Linux host spins only below that, or not at all (docs/backlog.md item 35). #define SLEEP_SPIN_NS 1000000 static void sleep_ns(RtThread *t, int64_t ns) { if (ns <= SLEEP_SPIN_NS) {