hn.today

A Clock Made of Branches

fzakaria.com3 points0 comments
Screenshot of A Clock Made of Branches

A deterministic virtual machine must give a guest program the same sense of time every time it is replayed, so host wall-clock time is unsuitable: load, CPU speed, and other activity vary between runs. Rewind offers two clocks. Exit time advances by an estimated five microseconds whenever the guest exits, treating all work between exits as instantaneous. Counter time adds one nanosecond for each conditional branch, using progress through the guest’s instruction stream as a repeatable proxy for elapsed work. This makes CPU-heavy computation count toward time rather than appearing free.

The case for counting conditional branches comes from a countdown-loop experiment. Repeated runs executed the same billion branches, while the hardware instruction counter varied by about a thousand counts. The discrepancy tracked interrupts: the instruction counter included activity invisible to the program, such as kernel work triggered by interrupts or page faults, while the conditional-branch counter remained stable. Counter time is not exact real time, but it approximates it better than exit time. In a comparison, a workload took 2.1 seconds by exit time and 11.7 seconds by counter time, against 15.7 and 14.2 seconds on the host, respectively. A more realistic deterministic clock matters because programs make timing-dependent decisions: exit time can hide timeout bugs and distort thread races. Rewind therefore defaults to counter time to improve the odds of reproducing real-world failures.

Read on fzakaria.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.