Skip to content

Commit

Permalink
thread-pool: add missing qemu_bh_cancel in completion function
Browse files Browse the repository at this point in the history
commit 3c80ca1 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: 3c80ca1
Cc: [email protected]
Signed-off-by: Peter Lieven <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
plieven authored and kevmw committed Mar 17, 2017
1 parent 8cd1a3e commit b7a745d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions util/thread-pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ static void thread_pool_completion_bh(void *opaque)
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 {
Expand Down

0 comments on commit b7a745d

Please sign in to comment.