Received: from eggs.gnu.org ([2001:4830:134:3::10]:55314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD2oj-0006xi-5O for qemu-devel@nongnu.org; Wed, 08 Jul 2015 23:48:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZD2oi-0004eY-8c for qemu-devel@nongnu.org; Wed, 08 Jul 2015 23:48:09 -0400 From: Fam Zheng Date: Thu, 9 Jul 2015 11:47:56 +0800 Message-Id: <1436413678-7114-2-git-send-email-famz@redhat.com> In-Reply-To: <1436413678-7114-1-git-send-email-famz@redhat.com> References: <1436413678-7114-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] blockjob: Introduce block_job_relax_cpu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Jeff Cody , qemu-block@nongnu.org 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. Introduce block_job_relax_cpu which will at least for BLOCK_JOB_RELAX_CPU_NS. Existing block_job_sleep_ns(job, 0) callers can be replaced by this later. Reported-by: Alexandre DERUMIER Signed-off-by: Fam Zheng --- include/block/blockjob.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 57d8ef1..53ac4f4 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -157,6 +157,22 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, */ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns); +#define BLOCK_JOB_RELAX_CPU_NS 10000000L + +/** + * block_job_relax_cpu: + * @job: The job that calls the function. + * + * Sleep a little to avoid intensive cpu time occupation. Block jobs should + * call this or block_job_sleep_ns (for more precision, but note that 0 ns is + * usually not enought) periodically, otherwise the QMP and VCPU could starve + * on CPU and/or BQL. + */ +static inline void block_job_relax_cpu(BlockJob *job) +{ + return block_job_sleep_ns(job, QEMU_CLOCK_REALTIME, BLOCK_JOB_RELAX_CPU_NS); +} + /** * block_job_yield: * @job: The job that calls the function. -- 2.4.3