[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 36/51] cpus: unify qemu_*_wait_io_event
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 36/51] cpus: unify qemu_*_wait_io_event |
Date: |
Tue, 16 Jan 2018 15:17:18 +0100 |
Except for round-robin TCG, every other accelerator is using more or
less the same code around qemu_wait_io_event_common. The exception
is HAX, which also has to eat the dummy APC that is queued by
qemu_cpu_kick_thread.
We can add the SleepEx call to qemu_wait_io_event under "if
(!tcg_enabled())", since that is the condition that is used in
qemu_cpu_kick_thread, and unify the function for KVM, HAX, HVF and
multi-threaded TCG. Single-threaded TCG code can also be simplified
since it is only used in the round-robin, sleep-if-all-CPUs-idle case.
Signed-off-by: Paolo Bonzini <address@hidden>
---
cpus.c | 49 +++++++++++++++++--------------------------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/cpus.c b/cpus.c
index f992537..2cb0af9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -909,7 +909,8 @@ static void kick_tcg_thread(void *opaque)
static void start_tcg_kick_timer(void)
{
- if (!mttcg_enabled && !tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
+ assert(!mttcg_enabled);
+ if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
kick_tcg_thread, NULL);
timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
@@ -918,6 +919,7 @@ static void start_tcg_kick_timer(void)
static void stop_tcg_kick_timer(void)
{
+ assert(!mttcg_enabled);
if (tcg_kick_vcpu_timer) {
timer_del(tcg_kick_vcpu_timer);
tcg_kick_vcpu_timer = NULL;
@@ -1137,18 +1139,9 @@ static void qemu_wait_io_event_common(CPUState *cpu)
process_queued_cpu_work(cpu);
}
-static bool qemu_tcg_should_sleep(CPUState *cpu)
+static void qemu_tcg_rr_wait_io_event(CPUState *cpu)
{
- if (mttcg_enabled) {
- return cpu_thread_is_idle(cpu);
- } else {
- return all_cpu_threads_idle();
- }
-}
-
-static void qemu_tcg_wait_io_event(CPUState *cpu)
-{
- while (qemu_tcg_should_sleep(cpu)) {
+ while (all_cpu_threads_idle()) {
stop_tcg_kick_timer();
qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
}
@@ -1158,20 +1151,18 @@ static void qemu_tcg_wait_io_event(CPUState *cpu)
qemu_wait_io_event_common(cpu);
}
-static void qemu_kvm_wait_io_event(CPUState *cpu)
+static void qemu_wait_io_event(CPUState *cpu)
{
while (cpu_thread_is_idle(cpu)) {
qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
}
- qemu_wait_io_event_common(cpu);
-}
-
-static void qemu_hvf_wait_io_event(CPUState *cpu)
-{
- while (cpu_thread_is_idle(cpu)) {
- qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
+#ifdef _WIN32
+ /* Eat dummy APC queued by qemu_cpu_kick_thread. */
+ if (!tcg_enabled()) {
+ SleepEx(0, TRUE);
}
+#endif
qemu_wait_io_event_common(cpu);
}
@@ -1207,7 +1198,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
cpu_handle_guest_debug(cpu);
}
}
- qemu_kvm_wait_io_event(cpu);
+ qemu_wait_io_event(cpu);
} while (!cpu->unplug || cpu_can_run(cpu));
qemu_kvm_destroy_vcpu(cpu);
@@ -1253,7 +1244,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
exit(1);
}
qemu_mutex_lock_iothread();
- qemu_wait_io_event_common(cpu);
+ qemu_wait_io_event(cpu);
}
return NULL;
@@ -1470,7 +1461,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
atomic_mb_set(&cpu->exit_request, 0);
}
- qemu_tcg_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus));
+ qemu_tcg_rr_wait_io_event(cpu ? cpu : QTAILQ_FIRST(&cpus));
deal_with_unplugged_cpus();
}
@@ -1501,13 +1492,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg)
}
}
- while (cpu_thread_is_idle(cpu)) {
- qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
- }
-#ifdef _WIN32
- SleepEx(0, TRUE);
-#endif
- qemu_wait_io_event_common(cpu);
+ qemu_wait_io_event(cpu);
}
return NULL;
}
@@ -1544,7 +1529,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)
cpu_handle_guest_debug(cpu);
}
}
- qemu_hvf_wait_io_event(cpu);
+ qemu_wait_io_event(cpu);
} while (!cpu->unplug || cpu_can_run(cpu));
hvf_vcpu_destroy(cpu);
@@ -1623,7 +1608,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
}
atomic_mb_set(&cpu->exit_request, 0);
- qemu_tcg_wait_io_event(cpu);
+ qemu_wait_io_event(cpu);
}
return NULL;
--
1.8.3.1
- [Qemu-devel] [PULL 21/51] tests: fix qmp-test leak, (continued)
- [Qemu-devel] [PULL 21/51] tests: fix qmp-test leak, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 29/51] target/i386: move hflags update code to a function, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 28/51] tests/boot-serial-test: Add support for the raspi2 machine, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 31/51] target/i386: hax: Move x86_update_hflags., Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 35/51] icount: fixed saving/restoring of icount warp timers, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 30/51] target/i386: hax: change to use x86_update_hflags, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 34/51] scripts/qemu-gdb/timers.py: new helper to dump timer state, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 32/51] target-i386: update hflags on Hypervisor.framework, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 37/51] irq: fix memory leak, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 33/51] scripts/qemu-gdb: add simple tcg lock status helper, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 36/51] cpus: unify qemu_*_wait_io_event,
Paolo Bonzini <=
- [Qemu-devel] [PULL 41/51] chardev: Clean up previous patch indentation, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 38/51] net: Drop unusual use of do { } while (0);, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 39/51] mips: Tweak location of ';' in macros, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 40/51] chardev: Use goto/label instead of do/break/while(0), Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 42/51] tests: Avoid 'do/while(false); ' in vhost-user-bridge, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 43/51] maint: Fix macros with broken 'do/while(0); ' usage, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 45/51] cpu_physical_memory_sync_dirty_bitmap: Another alignment fix, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 44/51] checkpatch: Enforce proper do/while (0) style, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 47/51] find_ram_offset: Align ram_addr_t allocation on long boundaries, Paolo Bonzini, 2018/01/16
- [Qemu-devel] [PULL 51/51] scripts/analyse-locks-simpletrace.py: script to analyse lock times, Paolo Bonzini, 2018/01/16