cpus: fix various issues with vCPU unplug
cover cpus: fix various issues with vCPU unplug
Fix the thread exit conditions and clean up the threads correctly.
Thanks,
Paolo
Paolo Bonzini (6):
cpus: hax: register/unregister thread with RCU, exit loop on unplug
cpus: kvm: unregister thread with RCU
cpus: dummy: unregister thread with RCU, exit loop on unplug
cpus: tcg: unregister thread with RCU, fix exiting of loop on unplug
cpus: hvf: unregister thread with RCU
cpus: join thread when removing a vCPU
cpus.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/6 cpus: hax: register/unregister thread with RCU, exit loop on unplug
--- cpus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
cpus.c +4 -2
@@ -1474,6 +1474,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg)CPUState *cpu = arg;int r; +rcu_register_thread ();qemu_mutex_lock_iothread ();qemu_thread_get_self (cpu->thread);
@@ -1485,7 +1486,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg)hax_init_vcpu (cpu);qemu_cond_signal (&qemu_cpu_cond); -while (1 ) { + do { if (cpu_can_run(cpu)) { r = hax_smp_cpu_exec(cpu); if (r == EXCP_DEBUG) {
@@ -1494,7 +1495,8 @@ static void *qemu_hax_cpu_thread_fn(void *arg) }qemu_wait_io_event (cpu); - } + }while (!cpu->unplug ||cpu_can_run (cpu)); +rcu_unregister_thread ();return NULL ; }
Signature · 1 line
2.14.3
PATCH 2/6 cpus: kvm: unregister thread with RCU
In reply to Paolo Bonzini--- cpus.c | 1 + 1 file changed, 1 insertion(+)
cpus.c +1 -0
@@ -1206,6 +1206,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) cpu->created = false;qemu_cond_signal (&qemu_cpu_cond);qemu_mutex_unlock_iothread (); +rcu_unregister_thread ();return NULL ; }
Signature · 1 line
2.14.3
PATCH 3/6 cpus: dummy: unregister thread with RCU, exit loop on unplug
In reply to Paolo Bonzini--- cpus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
cpus.c +3 -2
@@ -1235,7 +1235,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) cpu->created = true;qemu_cond_signal (&qemu_cpu_cond); -while (1 ) { + do { qemu_mutex_unlock_iothread(); do { int sig;
@@ -1247,8 +1247,9 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) }qemu_mutex_lock_iothread ();qemu_wait_io_event (cpu); - } + }while (!cpu->unplug); +rcu_unregister_thread ();return NULL ;#endif }
Signature · 1 line
2.14.3
PATCH 4/6 cpus: tcg: unregister thread with RCU, fix exiting of loop on unplug
In reply to Paolo BonziniKeep running until cpu_can_run(cpu) becomes false, for consistency with other acceslerators.
--- cpus.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
cpus.c +7 -7
@@ -1468,6 +1468,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)deal_with_unplugged_cpus (); } +rcu_unregister_thread ();return NULL ; }
@@ -1644,18 +1645,17 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)/* Ignore everything else? */ break ; } - }else if (cpu->unplug) { -qemu_tcg_destroy_vcpu (cpu); - cpu->created = false; -qemu_cond_signal (&qemu_cpu_cond); -qemu_mutex_unlock_iothread (); -return NULL ; }atomic_mb_set (&cpu->exit_request,0 );qemu_wait_io_event (cpu); - } + }while (!cpu->unplug ||cpu_can_run (cpu)); +qemu_tcg_destroy_vcpu (cpu); + cpu->created = false; +qemu_cond_signal (&qemu_cpu_cond); +qemu_mutex_unlock_iothread (); +rcu_unregister_thread ();return NULL ; }
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH 4/6] cpus: tcg: unregister thread with RCU, fix exiting of loop on unplug
Quoted 2 lines · Paolo Bonzini
Keep running until
cpu_can_run(cpu)becomes false, for consistency with other acceslerators.
s/acceslerators/accelerators/
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH 5/6 cpus: hvf: unregister thread with RCU
In reply to Paolo Bonzini--- cpus.c | 1 + 1 file changed, 1 insertion(+)
cpus.c +1 -0
@@ -1542,6 +1542,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) cpu->created = false;qemu_cond_signal (&qemu_cpu_cond);qemu_mutex_unlock_iothread (); +rcu_unregister_thread ();return NULL ; }
Signature · 1 line
2.14.3
PATCH 6/6 cpus: join thread when removing a vCPU
In reply to Paolo BonziniIf no one joins the thread, its associated memory is leaked.
--- cpus.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
cpus.c +4 -9
@@ -1795,19 +1795,14 @@ void resume_all_vcpus(void) } } -void cpu_remove (CPUState *cpu) +void cpu_remove_sync (CPUState *cpu) { cpu->stop = true; cpu->unplug = true;qemu_cpu_kick (cpu); -} - -void cpu_remove_sync (CPUState *cpu) -{ -cpu_remove (cpu); -while (cpu->created) { -qemu_cond_wait (&qemu_cpu_cond, &qemu_global_mutex); - } +qemu_mutex_unlock_iothread (); +qemu_thread_join (cpu->thread); +qemu_mutex_lock_iothread (); }/* For temporary buffers for forming a name */
Signature · 1 line
2.14.3