qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] block: make aio_poll(ctx, true) block with no fds
@ 2013-09-25 12:15 Stefan Hajnoczi
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-09-25 12:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Ping Fan Liu, Alex Bligh, Jan Kiszka, Stefan Hajnoczi,
	Paolo Bonzini

Jan and Alex have expressed that aio_poll(ctx, blocking=true) should block even
when there are no file descriptors registered.  This can be handy since other
threads may still kick the AioContext using aio_notify(ctx).

A concrete example is a thread that has only a timer in its AioContext.
aio_poll(ctx, true) should block until the timer expires or another thread
invokes aio_notify(ctx).

Alex and Paolo were concerned about bdrv_drain_all() which has the following
comment:

  while (busy) {
      /* FIXME: We do not have timer support here, so this is effectively
       * a busy wait.
       */
      QTAILQ_FOREACH(bs, &bdrv_states, list) {
          if (bdrv_start_throttled_reqs(bs)) {
              busy = true;
          }
      }

      busy = bdrv_requests_pending_all();
      busy |= aio_poll(qemu_get_aio_context(), busy);
  }

Patch 1 drops this outdated comment.  The new I/O throttling code already
eliminated the busy wait.

Patch 2 drops the special case which returns immediately from aio_poll(ctx,
true) when no file descriptors are registered.

Note that aio_notify(ctx) still causes aio_poll(ctx, true) to return false.  I
don't see a need to change it so aio_poll(ctx, true) always returns true.

