Repository navigation
Windows: use high-resolution timers for Event timed waits - #538
pretend7979 wants to merge 2 commits into
Conversation
Block on a high-resolution timer and a signal event instead of polling or rounding every timeout to milliseconds. Give each waiting host thread its own reusable timer and retain blocking fallbacks for unavailable handles. Add Event regression coverage and the Clang sirit header include fix. Assisted-by: OpenAI Codex (implementation, investigation, tests and draft text)
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Add Doxygen comments for the changed Event and per-thread timer functions, including signal consumption, timeout results and handle ownership. Assisted-by: OpenAI Codex (documentation, investigation and validation)
Keep the existing monitor-based waiting policy, but check a fixed saturating deadline after every wake. Bound and round cycle budgets before narrowing to the 32-bit MWAITX counter. Preserve pending-signal consumption for nonpositive durations. Retain the six Event regressions from Eglantine Eglantine-Community#538 (a51de16) without importing its high-resolution timer policy. Add arithmetic, reset-wake and extreme-duration coverage plus a Windows QPC verification probe. The extreme-duration test also exposes condition_variable wait_for overflow on Linux; use the same saturating deadline with wait_until there. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ntine-Community#120) * common: retry unsignalled MWAITX wakes until the Event deadline Keep the existing monitor-based waiting policy, but check a fixed saturating deadline after every wake. Bound and round cycle budgets before narrowing to the 32-bit MWAITX counter. Preserve pending-signal consumption for nonpositive durations. Retain the six Event regressions from Eglantine Eglantine-Community#538 (a51de16) without importing its high-resolution timer policy. Add arithmetic, reset-wake and extreme-duration coverage plus a Windows QPC verification probe. The extreme-duration test also exposes condition_variable wait_for overflow on Linux; use the same saturating deadline with wait_until there. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * common: make steady clock authoritative for MWAITX timeout expiry The hardware clock uses a sampled TSC frequency rounded to 100 kHz; its nanoseconds can advance faster than Windows QPC. The prior deadline could therefore expire early on steady_clock even though the MWAITX tick budget rounded upward. Use steady_clock for both deadline construction and expiry, retaining the TSC estimate only for bounded hardware wait durations. Keep the existing concurrent timeout regression unchanged and add repeated 100 ms and 500 ms steady-clock checks. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* common: retry unsignalled MWAITX wakes until the Event deadline Keep the existing monitor-based waiting policy, but check a fixed saturating deadline after every wake. Bound and round cycle budgets before narrowing to the 32-bit MWAITX counter. Preserve pending-signal consumption for nonpositive durations. Retain the six Event regressions from Eglantine #538 (a51de16) without importing its high-resolution timer policy. Add arithmetic, reset-wake and extreme-duration coverage plus a Windows QPC verification probe. The extreme-duration test also exposes condition_variable wait_for overflow on Linux; use the same saturating deadline with wait_until there. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * common: make steady clock authoritative for MWAITX timeout expiry The hardware clock uses a sampled TSC frequency rounded to 100 kHz; its nanoseconds can advance faster than Windows QPC. The prior deadline could therefore expire early on steady_clock even though the MWAITX tick budget rounded upward. Use steady_clock for both deadline construction and expiry, retaining the TSC estimate only for bounded hardware wait durations. Keep the existing concurrent timeout regression unchanged and add repeated 100 ms and 500 ms steady-clock checks. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
can you fix conflicts ? |
…ntine-Community#120) * common: retry unsignalled MWAITX wakes until the Event deadline Keep the existing monitor-based waiting policy, but check a fixed saturating deadline after every wake. Bound and round cycle budgets before narrowing to the 32-bit MWAITX counter. Preserve pending-signal consumption for nonpositive durations. Retain the six Event regressions from Eglantine Eglantine-Community#538 (a51de16) without importing its high-resolution timer policy. Add arithmetic, reset-wake and extreme-duration coverage plus a Windows QPC verification probe. The extreme-duration test also exposes condition_variable wait_for overflow on Linux; use the same saturating deadline with wait_until there. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * common: make steady clock authoritative for MWAITX timeout expiry The hardware clock uses a sampled TSC frequency rounded to 100 kHz; its nanoseconds can advance faster than Windows QPC. The prior deadline could therefore expire early on steady_clock even though the MWAITX tick budget rounded upward. Use steady_clock for both deadline construction and expiry, retaining the TSC estimate only for bounded hardware wait durations. Keep the existing concurrent timeout regression unchanged and add repeated 100 ms and 500 ms steady-clock checks. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> (cherry picked from commit 687a494) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJNfzVjvfnqqaEjKL3CyAB
Summary
Replace Windows
Event::WaitForpolling with a blocking wait on a high-resolution timer and a signal event. This aims to reduce CPU usage while avoiding the whole-millisecond timeout rounding of the earlier WaitOnAddress proposal.Each waiting host thread owns a reusable timer, preventing concurrent waits from overwriting each other’s deadlines.
Set()interrupts the wait, and a successful wait consumes the signal. Blocking fallbacks remain available when high-resolution timers or handles cannot be used.Non-Windows wait behaviour is unchanged. This also includes the missing
<cstdlib>include for the sirit dependency when building with Clang.Type of change
Related issues
Separated from #532 following review feedback about emulator-wide timing changes.
Testing
The candidate Windows implementation compiled locally with Clang/MinGW.
Six Event regression cases passed, with 23 assertions covering:
Games tested:
Full emulator/game testing of this high-resolution implementation is pending. Earlier Star Fox and Mario Kart testing used the previous timer implementation.
Checklist
Screenshots / logs
Idle Windows benchmark, 1,000 waits per duration. The baseline is the previous WaitOnAddress prototype.
Neither blocking implementation returned early in these measurements. Sampled thread CPU usage was approximately 0–3% of one logical CPU, with accounting-granularity limitations.
The results show reduced latency or jitter in some cases, but do not establish microsecond-accurate wake-ups. CoreTiming also drives audio, vsync, syncpoint polling and guest timeouts, so broader testing is needed before merging.
AI disclosure
Assisted-by: OpenAI Codex (implementation, investigation, tests and draft text)
Summary by CodeRabbit