From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH] do not enter vcpu again if it was stopped during IO Date: Tue, 22 Jun 2010 08:18:14 +0300 Message-ID: <20100622051814.GO4689@redhat.com> References: <20100621090152.GG4689@redhat.com> <20100621204304.GB17906@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: avi@redhat.com, kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32562 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750905Ab0FVFSQ (ORCPT ); Tue, 22 Jun 2010 01:18:16 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5M5IFW9022924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Jun 2010 01:18:16 -0400 Content-Disposition: inline In-Reply-To: <20100621204304.GB17906@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jun 21, 2010 at 05:43:04PM -0300, Marcelo Tosatti wrote: > On Mon, Jun 21, 2010 at 12:01:52PM +0300, Gleb Natapov wrote: > > To prevent reentering vcpu after IO completion it is not enough > > to set env->stopped since it is checked only in main loop but control > > will not get there until next non-IO exit since kvm_run() will reenter > > vcpu to complete IO instruction. Solve this by sending self-signal to > > request exit after IO instruction completion. > > > > Signed-off-by: Gleb Natapov > > diff --git a/qemu-kvm.c b/qemu-kvm.c > > index be1dac2..4f7cf6d 100644 > > --- a/qemu-kvm.c > > +++ b/qemu-kvm.c > > @@ -603,6 +603,10 @@ int kvm_run(CPUState *env) > > r = pre_kvm_run(kvm, env); > > if (r) > > return r; > > + if (env->exit_request) { > > + env->exit_request = 0; > > + pthread_kill(env->kvm_cpu_state.thread, SIG_IPI); > > + } > > r = ioctl(fd, KVM_RUN, 0); > > Can't you check for env->stopped instead? > Why it would be better? exit_request is used exactly for purpose to notify cpu loop that is should exit. Sometimes it may be useful to request cpu exit without stopping the cpu. I see gdbstub uses it, haven't check if it applicable to kvm though. > > > > if (r == -1 && errno != EINTR && errno != EAGAIN) { > > diff --git a/vl.c b/vl.c > > index 9e9c176..dcfab13 100644 > > --- a/vl.c > > +++ b/vl.c > > @@ -1817,6 +1817,7 @@ void qemu_system_reset_request(void) > > } > > if (cpu_single_env) { > > cpu_single_env->stopped = 1; > > + cpu_exit(cpu_single_env); > > } > > qemu_notify_event(); > > } > > -- > > Gleb. -- Gleb.