From nobody Wed Oct 29 09:08:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524583849678611.0140184604726; Tue, 24 Apr 2018 08:30:49 -0700 (PDT) Received: from localhost ([::1]:59110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAzty-0003YP-Qs for importer@patchew.org; Tue, 24 Apr 2018 11:30:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAzoz-0007k5-1G for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:25:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAzox-0007im-Gu for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:25:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50732 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAzou-0007aV-6X; Tue, 24 Apr 2018 11:25:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFEAFC934A; Tue, 24 Apr 2018 15:25:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-100.ams2.redhat.com [10.36.117.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0D42202342F; Tue, 24 Apr 2018 15:25:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 24 Apr 2018 17:24:46 +0200 Message-Id: <20180424152515.25664-5-kwolf@redhat.com> In-Reply-To: <20180424152515.25664-1-kwolf@redhat.com> References: <20180424152515.25664-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 24 Apr 2018 15:25:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 24 Apr 2018 15:25:27 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC PATCH 04/33] blockjob: Introduce block_job_ratelimit_get_delay() 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, jsnow@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This gets us rid of more direct accesses to BlockJob fields from the job drivers. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/blockjob_int.h | 8 ++++++++ block/backup.c | 18 +++++++----------- block/commit.c | 4 ++-- block/mirror.c | 5 +---- block/stream.c | 4 ++-- blockjob.c | 9 +++++++++ 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 870bd346a8..d26115207b 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -166,6 +166,14 @@ void block_job_sleep_ns(BlockJob *job, int64_t ns); void block_job_yield(BlockJob *job); =20 /** + * block_job_ratelimit_get_delay: + * + * Calculate and return delay for the next request in ns. See the docuemnt= ation + * of ratelimit_calculate_delay() for details. + */ +int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n); + +/** * block_job_pause_all: * * Asynchronously pause all jobs. diff --git a/block/backup.c b/block/backup.c index 8468fd9f94..3f3ec6e408 100644 --- a/block/backup.c +++ b/block/backup.c @@ -325,21 +325,17 @@ static void backup_complete(BlockJob *job, void *opaq= ue) =20 static bool coroutine_fn yield_and_check(BackupBlockJob *job) { + uint64_t delay_ns; + if (block_job_is_cancelled(&job->common)) { return true; } =20 - /* we need to yield so that bdrv_drain_all() returns. - * (without, VM does not reboot) - */ - if (job->common.speed) { - uint64_t delay_ns =3D ratelimit_calculate_delay(&job->common.limit, - job->bytes_read); - job->bytes_read =3D 0; - block_job_sleep_ns(&job->common, delay_ns); - } else { - block_job_sleep_ns(&job->common, 0); - } + /* we need to yield even for delay_ns =3D 0 so that bdrv_drain_all() r= eturns. + * (without it, the VM does not reboot) */ + delay_ns =3D block_job_ratelimit_get_delay(&job->common, job->bytes_re= ad); + job->bytes_read =3D 0; + block_job_sleep_ns(&job->common, delay_ns); =20 if (block_job_is_cancelled(&job->common)) { return true; diff --git a/block/commit.c b/block/commit.c index 46cbeaec3e..ba5df6aa0a 100644 --- a/block/commit.c +++ b/block/commit.c @@ -197,8 +197,8 @@ static void coroutine_fn commit_run(void *opaque) /* Publish progress */ block_job_progress_update(&s->common, n); =20 - if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->common.limit, n); + if (copy) { + delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); } else { delay_ns =3D 0; } diff --git a/block/mirror.c b/block/mirror.c index de495fddc4..1cbdb1e0d8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -447,10 +447,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) assert(io_bytes); offset +=3D io_bytes; nb_chunks -=3D DIV_ROUND_UP(io_bytes, s->granularity); - if (s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->common.limit, - io_bytes_acct); - } + delay_ns =3D block_job_ratelimit_get_delay(&s->common, io_bytes_ac= ct); } return delay_ns; } diff --git a/block/stream.c b/block/stream.c index 797d7c4f21..df9660d2fc 100644 --- a/block/stream.c +++ b/block/stream.c @@ -185,8 +185,8 @@ static void coroutine_fn stream_run(void *opaque) =20 /* Publish progress */ block_job_progress_update(&s->common, n); - if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->common.limit, n); + if (copy) { + delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); } else { delay_ns =3D 0; } diff --git a/blockjob.c b/blockjob.c index 9b79abc821..31130d87cc 100644 --- a/blockjob.c +++ b/blockjob.c @@ -680,6 +680,15 @@ void block_job_set_speed(BlockJob *job, int64_t speed,= Error **errp) block_job_enter_cond(job, block_job_timer_pending); } =20 +int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n) +{ + if (!job->speed) { + return 0; + } + + return ratelimit_calculate_delay(&job->limit, n); +} + void block_job_complete(BlockJob *job, Error **errp) { /* Should not be reachable via external interface for internal jobs */ --=20 2.13.6