From patchwork Thu Mar 10 12:12:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 86275 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 DE63EB6F7F for ; Fri, 11 Mar 2011 00:23:22 +1100 (EST) Received: from localhost ([127.0.0.1]:35714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pxfpn-00089K-Mb for incoming@patchwork.ozlabs.org; Thu, 10 Mar 2011 08:23:20 -0500 Received: from [140.186.70.92] (port=52679 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pxejo-0002Vl-GK for qemu-devel@nongnu.org; Thu, 10 Mar 2011 07:13:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pxejn-0004f0-Ik for qemu-devel@nongnu.org; Thu, 10 Mar 2011 07:13:04 -0500 Received: from mail-gx0-f173.google.com ([209.85.161.173]:44111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pxejn-0004eo-DN for qemu-devel@nongnu.org; Thu, 10 Mar 2011 07:13:03 -0500 Received: by gxk28 with SMTP id 28so733765gxk.4 for ; Thu, 10 Mar 2011 04:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=jWQbd2ntM72wPbcs0ebFNJwsFg2dJZwaf23EEP30rC8=; b=p+147lFBodQ/WxR3YFTmsdu+nfH1fq23tLdEPUHs2F+34aZ6TLrhGWWX7fFbE5Gd85 5cc1Ix1Sko8h2igh6g73i7t+YtKQzqSZ+rTeZFu8yZiWCqFM8nWVlOxxStYs+Lcdj56w eaWA35oj2LI1EGFPkDz2gDs8HiLVIHPG2PPpc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=Mt7SKHcYGUMRiagzNFJCs27hEyJxXlm+3dxbVweSwLbcQFHsbKQM4ojy3YL35GlDLy vjF/ub1BlrlQG+gKPqaILu0j4g8dUFYmHY/Xa3CbmcP8LTqwCx7RzsfhOAsKU89Pmjvv +UA8osmy6blzTP9lGIP76068CmYUTTTlcJ9S4= Received: by 10.150.179.17 with SMTP id b17mr979400ybf.203.1299759182722; Thu, 10 Mar 2011 04:13:02 -0800 (PST) Received: from localhost.localdomain (93-34-197-200.ip51.fastwebnet.it [93.34.197.200]) by mx.google.com with ESMTPS id l2sm2224233ybn.3.2011.03.10.04.13.01 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 10 Mar 2011 04:13:02 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 10 Mar 2011 13:12:49 +0100 Message-Id: <1299759171-26095-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4 In-Reply-To: <1299759171-26095-1-git-send-email-pbonzini@redhat.com> References: <1299759171-26095-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.173 Cc: edgar.iglesias@gmail.com, jan.kiszka@web.de Subject: [Qemu-devel] [PATCH v2 1/3] really fix -icount in the iothread case 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 The correct fix for -icount is to consider the biggest difference between iothread and non-iothread modes. In the traditional model, CPUs run _before_ the iothread calls select (or WaitForMultipleObjects for Win32). In the iothread model, CPUs run while the iothread isn't holding the mutex, i.e. _during_ those same calls. So, the iothread should always block as long as possible to let the CPUs run smoothly---the timeout might as well be infinite---and either the OS or the CPU thread itself will let the iothread know when something happens. At this point, the iothread wakes up and interrupts the CPU. This is exactly the approach that this patch takes: when cpu_exec_all returns in -icount mode, and it is because a vm_clock deadline has been met, it wakes up the iothread to process the timers. This fixes icount better than any other patch that was posted. Signed-off-by: Paolo Bonzini --- cpus.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/cpus.c b/cpus.c index 0f33945..a953bac 100644 --- a/cpus.c +++ b/cpus.c @@ -861,6 +861,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) while (1) { cpu_exec_all(); + if (use_icount && qemu_next_deadline() <= 0) { + qemu_notify_event(); + } qemu_tcg_wait_io_event(); }