Repository navigation
Make the clock jitter a function of the emulated time - #2583
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain to block approval.
No open issues 🎉
What changed in this PR
Removes read-dependent clock jitter from Spice86 as the first step in the input-recording stack.
Changes:
- Remove the jitter option, implementation, and clock-state fields; update clock consumers.
- Delete jitter-only tests and fixtures, tighten timing assertions, and use invalid DOS state for restore-rejection tests.
- Update CLI documentation and deterministic-timing guidance.
| File | Description |
|---|---|
tests/Spice86.Tests/Video/CgaIntegrationTests.cs |
Update clock construction. |
tests/Spice86.Tests/Spice86Creator.cs |
Remove jitter configuration plumbing. |
tests/Spice86.Tests/Resources/VgaTests/vga_phase_lock.asm |
Delete jitter-dependent fixture. |
tests/Spice86.Tests/MouseDriverTests.cs |
Update clock construction. |
tests/Spice86.Tests/MouseDriverStateTests.cs |
Update clock construction. |
tests/Spice86.Tests/GeneratedCodeDifferentialReport.cs |
Remove jitter-state normalization. |
tests/Spice86.Tests/Emulator/VM/Clock/EmulatedClockStateTests.cs |
Remove jitter cases and assert exact elapsed time. |
tests/Spice86.Tests/Emulator/Devices/Video/VgaPhaseLockTests.cs |
Delete jitter-specific tests. |
tests/Spice86.Tests/Emulator/Devices/MachineDeviceStateTests.cs |
Trigger restore rejection with invalid DOS state. |
tests/Spice86.Tests/Emulator/Devices/Keyboard/PS2KeyboardReleaseAllKeysTests.cs |
Update custom clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/PitTimerTests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/PitTimerStateTests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/PitModeTests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/Pit8254Tests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/FloppyDiskTimingServiceTests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/FloppyDiskControllerTests.cs |
Update clock construction. |
tests/Spice86.Tests/Emulator/Devices/ExternalInput/DeviceSchedulerTests.cs |
Update clock construction. |
tests/Spice86.Tests/ClockTests.cs |
Remove jitter tests and tighten timing assertions. |
tests/Spice86.Tests/AsmFixtures/BiosDeviceScenarioCatalog.cs |
Remove phase-lock scenario and jitter settings. |
tests/Spice86.Tests/AsmFixtures/AsmRunSettings.cs |
Remove jitter seed setting. |
src/Spice86/Spice86DependencyInjection.cs |
Construct clocks without jitter arguments. |
src/Spice86.Core/Emulator/VM/Machine.cs |
Remove obsolete jitter comments and documentation. |
src/Spice86.Core/Emulator/VM/Clock/IEmulatedClock.cs |
Remove separate jitter-free clock property. |
src/Spice86.Core/Emulator/VM/Clock/EmulatedClockState.cs |
Remove captured jitter state. |
src/Spice86.Core/Emulator/VM/Clock/EmulatedClock.cs |
Remove jitter constructor parameter. |
src/Spice86.Core/Emulator/VM/Clock/CyclesClock.cs |
Remove jitter constructor parameter. |
src/Spice86.Core/Emulator/VM/Clock/ClockJitter.cs |
Delete jitter implementation. |
src/Spice86.Core/Emulator/VM/Clock/ClockBase.cs |
Remove jitter from reads, capture, and restore. |
src/Spice86.Core/Emulator/Devices/Sound/Opl3Fm.cs |
Read ElapsedTimeMs directly. |
src/Spice86.Core/CLI/Configuration.cs |
Remove --ClockJitterSeed. |
README.md |
Remove obsolete CLI option documentation. |
docs/index.html |
Remove obsolete CLI option documentation. |
.agents/skills/spice86-config/SKILL.md |
Remove jitter option and revise timing guidance. |
Review effort: Balanced
|
No change in generated code or listings. Base |
This was referenced Dec 2, 2026
maximilien-noal
self-requested a review
December 2, 2026 05:18
maximilien-noal
approved these changes
Dec 2, 2026
kevinferrare
marked this pull request as draft
December 2, 2026 12:17
Previously, each read of IEmulatedClock.ElapsedTimeMs stepped a PRNG state, so reading the clock had a side effect, reported time could go backward, and runs with a different number of clock reads (such as interpreted vs. generated code) diverged. Compute the jitter offset in [0, 0.01) ms as a pure, piecewise-linear function of the emulated time and the seed (1 ms period, splitmix64 endpoints). Keep --ClockJitterSeed and ElapsedTimeMsWithoutJitter (for OPL), remove EmulatedClockState.JitterState and the jitter restore check, update docs and tests, and add determinism and monotonicity tests.
kevinferrare
force-pushed
the
feature/remove-clock-jitter
branch
from
December 2, 2026 13:34
fadb484 to
042bff2
Compare
Contributor
Author
kevinferrare
marked this pull request as ready for review
December 2, 2026 14:11
maximilien-noal
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Previously, each read of
IEmulatedClock.ElapsedTimeMsstepped a PRNG state, so reading the clock had a side effect, reported time could go backward between consecutive reads, and runs with a different number of clock reads (such as interpreted vs. generated code) diverged.ClockJitterwith a pure, piecewise-linear function of the emulated time and the seed (offset in[0, 0.01)ms, 1 ms period, splitmix64 endpoints), keeping no mutable jitter state.--ClockJitterSeedandIEmulatedClock.ElapsedTimeMsWithoutJitter(used byOpl3Fmon the mixer thread), and keepVgaPhaseLockTestsunchanged.WithJitterinClockBase.ElapsedTimeMs(WithJitter(ComputeMs(state))) andClockBase.CurrentDateTime(WithJitter(ComputeMs(state) - state.AnchorMs)), dropping thestate.Multiplier > 0special case so freezing the clock stays continuous.EmulatedClockState.JitterState, the jitter mismatch check inClockBase.EnsureCanRestore,GeneratedCodeDifferentialReport.WithoutJitterState, and the obsolete generator-state tests; rewrite the twoMachineDeviceStateTestsrollback tests to use an invalid DOSAllocationStrategy.README.md,docs/index.html, and.agents/skills/spice86-config/SKILL.md.Stack
PR 1 of 4 in the input recording stack:
--ReproducibleRuncommand-line presetTest plan
origin/master(CyclesClock_WithSeed_TwoReadsAtTheSameCycleGiveTheSameTimeandCyclesClock_WithSeed_ElapsedTimeNeverDecreases):Test run summary: Failed! total: 2, failed: 2, succeeded: 0, skipped: 0(seconddiffered fromfirstby-0.001052503957907902;ElapsedTimeNeverDecreasesfailed at cycle 1 with difference-5.250395790668081E-05).RandomClockJitter.OffsetMs):Test run summary: Failed! total: 17, failed: 1, succeeded: 16, skipped: 0— onlyCyclesClock_WithSeed_ElapsedTimeNeverDecreasesfailed, at period boundary cycle 2000 (difference-0.004747008280940435). Reverted.VgaPhaseLockTests(SeededClockJitterBreaksTheVgaPhaseLockandMissingClockJitterKeepsTheVgaPhaseLock):Test run summary: Passed! total: 2, failed: 0, succeeded: 2, skipped: 0.ClockReadBenchmark, uncommitted, 100,000 reads per invoke, .NET 10.0.15 X64 RyuJIT x86-64-v4, AMD Ryzen 9 9950X3D):origin/master):ReadElapsedTimeMs_NoJitter2.132 ns (0 B),ReadElapsedTimeMs_SeededJitter2.160 ns (0 B, ratio 1.01).ReadElapsedTimeMs_NoJitter2.132 ns (0 B),ReadElapsedTimeMs_SeededJitter4.032 ns (0 B, ratio 1.89).dotnet build src/Spice86.sln:Build succeeded. 0 Warning(s), 0 Error(s).*ClockTests*,*ClockTimeMultiplierTests*,*EmulatedClockStateTests*,*MachineDeviceStateTests*,*VgaPhaseLockTests*,*Opl3FmTests*):Test run summary: Passed! total: 53, failed: 0, succeeded: 53, skipped: 0.--filter-not-class '*SingleStepTest*'):Test run summary: Passed! total: 8484, failed: 0, succeeded: 8484, skipped: 0.History
An earlier version of this PR removed the clock jitter by mistake, and the branch was rewritten from
masterto keep the jitter as a stateless function of the emulated time.