Skip to content

Commit 02596bb

Browse files
bonziniPatchew Applier
authored andcommitted
accel: make all calls to qemu_process_cpu_events look the same
There is no reason for some accelerators to use qemu_process_cpu_events_common (which is separated from qemu_process_cpu_events() specifically for round robin TCG). They can also check for events directly on the first pass through the loop, instead of setting cpu->exit_request to true. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]>
1 parent 4d1a4ee commit 02596bb

File tree

7 files changed

+30
-39
lines changed

7 files changed

+30
-39
lines changed

accel/dummy-cpus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static void *dummy_cpu_thread_fn(void *arg)
4343
qemu_guest_random_seed_thread_part2(cpu->random_seed);
4444

4545
do {
46+
qemu_process_cpu_events(cpu);
4647
bql_unlock();
4748
#ifndef _WIN32
4849
do {
@@ -57,7 +58,6 @@ static void *dummy_cpu_thread_fn(void *arg)
5758
qemu_sem_wait(&cpu->sem);
5859
#endif
5960
bql_lock();
60-
qemu_process_cpu_events(cpu);
6161
} while (!cpu->unplug);
6262

6363
bql_unlock();

accel/hvf/hvf-accel-ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ static void *hvf_cpu_thread_fn(void *arg)
192192
qemu_guest_random_seed_thread_part2(cpu->random_seed);
193193

194194
do {
195+
qemu_process_cpu_events(cpu);
195196
if (cpu_can_run(cpu)) {
196197
r = hvf_vcpu_exec(cpu);
197198
if (r == EXCP_DEBUG) {
198199
cpu_handle_guest_debug(cpu);
199200
}
200201
}
201-
qemu_process_cpu_events(cpu);
202202
} while (!cpu->unplug || cpu_can_run(cpu));
203203

204204
hvf_vcpu_destroy(cpu);

accel/kvm/kvm-accel-ops.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ static void *kvm_vcpu_thread_fn(void *arg)
4747
qemu_guest_random_seed_thread_part2(cpu->random_seed);
4848

4949
do {
50+
qemu_process_cpu_events(cpu);
51+
5052
if (cpu_can_run(cpu)) {
5153
r = kvm_cpu_exec(cpu);
5254
if (r == EXCP_DEBUG) {
5355
cpu_handle_guest_debug(cpu);
5456
}
5557
}
56-
qemu_process_cpu_events(cpu);
5758
} while (!cpu->unplug || cpu_can_run(cpu));
5859

5960
kvm_destroy_vcpu(cpu);

accel/tcg/tcg-accel-ops-mttcg.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ static void *mttcg_cpu_thread_fn(void *arg)
8484
cpu_thread_signal_created(cpu);
8585
qemu_guest_random_seed_thread_part2(cpu->random_seed);
8686

87-
/* process any pending work */
88-
qatomic_set(&cpu->exit_request, true);
89-
9087
do {
88+
qemu_process_cpu_events(cpu);
89+
9190
if (cpu_can_run(cpu)) {
9291
int r;
9392
bql_unlock();
@@ -112,8 +111,6 @@ static void *mttcg_cpu_thread_fn(void *arg)
112111
break;
113112
}
114113
}
115-
116-
qemu_process_cpu_events(cpu);
117114
} while (!cpu->unplug || cpu_can_run(cpu));
118115

119116
tcg_cpu_destroy(cpu);

accel/tcg/tcg-accel-ops-rr.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,30 @@ static void *rr_cpu_thread_fn(void *arg)
211211

212212
cpu = first_cpu;
213213

214-
/* process any pending work */
215-
qatomic_set(&cpu->exit_request, true);
216-
217214
while (1) {
218215
/* Only used for icount_enabled() */
219216
int64_t cpu_budget = 0;
220217

218+
if (cpu) {
219+
/*
220+
* This could even reset exit_request for all CPUs, but in practice
221+
* races between CPU exits and changes to "cpu" are so rare that
222+
* there's no advantage in doing so.
223+
*/
224+
qatomic_set(&cpu->exit_request, false);
225+
}
226+
227+
if (icount_enabled() && all_cpu_threads_idle()) {
228+
/*
229+
* When all cpus are sleeping (e.g in WFI), to avoid a deadlock
230+
* in the main_loop, wake it up in order to start the warp timer.
231+
*/
232+
qemu_notify_event();
233+
}
234+
235+
rr_wait_io_event();
236+
rr_deal_with_unplugged_cpus();
237+
221238
bql_unlock();
222239
replay_mutex_lock();
223240
bql_lock();
@@ -292,26 +309,6 @@ static void *rr_cpu_thread_fn(void *arg)
292309

293310
/* Does not need a memory barrier because a spurious wakeup is okay. */
294311
qatomic_set(&rr_current_cpu, NULL);
295-
296-
if (cpu) {
297-
/*
298-
* This could even reset exit_request for all CPUs, but in practice
299-
* races between CPU exits and changes to "cpu" are so rare that
300-
* there's no advantage in doing so.
301-
*/
302-
qatomic_set(&cpu->exit_request, false);
303-
}
304-
305-
if (icount_enabled() && all_cpu_threads_idle()) {
306-
/*
307-
* When all cpus are sleeping (e.g in WFI), to avoid a deadlock
308-
* in the main_loop, wake it up in order to start the warp timer.
309-
*/
310-
qemu_notify_event();
311-
}
312-
313-
rr_wait_io_event();
314-
rr_deal_with_unplugged_cpus();
315312
}
316313

317314
g_assert_not_reached();

target/i386/nvmm/nvmm-accel-ops.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg)
4242
qemu_guest_random_seed_thread_part2(cpu->random_seed);
4343

4444
do {
45+
qemu_process_cpu_events(cpu);
46+
4547
if (cpu_can_run(cpu)) {
4648
r = nvmm_vcpu_exec(cpu);
4749
if (r == EXCP_DEBUG) {
4850
cpu_handle_guest_debug(cpu);
4951
}
5052
}
51-
while (cpu_thread_is_idle(cpu)) {
52-
qemu_cond_wait_bql(cpu->halt_cond);
53-
}
54-
qemu_process_cpu_events_common(cpu);
5553
} while (!cpu->unplug || cpu_can_run(cpu));
5654

5755
nvmm_destroy_vcpu(cpu);

target/i386/whpx/whpx-accel-ops.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ static void *whpx_cpu_thread_fn(void *arg)
4242
qemu_guest_random_seed_thread_part2(cpu->random_seed);
4343

4444
do {
45+
qemu_process_cpu_events(cpu);
46+
4547
if (cpu_can_run(cpu)) {
4648
r = whpx_vcpu_exec(cpu);
4749
if (r == EXCP_DEBUG) {
4850
cpu_handle_guest_debug(cpu);
4951
}
5052
}
51-
while (cpu_thread_is_idle(cpu)) {
52-
qemu_cond_wait_bql(cpu->halt_cond);
53-
}
54-
qemu_process_cpu_events_common(cpu);
5553
} while (!cpu->unplug || cpu_can_run(cpu));
5654

5755
whpx_destroy_vcpu(cpu);

0 commit comments

Comments
 (0)