You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openvmm: frequent PIT reads make the counter run about 4.75% fast #1162
The PIT's counting rate depends on how frequently the guest polls it. Evaluating every 900 ns over 90 ms produces about 4.75% more ticks than evaluating once over the same interval, distorting clock calibration without a snapshot operation.
In vm/devices/chipset/src/pit/mod.rs, PitDevice::evaluate advances its anchor by whole PIT ticks:
NANOS_PER_TICK is 838, but VmTime::wrapping_add truncates each anchor update to 100 ns units. The discarded fraction is included again in the next evaluation, so more frequent reads count more time.
Reproduction
Configure two PITs identically in channel-0 rate-generator mode with count 65535. Evaluate one every 900 ns for 100,000 steps and the other once at 90 ms. Their remaining counter values are 18572 and 23673 instead of matching. Rejecting active periodic channel 0 at snapshot capture does not prevent this steady-state error.
Fix
fix.patch retains the sub-100 ns consumed-tick remainder, incorporates it into evaluation and wakeup scheduling, and clears it on reset. A new default-zero protobuf field preserves the fraction across save/restore; values of 100 ns or more are rejected before changing device state.
Older snapshots restore with remainder zero, and older readers ignore the new field. Pending wakeups remain derived from the restored counters and are recomputed on start.
Activity
tangruize commentedon Nov 1, 2026
Proposed patch
Patch against OpenVMM
998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below asfix.patchand rungit apply fix.patch.fix.patchopenvmm: pin the PIT's sub-100 ns tick time
chipset: keep the sub-100 ns part of the PIT's last tick time