From patchwork Tue Oct 8 19:10:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 281588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3151E2C0082 for ; Wed, 9 Oct 2013 06:11:12 +1100 (EST) Received: from localhost ([::1]:38547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTcgY-000495-7Z for incoming@patchwork.ozlabs.org; Tue, 08 Oct 2013 15:11:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTcg2-00047x-Ig for qemu-devel@nongnu.org; Tue, 08 Oct 2013 15:10:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTcfw-0004yE-EJ for qemu-devel@nongnu.org; Tue, 08 Oct 2013 15:10:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTcfw-0004y7-6g for qemu-devel@nongnu.org; Tue, 08 Oct 2013 15:10:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r98JAOBO002009 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Oct 2013 15:10:24 -0400 Received: from shalem.localdomain.com (vpn1-4-101.ams2.redhat.com [10.36.4.101]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r98JA5WK027620; Tue, 8 Oct 2013 15:10:05 -0400 From: Hans de Goede To: qemu-devel@nongnu.org, Alex Bligh Date: Tue, 8 Oct 2013 21:10:03 +0200 Message-Id: <1381259403-7386-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Hans de Goede Subject: [Qemu-devel] [PATCH] main-loop: Don't lock starve io-threads when main_loop_tlg has pending events 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 I noticed today that current qemu master would hang as soon as Xorg starts in the guest when using qxl + a Linux guest. This message would be printed: main-loop: WARNING: I/O thread spun for 1000 iterations And from then on the guest hangs and qemu consumes 100% cpu, bisecting pointed out commit 7b595f35d89d73bc69c35bf3980a89c420e8a44b: "aio / timers: Convert mainloop to use timeout" After looking at that commit I had a hunch the problem might be blocking main_loop_wait calls being turned into non-blocking ones (and thus never releasing the io-lock), a debug printf confirmed this was happening at the moment of the hang, so I wrote this patch which fixes the hang for me and seems like a good idea in general. Signed-off-by: Hans de Goede --- main-loop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main-loop.c b/main-loop.c index c3c9c28..921c939 100644 --- a/main-loop.c +++ b/main-loop.c @@ -480,6 +480,11 @@ int main_loop_wait(int nonblocking) timerlistgroup_deadline_ns( &main_loop_tlg)); + /* When not non-blocking always allow io-threads to acquire the lock */ + if (timeout != 0 && timeout_ns == 0) { + timeout_ns = 1; + } + ret = os_host_main_loop_wait(timeout_ns); qemu_iohandler_poll(gpollfds, ret); #ifdef CONFIG_SLIRP