From patchwork Mon Jul 6 10:11:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre DERUMIER X-Patchwork-Id: 491529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 01BDD140216 for ; Mon, 6 Jul 2015 20:12:26 +1000 (AEST) Received: from localhost ([::1]:49895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3Nw-0002wf-PO for incoming@patchwork.ozlabs.org; Mon, 06 Jul 2015 06:12:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3NU-0002QM-NL for qemu-devel@nongnu.org; Mon, 06 Jul 2015 06:11:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZC3NT-0007bx-S0 for qemu-devel@nongnu.org; Mon, 06 Jul 2015 06:11:56 -0400 Received: from mailpro.odiso.net ([89.248.209.98]:43571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC3NN-0007Sc-ON; Mon, 06 Jul 2015 06:11:49 -0400 Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id 1D35A40BBD893; Mon, 6 Jul 2015 12:11:48 +0200 (CEST) Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id vCpevLmhNLOF; Mon, 6 Jul 2015 12:11:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailpro.odiso.net (Postfix) with ESMTP id DE569442D907D; Mon, 6 Jul 2015 12:11:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at mailpro.odiso.com Received: from mailpro.odiso.net ([127.0.0.1]) by localhost (mailpro.odiso.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jhKCJ3ll7tLB; Mon, 6 Jul 2015 12:11:47 +0200 (CEST) Received: from mailpro.odiso.net (mailpro.odiso.net [10.1.31.112]) by mailpro.odiso.net (Postfix) with ESMTP id ABE6340BBD893; Mon, 6 Jul 2015 12:11:47 +0200 (CEST) Date: Mon, 6 Jul 2015 12:11:47 +0200 (CEST) From: Alexandre DERUMIER To: Fam Zheng Message-ID: <947457006.7135924.1436177507489.JavaMail.zimbra@oxygem.tv> In-Reply-To: <1436153291-13908-1-git-send-email-famz@redhat.com> References: <1436153291-13908-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 X-Mailer: Zimbra 8.6.0_GA_1169 (ZimbraWebClient - GC38 (Linux)/8.6.0_GA_1169) Thread-Topic: blockjob: Don't sleep too short Thread-Index: TEeERG4V+XQIVVSK3l0HvcneIL3xKQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 89.248.209.98 Cc: Kevin Wolf , qemu-block@nongnu.org, Jeff Cody , qemu-devel , mreitz@redhat.com, stefanha , pbonzini , jsnow@redhat.com Subject: Re: [Qemu-devel] [PATCH] blockjob: Don't sleep too short X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Works fine here, Thanks ! ----- Mail original ----- De: "Fam Zheng" À: "qemu-devel" Cc: "Kevin Wolf" , "Jeff Cody" , qemu-block@nongnu.org, mreitz@redhat.com, jsnow@redhat.com, "aderumier" , "stefanha" , "pbonzini" 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. 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.