diff mbox

[RFC,v13,15/21] bottom halves: introduce bh call function

Message ID 20150506140406.17288.85396.stgit@PASHA-ISP
State New
Headers show

Commit Message

Pavel Dovgalyuk May 6, 2015, 2:04 p.m. UTC
This patch introduces aio_bh_call function. It is used to execute
bottom halves as callbacks without adding them to the queue.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
 async.c             |    8 +++++++-
 include/block/aio.h |    5 +++++
 2 files changed, 12 insertions(+), 1 deletions(-)

Comments

Paolo Bonzini May 6, 2015, 2:39 p.m. UTC | #1
On 06/05/2015 16:04, Pavel Dovgalyuk wrote:
> This patch introduces aio_bh_call function. It is used to execute
> bottom halves as callbacks without adding them to the queue.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> ---
>  async.c             |    8 +++++++-
>  include/block/aio.h |    5 +++++
>  2 files changed, 12 insertions(+), 1 deletions(-)
> 
> diff --git a/async.c b/async.c
> index 46d9e63..734c76c 100644
> --- a/async.c
> +++ b/async.c
> @@ -59,6 +59,12 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
>      return bh;
>  }
>  
> +void aio_bh_call(void *opaque)
> +{
> +    QEMUBH *bh = (QEMUBH *)opaque;

This can have a QEMUBH * argument.  I can fix it when committing.

> +    bh->cb(bh->opaque);
> +}
> +
>  /* Multiple occurrences of aio_bh_poll cannot be called concurrently */
>  int aio_bh_poll(AioContext *ctx)
>  {
> @@ -82,7 +88,7 @@ int aio_bh_poll(AioContext *ctx)
>              if (!bh->idle)
>                  ret = 1;
>              bh->idle = 0;
> -            bh->cb(bh->opaque);
> +            aio_bh_call(bh);
>          }
>      }
>  
> diff --git a/include/block/aio.h b/include/block/aio.h
> index d2bb423..b498704 100644
> --- a/include/block/aio.h
> +++ b/include/block/aio.h
> @@ -157,6 +157,11 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
>  void aio_notify(AioContext *ctx);
>  
>  /**
> + * aio_bh_call: Executes callback function of the specified BH.
> + */
> +void aio_bh_call(void *opaque);
> +
> +/**
>   * aio_bh_poll: Poll bottom halves for an AioContext.
>   *
>   * These are internal functions used by the QEMU main loop.
> 

Works for me!  I am not sure why patch 16 works though. :)  I'll ponder
on it, in the meanwhile some extra explanation from you would be welcome...

Paolo
Pavel Dovgalyuk May 7, 2015, 6:48 a.m. UTC | #2
> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> On 06/05/2015 16:04, Pavel Dovgalyuk wrote:
> > This patch introduces aio_bh_call function. It is used to execute
> > bottom halves as callbacks without adding them to the queue.
> >
> > Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> > ---
> >  async.c             |    8 +++++++-
> >  include/block/aio.h |    5 +++++
> >  2 files changed, 12 insertions(+), 1 deletions(-)
> >
> > diff --git a/async.c b/async.c
> > index 46d9e63..734c76c 100644
> > --- a/async.c
> > +++ b/async.c
> > @@ -59,6 +59,12 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
> >      return bh;
> >  }
> >
> > +void aio_bh_call(void *opaque)
> > +{
> > +    QEMUBH *bh = (QEMUBH *)opaque;
> 
> This can have a QEMUBH * argument.  I can fix it when committing.
> 
> > +    bh->cb(bh->opaque);
> > +}
> > +
> >  /* Multiple occurrences of aio_bh_poll cannot be called concurrently */
> >  int aio_bh_poll(AioContext *ctx)
> >  {
> > @@ -82,7 +88,7 @@ int aio_bh_poll(AioContext *ctx)
> >              if (!bh->idle)
> >                  ret = 1;
> >              bh->idle = 0;
> > -            bh->cb(bh->opaque);
> > +            aio_bh_call(bh);
> >          }
> >      }
> >
> > diff --git a/include/block/aio.h b/include/block/aio.h
> > index d2bb423..b498704 100644
> > --- a/include/block/aio.h
> > +++ b/include/block/aio.h
> > @@ -157,6 +157,11 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
> >  void aio_notify(AioContext *ctx);
> >
> >  /**
> > + * aio_bh_call: Executes callback function of the specified BH.
> > + */
> > +void aio_bh_call(void *opaque);
> > +
> > +/**
> >   * aio_bh_poll: Poll bottom halves for an AioContext.
> >   *
> >   * These are internal functions used by the QEMU main loop.
> >
> 
> Works for me!  I am not sure why patch 16 works though. :)  I'll ponder
> on it, in the meanwhile some extra explanation from you would be welcome...

As you know, there is a replay queue for different asynchronous events like user input or thread pool callback.
ptimer uses bottom halves layer to execute such an asynchronous callback.
We put this callback into the replay queue instead of bottom halves one.
When checkpoint is met by main loop thread, the replay queue is processed and callback is executed.
Binding callback moment to one of the checkpoints makes it deterministic.

Pavel Dovgalyuk
diff mbox

Patch

diff --git a/async.c b/async.c
index 46d9e63..734c76c 100644
--- a/async.c
+++ b/async.c
@@ -59,6 +59,12 @@  QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
     return bh;
 }
 
+void aio_bh_call(void *opaque)
+{
+    QEMUBH *bh = (QEMUBH *)opaque;
+    bh->cb(bh->opaque);
+}
+
 /* Multiple occurrences of aio_bh_poll cannot be called concurrently */
 int aio_bh_poll(AioContext *ctx)
 {
@@ -82,7 +88,7 @@  int aio_bh_poll(AioContext *ctx)
             if (!bh->idle)
                 ret = 1;
             bh->idle = 0;
-            bh->cb(bh->opaque);
+            aio_bh_call(bh);
         }
     }
 
diff --git a/include/block/aio.h b/include/block/aio.h
index d2bb423..b498704 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -157,6 +157,11 @@  QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
 void aio_notify(AioContext *ctx);
 
 /**
+ * aio_bh_call: Executes callback function of the specified BH.
+ */
+void aio_bh_call(void *opaque);
+
+/**
  * aio_bh_poll: Poll bottom halves for an AioContext.
  *
  * These are internal functions used by the QEMU main loop.