From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: kwolf@redhat.com, den@openvz.org, armbru@redhat.com,
stefanha@redhat.com, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 5/7] qemu-coroutine-sleep: introduce qemu_co_sleep_wake
Date: Thu, 6 Jun 2019 21:48:47 -0500 [thread overview]
Message-ID: <834d25f9-23c9-287c-0599-905a7669a6c5@redhat.com> (raw)
In-Reply-To: <20190411172709.205032-6-vsementsov@virtuozzo.com>
[-- Attachment #1.1: Type: text/plain, Size: 2985 bytes --]
On 4/11/19 12:27 PM, Vladimir Sementsov-Ogievskiy wrote:
> Introduce a function to gracefully wake-up a coroutine, sleeping in
> qemu_co_sleep_ns() sleep.
Maybe:
Introduce a function to gracefully short-circuit the remainder of the
delay for a coroutine sleeping in qemu_co_sleep_ns().
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> include/qemu/coroutine.h | 6 ++++++
> util/qemu-coroutine-sleep.c | 20 ++++++++++++++++----
> 2 files changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
> index 9801e7f5a4..ec765c26f0 100644
> --- a/include/qemu/coroutine.h
> +++ b/include/qemu/coroutine.h
> @@ -278,6 +278,12 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);
> */
> void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns);
>
> +/*
> + * Wake a coroutine if it is sleeping by qemu_co_sleep_ns. Timer will be
> + * deleted.
Maybe:
Wake a coroutine if it is sleeping in qemu_co_sleep_ns, and delete the
timer.
> +++ b/util/qemu-coroutine-sleep.c
> @@ -17,13 +17,24 @@
> #include "qemu/timer.h"
> #include "block/aio.h"
>
> +const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
> +
> +void qemu_co_sleep_wake(Coroutine *co)
> +{
> + /* Write of schedule protected by barrier write in aio_co_schedule */
> + const char *scheduled = atomic_cmpxchg(&co->scheduled,
> + qemu_co_sleep_ns__scheduled, NULL);
> +
> + if (scheduled == qemu_co_sleep_ns__scheduled) {
> + aio_co_wake(co);
> + }
> +}
> +
> static void co_sleep_cb(void *opaque)
> {
> Coroutine *co = opaque;
>
> - /* Write of schedule protected by barrier write in aio_co_schedule */
> - atomic_set(&co->scheduled, NULL);
> - aio_co_wake(co);
> + qemu_co_sleep_wake(co);
> }
>
> void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
> @@ -32,7 +43,8 @@ void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
> QEMUTimer *ts;
> Coroutine *co = qemu_coroutine_self();
>
> - const char *scheduled = atomic_cmpxchg(&co->scheduled, NULL, __func__);
> + const char *scheduled = atomic_cmpxchg(&co->scheduled, NULL,
> + qemu_co_sleep_ns__scheduled);
> if (scheduled) {
> fprintf(stderr,
> "%s: Co-routine was already scheduled in '%s'\n",
>
Here, I'd rather get an additional review from anyone more familiar with
coroutine sleeps. I'm guessing that your intent is to request a maximum
timeout for a given operation to complete in, but to leave the sleep
loop early if the operation completes earlier. I don't know if any
existing coroutine code can be used to express that same idea.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-06-07 2:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-11 17:27 [Qemu-devel] [PATCH v6 0/7] NBD reconnect Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 1/7] block/nbd-client: split connection_co start out of nbd_client_connect Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 2:32 ` Eric Blake
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 2/7] block/nbd-client: use non-blocking io channel for nbd negotiation Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 2:34 ` Eric Blake
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 3/7] block/nbd-client: move from quit to state Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 2:38 ` Eric Blake
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 4/7] block/nbd: add cmdline and qapi parameter reconnect-delay Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 2:43 ` Eric Blake
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 5/7] qemu-coroutine-sleep: introduce qemu_co_sleep_wake Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 2:48 ` Eric Blake [this message]
2019-06-07 7:57 ` Kevin Wolf
2019-06-07 11:18 ` Vladimir Sementsov-Ogievskiy
2019-06-07 13:02 ` Kevin Wolf
2019-06-07 15:01 ` Vladimir Sementsov-Ogievskiy
2019-06-07 15:52 ` Vladimir Sementsov-Ogievskiy
2019-06-07 17:10 ` Vladimir Sementsov-Ogievskiy
2019-06-11 8:53 ` Kevin Wolf
2019-06-11 10:28 ` Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 6/7] block/nbd-client: nbd reconnect Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 3:17 ` Eric Blake
2019-06-07 8:06 ` Kevin Wolf
2019-06-07 12:02 ` Vladimir Sementsov-Ogievskiy
2019-06-07 13:26 ` Kevin Wolf
2019-06-07 14:27 ` Vladimir Sementsov-Ogievskiy
2019-06-07 14:54 ` Kevin Wolf
2019-06-07 11:44 ` Vladimir Sementsov-Ogievskiy
2019-06-10 12:38 ` Vladimir Sementsov-Ogievskiy
2019-06-10 13:29 ` Vladimir Sementsov-Ogievskiy
2019-06-10 14:33 ` Eric Blake
2019-04-11 17:27 ` [Qemu-devel] [PATCH v6 7/7] iotests: test " Vladimir Sementsov-Ogievskiy
2019-04-11 17:27 ` Vladimir Sementsov-Ogievskiy
2019-04-30 17:50 ` [Qemu-devel] [PATCH v6 0/7] NBD reconnect Vladimir Sementsov-Ogievskiy
2019-04-30 17:50 ` Vladimir Sementsov-Ogievskiy
2019-05-15 9:03 ` [Qemu-devel] ping " Vladimir Sementsov-Ogievskiy
2019-06-04 12:42 ` Vladimir Sementsov-Ogievskiy
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=834d25f9-23c9-287c-0599-905a7669a6c5@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.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 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).