On 09/09/2015 13:01, Juan Quintela wrote: > Paolo Bonzini <pbonz...@redhat.com> wrote: >> On 09/09/2015 12:41, Juan Quintela wrote: >>>>> + qemu_mutex_unlock_iothread(); >>>>> + atomic_set(&cpu->throttle_thread_scheduled, 0); >>>>> + g_usleep(sleeptime_ns / 1000); /* Convert ns to us for usleep call */ >>>>> + qemu_mutex_lock_iothread(); >>> >>> Why is this thread safe? >>> >>> qemu_mutex_lock_iothread() is protecting (at least) cpu_work_first on >>> each cpu. How can we be sure that _nothing_ will change that while we >>> are waiting? >> >> You only have to be sure that the queued work list remains consistent; >> not that nothing changes. > > > But nothing else is protected by the iothread?
Not at this point. Notice how qemu_kvm_wait_io_event calls qemu_cond_wait just before qemu_wait_io_event_common (which in turn is what calls flush_queued_work). So you can be quite sure that qemu_wait_io_event_common runs at a point where there's nothing hidden that relies on the iothread mutex. Paolo