From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH] kvm tools: Wait for all VCPU threads to exit while rebooting Date: Thu, 11 Aug 2011 13:14:58 +0300 Message-ID: <1313057698.3456.10.camel@lappy> References: <1313056043-17405-1-git-send-email-levinsasha928@gmail.com> <1313056043-17405-2-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com To: Pekka Enberg Return-path: Received: from mail-fx0-f46.google.com ([209.85.161.46]:40098 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753310Ab1HKKP6 (ORCPT ); Thu, 11 Aug 2011 06:15:58 -0400 Received: by fxh19 with SMTP id 19so1556065fxh.19 for ; Thu, 11 Aug 2011 03:15:57 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Thu, 2011-08-11 at 13:02 +0300, Pekka Enberg wrote: > On Thu, Aug 11, 2011 at 12:47 PM, Sasha Levin wrote: > > This patch changes kvm_cpu__reboot() behaviour to block until all VCPU > > threads have ended, this allows us to assume that the guest is stopped > > when the function has returned. > > > > This fixes errors on close caused by releasing KVM_RUN structure while > > VCPUs were still running. > > > > Signed-off-by: Sasha Levin > > --- > > tools/kvm/kvm-cpu.c | 10 ++++++++-- > > 1 files changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c > > index 2f5d23c..64c0997 100644 > > --- a/tools/kvm/kvm-cpu.c > > +++ b/tools/kvm/kvm-cpu.c > > @@ -421,7 +421,13 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu) > > > > void kvm_cpu__reboot(void) > > { > > - pthread_kill(kvm_cpus[0]->thread, SIGKVMEXIT); > > + int i; > > + > > + for (i = 0; i < KVM_NR_CPUS; i++) > > + if (kvm_cpus[i]) { > > + pthread_kill(kvm_cpus[i]->thread, SIGKVMEXIT); > > + pthread_join(kvm_cpus[i]->thread, NULL); > > + } > > Wouldn't it be better to first pthread_kill() all CPUs first and do > pthread_join() in separate loop? That should be faster especially if > there's lots of CPUs. Actually, we don't even need a pthread_kill() there. I'll send a new version :) -- Sasha.