hn.today

A Clock Made of Branches

fzakaria.com15 points2 comments
Screenshot of A Clock Made of Branches

Rewind, a deterministic virtual machine, needs a guest clock that advances identically on every replay. Host wall-clock time cannot provide that: CPU load, hardware behavior, and other processes change how long the same guest work takes. Rewind offers two alternatives. “Exit time” advances by five microseconds whenever the guest exits, such as for a system call, treating all computation between exits as instantaneous. “Counter time” adds one nanosecond for each conditional branch the guest executes, so it accounts for computational work as well as exits. The difference matters for reproducing timeouts and races: exit time can make lengthy computations appear free and bunch activity together unrealistically.

The case for counter time rests on measuring progress through a repeatable instruction stream. In a countdown test, hardware reported the same one billion conditional branches across runs, while total instruction counts varied by roughly a thousand. Interrupts explain the mismatch: the instruction counter includes work done by the operating system to handle them, even though the guest program does not see that work. The branch counter remained unchanged as interrupts accumulated, making it a more reliable measure of guest progress. The approach is not perfect - some AMD processors need a setting to prevent speculative execution from slightly inflating branch counts - but counter time better approximates real elapsed work than exit time while remaining deterministic. It is therefore Rewind’s default clock.

Read on fzakaria.com2 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.