All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergio Lopez <slp@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@gmail.com>,
	Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 for-4.0?] aio-posix: ensure poll mode is left when aio_notify is called
Date: Wed, 10 Apr 2019 09:56:57 +0200	[thread overview]
Message-ID: <87k1g2i986.fsf@redhat.com> (raw)
In-Reply-To: <20190409122823.12416-1-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3138 bytes --]


Paolo Bonzini <pbonzini@redhat.com> writes:

> With aio=thread, adaptive polling makes latency worse rather than
> better, because it delays the execution of the ThreadPool's
> completion bottom half.
>
> event_notifier_poll() does run while polling, detecting that
> a bottom half was scheduled by a worker thread, but because
> ctx->notifier is explicitly ignored in run_poll_handlers_once(),
> scheduling the BH does not count as making progress and
> run_poll_handlers() keeps running.  Fix this by recomputing
> the deadline after *timeout could have changed.
>
> With this change, ThreadPool still cannot participate in polling
> but at least it does not suffer from extra latency.
>
> Reported-by: Sergio Lopez <slp@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@gmail.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: qemu-block@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Message-Id: <1553692145-86728-1-git-send-email-pbonzini@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>         v1->v2: use qemu_soonest_timeout to handle timeout == -1
>  util/aio-posix.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/util/aio-posix.c b/util/aio-posix.c
> index 6fbfa7924f..db11021287 100644
> --- a/util/aio-posix.c
> +++ b/util/aio-posix.c
> @@ -519,6 +519,10 @@ static bool run_poll_handlers_once(AioContext *ctx, int64_t *timeout)
>          if (!node->deleted && node->io_poll &&
>              aio_node_check(ctx, node->is_external) &&
>              node->io_poll(node->opaque)) {
> +            /*
> +             * Polling was successful, exit try_poll_mode immediately
> +             * to adjust the next polling time.
> +             */
>              *timeout = 0;
>              if (node->opaque != &ctx->notifier) {
>                  progress = true;
> @@ -558,8 +562,9 @@ static bool run_poll_handlers(AioContext *ctx, int64_t max_ns, int64_t *timeout)
>      do {
>          progress = run_poll_handlers_once(ctx, timeout);
>          elapsed_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_time;
> -    } while (!progress && elapsed_time < max_ns
> -             && !atomic_read(&ctx->poll_disable_cnt));
> +        max_ns = qemu_soonest_timeout(*timeout, max_ns);
> +        assert(!(max_ns && progress));
> +    } while (elapsed_time < max_ns && !atomic_read(&ctx->poll_disable_cnt));
>  
>      /* If time has passed with no successful polling, adjust *timeout to
>       * keep the same ending time.
> @@ -585,8 +590,7 @@ static bool run_poll_handlers(AioContext *ctx, int64_t max_ns, int64_t *timeout)
>   */
>  static bool try_poll_mode(AioContext *ctx, int64_t *timeout)
>  {
> -    /* See qemu_soonest_timeout() uint64_t hack */
> -    int64_t max_ns = MIN((uint64_t)*timeout, (uint64_t)ctx->poll_ns);
> +    int64_t max_ns = qemu_soonest_timeout(*timeout, ctx->poll_ns);
>  
>      if (max_ns && !atomic_read(&ctx->poll_disable_cnt)) {
>          poll_set_started(ctx, true);

Thanks, this one does the trick.

Reviewed-by: Sergio Lopez <slp@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Sergio Lopez <slp@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 for-4.0?] aio-posix: ensure poll mode is left when aio_notify is called
Date: Wed, 10 Apr 2019 09:56:57 +0200	[thread overview]
Message-ID: <87k1g2i986.fsf@redhat.com> (raw)
Message-ID: <20190410075657.KQ4txSYyCOoRpduBlxPBpL-1gzkP8G3DjKV4M2NC1r0@z> (raw)
In-Reply-To: <20190409122823.12416-1-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3138 bytes --]


Paolo Bonzini <pbonzini@redhat.com> writes:

> With aio=thread, adaptive polling makes latency worse rather than
> better, because it delays the execution of the ThreadPool's
> completion bottom half.
>
> event_notifier_poll() does run while polling, detecting that
> a bottom half was scheduled by a worker thread, but because
> ctx->notifier is explicitly ignored in run_poll_handlers_once(),
> scheduling the BH does not count as making progress and
> run_poll_handlers() keeps running.  Fix this by recomputing
> the deadline after *timeout could have changed.
>
> With this change, ThreadPool still cannot participate in polling
> but at least it does not suffer from extra latency.
>
> Reported-by: Sergio Lopez <slp@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@gmail.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: qemu-block@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Message-Id: <1553692145-86728-1-git-send-email-pbonzini@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>         v1->v2: use qemu_soonest_timeout to handle timeout == -1
>  util/aio-posix.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/util/aio-posix.c b/util/aio-posix.c
> index 6fbfa7924f..db11021287 100644
> --- a/util/aio-posix.c
> +++ b/util/aio-posix.c
> @@ -519,6 +519,10 @@ static bool run_poll_handlers_once(AioContext *ctx, int64_t *timeout)
>          if (!node->deleted && node->io_poll &&
>              aio_node_check(ctx, node->is_external) &&
>              node->io_poll(node->opaque)) {
> +            /*
> +             * Polling was successful, exit try_poll_mode immediately
> +             * to adjust the next polling time.
> +             */
>              *timeout = 0;
>              if (node->opaque != &ctx->notifier) {
>                  progress = true;
> @@ -558,8 +562,9 @@ static bool run_poll_handlers(AioContext *ctx, int64_t max_ns, int64_t *timeout)
>      do {
>          progress = run_poll_handlers_once(ctx, timeout);
>          elapsed_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_time;
> -    } while (!progress && elapsed_time < max_ns
> -             && !atomic_read(&ctx->poll_disable_cnt));
> +        max_ns = qemu_soonest_timeout(*timeout, max_ns);
> +        assert(!(max_ns && progress));
> +    } while (elapsed_time < max_ns && !atomic_read(&ctx->poll_disable_cnt));
>  
>      /* If time has passed with no successful polling, adjust *timeout to
>       * keep the same ending time.
> @@ -585,8 +590,7 @@ static bool run_poll_handlers(AioContext *ctx, int64_t max_ns, int64_t *timeout)
>   */
>  static bool try_poll_mode(AioContext *ctx, int64_t *timeout)
>  {
> -    /* See qemu_soonest_timeout() uint64_t hack */
> -    int64_t max_ns = MIN((uint64_t)*timeout, (uint64_t)ctx->poll_ns);
> +    int64_t max_ns = qemu_soonest_timeout(*timeout, ctx->poll_ns);
>  
>      if (max_ns && !atomic_read(&ctx->poll_disable_cnt)) {
>          poll_set_started(ctx, true);

Thanks, this one does the trick.

Reviewed-by: Sergio Lopez <slp@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2019-04-10  7:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 12:28 [Qemu-devel] [PATCH v2 for-4.0?] aio-posix: ensure poll mode is left when aio_notify is called Paolo Bonzini
2019-04-09 12:28 ` Paolo Bonzini
2019-04-10  7:56 ` Sergio Lopez [this message]
2019-04-10  7:56   ` Sergio Lopez
2019-04-10 14:57 ` Stefan Hajnoczi
2019-04-10 14:57   ` Stefan Hajnoczi
2019-04-10 15:03 ` Stefan Hajnoczi
2019-04-10 15:03   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k1g2i986.fsf@redhat.com \
    --to=slp@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.