From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YT4rH-0001FY-NO for qemu-devel@nongnu.org; Wed, 04 Mar 2015 03:40:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YT4rG-0004tG-7M for qemu-devel@nongnu.org; Wed, 04 Mar 2015 03:40:47 -0500 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]:32873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YT4rF-0004s2-Sk for qemu-devel@nongnu.org; Wed, 04 Mar 2015 03:40:46 -0500 Received: by padet14 with SMTP id et14so35162829pad.0 for ; Wed, 04 Mar 2015 00:40:44 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 4 Mar 2015 14:10:44 +0530 Message-ID: From: Bharata B Rao Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 7/7] cpus: reclaim allocated vCPU objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhu Guihua Cc: "qemu-devel@nongnu.org" , tangchen@cn.fujitsu.com, ChenFan , isimatu yasuaki , Igor Mammedov , Gu Zheng , Anshul Makkar , "afaerber@suse.de" On Fri, Feb 13, 2015 at 4:10 PM, Zhu Guihua wro= te: > From: Gu Zheng > > After ACPI get a signal to eject a vCPU, the vCPU must be > removed from CPU list=EF=BC=8Cbefore the vCPU really removed, then > release the all related vCPU objects. > > In order to deal well with the kvm vcpus (which can not be removed withou= t any > protection), we do not close KVM vcpu fd, just record and mark it as stop= ped > into a list, so that we can reuse it for the appending cpu hot-add reques= t if > possible. It is also the approach that kvm guys suggested: > https://www.mail-archive.com/kvm@vger.kernel.org/msg102839.html > > Signed-off-by: Chen Fan > Signed-off-by: Gu Zheng > Signed-off-by: Zhu Guihua > --- > cpus.c | 37 ++++++++++++++++++++++++++++++++++ > include/sysemu/kvm.h | 1 + > kvm-all.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++= +++++- > 3 files changed, 94 insertions(+), 1 deletion(-) > > diff --git a/cpus.c b/cpus.c > index d6e5a5f..a11941f 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -854,6 +854,24 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(vo= id *data), void *data) > qemu_cpu_kick(cpu); > } > > +static void qemu_kvm_destroy_vcpu(CPUState *cpu) > +{ > + CPU_REMOVE(cpu); > + > + if (kvm_destroy_vcpu(cpu) < 0) { > + error_report("kvm_destroy_vcpu failed.\n"); > + exit(EXIT_FAILURE); > + } > + > + object_unparent(OBJECT(cpu)); > +} > + > +static void qemu_tcg_destroy_vcpu(CPUState *cpu) > +{ > + CPU_REMOVE(cpu); > + object_unparent(OBJECT(cpu)); > +} > + > static void flush_queued_work(CPUState *cpu) > { > struct qemu_work_item *wi; > @@ -946,6 +964,11 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) > } > } > qemu_kvm_wait_io_event(cpu); > + if (cpu->exit && !cpu_can_run(cpu)) { > + qemu_kvm_destroy_vcpu(cpu); > + qemu_mutex_unlock(&qemu_global_mutex); > + return NULL; > + } > } > > return NULL; > @@ -999,6 +1022,7 @@ static void tcg_exec_all(void); > static void *qemu_tcg_cpu_thread_fn(void *arg) > { > CPUState *cpu =3D arg; > + CPUState *remove_cpu =3D NULL; > > qemu_tcg_init_cpu_signals(); > qemu_thread_get_self(cpu->thread); > @@ -1032,6 +1056,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) > } > } > qemu_tcg_wait_io_event(); > + CPU_FOREACH(cpu) { > + if (cpu->exit && !cpu_can_run(cpu)) { > + remove_cpu =3D cpu; > + break; > + } > + } > + if (remove_cpu) { > + qemu_tcg_destroy_vcpu(remove_cpu); > + remove_cpu =3D NULL; > + } > } > > return NULL; > @@ -1389,6 +1423,9 @@ static void tcg_exec_all(void) > break; > } > } else if (cpu->stop || cpu->stopped) { > + if (cpu->exit) { > + next_cpu =3D CPU_NEXT(cpu); > + } > break; > } > } > diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > index 30cb84d..560caef 100644 > --- a/include/sysemu/kvm.h > +++ b/include/sysemu/kvm.h > @@ -188,6 +188,7 @@ int kvm_has_intx_set_mask(void); > > int kvm_init_vcpu(CPUState *cpu); > int kvm_cpu_exec(CPUState *cpu); > +int kvm_destroy_vcpu(CPUState *cpu); > > #ifdef NEED_CPU_H > > diff --git a/kvm-all.c b/kvm-all.c > index 05a79c2..46e7853 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -71,6 +71,12 @@ typedef struct KVMSlot > > typedef struct kvm_dirty_log KVMDirtyLog; > > +struct KVMParkedVcpu { > + unsigned long vcpu_id; > + int kvm_fd; > + QLIST_ENTRY(KVMParkedVcpu) node; > +}; > + > struct KVMState > { > AccelState parent_obj; > @@ -107,6 +113,7 @@ struct KVMState > QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SI= ZE]; > bool direct_msi; > #endif > + QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus; > }; > > #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") > @@ -247,6 +254,53 @@ static int kvm_set_user_memory_region(KVMState *s, K= VMSlot *slot) > return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); > } > > +int kvm_destroy_vcpu(CPUState *cpu) You need to provide a stub for this in kvm-stub.c without which I see that aarch64-softmmu won't compile. Regards, Bharata.