From nobody Fri May 3 11:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213358216818.2832133193666; Wed, 13 Dec 2017 17:02:38 -0800 (PST) Received: from localhost ([::1]:38572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHuw-0002pH-E3 for importer@patchew.org; Wed, 13 Dec 2017 20:02:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsi-0001Ow-LR for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePHsh-0002xo-Ot for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHsf-0002sN-8W; Wed, 13 Dec 2017 20:00:09 -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 5A6E9800A4; Thu, 14 Dec 2017 01:00:08 +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 743B7173C6; Thu, 14 Dec 2017 01:00:04 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:47 -0500 Message-Id: <20171214005953.8898-2-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.28]); Thu, 14 Dec 2017 01:00:08 +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 1/7] blockjob: record time of last yield 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The mirror job makes a semi-inaccurate record of the last time we left a "pause", but this doesn't always correlate to the time we actually last successfully yielded control. Record the time we last left a yield centrally. Signed-off-by: John Snow --- block/mirror.c | 8 ++------ blockjob.c | 2 ++ include/block/blockjob.h | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index c9badc1203..d35c688faa 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -63,7 +63,6 @@ typedef struct MirrorBlockJob { QSIMPLEQ_HEAD(, MirrorBuffer) buf_free; int buf_free_count; =20 - uint64_t last_pause_ns; unsigned long *in_flight_bitmap; int in_flight; int64_t bytes_in_flight; @@ -596,8 +595,7 @@ static void mirror_throttle(MirrorBlockJob *s) { int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); =20 - if (now - s->last_pause_ns > SLICE_TIME) { - s->last_pause_ns =3D now; + if (now - s->common.last_yield_ns > SLICE_TIME) { block_job_sleep_ns(&s->common, 0); } else { block_job_pause_point(&s->common); @@ -769,7 +767,6 @@ static void coroutine_fn mirror_run(void *opaque) =20 mirror_free_init(s); =20 - s->last_pause_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); if (!s->is_none_mode) { ret =3D mirror_dirty_init(s); if (ret < 0 || block_job_is_cancelled(&s->common)) { @@ -803,7 +800,7 @@ static void coroutine_fn mirror_run(void *opaque) * We do so every SLICE_TIME nanoseconds, or when there is an erro= r, * or when the source is clean, whichever comes first. */ - delta =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_n= s; + delta =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->common.last_= yield_ns; if (delta < SLICE_TIME && s->common.iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight >=3D MAX_IN_FLIGHT || s->buf_free_count =3D= =3D 0 || @@ -878,7 +875,6 @@ static void coroutine_fn mirror_run(void *opaque) delay_ns =3D (s->in_flight =3D=3D 0 && cnt =3D=3D 0 ? SLICE_TI= ME : 0); block_job_sleep_ns(&s->common, delay_ns); } - s->last_pause_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 immediate_exit: diff --git a/blockjob.c b/blockjob.c index 715c2c2680..8cbc142f57 100644 --- a/blockjob.c +++ b/blockjob.c @@ -692,6 +692,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, job->paused =3D true; job->pause_count =3D 1; job->refcnt =3D 1; + job->last_yield_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); aio_timer_init(qemu_get_aio_context(), &job->sleep_timer, QEMU_CLOCK_REALTIME, SCALE_NS, block_job_sleep_timer_cb, job); @@ -776,6 +777,7 @@ static void block_job_do_yield(BlockJob *job, uint64_t = ns) job->busy =3D false; block_job_unlock(); qemu_coroutine_yield(); + job->last_yield_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); =20 /* Set by block_job_enter before re-entering the coroutine. */ assert(job->busy); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 00403d9482..2712e2fd4e 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -141,6 +141,11 @@ typedef struct BlockJob { */ QEMUTimer sleep_timer; =20 + /** + * Timestamp of the last yield + */ + uint64_t last_yield_ns; + /** Non-NULL if this job is part of a transaction */ BlockJobTxn *txn; QLIST_ENTRY(BlockJob) txn_list; --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213348452237.52914629129407; Wed, 13 Dec 2017 17:02:28 -0800 (PST) Received: from localhost ([::1]:38571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHup-0002ke-Ls for importer@patchew.org; Wed, 13 Dec 2017 20:02:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsp-0001Vv-MA for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePHsm-00030x-Ke for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHsj-0002yc-5B; Wed, 13 Dec 2017 20:00:13 -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 2DA2F81DE8; Thu, 14 Dec 2017 01:00:12 +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 7D74A174B4; Thu, 14 Dec 2017 01:00:08 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:48 -0500 Message-Id: <20171214005953.8898-3-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.25]); Thu, 14 Dec 2017 01:00:12 +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 2/7] blockjob: consolidate SLICE_TIME definition 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" They're all the same. If it actually becomes important to configure it, it can become a job or driver property. Signed-off-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 1 - block/commit.c | 2 -- block/mirror.c | 1 - block/stream.c | 2 -- include/block/blockjob_int.h | 2 ++ 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/block/backup.c b/block/backup.c index 99e6bcc748..d71b25c017 100644 --- a/block/backup.c +++ b/block/backup.c @@ -27,7 +27,6 @@ #include "qemu/error-report.h" =20 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) -#define SLICE_TIME 100000000ULL /* ns */ =20 typedef struct BackupBlockJob { BlockJob common; diff --git a/block/commit.c b/block/commit.c index c5327551ce..873e749d50 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,6 @@ enum { COMMIT_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ }; =20 -#define SLICE_TIME 100000000ULL /* ns */ - typedef struct CommitBlockJob { BlockJob common; RateLimit limit; diff --git a/block/mirror.c b/block/mirror.c index d35c688faa..eef5b598f5 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -22,7 +22,6 @@ #include "qemu/ratelimit.h" #include "qemu/bitmap.h" =20 -#define SLICE_TIME 100000000ULL /* ns */ #define MAX_IN_FLIGHT 16 #define MAX_IO_BYTES (1 << 20) /* 1 Mb */ #define DEFAULT_MIRROR_BUF_SIZE (MAX_IN_FLIGHT * MAX_IO_BYTES) diff --git a/block/stream.c b/block/stream.c index 499cdacdb0..e85af18c54 100644 --- a/block/stream.c +++ b/block/stream.c @@ -29,8 +29,6 @@ enum { STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ }; =20 -#define SLICE_TIME 100000000ULL /* ns */ - typedef struct StreamBlockJob { BlockJob common; RateLimit limit; diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index c9b23b0cc9..209fa1bb3e 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -29,6 +29,8 @@ #include "block/blockjob.h" #include "block/block.h" =20 +#define SLICE_TIME 100000000ULL /* ns */ + /** * BlockJobDriver: * --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151321349404964.0978830174007; Wed, 13 Dec 2017 17:04:54 -0800 (PST) Received: from localhost ([::1]:38594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHxA-0004iO-C5 for importer@patchew.org; Wed, 13 Dec 2017 20:04:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsv-0001Yl-At 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-00035X-Bn for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHsp-00031o-DK; Wed, 13 Dec 2017 20:00:19 -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 6FCEB83F40; Thu, 14 Dec 2017 01:00:18 +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 50687173C6; Thu, 14 Dec 2017 01:00:12 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:49 -0500 Message-Id: <20171214005953.8898-4-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.27]); Thu, 14 Dec 2017 01:00:18 +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 3/7] blockjob: create block_job_throttle 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+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 will replace mirror_throttle, for reuse in other jobs. Signed-off-by: John Snow Reviewed-by: Jeff Cody --- block/mirror.c | 15 ++------------- blockjob.c | 11 +++++++++++ include/block/blockjob_int.h | 9 +++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index eef5b598f5..60b52cfb19 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -590,17 +590,6 @@ static void mirror_exit(BlockJob *job, void *opaque) bdrv_unref(src); } =20 -static void mirror_throttle(MirrorBlockJob *s) -{ - int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - - if (now - s->common.last_yield_ns > SLICE_TIME) { - block_job_sleep_ns(&s->common, 0); - } else { - block_job_pause_point(&s->common); - } -} - static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) { int64_t offset; @@ -621,7 +610,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) int bytes =3D MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); =20 - mirror_throttle(s); + block_job_throttle(&s->common); =20 if (block_job_is_cancelled(&s->common)) { s->initial_zeroing_ongoing =3D false; @@ -649,7 +638,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) int bytes =3D MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); =20 - mirror_throttle(s); + block_job_throttle(&s->common); =20 if (block_job_is_cancelled(&s->common)) { return 0; diff --git a/blockjob.c b/blockjob.c index 8cbc142f57..8d0c89a813 100644 --- a/blockjob.c +++ b/blockjob.c @@ -882,6 +882,17 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } =20 +void block_job_throttle(BlockJob *job) +{ + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + + if (now - job->last_yield_ns > SLICE_TIME) { + block_job_sleep_ns(job, 0); + } else { + block_job_pause_point(job); + } +} + void block_job_iostatus_reset(BlockJob *job) { if (job->iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 209fa1bb3e..1a771b1e2e 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -157,6 +157,15 @@ void block_job_sleep_ns(BlockJob *job, int64_t ns); */ void block_job_yield(BlockJob *job); =20 +/** + * block_job_throttle: + * @job: The job that calls the function. + * + * Yield if it has been SLICE_TIME nanoseconds since the last yield. + * Otherwise, check if we need to pause (and update the yield counter). + */ +void block_job_throttle(BlockJob *job); + /** * block_job_pause_all: * --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213534053385.1260374886077; Wed, 13 Dec 2017 17:05:34 -0800 (PST) Received: from localhost ([::1]:38602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHxq-0005H2-Dv for importer@patchew.org; Wed, 13 Dec 2017 20:05:30 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(MirrorBlockJo= b *s) int bytes =3D MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); =20 - block_job_throttle(&s->common); + block_job_throttle(&s->common, 0); =20 if (block_job_is_cancelled(&s->common)) { s->initial_zeroing_ongoing =3D false; @@ -638,7 +638,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) int bytes =3D MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); =20 - block_job_throttle(&s->common); + block_job_throttle(&s->common, 0); =20 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); } =20 -void block_job_throttle(BlockJob *job) +void block_job_throttle(BlockJob *job, int64_t delay_ns) { - int64_t now =3D 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); =20 /** * block_job_pause_all: --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 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: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213361575128.72408256236588; Wed, 13 Dec 2017 17:02:41 -0800 (PST) Received: from localhost ([::1]:38573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHv0-0002td-Bi for importer@patchew.org; Wed, 13 Dec 2017 20:02:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsv-0001Yo-Bf 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-00035P-Bf for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHsr-00032n-7o; Wed, 13 Dec 2017 20:00:21 -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 547B380460; Thu, 14 Dec 2017 01:00:20 +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 8265E17122; Thu, 14 Dec 2017 01:00:19 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:51 -0500 Message-Id: <20171214005953.8898-6-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.28]); Thu, 14 Dec 2017 01:00:20 +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 5/7] block/commit: use block_job_throttle 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+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" Depending on the value of `speed` and how fast our backends are, delay_ns might be 0 very, very often. This creates some warning messages that spook users, but it's also pretty inefficient. Use block_job_throttle instead to yield a little more intelligently. Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/commit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/commit.c b/block/commit.c index 873e749d50..567064215b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -172,7 +172,8 @@ static void coroutine_fn commit_run(void *opaque) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - block_job_sleep_ns(&s->common, delay_ns); + block_job_throttle(&s->common, delay_ns); + if (block_job_is_cancelled(&s->common)) { break; } --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213606226218.08346053118828; Wed, 13 Dec 2017 17:06:46 -0800 (PST) Received: from localhost ([::1]:38611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHz1-0005w6-F0 for importer@patchew.org; Wed, 13 Dec 2017 20:06:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsv-0001Ym-BL 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-00035e-Cg for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51712) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHss-00033a-5G; Wed, 13 Dec 2017 20:00:22 -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 417D983F43; Thu, 14 Dec 2017 01:00:21 +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 74911173C6; Thu, 14 Dec 2017 01:00:20 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:52 -0500 Message-Id: <20171214005953.8898-7-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.27]); Thu, 14 Dec 2017 01:00:21 +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 6/7] block/stream: use block_job_throttle 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+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" Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/stream.c b/block/stream.c index e85af18c54..3ad3190387 100644 --- a/block/stream.c +++ b/block/stream.c @@ -139,7 +139,7 @@ static void coroutine_fn stream_run(void *opaque) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - block_job_sleep_ns(&s->common, delay_ns); + block_job_throttle(&s->common, delay_ns); if (block_job_is_cancelled(&s->common)) { break; } --=20 2.14.3 From nobody Fri May 3 11:55:42 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513213679625385.3883450708287; Wed, 13 Dec 2017 17:07:59 -0800 (PST) Received: from localhost ([::1]:38617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePI09-0006Zq-TA for importer@patchew.org; Wed, 13 Dec 2017 20:07:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePHsy-0001cK-J6 for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePHsw-00037G-D6 for qemu-devel@nongnu.org; Wed, 13 Dec 2017 20:00:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ePHst-000347-5X; Wed, 13 Dec 2017 20:00:23 -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 3A9C880F79; Thu, 14 Dec 2017 01:00:22 +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 6315017168; Thu, 14 Dec 2017 01:00:21 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Wed, 13 Dec 2017 19:59:53 -0500 Message-Id: <20171214005953.8898-8-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.27]); Thu, 14 Dec 2017 01:00:22 +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 7/7] block/backup: use block_job_throttle 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+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" Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/block/backup.c b/block/backup.c index d71b25c017..a5ede5f643 100644 --- a/block/backup.c +++ b/block/backup.c @@ -334,6 +334,8 @@ static void backup_complete(BlockJob *job, void *opaque) =20 static bool coroutine_fn yield_and_check(BackupBlockJob *job) { + uint64_t delay_ns =3D 0; + if (block_job_is_cancelled(&job->common)) { return true; } @@ -342,14 +344,13 @@ static bool coroutine_fn yield_and_check(BackupBlockJ= ob *job) * (without, VM does not reboot) */ if (job->common.speed) { - uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, - job->bytes_read); + delay_ns =3D ratelimit_calculate_delay(&job->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); } =20 + block_job_throttle(&job->common, delay_ns); + if (block_job_is_cancelled(&job->common)) { return true; } --=20 2.14.3