Received: from eggs.gnu.org ([2001:4830:134:3::10]:45511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ydz1A-0005QQ-Pd for qemu-devel@nongnu.org; Fri, 03 Apr 2015 06:40:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ydz14-00015n-7x for qemu-devel@nongnu.org; Fri, 03 Apr 2015 06:40:04 -0400 From: Fam Zheng Date: Fri, 3 Apr 2015 18:39:00 +0800 Message-Id: <1428057542-24310-2-git-send-email-famz@redhat.com> In-Reply-To: <1428057542-24310-1-git-send-email-famz@redhat.com> References: <1428057542-24310-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] blockjob: Don't sleep meaninglessly short List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , berto@igalia.com, qemu-block@nongnu.org, Jeff Cody , Stefan Hajnoczi , pbonzini@redhat.com A timer that will immediately wake the job up spoils the point to call block_job_sleep_ns in the first place - bdrv_drain_all has to return. Let's sleep longer to let aio_poll return, before the job resumes and submitts more IO requests. Signed-off-by: Fam Zheng --- blockjob.c | 3 ++- include/block/blockjob.h | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/blockjob.c b/blockjob.c index ba2255d..f04a16c 100644 --- a/blockjob.c +++ b/blockjob.c @@ -232,7 +232,8 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns) if (block_job_is_paused(job)) { qemu_coroutine_yield(); } else { - co_aio_sleep_ns(bdrv_get_aio_context(job->bs), type, ns); + co_aio_sleep_ns(bdrv_get_aio_context(job->bs), type, + MAX(ns, BLOCK_JOB_SLEEP_MIN)); } job->busy = true; } diff --git a/include/block/blockjob.h b/include/block/blockjob.h index b6d4ebb..97835aa 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -140,11 +140,15 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp); +#define BLOCK_JOB_SLEEP_MIN 100000LL /** * 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 would be meaningless if it is + * very short, because the timer to wake up the job could fire right very + * quickly even before anything else is done. Hence, a minimum, + * BLOCK_JOB_SLEEP_MIN, is defined. * * Put the job to sleep (assuming that it wasn't canceled) for @ns * nanoseconds. Canceling the job will interrupt the wait immediately. -- 2.1.0