On 14/08/2018 03:37, Emilio G. Cota wrote: > Signed-off-by: Emilio G. Cota <c...@braap.org> > --- > hw/i386/pc.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index 83a444472b..7371cd9960 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -158,7 +158,18 @@ static uint64_t ioportF0_read(void *opaque, hwaddr addr, > unsigned size) > /* TSC handling */ > uint64_t cpu_get_tsc(CPUX86State *env) > { > - return cpu_get_ticks(); > + uint64_t ret; > + bool locked; > + > + locked = qemu_mutex_iothread_locked(); > + if (!locked) { > + qemu_mutex_lock_iothread(); > + } > + ret = cpu_get_ticks(); > + if (!locked) { > + qemu_mutex_unlock_iothread(); > + } > + return ret; > } > > /* IRQ handling */ >
We could use a spinlock for the rare case of timers_state.cpu_ticks_prev > ticks (or even, on 64-bit, a seqlock+spinlock). I'll give it a shot. Paolo