From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBx50-000893-NR for qemu-devel@nongnu.org; Sun, 05 Jul 2015 23:28:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBx4z-0005DG-PH for qemu-devel@nongnu.org; Sun, 05 Jul 2015 23:28:26 -0400 From: Fam Zheng Date: Mon, 6 Jul 2015 11:28:11 +0800 Message-Id: <1436153291-13908-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] blockjob: Don't sleep too short List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-block@nongnu.org, Jeff Cody , aderumier@odiso.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, jsnow@redhat.com 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. Reported-by: Alexandre DERUMIER Signed-off-by: Fam Zheng --- blockjob.c | 2 ++ include/block/blockjob.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/blockjob.c b/blockjob.c index ec46fad..b17ed1f 100644 --- a/blockjob.c +++ b/blockjob.c @@ -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(); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 57d8ef1..3deb731 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -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. -- 2.4.3