From patchwork Tue Jan 18 00:19:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 79237 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 5C345B7112 for ; Tue, 18 Jan 2011 11:20:33 +1100 (EST) Received: from localhost ([127.0.0.1]:35242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PezJG-0002j7-4v for incoming@patchwork.ozlabs.org; Mon, 17 Jan 2011 19:20:30 -0500 Received: from [140.186.70.92] (port=49907 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PezIm-0002gi-Ba for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:20:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PezIh-0006WC-75 for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:20:00 -0500 Received: from mail-ey0-f173.google.com ([209.85.215.173]:50274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PezIg-0006W6-TD for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:19:55 -0500 Received: by eyg7 with SMTP id 7so3126346eyg.4 for ; Mon, 17 Jan 2011 16:19:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=RV1rS60PqLNhiejARjw3FhSqi788eJRqMAzteAK9d98=; b=Dj22pB8d83vh8bH41h7M+SAecSej/Opz4lKwPK+6WvwsWyN91Y0+cPE+ZPGgtiaHWy /80C+fpHrVKDs5lCvMuCr3NorW+lhz2jIZnVxPOobcJVDFKlVADGnGzDZB2OpZHJTr9+ 0yJukuzqfKGWR+s3khCWnwgsD3Pqm53DDYPKU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=BErn4kfXQ7vG+5+AMFOm2BKv/I3O6cmuTANg1TXDvZj2varqP/rwTzc8mK29vm2+aA 9GgaH3XUH+nQC1zSAwH4H0CclsDo7/xfI+tHQ8sjuqN9ToDl525YdYNC5aBqrc+/2ze3 on/7X7xzGXD6CoA4LMW0nMHiSh8cA3SVuxkLA= Received: by 10.213.104.136 with SMTP id p8mr4585683ebo.59.1295309993823; Mon, 17 Jan 2011 16:19:53 -0800 (PST) Received: from localhost (h59ec3266.selukar.dyn.perspektivbredband.net [89.236.50.102]) by mx.google.com with ESMTPS id v59sm4074268eeh.9.2011.01.17.16.19.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 17 Jan 2011 16:19:52 -0800 (PST) Date: Tue, 18 Jan 2011 01:19:50 +0100 From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Message-ID: <20110118001950.GA11802@laped.lan> References: <20110117100308.GA12308@edde.se.axis.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110117100308.GA12308@edde.se.axis.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] Re: MIPS, io-thread, icount and wfi 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 On Mon, Jan 17, 2011 at 11:03:08AM +0100, Edgar E. Iglesias wrote: > Hi, > > I'm running an io-thread enabled qemu-system-mipsel with icount. > When the guest (linux) goes to sleep through the wait insn (waiting > to be woken up by future timer interrupts), the thing deadlocks. > > IIUC, this is because vm timers are driven by icount, but the CPU is > halted so icount makes no progress and time stands still. > > I've locally disabled vcpu halting when icount is enabled, that > works around my problem but of course makes qemu consume 100% host cpu. > > I don't know why I only see this problem with io-thread builds? > Could be related timing and luck. > > Would be interesting to know if someone has any info on how this was > intended to work (if it was)? And if there are ideas for better > workarounds or fixes that don't disable vcpu halting entirely. Hi, I've found the problem. For some reason io-thread builds use a static timeout for wait loops. The entire chunk of code that makes sure qemu_icount makes forward progress when the CPU's are idle has been ifdef'ed away... This fixes the problem for me, hopefully without affecting io-thread runs without icount. commit 0f4f3a919952500b487b438c5520f07a1c6be35b Author: Edgar E. Iglesias Date: Tue Jan 18 01:01:57 2011 +0100 qemu-timer: Fix timeout calc for io-thread with icount Make sure we always make forward progress with qemu_icount to avoid deadlocks. For io-thread, use the static 1000 timeout only if icount is disabled. Signed-off-by: Edgar E. Iglesias diff --git a/qemu-timer.c b/qemu-timer.c index 95814af..db1ec49 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -110,7 +110,6 @@ static int64_t cpu_get_clock(void) } } -#ifndef CONFIG_IOTHREAD static int64_t qemu_icount_delta(void) { if (!use_icount) { @@ -124,7 +123,6 @@ static int64_t qemu_icount_delta(void) return cpu_get_icount() - cpu_get_clock(); } } -#endif /* enable cpu_get_ticks() */ void cpu_enable_ticks(void) @@ -1077,9 +1075,17 @@ void quit_timers(void) int qemu_calculate_timeout(void) { -#ifndef CONFIG_IOTHREAD int timeout; +#ifdef CONFIG_IOTHREAD + /* When using icount, making forward progress with qemu_icount when the + guest CPU is idle is critical. We only use the static io-thread timeout + for non icount runs. */ + if (!use_icount) { + return 1000; + } +#endif + if (!vm_running) timeout = 5000; else { @@ -1110,8 +1116,5 @@ int qemu_calculate_timeout(void) } return timeout; -#else /* CONFIG_IOTHREAD */ - return 1000; -#endif }