From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [patch uq/master 2/4] qemu: kvm specific wait_io_event Date: Thu, 18 Feb 2010 10:29:35 +0200 Message-ID: <4B7CFA6F.3080801@redhat.com> References: <20100217221439.351652889@redhat.com> <20100217221701.041682707@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:3441 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753282Ab0BRI3i (ORCPT ); Thu, 18 Feb 2010 03:29:38 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1I8Tcxa018689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Feb 2010 03:29:38 -0500 In-Reply-To: <20100217221701.041682707@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 02/18/2010 12:14 AM, Marcelo Tosatti wrote: > In KVM mode the global mutex is released when vcpus are executing, > which means acquiring the fairness mutex is not required. > > Also for KVM there is one thread per vcpu, so tcg_has_work is meaningless. > > Add a new qemu_wait_io_event_common function to hold common code > between TCG/KVM. > > Signed-off-by: Marcelo Tosatti > > Index: qemu/vl.c > =================================================================== > --- qemu.orig/vl.c > +++ qemu/vl.c > @@ -3382,6 +3382,7 @@ static QemuCond qemu_pause_cond; > static void block_io_signals(void); > static void unblock_io_signals(void); > static int tcg_has_work(void); > +static int cpu_has_work(CPUState *env); > > static int qemu_init_main_loop(void) > { > @@ -3402,6 +3403,15 @@ static int qemu_init_main_loop(void) > return 0; > } > > +static void qemu_wait_io_event_common(CPUState *env) > +{ > + if (env->stop) { > + env->stop = 0; > + env->stopped = 1; > + qemu_cond_signal(&qemu_pause_cond); > + } > +} > + > static void qemu_wait_io_event(CPUState *env) > { > while (!tcg_has_work()) > @@ -3418,11 +3428,15 @@ static void qemu_wait_io_event(CPUState > qemu_mutex_unlock(&qemu_fair_mutex); > > qemu_mutex_lock(&qemu_global_mutex); > - if (env->stop) { > - env->stop = 0; > - env->stopped = 1; > - qemu_cond_signal(&qemu_pause_cond); > - } > + qemu_wait_io_event_common(env); > +} > + > +static void qemu_kvm_wait_io_event(CPUState *env) > +{ > + while (!cpu_has_work(env)) > + qemu_cond_timedwait(env->halt_cond,&qemu_global_mutex, 1000); > + > + qemu_wait_io_event_common(env); > } > Shouldn't kvm specific code be in kvm-all.c? > > static int qemu_cpu_exec(CPUState *env); > @@ -3448,7 +3462,7 @@ static void *kvm_cpu_thread_fn(void *arg > while (1) { > if (cpu_can_run(env)) > qemu_cpu_exec(env); > - qemu_wait_io_event(env); > + qemu_kvm_wait_io_event(env); > } > > return NULL; > Well, kvm_cpu_thread_fn() apparently isn't. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.