When building a deterministic virtual machine (VM) designed to replay execution, developers face a fundamental challenge: how to represent time consistently. Standard wall-clock time is unsuitable for replays because the time elapsed between two points in a program depends on external factors like host CPU load, cache states, and other running processes. If a guest program's decisions depend on the current time, using the host's wall-clock would cause the program to behave differently on every run, breaking the core requirement of determinism.

To solve this, the Rewind VM utilizes a mechanism that measures progress through the guest's instruction stream rather than the host's clock. While one might consider using a raw instruction count, the author of Rewind demonstrates that this is unreliable. In a test involving a simple loop, the instruction count varied because the hardware counter captured external events—such as network packets, inter-processor interrupts (IPIs), and page faults—that the guest program itself cannot see. In contrast, the conditional branch counter remains stable because it only increments based on the guest's internal logic, making it a more reliable proxy for 'deterministic time.'

A distracted boyfriend meme illustrating Rewind's clock choosing conditional branches over instructions retired.
Rewind's clock prioritizes conditional branches over raw instruction counts to maintain determinism.fzakaria.com

This meme illustrates the choice to use conditional branches as the primary metric for time instead of raw instruction counts.

A Panik Kalm Panik meme showing the limitations of instruction counting versus the visibility of interrupts.
The meme highlights why instruction counts are unreliable due to their ability to capture external events like interrupts.fzakaria.com

This visual explains the technical reason why raw instruction counts fail to provide a deterministic time proxy.

Rewind offers two primary modes for this measurement: 'exit time' and 'counter time.' Exit time only advances the clock when the guest performs a system call (syscall), treating all internal computation as instantaneous. While simple, this can fail to reproduce bugs related to timeouts or specific race conditions because it crowds all work into the same time slice. Counter time, which advances one nanosecond for every conditional branch the guest retires, provides a more realistic approximation of the real world. Although counter time still differs from the actual host wall-clock (e.g., measuring 11.7 seconds for a task that took 14.2 seconds on the host), its consistency ensures that the same program will always produce the same results across every replay.

A Matrix Morpheus meme with the text 'What if I told you time is just counting branches'.
A conceptual meme summarizing the core mechanism of Rewind's counter time.fzakaria.com

This image serves as a summary of the Rewind VM's approach to measuring progress through the guest's internal logic.