From b7a745dc33a18377bb4a8dfe54d1df01ea60bf66 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Thu, 16 Mar 2017 17:02:49 +0100 Subject: [PATCH] thread-pool: add missing qemu_bh_cancel in completion function commit 3c80ca15 fixed a deadlock scenarion with nested aio_poll invocations. However, the rescheduling of the completion BH introcuded unnecessary spinning in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up. Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file. Fixes: 3c80ca158c96ff902a30883a8933e755988948b1 Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf --- util/thread-pool.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/thread-pool.c b/util/thread-pool.c index ce6cd30193..610646d131 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -188,6 +188,13 @@ restart: aio_context_release(pool->ctx); elem->common.cb(elem->common.opaque, elem->ret); aio_context_acquire(pool->ctx); + + /* We can safely cancel the completion_bh here regardless of someone + * else having scheduled it meanwhile because we reenter the + * completion function anyway (goto restart). + */ + qemu_bh_cancel(pool->completion_bh); + qemu_aio_unref(elem); goto restart; } else {