Skip to contentSkip to conversation

Bottom halves VS timers

Qemu-devel Pavel Dovgalyuk 2 participants 3 messages Jan 22, 2019

lore
Share & tools
lore
#0 lore raw

Hi!

I recently debugged record/replay for some platform which uses PIO access for IDE.

Handlers for these operations are called through BHs.

Scheduling new BH does not create a signal for the vCPU to suspend the execution and

process the main loop events (in record/replay we synchronize these two threads).

Therefore vCPU may execute 10000000 instruction until BH processing and the guest

software may get a timeout.

I thought about replacing BH to the timers with period=0. This solution has the following properties:

1. Avoid code duplication (BH and timers do virtually the same operations)

2. Timers affect the vCPU - adding new virtual timer suspends the execution to process the
callback

3. Timers are deterministic in record/replay mode (virtual ones of course). We have similar
deterministic concept for BHs, but selecting between virtual and realtime should be more familiar for other developers.

4. Timers require a little bit more code, but this could be solved with better interfaces

What do you think about this?

Did I miss anything?

Pavel Dovgalyuk

#1 lore raw
Quoted 3 lines · Pavel Dovgalyuk

Scheduling new BH does not create a signal for the vCPU to suspend the execution and process the main loop events (in record/replay we synchronize these two threads).

I think the bug is that in rr mode it should do so and cause a cpu_exit.
If replace these bottom halves with timers, other bottom halves from
the block layer may have the same issue; if you replace _all_ bottom halves with timers you have performance issues because bottom halves try very hard to avoid locks.

Unfortunately this is getting really ugly... Basically, rr is reintroducing all the complications with iothread_requesting_mutex that were removed with mtTCG.

Paolo

Quoted 4 lines

Therefore vCPU may execute 10000000 instruction until BH processing and the guest
software may get a timeout.

#2 lore raw
Quoted 7 lines

From: Paolo Bonzini [mailto:[email protected]]

Quoted 3 lines · Pavel Dovgalyuk

Scheduling new BH does not create a signal for the vCPU to suspend the execution and process the main loop events (in record/replay we synchronize these two threads).

I think the bug is that in rr mode it should do so and cause a cpu_exit.

Right. I combined adding cpu_exit (into our private version) and increasing an icount command-line parameter.

Quoted 4 lines

If replace these bottom halves with timers, other bottom halves from
the block layer may have the same issue; if you replace _all_ bottom halves with timers you have performance issues because bottom halves try very hard to avoid locks.

I see.

Quoted 3 lines

Unfortunately this is getting really ugly... Basically, rr is reintroducing all the complications with iothread_requesting_mutex that were removed with mtTCG.

True. There are too many non-synchronized entities: bottom halves, worker threads, iothreads, timers...
But RR is only possible when we have kind of synchronization objects for them.

Pavel Dovgalyuk