From 05e514b1d4d5bd4209e2c8bbc76ff05c85a235f3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 21 Jul 2015 16:07:53 +0200 Subject: AioContext: optimize clearing the EventNotifier It is pretty rare for aio_notify to actually set the EventNotifier. It can happen with worker threads such as thread-pool.c's, but otherwise it should never be set thanks to the ctx->notify_me optimization. The previous patch, unfortunately, added an unconditional call to event_notifier_test_and_clear; now add a userspace fast path that avoids the call. Note that it is not possible to do the same with event_notifier_set; it would break, as proved (again) by the included formal model. This patch survived over 3000 reboots on aarch64 KVM. Signed-off-by: Paolo Bonzini Reviewed-by: Fam Zheng Tested-by: Richard W.M. Jones Message-id: 1437487673-23740-7-git-send-email-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- async.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'async.c') diff --git a/async.c b/async.c index d625e8a803..9a98a74acb 100644 --- a/async.c +++ b/async.c @@ -203,7 +203,7 @@ aio_ctx_check(GSource *source) QEMUBH *bh; atomic_and(&ctx->notify_me, ~1); - event_notifier_test_and_clear(&ctx->notifier); + aio_notify_accept(ctx); for (bh = ctx->first_bh; bh; bh = bh->next) { if (!bh->deleted && bh->scheduled) { @@ -267,6 +267,14 @@ void aio_notify(AioContext *ctx) smp_mb(); if (ctx->notify_me) { event_notifier_set(&ctx->notifier); + atomic_mb_set(&ctx->notified, true); + } +} + +void aio_notify_accept(AioContext *ctx) +{ + if (atomic_xchg(&ctx->notified, false)) { + event_notifier_test_and_clear(&ctx->notifier); } } -- cgit 1.4.1