From: Stefan Hajnoczi <stefanha@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
qemu-trivial@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] coroutine: Fix documentation of co_aio_sleep_ns()
Date: Wed, 8 Nov 2017 17:36:21 +0000 [thread overview]
Message-ID: <20171108173621.GB8403@stefanha-x1.localdomain> (raw)
In-Reply-To: <061e94f4-602e-3ff3-0f20-d3915e7a5550@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1845 bytes --]
On Wed, Nov 08, 2017 at 09:57:47AM -0600, Eric Blake wrote:
> On 11/08/2017 09:47 AM, Paolo Bonzini wrote:
> > On 08/11/2017 16:42, Stefan Hajnoczi wrote:
> >>> In any case, co_aio_sleep_ns()
> >>> + * does not affect the #AioContext where the current coroutine is running,
> >>> + * as the coroutine will restart on the same #AioContext that it is
> >>> + * running on.
> >> I cannot parse the second sentence. What does "affecting" an AioContext
> >> mean? Does "where the current coroutine is running" simply mean "the
> >> caller"?
> >>
> >> What is it trying to say? My guess is: the caller will be resumed in
> >> the current AioContext, not the timer's AioContext.
> >
> > Yes, that is the intended meaning. Perhaps just s/current//.
>
> How about:
>
> This function uses timers and hence needs to know the event loop
> (#AioContext) to place the timer on. After the time elapses, the
> current coroutine will restart with the same #AioContext it is currently
> running in, even if that is different than the timer context passed to
> co_aio_sleep_ns().
These complicated semantics are a clue that the API should be
simplified. QEMU has changed since this function was first introduced.
Now we can do the following:
void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
{
AioContext *ctx = qemu_get_current_aio_context();
CoSleepCB sleep_cb = {
.co = qemu_coroutine_self(),
};
sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb);
timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns);
qemu_coroutine_yield();
timer_del(sleep_cb.ts);
timer_free(sleep_cb.ts);
}
I don't see a reason for the caller to pass in an AioContext.
Any objections? Will send a patch if this is okay.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2017-11-08 17:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-07 22:37 [Qemu-devel] [PATCH] coroutine: Fix documentation of co_aio_sleep_ns() Eric Blake
2017-11-08 13:39 ` Marc-André Lureau
2017-11-08 15:42 ` Stefan Hajnoczi
2017-11-08 15:47 ` Paolo Bonzini
2017-11-08 15:57 ` Eric Blake
2017-11-08 17:36 ` Stefan Hajnoczi [this message]
2017-11-08 17:42 ` Eric Blake
2017-11-08 17:44 ` Paolo Bonzini
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=20171108173621.GB8403@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.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).