From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3zzT-000799-Uc for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:30:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3zzQ-0001jz-KI for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:30:07 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:60331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3zzQ-0001ic-2h for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:30:04 -0500 Received: from localhost by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 Dec 2015 15:29:59 +1000 Date: Wed, 2 Dec 2015 10:58:51 +0530 From: Bharata B Rao Message-ID: <20151202052851.GE16342@in.ibm.com> References: <1448024079-20808-1-git-send-email-bharata@linux.vnet.ibm.com> <1448024079-20808-5-git-send-email-bharata@linux.vnet.ibm.com> <20151201005558.GC31343@voom.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151201005558.GC31343@voom.redhat.com> Subject: Re: [Qemu-devel] [PATCH v5 04/10] cpu: Reclaim vCPU objects Reply-To: bharata@linux.vnet.ibm.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: Zhu Guihua , mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org, pbonzini@redhat.com, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, Chen Fan , imammedo@redhat.com, afaerber@suse.de On Tue, Dec 01, 2015 at 11:55:58AM +1100, David Gibson wrote: > On Fri, Nov 20, 2015 at 06:24:33PM +0530, Bharata B Rao wrote: > > From: Gu Zheng > > > > In order to deal well with the kvm vcpus (which can not be removed without any > > protection), we do not close KVM vcpu fd, just record and mark it as stopped > > into a list, so that we can reuse it for the appending cpu hot-add request 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 > > Signed-off-by: Bharata B Rao > > [- Explicit CPU_REMOVE() from qemu_kvm/tcg_destroy_vcpu() > > isn't needed as it is done from cpu_exec_exit()] > > --- > > cpus.c | 41 +++++++++++++++++++++++++++++++++++++ > > include/qom/cpu.h | 10 +++++++++ > > include/sysemu/kvm.h | 1 + > > kvm-all.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- > > kvm-stub.c | 5 +++++ > > 5 files changed, 113 insertions(+), 1 deletion(-) > > > > diff --git a/cpus.c b/cpus.c > > index 877bd70..af2b274 100644 > > --- a/cpus.c > > +++ b/cpus.c > > @@ -953,6 +953,21 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data) > > qemu_cpu_kick(cpu); > > } > > > > +static void qemu_kvm_destroy_vcpu(CPUState *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) > > +{ > > + object_unparent(OBJECT(cpu)); > > +} > > + > > static void flush_queued_work(CPUState *cpu) > > { > > struct qemu_work_item *wi; > > @@ -1053,6 +1068,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); > > This looks like a change to locking semantics, and I can't see the > connection to the described purpose of the patch. As I replied in another thread to Alexey, this needs fixing. > > > + return NULL; > > + } > > } > > > > return NULL; > > @@ -1108,6 +1128,7 @@ static void tcg_exec_all(void); > > static void *qemu_tcg_cpu_thread_fn(void *arg) > > { > > CPUState *cpu = arg; > > + CPUState *remove_cpu = NULL; > > > > rcu_register_thread(); > > > > @@ -1145,6 +1166,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) > > } > > } > > qemu_tcg_wait_io_event(QTAILQ_FIRST(&cpus)); > > + CPU_FOREACH(cpu) { > > + if (cpu->exit && !cpu_can_run(cpu)) { > > + remove_cpu = cpu; > > + break; > > + } > > + } > > + if (remove_cpu) { > > + qemu_tcg_destroy_vcpu(remove_cpu); > > + remove_cpu = NULL; > > + } > > Any particular reason to only cleanup one cpu per iteration? Not sure, this is borrowed from x86 CPU hotplug patchset. Zhu - do you know why ? > > Also, any particular reason this isn't folded into tcg_exec_all with > the other cpu->exit logic? Looks like it can be done. Will give it a try in the next iteration. Regards, Bharata.