diff mbox series

[v2] vcpu: join vcpu thread after it exiting

Message ID 1517483068-18735-1-git-send-email-linzc@zju.edu.cn
State New
Headers show
Series [v2] vcpu: join vcpu thread after it exiting | expand

Commit Message

CheneyLin Feb. 1, 2018, 11:04 a.m. UTC
As we create vcpu thread with QEMU_THREAD_JOINABLE mode,
we should join it after it exiting to cleanup resources.

Signed-off-by: linzhecheng <linzhecheng@huawei.com>

Comments

Paolo Bonzini Feb. 1, 2018, 2:41 p.m. UTC | #1
On 01/02/2018 06:04, linzhecheng wrote:
> As we create vcpu thread with QEMU_THREAD_JOINABLE mode,
> we should join it after it exiting to cleanup resources.
> 
> Signed-off-by: linzhecheng <linzhecheng@huawei.com>
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index f290f48..5cc1ba2 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -282,9 +282,9 @@ err:
>  
>  static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
>  {
> -    struct KVMParkedVcpu *cpu;
> +    struct KVMParkedVcpu *cpu, *next_cpu;
>  
> -    QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) {
> +    QLIST_FOREACH_SAFE(cpu, &s->kvm_parked_vcpus, node, next_cpu) {
>          if (cpu->vcpu_id == vcpu_id) {
>              int kvm_fd;

This is not needed because removing the node results in an immediate
return..

> diff --git a/cpus.c b/cpus.c
> index 2cb0af9..1890bfe 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1205,6 +1205,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;
>  }
>  
> @@ -1759,6 +1760,7 @@ void cpu_remove_sync(CPUState *cpu)
>      cpu_remove(cpu);
>      while (cpu->created) {
>          qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
> +        qemu_thread_join(cpu->thread);
>      }
>  }
>  
> 

Thanks.  There are other issues in qemu_*_cpu_thread_fn, I'll send a
more complete series shortly.

Paolo
diff mbox series

Patch

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index f290f48..5cc1ba2 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -282,9 +282,9 @@  err:
 
 static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
 {
-    struct KVMParkedVcpu *cpu;
+    struct KVMParkedVcpu *cpu, *next_cpu;
 
-    QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) {
+    QLIST_FOREACH_SAFE(cpu, &s->kvm_parked_vcpus, node, next_cpu) {
         if (cpu->vcpu_id == vcpu_id) {
             int kvm_fd;
 
diff --git a/cpus.c b/cpus.c
index 2cb0af9..1890bfe 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1205,6 +1205,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;
 }
 
@@ -1759,6 +1760,7 @@  void cpu_remove_sync(CPUState *cpu)
     cpu_remove(cpu);
     while (cpu->created) {
         qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
+        qemu_thread_join(cpu->thread);
     }
 }