From nobody Tue Apr 22 07:07:11 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 Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499448433587240.9513675567042; Fri, 7 Jul 2017 10:27:13 -0700 (PDT) Received: from localhost ([::1]:57787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>) id 1dTX28-0003rL-73 for importer@patchew.org; Fri, 07 Jul 2017 13:27:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1dTWl9-0004ws-0n for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1dTWl7-0007qk-Kr for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1dTWl4-0007nl-9U; Fri, 07 Jul 2017 13:09:34 -0400 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 57F89C0467C5; Fri, 7 Jul 2017 17:09:33 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7015361F23; Fri, 7 Jul 2017 17:09:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57F89C0467C5 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 57F89C0467C5 From: Kevin Wolf <kwolf@redhat.com> To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:35 +0200 Message-Id: <1499447335-6125-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@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.31]); Fri, 07 Jul 2017 17:09:33 +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] [PULL 020/100] blockjob: Track job ratelimits via bytes, not sectors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org> X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake <eblake@redhat.com> The user interface specifies job rate limits in bytes/second. It's pointless to have our internal representation track things in sectors/second, particularly since we want to move away from sector-based interfaces. Fix up a doc typo found while verifying that the ratelimit code handles the scaling difference. Repetition of expressions like 'n * BDRV_SECTOR_SIZE' will be cleaned up later when functions are converted to iterate over images by bytes rather than by sectors. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- block/backup.c | 5 +++-- block/commit.c | 5 +++-- block/mirror.c | 13 +++++++------ block/stream.c | 5 +++-- include/qemu/ratelimit.h | 3 ++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/block/backup.c b/block/backup.c index 5387fbd..9ca1d8e 100644 --- a/block/backup.c +++ b/block/backup.c @@ -208,7 +208,7 @@ static void backup_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret) @@ -359,7 +359,8 @@ static bool coroutine_fn yield_and_check(BackupBlockJob= *job) */ if (job->common.speed) { uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, - job->sectors_read); + job->sectors_read * + BDRV_SECTOR_SIZE); job->sectors_read =3D 0; block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, delay_ns); } else { diff --git a/block/commit.c b/block/commit.c index 524bd54..6993994 100644 --- a/block/commit.c +++ b/block/commit.c @@ -209,7 +209,8 @@ static void coroutine_fn commit_run(void *opaque) s->common.offset +=3D n * BDRV_SECTOR_SIZE; =20 if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->limit, + n * BDRV_SECTOR_SIZE); } } =20 @@ -231,7 +232,7 @@ static void commit_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static const BlockJobDriver commit_job_driver =3D { diff --git a/block/mirror.c b/block/mirror.c index 61a862d..eb27efc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -396,7 +396,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) bitmap_set(s->in_flight_bitmap, sector_num / sectors_per_chunk, nb_chu= nks); while (nb_chunks > 0 && sector_num < end) { int64_t ret; - int io_sectors, io_sectors_acct; + int io_sectors; + int64_t io_bytes_acct; BlockDriverState *file; enum MirrorMethod { MIRROR_METHOD_COPY, @@ -444,16 +445,16 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) switch (mirror_method) { case MIRROR_METHOD_COPY: io_sectors =3D mirror_do_read(s, sector_num, io_sectors); - io_sectors_acct =3D io_sectors; + io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: mirror_do_zero_or_discard(s, sector_num, io_sectors, mirror_method =3D=3D MIRROR_METHOD_D= ISCARD); if (write_zeroes_ok) { - io_sectors_acct =3D 0; + io_bytes_acct =3D 0; } else { - io_sectors_acct =3D io_sectors; + io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; } break; default: @@ -463,7 +464,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) sector_num +=3D io_sectors; nb_chunks -=3D DIV_ROUND_UP(io_sectors, sectors_per_chunk); if (s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, io_sectors_a= cct); + delay_ns =3D ratelimit_calculate_delay(&s->limit, io_bytes_acc= t); } } return delay_ns; @@ -929,7 +930,7 @@ static void mirror_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static void mirror_complete(BlockJob *job, Error **errp) diff --git a/block/stream.c b/block/stream.c index 52d329f..29273a5 100644 --- a/block/stream.c +++ b/block/stream.c @@ -191,7 +191,8 @@ static void coroutine_fn stream_run(void *opaque) /* Publish progress */ s->common.offset +=3D n * BDRV_SECTOR_SIZE; if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->limit, + n * BDRV_SECTOR_SIZE); } } =20 @@ -220,7 +221,7 @@ static void stream_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static const BlockJobDriver stream_job_driver =3D { diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h index 8da1232..8dece48 100644 --- a/include/qemu/ratelimit.h +++ b/include/qemu/ratelimit.h @@ -24,7 +24,8 @@ typedef struct { =20 /** Calculate and return delay for next request in ns * - * Record that we sent @p n data units. If we may send more data units + * Record that we sent @n data units (where @n matches the scale chosen + * during ratelimit_set_speed). If we may send more data units * in the current time slice, return 0 (i.e. no delay). Otherwise * return the amount of time (in ns) until the start of the next time * slice that will permit sending the next chunk of data. --=20 1.8.3.1