[PATCH v2 9/9] async: clarify usage of barriers in the polling case

Paolo Bonzini posted 9 patches 2 years, 4 months ago
[PATCH v2 9/9] async: clarify usage of barriers in the polling case
Posted by Paolo Bonzini 2 years, 4 months ago
Explain that aio_context_notifier_poll() relies on
aio_notify_accept() to catch all the memory writes that were
done before ctx->notified was set to true.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 util/async.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/util/async.c b/util/async.c
index e4b494150e7d..21016a1ac7c1 100644
--- a/util/async.c
+++ b/util/async.c
@@ -474,8 +474,9 @@ void aio_notify_accept(AioContext *ctx)
     qatomic_set(&ctx->notified, false);
 
     /*
-     * Write ctx->notified before reading e.g. bh->flags.  Pairs with smp_wmb
-     * in aio_notify.
+     * Order reads of ctx->notified (in aio_context_notifier_poll()) and the
+     * above clearing of ctx->notified before reads of e.g. bh->flags.  Pairs
+     * with smp_wmb() in aio_notify.
      */
     smp_mb();
 }
@@ -498,6 +499,11 @@ static bool aio_context_notifier_poll(void *opaque)
     EventNotifier *e = opaque;
     AioContext *ctx = container_of(e, AioContext, notifier);
 
+    /*
+     * No need for load-acquire because we just want to kick the
+     * event loop.  aio_notify_accept() takes care of synchronizing
+     * the event loop with the producers.
+     */
     return qatomic_read(&ctx->notified);
 }
 
-- 
2.39.1
Re: [PATCH v2 9/9] async: clarify usage of barriers in the polling case
Posted by David Hildenbrand 2 years, 4 months ago
On 06.03.23 23:33, Paolo Bonzini wrote:
> Explain that aio_context_notifier_poll() relies on
> aio_notify_accept() to catch all the memory writes that were
> done before ctx->notified was set to true.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   util/async.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/util/async.c b/util/async.c
> index e4b494150e7d..21016a1ac7c1 100644
> --- a/util/async.c
> +++ b/util/async.c
> @@ -474,8 +474,9 @@ void aio_notify_accept(AioContext *ctx)
>       qatomic_set(&ctx->notified, false);
>   
>       /*
> -     * Write ctx->notified before reading e.g. bh->flags.  Pairs with smp_wmb
> -     * in aio_notify.
> +     * Order reads of ctx->notified (in aio_context_notifier_poll()) and the
> +     * above clearing of ctx->notified before reads of e.g. bh->flags.  Pairs
> +     * with smp_wmb() in aio_notify.
>        */
>       smp_mb();
>   }
> @@ -498,6 +499,11 @@ static bool aio_context_notifier_poll(void *opaque)
>       EventNotifier *e = opaque;
>       AioContext *ctx = container_of(e, AioContext, notifier);
>   
> +    /*
> +     * No need for load-acquire because we just want to kick the
> +     * event loop.  aio_notify_accept() takes care of synchronizing
> +     * the event loop with the producers.
> +     */
>       return qatomic_read(&ctx->notified);
>   }
>   

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb
Re: [PATCH v2 9/9] async: clarify usage of barriers in the polling case
Posted by Stefan Hajnoczi 2 years, 4 months ago
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>