From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3IvS-0003fS-Os for qemu-devel@nongnu.org; Mon, 30 Nov 2015 02:31:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3IvO-0000CX-Jk for qemu-devel@nongnu.org; Mon, 30 Nov 2015 02:31:06 -0500 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]:35549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3IvO-0000CD-BB for qemu-devel@nongnu.org; Mon, 30 Nov 2015 02:31:02 -0500 Received: by pacej9 with SMTP id ej9so176172731pac.2 for ; Sun, 29 Nov 2015 23:31:01 -0800 (PST) References: <1448024079-20808-1-git-send-email-bharata@linux.vnet.ibm.com> <1448024079-20808-5-git-send-email-bharata@linux.vnet.ibm.com> From: Alexey Kardashevskiy Message-ID: <565BFB2C.6040201@ozlabs.ru> Date: Mon, 30 Nov 2015 18:30:52 +1100 MIME-Version: 1.0 In-Reply-To: <1448024079-20808-5-git-send-email-bharata@linux.vnet.ibm.com> Content-Type: text/plain; charset=koi8-r; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 04/10] cpu: Reclaim vCPU objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao , qemu-devel@nongnu.org Cc: Zhu Guihua , mdroth@linux.vnet.ibm.com, agraf@suse.de, Chen Fan , pbonzini@redhat.com, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, Gu Zheng , imammedo@redhat.com, afaerber@suse.de, david@gibson.dropbear.id.au On 11/20/2015 11:54 PM, 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()] > Reviewed-by: David Gibson > --- > 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); Nit: qemu_mutex_unlock_iothread() may be? Or it is important for iothread_locked to remain "true"? It does not seem to be used much though. -- Alexey