From patchwork Thu Dec 14 00:59:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 848339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yxwMR5pb5z9t3m for ; Thu, 14 Dec 2017 12:04:51 +1100 (AEDT) Received: from localhost ([::1]:38593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHxB-0004eK-UR for incoming@patchwork.ozlabs.org; Wed, 13 Dec 2017 20:04:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsv-0001ZB-Io for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePHsu-00035j-CX for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHsq-00032E-A1; Wed, 13 Dec 2017 20:00:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62350820F2; Thu, 14 Dec 2017 01:00:19 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91ED517122; Thu, 14 Dec 2017 01:00:18 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:50 -0500 Message-Id: <20171214005953.8898-5-jsnow@redhat.com> In-Reply-To: <20171214005953.8898-1-jsnow@redhat.com> References: <20171214005953.8898-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 14 Dec 2017 01:00:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/7] blockjob: allow block_job_throttle to take delay_ns X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of only sleeping for 0ms when we've hit a timeout, optionally take a longer more explicit delay_ns that always forces the sleep. Signed-off-by: John Snow --- block/mirror.c | 4 ++-- blockjob.c | 9 ++++----- include/block/blockjob_int.h | 10 +++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 60b52cfb19..81450e6ac4 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -610,7 +610,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) int bytes = MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); - block_job_throttle(&s->common); + block_job_throttle(&s->common, 0); if (block_job_is_cancelled(&s->common)) { s->initial_zeroing_ongoing = false; @@ -638,7 +638,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) int bytes = MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); - block_job_throttle(&s->common); + block_job_throttle(&s->common, 0); if (block_job_is_cancelled(&s->common)) { return 0; diff --git a/blockjob.c b/blockjob.c index 8d0c89a813..b0868c3ed5 100644 --- a/blockjob.c +++ b/blockjob.c @@ -882,12 +882,11 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } -void block_job_throttle(BlockJob *job) +void block_job_throttle(BlockJob *job, int64_t delay_ns) { - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - - if (now - job->last_yield_ns > SLICE_TIME) { - block_job_sleep_ns(job, 0); + if (delay_ns || (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - \ + job->last_yield_ns > SLICE_TIME)) { + block_job_sleep_ns(job, delay_ns); } else { block_job_pause_point(job); } diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 1a771b1e2e..8faec3f5e0 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -160,11 +160,15 @@ void block_job_yield(BlockJob *job); /** * block_job_throttle: * @job: The job that calls the function. + * @delay_ns: The amount of time to sleep for * - * Yield if it has been SLICE_TIME nanoseconds since the last yield. - * Otherwise, check if we need to pause (and update the yield counter). + * Sleep for delay_ns nanoseconds. + * + * If delay_ns is 0, yield if it has been SLICE_TIME + * nanoseconds since the last yield. Otherwise, check + * if we need to yield for a pause event. */ -void block_job_throttle(BlockJob *job); +void block_job_throttle(BlockJob *job, int64_t delay_ns); /** * block_job_pause_all: