startup: keep GameInput timestamps from wrapping after 21 days #1551
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1558"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:59:57Z.
Change
The GameInput stand-in (
src/startup_stubs/gameinput.cpp,now_microseconds()) converted the performance counter to microseconds with one 64-bit product:counter * 1000000wraps once the counter passes 18,446,744,073,709 ticks. At a counter frequency of 10 MHz that is 21.35 days of counting. From then on the three timestamps the stand-in hands out (IGameInput::GetCurrentTimestamp, the reading timestamp and the device-callback timestamp) are no longer the counter in microseconds: they start again near zero and repeat every 21.35 days.src/startup_stubs/qpc_microseconds.h(x2w_startup::qpc_microseconds(counter, frequency)), so it can be checked without a device.counter / frequency * 1000000 + counter % frequency * 1000000 / frequency. This is the samefloor(counter * 1000000 / frequency). The rest is belowfrequency, so its product fits for every frequency up to 18,446,744,073,709 Hz.now_microseconds()calls the helper. Nothing else ingameinput.cppchanges. Results below the old wrap point are identical.tests/startup_qpc_microseconds_check.cpp, registered next to the other header checks inCMakeLists.txtasstartup_qpc_microseconds, withstartup_qpc_microseconds_product_control(--mutate product,WILL_FAIL) as the negative control, followingstartup_storage_rootandstartup_plane_size.Worked values at 10,000,000 Hz (recomputed with Python integers):
Verification
Environment: Windows 11 x64, MSVC 19.51 (VS Build Tools 2026), Ninja,
devpreset (Debug), Python 3.14.5. Base:origin/mainatbc43e665. The local counter frequency is 10,000,000 Hz ([System.Diagnostics.Stopwatch]::Frequency).Commands (PowerShell, repository root):
Observed with the fix:
100% tests passed, 0 tests failed out of 3.startup_qpc_microseconds:startup_qpc_microseconds: PASS (17 conversions).startup_qpc_microseconds_product_control: the check exits 1 withstartup_qpc_microseconds: 10 FAILED; CTest reportsPassedbecause ofWILL_FAIL.startup_gameinput_keys:PASS: startup_gameinput_keys(loads the rebuiltGameInput.dll).The 17 values cover: 0, 9 and 10 ticks, one second, the last counter the single product holds, the first one past it, about 23 days, 30 days and one tick before it, the largest signed counter, 3,579,545 Hz with a non-zero rest and around a whole-second boundary at 70 days, 2,435,886 Hz at 400 days plus 1,234,567 ticks, 1 MHz and 1 kHz. Expected values are literal constants computed with Python integers.
Negative control: with the old one-line formula (
return counter * 1000000 / frequency;) put back into the header and onlystartup_qpc_microseconds_checkrebuilt,ctest ... -R '^startup_qpc_microseconds' -Vgave50% tests passed, 1 tests failed out of 2:startup_qpc_microsecondsfailed withstartup_qpc_microseconds: 10 FAILED. First lines:The seven values at or below 18,446,744,073,709 ticks pass with both formulas. The header was then restored and the check rebuilt; the committed tree gives the result above.
Also run:
python -B tests/docs_links_check.py(Checked 16 Markdown files and 339 links.) andpython -B tests/bidi_controls_check.py(Checked 1235 tracked source, script and build/CI files: no bidirectional controls.), both exit 0.Rebased onto
origin/mainata3633d4dbefore opening this pull request and re-run there:startup_qpc_microseconds,startup_qpc_microseconds_product_controlandstartup_gameinput_keysgive the same results (3 of 3 passed).Not run: the full test suite, the Release configuration, the
prpreset and any hardware test. The wrap was shown with constructed counter values only; it was not observed on a machine whose counter had passed 21 days (the test machine had been up for a few hours). What a console executable does with a timestamp that jumps back is not measured.Evidence and follow-up
No open pull request touches
src/startup_stubs/gameinput.cpportests/startup_gameinput_keys.cpp(checked withgh pr list ... --json number,title,filesright before the commit and again after it; 53 open pull requests at the last check). 31 of them touchCMakeLists.txt; none of their diffs touches thestartup_plane_size/startup_derived_blendlines this registration sits between. No open issue mentions the GameInput timestamp; none is linked.No documentation row was added:
docs/startup-runtime.mdhas no section on the GameInput timestamps, and no list inAGENTS.md, the workflow orCMakePresets.jsonenumerates the sibling header checks.AI-assisted.