Stefan Hajnoczi (2):
  block: clean up bdrv_drain_all() throttling comments
  aio: make aio_poll(ctx, true) block with no fds

 aio-posix.c      | 5 -----
 aio-win32.c      | 5 -----
 block.c          | 7 +------
 tests/test-aio.c | 1 -
 4 files changed, 1 insertion(+), 17 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments
  2013-09-25 12:15 [Qemu-devel] [PATCH 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
@ 2013-09-25 12:15 ` Stefan Hajnoczi
  2013-09-25 13:32   ` Alex Bligh
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-09-25 12:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Ping Fan Liu, Alex Bligh, Jan Kiszka, Stefan Hajnoczi,
	Paolo Bonzini

Since cc0681c45430a1f1a4c2d06e9499b7775afc9a18 ("block: Enable the new
throttling code in the block layer.") bdrv_drain_all() no longer spins.
The code used to look as follows:

  do {
      busy = qemu_aio_wait();

      /* FIXME: We do not have timer support here, so this is effectively
       * a busy wait.
       */
      QTAILQ_FOREACH(bs, &bdrv_states, list) {
          while (qemu_co_enter_next(&bs->throttled_reqs)) {
              busy = true;
          }
      }
  } while (busy);

Note that throttle requests are kicked but I/O throttling limits are
still in effect.  The loop spins until the vm_clock time allows the
request to make progress and complete.

The new throttling code introduced bdrv_start_throttled_reqs().  This
function not only kicks throttled requests but also temporarily disables
throttling so requests can run.

The outdated FIXME comment can be removed.  Also drop the busy = true
assignment since we overwrite it immediately afterwards.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/block.c b/block.c
index ea4956d..5b276fb 100644
--- a/block.c
+++ b/block.c
@@ -1558,13 +1558,8 @@ void bdrv_drain_all(void)
     BlockDriverState *bs;
 
     while (busy) {
-        /* FIXME: We do not have timer support here, so this is effectively
-         * a busy wait.
-         */
         QTAILQ_FOREACH(bs, &bdrv_states, list) {
-            if (bdrv_start_throttled_reqs(bs)) {
-                busy = true;
-            }
+            bdrv_start_throttled_reqs(bs);
         }
 
         busy = bdrv_requests_pending_all();
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds
  2013-09-25 12:15 [Qemu-devel] [PATCH 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
@ 2013-09-25 12:15 ` Stefan Hajnoczi
  2013-09-25 13:32   ` Alex Bligh
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-09-25 12:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Ping Fan Liu, Alex Bligh, Jan Kiszka, Stefan Hajnoczi,
	Paolo Bonzini

This patch drops a special case where aio_poll(ctx, true) returns false
instead of blocking if no file descriptors are waiting on I/O.  Now it
is possible to block in aio_poll() to wait for aio_notify().

This change eliminates busy waiting.  bdrv_drain_all() used to rely on
busy waiting to completed throttled I/O requests but this is no longer
required so we can simplify aio_poll().

Note that aio_poll() still returns false when aio_notify() was used.  In
other words, stopping a blocking aio_poll() wait is not considered
making progress.

Adjust test-aio /aio/bh/callback-delete/one which assumed aio_poll(ctx,
true) would immediately return false instead of blocking.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 aio-posix.c      | 5 -----
 aio-win32.c      | 5 -----
 tests/test-aio.c | 1 -
 3 files changed, 11 deletions(-)

diff --git a/aio-posix.c b/aio-posix.c
index bd06f33..f921d4f 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -217,11 +217,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
 
     ctx->walking_handlers--;
 
-    /* early return if we only have the aio_notify() fd */
-    if (ctx->pollfds->len == 1) {
-        return progress;
-    }
-
     /* wait until next event */
     ret = qemu_poll_ns((GPollFD *)ctx->pollfds->data,
                          ctx->pollfds->len,
diff --git a/aio-win32.c b/aio-win32.c
index f9cfbb7..23f4e5b 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -161,11 +161,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
 
     ctx->walking_handlers--;
 
-    /* early return if we only have the aio_notify() fd */
-    if (count == 1) {
-        return progress;
-    }
-
     /* wait until next event */
     while (count > 0) {
         int ret;
diff --git a/tests/test-aio.c b/tests/test-aio.c
index c4fe0fc..592721e 100644
--- a/tests/test-aio.c
+++ b/tests/test-aio.c
@@ -195,7 +195,6 @@ static void test_bh_delete_from_cb(void)
     g_assert(data1.bh == NULL);
 
     g_assert(!aio_poll(ctx, false));
-    g_assert(!aio_poll(ctx, true));
 }
 
 static void test_bh_delete_from_cb_many(void)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
@ 2013-09-25 13:32   ` Alex Bligh
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Bligh @ 2013-09-25 13:32 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Ping Fan Liu, Jan Kiszka, qemu-devel, Alex Bligh,
	Paolo Bonzini


On 25 Sep 2013, at 13:15, Stefan Hajnoczi wrote:

> Since cc0681c45430a1f1a4c2d06e9499b7775afc9a18 ("block: Enable the new
> throttling code in the block layer.") bdrv_drain_all() no longer spins.
> The code used to look as follows:
> 
>  do {
>      busy = qemu_aio_wait();
> 
>      /* FIXME: We do not have timer support here, so this is effectively
>       * a busy wait.
>       */
>      QTAILQ_FOREACH(bs, &bdrv_states, list) {
>          while (qemu_co_enter_next(&bs->throttled_reqs)) {
>              busy = true;
>          }
>      }
>  } while (busy);
> 
> Note that throttle requests are kicked but I/O throttling limits are
> still in effect.  The loop spins until the vm_clock time allows the
> request to make progress and complete.
> 
> The new throttling code introduced bdrv_start_throttled_reqs().  This
> function not only kicks throttled requests but also temporarily disables
> throttling so requests can run.
> 
> The outdated FIXME comment can be removed.  Also drop the busy = true
> assignment since we overwrite it immediately afterwards.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Signed-off-by: Alex Bligh <alex@alex.org.uk>

(if I meant 'Reviewed-By:' please change it!)

> ---
> block.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/block.c b/block.c
> index ea4956d..5b276fb 100644
> --- a/block.c
> +++ b/block.c
> @@ -1558,13 +1558,8 @@ void bdrv_drain_all(void)
>     BlockDriverState *bs;
> 
>     while (busy) {
> -        /* FIXME: We do not have timer support here, so this is effectively
> -         * a busy wait.
> -         */
>         QTAILQ_FOREACH(bs, &bdrv_states, list) {
> -            if (bdrv_start_throttled_reqs(bs)) {
> -                busy = true;
> -            }
> +            bdrv_start_throttled_reqs(bs);
>         }
> 
>         busy = bdrv_requests_pending_all();
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Alex Bligh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds
  2013-09-25 12:15 ` [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
@ 2013-09-25 13:32   ` Alex Bligh
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Bligh @ 2013-09-25 13:32 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Ping Fan Liu, Jan Kiszka, qemu-devel, Alex Bligh,
	Paolo Bonzini


On 25 Sep 2013, at 13:15, Stefan Hajnoczi wrote:

> This patch drops a special case where aio_poll(ctx, true) returns false
> instead of blocking if no file descriptors are waiting on I/O.  Now it
> is possible to block in aio_poll() to wait for aio_notify().
> 
> This change eliminates busy waiting.  bdrv_drain_all() used to rely on
> busy waiting to completed throttled I/O requests but this is no longer
> required so we can simplify aio_poll().
> 
> Note that aio_poll() still returns false when aio_notify() was used.  In
> other words, stopping a blocking aio_poll() wait is not considered
> making progress.
> 
> Adjust test-aio /aio/bh/callback-delete/one which assumed aio_poll(ctx,
> true) would immediately return false instead of blocking.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>


Signed-off-by: Alex Bligh <alex@alex.org.uk>

(if I meant 'Reviewed-By:' please change it!)

> ---
> aio-posix.c      | 5 -----
> aio-win32.c      | 5 -----
> tests/test-aio.c | 1 -
> 3 files changed, 11 deletions(-)
> 
> diff --git a/aio-posix.c b/aio-posix.c
> index bd06f33..f921d4f 100644
> --- a/aio-posix.c
> +++ b/aio-posix.c
> @@ -217,11 +217,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
> 
>     ctx->walking_handlers--;
> 
> -    /* early return if we only have the aio_notify() fd */
> -    if (ctx->pollfds->len == 1) {
> -        return progress;
> -    }
> -
>     /* wait until next event */
>     ret = qemu_poll_ns((GPollFD *)ctx->pollfds->data,
>                          ctx->pollfds->len,
> diff --git a/aio-win32.c b/aio-win32.c
> index f9cfbb7..23f4e5b 100644
> --- a/aio-win32.c
> +++ b/aio-win32.c
> @@ -161,11 +161,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
> 
>     ctx->walking_handlers--;
> 
> -    /* early return if we only have the aio_notify() fd */
> -    if (count == 1) {
> -        return progress;
> -    }
> -
>     /* wait until next event */
>     while (count > 0) {
>         int ret;
> diff --git a/tests/test-aio.c b/tests/test-aio.c
> index c4fe0fc..592721e 100644
> --- a/tests/test-aio.c
> +++ b/tests/test-aio.c
> @@ -195,7 +195,6 @@ static void test_bh_delete_from_cb(void)
>     g_assert(data1.bh == NULL);
> 
>     g_assert(!aio_poll(ctx, false));
> -    g_assert(!aio_poll(ctx, true));
> }
> 
> static void test_bh_delete_from_cb_many(void)
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Alex Bligh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-25 13:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-25 12:15 [Qemu-devel] [PATCH 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-09-25 12:15 ` [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
2013-09-25 13:32   ` Alex Bligh
2013-09-25 12:15 ` [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-09-25 13:32   ` Alex Bligh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).