From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAY4U-0001LS-U2 for qemu-devel@nongnu.org; Thu, 02 Jul 2015 02:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAY4R-0007gB-NF for qemu-devel@nongnu.org; Thu, 02 Jul 2015 02:34:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAY4R-0007fu-IF for qemu-devel@nongnu.org; Thu, 02 Jul 2015 02:34:03 -0400 From: Fam Zheng Date: Thu, 2 Jul 2015 14:33:59 +0800 Message-Id: <1435818839-5376-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] thread-pool: Notify AIO context upon completion List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi , borntraeger@de.ibm.com bdrv_flush() uses a loop like while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } to wait for thread pool, which may not get notified about the scheduled BH right away, if there is no new event that wakes up a blocking qemu_poll_ns(). In this case, it may even be a permanent hang. Wake the main thread up by writing to the event notifier fd. Cc: Paolo Bonzini Cc: Christian Borntraeger Signed-off-by: Fam Zheng --- I suspect this may relate to [Qemu-devel] "iothread: release iothread around aio_poll" causes random hangs at startup [http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg00623.html] reported by Christian Borntraeger. Because in iothread there is rarely any fd activity, so the blocking aio_poll() may block forever if it misses the BH schedule. Christian, could you test this patch against your reproducer? --- thread-pool.c | 1 + 1 file changed, 1 insertion(+) diff --git a/thread-pool.c b/thread-pool.c index ac909f4..9b9c065 100644 --- a/thread-pool.c +++ b/thread-pool.c @@ -112,6 +112,7 @@ static void *worker_thread(void *opaque) qemu_mutex_lock(&pool->lock); qemu_bh_schedule(pool->completion_bh); + aio_notify(pool->ctx); } pool->cur_threads--; -- 2.4.3