From patchwork Thu Oct 22 19:38:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 36742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AD25EB7BB7 for ; Fri, 23 Oct 2009 06:43:17 +1100 (EST) Received: from localhost ([127.0.0.1]:47781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N13Z4-0007uU-Oc for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 15:43:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N13Wg-0005aZ-Lh for qemu-devel@nongnu.org; Thu, 22 Oct 2009 15:40:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N13Wb-0005Nf-KS for qemu-devel@nongnu.org; Thu, 22 Oct 2009 15:40:45 -0400 Received: from [199.232.76.173] (port=53618 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N13Wb-0005NQ-HH for qemu-devel@nongnu.org; Thu, 22 Oct 2009 15:40:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31315) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N13Wb-0006IQ-1R for qemu-devel@nongnu.org; Thu, 22 Oct 2009 15:40:41 -0400 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 n9MJedX6011125; Thu, 22 Oct 2009 15:40:39 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MJeBHM026028; Thu, 22 Oct 2009 15:40:38 -0400 Received: from amt.cnet (vpn-10-110.str.redhat.com [10.32.10.110]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n9MJe8pY010862; Thu, 22 Oct 2009 15:40:09 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C121B5880F7; Thu, 22 Oct 2009 17:39:51 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n9MJdnxB020379; Thu, 22 Oct 2009 17:39:49 -0200 Message-Id: <20091022193912.273762726@redhat.com> User-Agent: quilt/0.47-1 Date: Thu, 22 Oct 2009 17:38:18 -0200 From: Marcelo Tosatti To: qemu-devel@nongnu.org References: <20091022193816.147000901@redhat.com> Content-Disposition: inline; filename=wait-io-event X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: glommer@redhat.com, Marcelo Tosatti , aliguori@us.ibm.com Subject: [Qemu-devel] [patch 2/2] qemu: kvm specific wait_io_event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 @@ -3590,6 +3590,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) { @@ -3610,6 +3611,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()) @@ -3626,11 +3636,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); } static int qemu_cpu_exec(CPUState *env); @@ -3656,7 +3670,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;