From patchwork Wed Apr 13 08:03:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 90967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07273B6F7D for ; Wed, 13 Apr 2011 18:05:32 +1000 (EST) Received: from localhost ([::1]:49362 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9v4l-00067h-T7 for incoming@patchwork.ozlabs.org; Wed, 13 Apr 2011 04:05:23 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9v3j-0004js-Bi for qemu-devel@nongnu.org; Wed, 13 Apr 2011 04:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9v3d-0005N6-J8 for qemu-devel@nongnu.org; Wed, 13 Apr 2011 04:04:19 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:43652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9v3d-0005N1-FU for qemu-devel@nongnu.org; Wed, 13 Apr 2011 04:04:13 -0400 Received: by ywl41 with SMTP id 41so201258ywl.4 for ; Wed, 13 Apr 2011 01:04:12 -0700 (PDT) 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=YheREeMv7hBD/17XeARtJb7wmPstC9paNfJPUy+pYQ4=; b=Bvl4AVVKiKgxB9xHAbVdxFI1h3IVnXP3ZE+fyAIh6Hn2WVieFbJ5TPd4tmN6zN5IT9 atPDeGBEu8oYPOetXieHe55lCOgq4wLgaQWD02YnPy7U/qxptqJ5sHJyZPIlFug5Ujgi UfTUSwdlyc7lqvbj/mq9N63X/evmxNnYvl92Y= 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=LQUJ23dDOutN2OMxhl3+LvrhWxRKgqscU/T7O3ERU27036iwYlFguPtxP9oJb+O9sE 7ENpC3+uyUtNcwEYcaquefyVaXaGQJp1Odj7bh2S9H4mkntA3e8fC7nYYgVYi0QFjKGr L12LJqshopUooJJNfOhPjqk2a4bqbXEvtXEd4= Received: by 10.100.53.28 with SMTP id b28mr4967218ana.119.1302681852654; Wed, 13 Apr 2011 01:04:12 -0700 (PDT) Received: from localhost.localdomain (93-34-184-88.ip51.fastwebnet.it [93.34.184.88]) by mx.google.com with ESMTPS id w6sm371575anf.32.2011.04.13.01.04.11 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 13 Apr 2011 01:04:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 13 Apr 2011 10:03:43 +0200 Message-Id: <1302681826-10236-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4 In-Reply-To: <1302681826-10236-1-git-send-email-pbonzini@redhat.com> References: <1302681826-10236-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.213.45 Cc: edgar.iglesias@gmail.com Subject: [Qemu-devel] [PATCH v4 1/4] really fix -icount in the iothread case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: 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 is really the "bulk" of fixing icount. Signed-off-by: Paolo Bonzini Tested-by: Edgar E. Iglesias --- cpus.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/cpus.c b/cpus.c index 41bec7c..cbeac7a 100644 --- a/cpus.c +++ b/cpus.c @@ -830,6 +830,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(); }