On Fri, Feb 20, 2026 at 03:06:20PM +0000, Alex Bennée wrote:
> Jim MacArthur <[email protected]> writes:
> 
> > It looks like we have a solution to the RCU patch which was causing 
> > problems with the func-alpha-replay test (see 
> > [email protected]).
> > While this was going on I spent a bit of time investigating repeatability 
> > in record/replay and I think there may be broader problems with record & 
> > replay.
> >
> > While running the func-alpha-replay test we have two threads reading
> > or writing the replay event log; the "main" thread running
> > qemu_main_loop and the "RR" (round robin) thread running
> > rr_cpu_thread_fn. Both of these use replay_mutex_lock() and bql_lock()
> > to synchronize some actions. There's a third thread running RCU
> > maintenance which also uses bql_lock(), but not replay_mutex_lock().
> >
> > replay_mutex_lock() has some extra logic to improve fairness of
> > locking. This means that the first caller of replay_mutex_lock()
> > should obtain the lock first. However, so far as I can see, this
> > doesn't make the scheduling of the Main and RR threads deterministic.
> > I have observed times when neither of those threads holds the lock,
> > and as such, there's no way to predict which will call
> > replay_mutex_lock() first. This means the ordering of events during
> > either recording or replay is not deterministic.
> 
> The replay_lock was a kludge we added when we did the original
> transition to multi-threaded TCG which involved nailing down the BQL
> calls that had previously kept everything in sync.
> 
> However if we could keep all replay events in the single RR thread we
> could get rid of replay lock because everything should behave serially.

With these modifications:
  * Move qemu_clock_run_all_timers into the RR thread
  * Disable calling qemu_soonest_timeout in the main thread

... the number of record/replay events generated by the main thread falls 
drastically, and also the remaining events generated by the main thread are 
always at the very start and end of the log, so should not affect the ordering 
much.

Rather than removing calls to qemu_soonest_timeout altogether, another option 
is to modify its calls to qemu_clock_get_ns such that they do not record the 
clock times in the log. Since these functions only affect how long main waits 
while polling FDs, I would *guess* that they do not need to be recorded.

I have no idea how safe these modifications are yet, only that they remove the 
occasional errors we used to see while running the func-replay-alpha test.

Jim



Reply via email to