blockjob: Don't sleep too short
PATCH 1/1 blockjob: Don't sleep too short
block_job_sleep_ns is called by block job coroutines to yield the execution to VCPU threads and monitor etc. It is pointless to sleep for 0 or a few nanoseconds, because that equals to a "yield + enter" with no intermission in between (the timer fires immediately in the same iteration of event loop), which means other code still doesn't get a fair share of main loop / BQL.
Trim the sleep duration with a minimum value.
--- blockjob.c | 2 ++ include/block/blockjob.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
blockjob.c +2 -0
@@ -238,6 +238,8 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)return ; } + ns =MAX (ns,BLOCK_JOB_SLEEP_NS_MIN ); + job->busy = false;if (block_job_is_paused (job)) {qemu_coroutine_yield ();
include/block/blockjob.h +3 -1
@@ -146,11 +146,13 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp); +#define BLOCK_JOB_SLEEP_NS_MIN 10000000L/** * block_job_sleep_ns: * @job: The job that calls the function. * @clock: The clock to sleep on. -* @ns: How many nanoseconds to stop for. +* @ns: How many nanoseconds to stop for. It sleeps at least +* for BLOCK_JOB_SLEEP_NS_MIN ns, even if a smaller value is specified. * * Put the job to sleep (assuming that it wasn't canceled) for @ns * nanoseconds. Canceling the job will interrupt the wait immediately.
Signature · 1 line
2.4.3
Works fine here,
Thanks !
----- Mail original -----
De: "Fam Zheng" <[email protected]>
À: "qemu-devel" <[email protected]>
Cc: "Kevin Wolf" <[email protected]>, "Jeff Cody" <[email protected]>, [email protected], [email protected], [email protected], "aderumier" <[email protected]>, "stefanha" <[email protected]>, "pbonzini" <[email protected]> Envoyé: Lundi 6 Juillet 2015 05:28:11
Objet: [PATCH] blockjob: Don't sleep too short
block_job_sleep_ns is called by block job coroutines to yield the execution to VCPU threads and monitor etc. It is pointless to sleep for 0 or a few nanoseconds, because that equals to a "yield + enter" with no intermission in between (the timer fires immediately in the same iteration of event loop), which means other code still doesn't get a fair share of main loop / BQL.
Trim the sleep duration with a minimum value.
---blockjob.c | 2 ++include/block/blockjob.h | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
blockjob.c +0 -0
@@ -238,6 +238,8 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
return;
}
+ ns = MAX(ns, BLOCK_JOB_SLEEP_NS_MIN);
+job->busy = false;
if (block_job_is_paused(job)) {qemu_coroutine_yield();
include/block/blockjob.h +0 -0
@@ -146,11 +146,13 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockCompletionFunc *cb,
void *opaque, Error **errp);
+#define BLOCK_JOB_SLEEP_NS_MIN 10000000L
/**
* block_job_sleep_ns:
* @job: The job that calls the function.
* @clock: The clock to sleep on.
- * @ns: How many nanoseconds to stop for.
+ * @ns: How many nanoseconds to stop for. It sleeps at least
+ * for BLOCK_JOB_SLEEP_NS_MIN ns, even if a smaller value is specified. *
* Put the job to sleep (assuming that it wasn't canceled) for @ns
* nanoseconds. Canceling the job will interrupt the wait immediately.
Signature · 1 line
2.4.3
include/block/blockjob.h void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, · line 149
Quoted 9 lines · Fam Zheng
include/block/blockjob.h +1
-0@@ -146,11 +146,13 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp); +#define BLOCK_JOB_SLEEP_NS_MIN 10000000L
Please introduce a block_job_relax_cpu() or similar function instead of changing block_job_sleep_ns() to 10 millisecond minimum. This change would make legitimate <10 ms users imprecise!