From nobody Sun Feb 8 04:07:53 2026 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525883756313167.8535137921782; Wed, 9 May 2018 09:35:56 -0700 (PDT) Received: from localhost ([::1]:57560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGS4J-0003dQ-G2 for importer@patchew.org; Wed, 09 May 2018 12:35:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGRvy-0005B5-RP for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGRvx-0001VJ-Lv for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42114 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 1fGRvs-0001K6-AG; Wed, 09 May 2018 12:27:12 -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 DB795819D1D1; Wed, 9 May 2018 16:27:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D70D202342D; Wed, 9 May 2018 16:27:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:26:00 +0200 Message-Id: <20180509162637.15575-6-kwolf@redhat.com> In-Reply-To: <20180509162637.15575-1-kwolf@redhat.com> References: <20180509162637.15575-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.8]); Wed, 09 May 2018 16:27:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:27:11 +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] [PATCH 05/42] 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, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@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 Reviewed-by: John Snow Reviewed-by: Max Reitz --- 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..4d0439c51e 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 document= 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..cfdb6ecdf5 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() c= an + * return. Without a yield, the VM would 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 21eb04f1d2..350f733d0a 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 5d050e65d3..b6e27c7f80 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