coroutine: Fix documentation of co_aio_sleep_ns()
PATCH 1/1 coroutine: Fix documentation of co_aio_sleep_ns()
co_sleep_ns() was removed in commit 0b9caf9b, leaving behind a stale comment. Update the documentation to match the current usage of this function.
--- include/qemu/coroutine.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/qemu/coroutine.h +5 -2
@@ -262,8 +262,11 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);/** * Yield the coroutine for a given duration * -* Behaves similarly to co_sleep_ns(), but the sleeping coroutine will be -* resumed when using aio_poll(). +* This function uses timers and hence needs to know the event loop +* (#AioContext) to place the timer on. 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. */ void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,int64_t ns);
Signature · 1 line
2.13.6
Hi
Quoted 16 lines · Eric Blake
co_sleep_ns()was removed in commit0b9caf9b, leaving behind a stale comment. Update the documentation to match the current usage of this function.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Eric Blake <[email protected]>--- include/qemu/coroutine.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)include/qemu/coroutine.h +0
-0@@ -262,8 +262,11 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);/**
include/qemu/coroutine.h void qemu_co_rwlock_unlock(CoRwlock *lock); · line 270
Quoted 10 lines
include/qemu/coroutine.h +5
-2* Yield the coroutine for a given duration * -* Behaves similarly to co_sleep_ns(), but the sleeping coroutine will be -* resumed when using aio_poll(). +* This function uses timers and hence needs to know the event loop +* (#AioContext) to place the timer on. 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. */
comment seems correct to me,
Quoted 6 lines
include/qemu/coroutine.h +0
-1void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,int64_t ns); --2.13.6
Signature · 1 line
Marc-André Lureau
Quoted 15 lines · Eric Blake
co_sleep_ns()was removed in commit0b9caf9b, leaving behind a stale comment. Update the documentation to match the current usage of this function.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Eric Blake <[email protected]>--- include/qemu/coroutine.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)include/qemu/coroutine.h +0
-0
include/qemu/coroutine.h void qemu_co_rwlock_unlock(CoRwlock *lock); · line 269
Quoted 10 lines
include/qemu/coroutine.h +5
-2@@ -262,8 +262,11 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);/** * Yield the coroutine for a given duration * -* Behaves similarly to co_sleep_ns(), but the sleeping coroutine will be -* resumed when using aio_poll(). +* This function uses timers and hence needs to know the event loop +* (#AioContext) to place the timer on. 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.
Quoted 10 lines · Stefan Hajnoczi
Quoted 4 lines
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//.
Paolo
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi
Quoted 4 lines
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.
Quoted 8 lines
Quoted 6 lines
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().
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 15 lines · Eric Blake
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi
Quoted 4 lines
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.Quoted 8 lines
Quoted 6 lines
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//.
Quoted 7 lines
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
Quoted 23 lines · Stefan Hajnoczi
Quoted 5 lines
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); }
Quoted 3 lines
I don't see a reason for the caller to pass in an AioContext.
Any objections? Will send a patch if this is okay.
Makes sense to me.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 41 lines · Stefan Hajnoczi
Quoted 15 lines · Eric Blake
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Stefan Hajnoczi
Quoted 4 lines
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.Quoted 8 lines
Quoted 6 lines
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//.
Quoted 7 lines
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); }
Quoted 1 line
I don't see a reason for the caller to pass in an AioContext.
That should work, yes.
Paolo
Quoted 5 lines
Any objections? Will send a patch if this is okay.
Stefan