WIP: feat(os): HOS_WAKE_LAT also counts the event sleepers that slept more than once #1967
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1967
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:feat/wake-lat-resleeps"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
HOS_WAKE_LAT=1(a diagnostic, off) logs every 5 s, for each thread, how its event and queue waits were met: ready,after spinning, after sleeping, and the signal-to-running latency of the sleepers. An event waiter that wakes to a clear
event (a signal another waiter took first, or a wake with no signal for it) goes back to sleep, and the line did not
show it. It now says how many of the sleepers slept more than once (the line's format in
wake_lat_note):so a wake of every waiter that wakes threads for nothing shows. Those sleepers still count as sleepers, with their
latency as before. What the line counts (the comment above
wake_lat_onand the switch's row ingpu/vk/switches.defsay the same):
in no bucket, however often it slept;
a fraction of event sleepers alone;
event_waitcounts its sleeps in one state saturated at 2 (0 never slept, 1 slept, 2 slept again), in place of thesleptflag: bounded, as an untimed waiter can lose an auto-clear signal to other waiters without end. The table's rowsare keyed by the thread's id and keep a copy of its name (
hos_thread_name_copy,host/hos_thread.c), taken under thelock
hos_thread_set_namenow writes the name under: a thread that ends before the report (itsHosThreadfreed orreused) is printed by its own name, and another thread never merges into its row. Main's table kept the name pointer;
that is fixed here too, as this line extends it. Without the switch nothing changes in what the game does or logs.
From 78c83308 on
exp/x86-asm-sync.Read first:
wake_lat_noteandevent_wait(itsnaps) inhost/nn_os_sync.c;tests/test_wake_lat.py.Testing
Tested: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), llvm-mingw clang 23.1.5; game-free checks only. This change
has not run in the game on this PC yet (the run with
HOS_WAKE_LAT=1: Still to test). Each check ran in a hidden consoleof its own, in one job of the PC's job queue (fb3-1967-1), on this branch rebased onto
main@f1f2dc5b(head4d2ebc2a):python -I -B tests/test_wake_lat.py(new,8f465100): passes at the head, three runs (with--cxxllvm-mingw clang++and with the compiler found from
LONGSHOT_MINGW): Again 102 after sleeping, 101 of them more than once; Once 101, 0;TimedOut 101, 0 (its timed-out wait in no bucket); Queue 102, 1; Reused 101, 0; "wake lat: ok". At
8f465100, withoutthe fix, it fails: the ended thread's row merges into the thread that reused its
HosThread, under the new name("Reused: ... 203 after sleeping, 101 of them more than once").
python -I -B tests/test_event_handoff.py: passes.python -I -B tests/test_multiwait_wake.py: passes (head 4d2ebc2a's code before the fixture's last change, the samesource).
python -I -B tests/run_all.py --strict --changed origin/main(5 files changed, 85 checks read them; 8 at once): 69passed, 16 failed, 4 skipped. 13 of the 16 failing checks (
test_crash_dialog.py,test_crash_record.py,test_dev_ab.py,test_dev_packs.py,test_frame_overlap.py,test_host_guest_writes.py,test_libc_hooks.py,test_linux_pressure.py,test_mods_list.py,test_profiling_mode.py,test_slow_frames.py,test_vcore_escape.py,test_vcore_mask0.py) fail onmain@f1f2dc5btoo, each run by name in the same queue'sjobs. The other three (
test_present_queue_default,test_target_reuse_memory,test_vk_occlusion_queries) compilednothing in that run nor in the run on
main(no Vulkan headers on the job's path: "not found: vulkan_headers(--strict)"). Rerun with the headers (job fb3-vk-1,
RX_CPMset) at the head4d2ebc2aand onmain@f1f2dc5b, eachfails at both with the same first error:
test_present_queue_default"srccut: '{TAB_DEBUG, "Present queue",&opts.present_queue, ...' is not in gpu/vk/vk_menu.cpp";
test_target_reuse_memory2 of its 8 tests("'vmaGetAllocationInfo2' unexpectedly found" in the VMA source, and its fixture's "use of undeclared identifier
'destroy_image_later'");
test_vk_occlusion_queries"the ring fixture did not compile" ("no member named 'policy'").None fails on this branch alone.
Still to test:
HOS_WAKE_LAT=1, expectingthe
wake:lines with their "of them more than once" count, at most the "after sleeping" count (by hand)HOS_WAKE_LAT=1, expecting the samewake:lines (by hand)Measurements
Nothing to measure in play: it changes a diagnostic's log line, off by default (
HOS_WAKE_LATkeeps its default); off, an event wait that sleeps updates one local state (the slept flag it replaces) per sleep.Risks
Only the diagnostic's log line changes, and only with
HOS_WAKE_LATset; a script that reads the old line by its exacttext would need the new field. Off, an event wait that sleeps counts its sleeps in a local state of three values.
hos_thread_set_namenow takes a lock around its write of the name (a guest SetThreadName, rare). #2020 fixes thesame rename race for every name reader another way (a thread's names are kept, never written over, and published
with one atomic store), and conflicts with this PR in
host/hos_thread.candhost/hos.h: proposed order #2020first, then this PR rebased onto it without its lock (
hos_thread_name_copythen copies the kept name). No new switch: arevert is enough. Players notice nothing: the switch is not set for them.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
Recommendation: Request changes. The new count can help diagnose event wakeups, but its signed sleep counter can overflow even with the diagnostic off, and the report can read a destroyed thread’s name. The reported checks never verify a nonzero repeat-sleeper count.
With HOS_WAKE_LAT enabled, the log gains a count of completed event waits that slept again. Those waits still count once in the sleeper total and latency calculation. The change adds one counter per report slot and extra bookkeeping to event waits that sleep, including with the default settings.
@fixwill do (6)host/nn_os_sync.c:941: The signed naps counter increments without a bound, even with HOS_WAKE_LAT off. (more on the line)host/nn_os_sync.c:886: The report table retains a pointer into HosThread. (more on the line)host/nn_os_sync.c:947: The existing event handoff test disables the diagnostic and the multi-wait fixture discards its samples. (more on the line)gpu/vk/switches.def:228: The row and PR summary promise a five-second per-thread report, but the logger only emits a row when that thread completes more than 100 sleeping waits in the interval. (more on the line)host/nn_os_sync.c:947: Use one bounded sleep state in place of two variables to shrink the default-path bookkeeping. Add a controlled event fixture to verify a nonzero count when the game workload cannot reliably produce one.For the author (1) (a run, a measurement or a decision)
host/nn_os_sync.c:947: The planned smoke runs would pass if the new field always printed zero. (more on the line)Checks: Still running:
PR description / Description follows the template (pull_request_target),CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven. The PR reports 31 passes, seven failures also seen on main, and three skips on Windows at the earlier rebased head bdeabe83. No run shows a nonzero repeat-sleeper count, and no frame-time comparison measures the cost with the diagnostic off.
Other systems: Normal, light, and system event waits share the changed loop, so the extra bookkeeping can reach frame workers and device waits on Windows and Linux, including Steam Deck. Queue waits keep their existing classification and latency path but gain the field in their shared report. Multi-wait, timer, and semaphore waits stay outside the new count. No in-game evidence covers the affected Tier 1 systems.
Switches: HOS_WAKE_LAT remains a developer diagnostic, off by default on all platforms. That is the right default for periodic logging. The switch table documents the new field but omits its reporting limits, and the default-off cost remains unmeasured.
Reviewed:
10bf17beeaagainst6e1521a70a: Read host/nn_os_sync.c in full, the complete diff and commit message, AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, and the Forgejo template. Read the changed switch row and its neighboring rows, and inspected the switch consumer, thread naming and destruction, host wait implementations, and event test fixtures. Skimmed the rest of the switch table and the reported Windows results. docs/review-checklist.md and the sibling Tooling checkout were absent. The PR supplied no run logs, comments, or earlier reviews.; nothing run (a code review).Checked and fine:
Testing: Read-only review. The author reports the targeted Windows checks on bdeabe83. The seven named failures also occurred on the earlier base. The author reports an unchanged rebase to
10bf17be. Head CI is pending, and the Windows and Linux in-game runs are outstanding.Overlaps and merge order: No overlapping pull request was visible in the supplied material. The PR names exp/x86-asm-sync as the source of the change, and the source commit is absent from the checkout.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -226,3 +226,3 @@SW(HOS_WAIT_WHO, diag, string, "off", "For the named thread, logs the events it waits on and who signals them.")SW(HOS_WAIT_WHO_LR, diag, string, "every caller", "Narrows HOS_WAIT_WHO to waits from one guest caller (hex return address).")SW(HOS_WAKE_LAT, diag, bool, "off", "Every 5 s, per thread: how event and queue waits were met and the signal-to-running latency.")SW(HOS_WAKE_LAT, diag, bool, "off", "Every 5 s, per thread: how event and queue waits were met (ready, after spinning, after sleeping, and how many event sleepers woke to a clear event and slept again) and the signal-to-running latency.")L4 (minor): The row and PR summary promise a five-second per-thread report, but the logger only emits a row when that thread completes more than 100 sleeping waits in the interval. A worker can sleep again and complete ten waits without a line, and a timed wait that expires contributes nothing. Document the threshold and say that the repeat count covers successful event waits.
@ -885,2 +884,3 @@static void wake_lat_note(int how, int64_t lat_ns) { /* how: 0 ready, 1 spun, 2 slept, 3 slept more than once */static SRWLOCK lk = SRWLOCK_INIT;static struct { const char *thread; int64_t n[3], lat, max; } tab[32];static struct { const char *thread; int64_t n[4], lat, max; } tab[32];L2: The report table retains a pointer into HosThread. A worker can record 101 sleeps, then be joined and freed before another thread prints its row. The %s then reads freed memory, and allocator reuse can also merge two workers' counts. SetThreadName can also rewrite that buffer while it is being read. This is already present on main in the logger being extended here. Key rows by stable thread ID and keep an owned name snapshot taken under synchronization shared with renames.
@ -937,3 +939,3 @@hos_cv_sleep(&e->cv, &e->lk, INFINITE);}slept = 1;slept = 1, naps++;L1: The signed naps counter increments without a bound, even with HOS_WAKE_LAT off. An untimed waiter that repeatedly loses an auto-clear signal can stay in the loop indefinitely. At 10,000 retries per second it would reach signed overflow in about 60 hours. Track three states instead, saturate at two sleeps, and use that state in place of the separate slept flag.
@ -943,3 +945,3 @@ReleaseSRWLockExclusive(&e->lk);}if (got && wake_lat_on()) wake_lat_note(slept ? 2 : 1, slept ? hos_now_ns() - signaled_at : 0);if (got && wake_lat_on()) wake_lat_note(naps > 1 ? 3 : slept ? 2 : 1, slept ? hos_now_ns() - signaled_at : 0);L3 (minor): The existing event handoff test disables the diagnostic and the multi-wait fixture discards its samples. Reverting the repeat classification or omitting its contribution to the sleeper total would escape both. Extend the event fixture with a controlled clear wake followed by a successful signal, and check the reported repeat subset, total sleepers, and latency. Include a single sleep as a control and use the existing compiler selection.
L5 (minor): The planned smoke runs would pass if the new field always printed zero. On the Windows and Linux head builds, exercise a workload that produces a repeat sleeper and verify a nonzero count within the sleeper total. Include the affected Tier 1 systems in the run record and a matched, interleaved frame-time comparison with main at the default off setting. The PR opened before the required author-side game run.
Recommendation: Request changes. A bounded sleep state can make the diagnostic useful without introducing a signed counter that can overflow even when the switch is off. The retained thread-name pointer also needs a lifetime-safe representation before this diagnostic is used to compare wake paths. Existing exact-head review
Reviewed. Head
10bf17beea8c07c44387abfd90f3f1a5c2a6acc4against merge base6e1521a70a32603ed60a8263e4072625885669b7. Read both changed files, the event wait, signal, timeout and queue-receive callers, and the fixtures that cut those paths. Validated both source-only Graphify maps. No code run.Checked and fine. The repeat bucket counts once in the total sleeper bucket and contributes one latency sample. The existing predicate, try-only path and absolute timeout handling stay in place. The default for
HOS_WAKE_LATstays off.Blocking. A waiter can repeatedly wake without acquiring the event over an unbounded wait. The new signed increment at
host/nn_os_sync.c:941runs on the disabled path as well. Use one state saturated after the second completed sleep. The same report's existing borrowed thread-name pointer can outlive its owner. Use a stable ID and a lifetime-safe snapshot. Both lines are already discussed in the linked review.Measurement interpretation. The added field counts completed event waits that returned from a wait more than once. A waiter that re-sleeps and eventually times out contributes nothing. The aggregate sleeper denominator is also shared with queue receivers. Document those boundaries before using the value to infer event fairness or report a repeat-wake fraction. A small fixture should drive a clear wake followed by another sleep, plus a timeout control and a queue sample, to check what lands in each bucket.
Testing. The author reports targeted Windows game-free results with baseline failures at earlier revisions. The PR has no direct assertion for the new field, no Windows or Linux gameplay confirmation, and pending or blocked check contexts. Verify Windows and Linux diagnostic output on the corrected head. This is diagnostic evidence, so a frame-rate farm trial now would add little.
Overlap and merge order. This touches the same
event_waitandwake_lat_notepaths as 1970 and 1971. Settle the metric and its test first, then preserve it when the park and handoff track is rebased.@ -943,3 +945,3 @@ReleaseSRWLockExclusive(&e->lk);}if (got && wake_lat_on()) wake_lat_note(slept ? 2 : 1, slept ? hos_now_ns() - signaled_at : 0);if (got && wake_lat_on()) wake_lat_note(naps > 1 ? 3 : slept ? 2 : 1, slept ? hos_now_ns() - signaled_at : 0);Please document that this samples only completed event waits. An event waiter can re-sleep and then time out without appearing here, while the sleeper denominator in wake_lat_note also includes queue waits. Those distinctions matter when comparing event fairness across wake implementations.
10bf17beea4d2ebc2ae8Pushed
4d2ebc2a(rebased ontomain@f1f2dc5b; the PR's commit unchanged):event_wait's sleep count is one bounded state,HOS_WAKE_LAT's rows are keyed by thread id with an owned copy of the name, the comment, switch row and Summary say what the line counts (completed waits only; event and queue sleepers together), and the newtests/test_wake_lat.pychecks each bucket. Testing lists this head's checks.@futondestroyer, on your review and inline, head
4d2ebc2a(rebased ontomain@f1f2dc5b; the PR's own commit unchanged,git range-diff"="):host/nn_os_sync.c:941): fixed in4d2ebc2a.event_waitkeeps one state saturated at 2 (naps += naps < 2: 0 never slept, 1 slept, 2 slept again) in place of bothsleptand the counter, so nothing grows however often an untimed waiter loses the signal. Bounded by construction; no test drives 2^31 sleeps.4d2ebc2a. Rows are keyed byhos_thread_idand keep a 48-byte copy of the name, taken at the thread's first note of the 5 s with the newhos_thread_name_copyunder the lockhos_thread_set_namenow writes the name under (the same idea as18e90465: copy while the owner cannot change or end it; here the caller is the thread itself).tests/test_wake_lat.py(8f465100) ends a thread, reuses itsHosThreadrenamed for another thread and checks two rows with their own names; at8f465100without the fix it fails: the ended thread's 102 sleepers merge into the new one's row under the new name (203).wake_lat_on, the switch row and the description now say it: only completed waits (an event waiter that sleeps again and then times out counts in no bucket), "after sleeping" and the latency are the thread's event and queue waits together, "of them more than once" is event waits only, a line needs more than 100 sleepers. The fixture runs nn_os_sync.c's ownevent_wait,queue_getandwake_lat_noteon real threads: 101 clear wakes then another sleep each (102 sleepers, 101 more than once), 101 single sleeps (101, 0), a timed wait woken to a clear event that sleeps again and runs out plus 101 single sleeps (101, 0: the timeout counts nothing), and 101 queue receives that slept plus one event re-sleep on one thread (102, 1: the shared denominator).Checks:
tests/test_wake_lat.py,test_event_handoff.py,test_multiwait_wake.pypass;run_all.py --strict --changed origin/main: 69 passed, 16 failed, 4 skipped, all 16 failing onmain@f1f2dc5btoo (Testing in the description).BeanBot's review, head
4d2ebc2a:slept(4d2ebc2a).4d2ebc2a;tests/test_wake_lat.py, failing at8f465100).tests/test_wake_lat.py(8f465100), with the real wake_lat_note (the handoff test keeps its stub): clear wake then success, single-sleep control, timeout, queue; latency checked as 0 on the fixture's own clock. Compiler:--cxx, thenCXX, thenLONGSHOT_MINGW's clang++, then PATH.mise run testin full has not run, so its box stays open.@Beanstalk This touches only the HOS_WAKE_LAT diagnostic (off unless set) in the guest event and queue waits (host/nn_os_sync.c): its wake log lines also say how many event sleepers slept more than once. Nothing is meant to get faster, so no frame-time comparison is asked. It has not run in the game on these PCs yet. Please start the game and play Castle Town Market for one minute with HOS_WAKE_LAT=1, on a Windows PC and on a Linux PC. No crash; the log must have the wake lines every 5 s with their "of them more than once" count.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Description: Risks names #2020 (the same rename race fixed for every reader) and the proposed landing order; no code change.
The three renderer checks (
test_present_queue_default,test_target_reuse_memory,test_vk_occlusion_queries) did not compile in the earlier run (no Vulkan headers on that job's path); rerun with them in job fb3-vk-1, at the head4d2ebc2aand onmain@f1f2dc5b: all three fail at both with the same first error, so they fail onmaintoo; Tested's sentence and counts corrected.Recommendation: Wait for a Windows and Linux diagnostic smoke test. The saturating wait state and owned thread-name copy address the earlier source findings. The switch stays off by default.
For the pending Farm request, the reviewed pair predates the
market-entrancerepository save. Both revisions supportkokiri-startand the control bridge'sMarket_Childteleport. Start from that save on both sides, wait for gameplay, use the teleport and verify arrival before the one-minute window. Check the new count in an eligible candidate row. Existing requestOn a completed event wait the counter now stays at two after the second sleep. A timed-out wait contributes no sample. Queue waits remain in the total sleeper count and never enter the repeat-event bucket. The fixture compares those cases explicitly and reuses a thread record under a new ID. Host IDs are allocated by the shared 64-bit counter. The collector copies the current thread's name under the same lock the setter holds while writing it, so the logged row can safely outlive the thread.
The report is evaluated on a completed wait after five seconds have elapsed. It emits rows only for threads with more than 100 completed sleeping waits in the interval. A Market smoke should look for an eligible
wake:row with the new count and record an interval without eligible rows as inconclusive. A zero repeat count is valid. This diagnostic adds no intended gameplay speedup. The author reports the focused Windows fixture passing on this head. Cross-host gameplay and CI are still outstanding. Author evidence · Existing Test Farm requestRecheck the fixture when rebasing onto main's later presentation wait change: the base here still has the full
queue_getbody where the fixture cuts it. Keep this bucket definition when reconciling the event handoff and park series. Presentation wait changeReviewed.
4d2ebc2ae833fac60c9f32244eb872fdddb1b689against actual merge basef1f2dc5bd2821cef061798ba40a043d281ac1707. Reviewed the five changed files, the event and queue callers and the thread ID and name ownership. Both revision-matched Graphify maps verified and queried. Source only.Beanstalk test farm · 🔄 testing (0 of 2 reports so far)
Commit
4d2ebc2· approved by futondestroyer (👍 on siantm's request) (reviewed) · dashboard⚠️ Note: Rows are emitted only for threads with more than 100 completed sleeping waits, so no eligible row makes the expected-line check inconclusive.
⚠️ Note: The farm cannot verify the five-second cadence or compare the repeat count numerically with the sleeper count; the one-minute measurement is stationary after the movement step.
Started at 09:39 UTC.
Estimate: done in about 40 min, from the queue and the testers online now.
windowslinuxWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)On one Windows PC and one Linux PC, the game will run with HOS_WAKE_LAT=1, teleport to Castle Town Market, move, and spend one minute there. The test checks for crashes and an eligible wake log row containing the new numeric count; a missing eligible row is inconclusive. Each PC's runs take about 12 minutes, excluding builds.
kokiri-start(switchesHOS_WAKE_LAT=1), then teleport to Market, move the stick, measure market for 60 s (after 0 s warm-up); 1 run on each side.@Beanstalk This replaces my request 63555 on this head (please do not run that one): the same check, with the start and the scene pinned as the reviewer asked. This touches only the HOS_WAKE_LAT diagnostic (off unless set) in the guest event and queue waits (host/nn_os_sync.c): its wake log lines also count the event sleepers that slept more than once. Nothing is meant to get faster. Please start both sides from the kokiri-start save, teleport to Market_Child and check the game arrived there before the one-minute window, then play Castle Town Market for one minute with HOS_WAKE_LAT=1, the PR against main on the same PC, on a Windows PC and on a Linux PC. No crash; on the PR's side, look for a wake row eligible for the new count with its "of them more than once" figure: zero repeats is a valid result, and no eligible row makes it inconclusive.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.