From patchwork Fri Jan 19 20:58:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863808 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 3zNYFX64nmz9s75 for ; Sat, 20 Jan 2018 08:03:12 +1100 (AEDT) Received: from localhost ([::1]:44751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdoc-0004TA-TT for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:03:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkd-0001X6-PA for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkc-0005vU-VI for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkY-0005t4-0D; Fri, 19 Jan 2018 15:58:58 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1182D5F22; Fri, 19 Jan 2018 20:58:57 +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 C89575C1B7; Fri, 19 Jan 2018 20:58:54 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:35 -0500 Message-Id: <20180119205847.7141-2-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 19 Jan 2018 20:58:57 +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 v2 01/13] blockjob: record time of last entrance 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" The mirror job makes a semi-inaccurate record of the last time we yielded by recording the last time we left a "pause", but this doesn't always correlate to the time we actually last successfully ceded control. Record the time we last *exited* a yield centrally. In other words, record the time we began execution of this job to know how long we have been selfish for. 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..88f4e8964d 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; - 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 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - if (now - s->last_pause_ns > SLICE_TIME) { - s->last_pause_ns = now; + if (now - s->common.last_enter_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) mirror_free_init(s); - s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); if (!s->is_none_mode) { ret = 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 error, * or when the source is clean, whichever comes first. */ - delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_ns; + delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->common.last_enter_ns; if (delta < SLICE_TIME && s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 || @@ -878,7 +875,6 @@ static void coroutine_fn mirror_run(void *opaque) delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0); block_job_sleep_ns(&s->common, delay_ns); } - s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } immediate_exit: diff --git a/blockjob.c b/blockjob.c index f5cea84e73..2a9ff66b95 100644 --- a/blockjob.c +++ b/blockjob.c @@ -321,6 +321,7 @@ void block_job_start(BlockJob *job) job->pause_count--; job->busy = true; job->paused = false; + job->last_enter_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); bdrv_coroutine_enter(blk_bs(job->blk), job->co); } @@ -786,6 +787,7 @@ static void block_job_do_yield(BlockJob *job, uint64_t ns) job->busy = false; block_job_unlock(); qemu_coroutine_yield(); + job->last_enter_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); /* 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..e965845c94 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -141,6 +141,11 @@ typedef struct BlockJob { */ QEMUTimer sleep_timer; + /** + * Timestamp of the last yield + */ + uint64_t last_enter_ns; + /** Non-NULL if this job is part of a transaction */ BlockJobTxn *txn; QLIST_ENTRY(BlockJob) txn_list; From patchwork Fri Jan 19 20:58:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863805 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 3zNY9w1Nctz9s74 for ; Sat, 20 Jan 2018 08:00:04 +1100 (AEDT) Received: from localhost ([::1]:44726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdla-0001kv-4n for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:00:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkd-0001Wx-I8 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkc-0005vM-Qo for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkZ-0005ti-Tr; Fri, 19 Jan 2018 15:59:00 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E833AC056826; Fri, 19 Jan 2018 20:58:58 +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 32B585C1B7; Fri, 19 Jan 2018 20:58:57 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:36 -0500 Message-Id: <20180119205847.7141-3-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 19 Jan 2018 20:58:59 +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 v2 02/13] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Jeff Cody --- 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 4a16a37229..7b1cdd038a 100644 --- a/block/backup.c +++ b/block/backup.c @@ -27,7 +27,6 @@ #include "qemu/error-report.h" #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) -#define SLICE_TIME 100000000ULL /* ns */ typedef struct BackupBlockJob { BlockJob common; diff --git a/block/commit.c b/block/commit.c index bb6c904704..898545b318 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,6 @@ enum { COMMIT_BUFFER_SIZE = 512 * 1024, /* in bytes */ }; -#define SLICE_TIME 100000000ULL /* ns */ - typedef struct CommitBlockJob { BlockJob common; RateLimit limit; diff --git a/block/mirror.c b/block/mirror.c index 88f4e8964d..1fb5fc0cb8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -22,7 +22,6 @@ #include "qemu/ratelimit.h" #include "qemu/bitmap.h" -#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 = 512 * 1024, /* in bytes */ }; -#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" +#define SLICE_TIME 100000000ULL /* ns */ + /** * BlockJobDriver: * From patchwork Fri Jan 19 20:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863806 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 3zNYB472Q3z9s9Y for ; Sat, 20 Jan 2018 08:00:12 +1100 (AEDT) Received: from localhost ([::1]:44728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdli-0001th-Tb for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:00:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkd-0001X7-Pt for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkd-0005vh-4l for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55322) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkb-0005uO-5L; Fri, 19 Jan 2018 15:59:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43FAA7855A; Fri, 19 Jan 2018 20:59:00 +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 128DA5C1B7; Fri, 19 Jan 2018 20:58:58 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:37 -0500 Message-Id: <20180119205847.7141-4-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 19 Jan 2018 20:59:00 +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 v2 03/13] blockjob: create block_job_relax 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" This will replace mirror_throttle, for reuse in other jobs. Signed-off-by: John Snow Reviewed-by: Max Reitz --- 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 1fb5fc0cb8..36c681c7a1 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -590,17 +590,6 @@ static void mirror_exit(BlockJob *job, void *opaque) bdrv_unref(src); } -static void mirror_throttle(MirrorBlockJob *s) -{ - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - - if (now - s->common.last_enter_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(MirrorBlockJob *s) int bytes = MIN(s->bdev_length - offset, QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); - mirror_throttle(s); + block_job_relax(&s->common); if (block_job_is_cancelled(&s->common)) { s->initial_zeroing_ongoing = false; @@ -649,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)); - mirror_throttle(s); + block_job_relax(&s->common); if (block_job_is_cancelled(&s->common)) { return 0; diff --git a/blockjob.c b/blockjob.c index 2a9ff66b95..6f2e709b51 100644 --- a/blockjob.c +++ b/blockjob.c @@ -906,6 +906,17 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } +void block_job_relax(BlockJob *job) +{ + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + + if (now - job->last_enter_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 == BLOCK_DEVICE_IO_STATUS_OK) { diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 209fa1bb3e..553784d86f 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); +/** + * block_job_relax: + * @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 yield if so. + */ +void block_job_relax(BlockJob *job); + /** * block_job_pause_all: * From patchwork Fri Jan 19 20:58:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863804 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 3zNY9t0DQsz9s74 for ; Sat, 20 Jan 2018 08:00:02 +1100 (AEDT) Received: from localhost ([::1]:44722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdlY-0001hP-2J for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:00:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkg-0001Zp-20 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkf-0005x6-DU for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkd-0005vG-5B; Fri, 19 Jan 2018 15:59:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43BB24E4C3; Fri, 19 Jan 2018 20:59:02 +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 64DE75C1B7; Fri, 19 Jan 2018 20:59:00 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:38 -0500 Message-Id: <20180119205847.7141-5-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 19 Jan 2018 20:59:02 +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 v2 04/13] 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 36c681c7a1..3c73caed5e 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_relax(&s->common); + block_job_relax(&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_relax(&s->common); + block_job_relax(&s->common, 0); if (block_job_is_cancelled(&s->common)) { return 0; diff --git a/blockjob.c b/blockjob.c index 6f2e709b51..51c0eb5d9e 100644 --- a/blockjob.c +++ b/blockjob.c @@ -906,12 +906,11 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } -void block_job_relax(BlockJob *job) +void block_job_relax(BlockJob *job, int64_t delay_ns) { - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - - if (now - job->last_enter_ns > SLICE_TIME) { - block_job_sleep_ns(job, 0); + if (delay_ns || (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - \ + job->last_enter_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 553784d86f..5f1520fab7 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_relax: * @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 yield if so. + * 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_relax(BlockJob *job); +void block_job_relax(BlockJob *job, int64_t delay_ns); /** * block_job_pause_all: From patchwork Fri Jan 19 20:58:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863810 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 3zNYGC0gJsz9s74 for ; Sat, 20 Jan 2018 08:03:46 +1100 (AEDT) Received: from localhost ([::1]:44759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdpA-0004zY-Le for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:03:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkg-0001aN-Ha for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkf-0005xK-WA for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35260) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdke-0005w5-4w; Fri, 19 Jan 2018 15:59:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37B91C0587C0; Fri, 19 Jan 2018 20:59:03 +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 66E755C1B7; Fri, 19 Jan 2018 20:59:02 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:39 -0500 Message-Id: <20180119205847.7141-6-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 19 Jan 2018 20:59:03 +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 v2 05/13] block/commit: use block_job_relax 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" 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_relax instead to yield a little more intelligently. Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/commit.c b/block/commit.c index 898545b318..9cfe3ed76b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -172,7 +172,7 @@ 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_relax(&s->common, delay_ns); if (block_job_is_cancelled(&s->common)) { break; } From patchwork Fri Jan 19 20:58:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863807 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 3zNYFW6Vcrz9s74 for ; Sat, 20 Jan 2018 08:03:11 +1100 (AEDT) Received: from localhost ([::1]:44750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdob-0004Sc-Tt for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:03:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkq-0001lC-0P for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkn-00060K-KZ for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44272) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkg-0005xD-CJ; Fri, 19 Jan 2018 15:59:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 730402CE930; Fri, 19 Jan 2018 20:59:05 +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 585F15C1B7; Fri, 19 Jan 2018 20:59:03 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:40 -0500 Message-Id: <20180119205847.7141-7-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 19 Jan 2018 20:59:05 +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 v2 06/13] block/stream: use block_job_relax 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" See prior commit for justification. 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..49dc102565 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_relax(&s->common, delay_ns); if (block_job_is_cancelled(&s->common)) { break; } From patchwork Fri Jan 19 20:58:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863811 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 3zNYK86hBSz9s74 for ; Sat, 20 Jan 2018 08:06:20 +1100 (AEDT) Received: from localhost ([::1]:44772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdre-0007BM-Dt for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:06:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkq-0001mA-Uy for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkq-00061M-9b for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkh-0005xu-Bi; Fri, 19 Jan 2018 15:59:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EFD085376; Fri, 19 Jan 2018 20:59:06 +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 9565E5C1B7; Fri, 19 Jan 2018 20:59:05 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:41 -0500 Message-Id: <20180119205847.7141-8-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 19 Jan 2018 20:59:06 +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 v2 07/13] block/backup: use block_job_relax 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" See two commits back for justification. Signed-off-by: John Snow Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/backup.c b/block/backup.c index 7b1cdd038a..b4204c0ee4 100644 --- a/block/backup.c +++ b/block/backup.c @@ -336,6 +336,8 @@ static void backup_complete(BlockJob *job, void *opaque) static bool coroutine_fn yield_and_check(BackupBlockJob *job) { + uint64_t delay_ns = 0; + if (block_job_is_cancelled(&job->common)) { return true; } @@ -344,14 +346,12 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job) * (without, VM does not reboot) */ if (job->common.speed) { - uint64_t delay_ns = ratelimit_calculate_delay(&job->limit, - job->bytes_read); + delay_ns = ratelimit_calculate_delay(&job->limit, + job->bytes_read); job->bytes_read = 0; - block_job_sleep_ns(&job->common, delay_ns); - } else { - block_job_sleep_ns(&job->common, 0); } + block_job_relax(&job->common, delay_ns); if (block_job_is_cancelled(&job->common)) { return true; } From patchwork Fri Jan 19 20:58:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863812 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 3zNYKS696zz9s74 for ; Sat, 20 Jan 2018 08:06:36 +1100 (AEDT) Received: from localhost ([::1]:44780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdru-0007NZ-Ry for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:06:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdku-0001qM-MT for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdkt-000636-NS for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36796) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkr-00061Q-2r; Fri, 19 Jan 2018 15:59:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D8ACC062EDC; Fri, 19 Jan 2018 20:59:16 +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 846855C1B7; Fri, 19 Jan 2018 20:59:06 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:42 -0500 Message-Id: <20180119205847.7141-9-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 20:59:16 +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 v2 08/13] allow block_job_relax to return -ECANCELED 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" This is just an optimization for callers who are likely going to want to check quite close to this call if the job was canceled or not anyway. Along the same lines, add the return to block_job_pause_point and block_job_sleep_ns, so we don't have to re-check it quite so excessively. Signed-off-by: John Snow Reviewed-by: Max Reitz --- blockjob.c | 28 +++++++++++++++++----------- include/block/blockjob_int.h | 8 +++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/blockjob.c b/blockjob.c index 51c0eb5d9e..b5a0cda412 100644 --- a/blockjob.c +++ b/blockjob.c @@ -793,15 +793,15 @@ static void block_job_do_yield(BlockJob *job, uint64_t ns) assert(job->busy); } -void coroutine_fn block_job_pause_point(BlockJob *job) +int coroutine_fn block_job_pause_point(BlockJob *job) { assert(job && block_job_started(job)); - if (!block_job_should_pause(job)) { - return; - } if (block_job_is_cancelled(job)) { - return; + return -ECANCELED; + } + if (!block_job_should_pause(job)) { + return 0; } if (job->driver->pause) { @@ -817,6 +817,8 @@ void coroutine_fn block_job_pause_point(BlockJob *job) if (job->driver->resume) { job->driver->resume(job); } + + return 0; } void block_job_resume_all(void) @@ -874,20 +876,20 @@ bool block_job_is_cancelled(BlockJob *job) return job->cancelled; } -void block_job_sleep_ns(BlockJob *job, int64_t ns) +int block_job_sleep_ns(BlockJob *job, int64_t ns) { assert(job->busy); /* Check cancellation *before* setting busy = false, too! */ if (block_job_is_cancelled(job)) { - return; + return -ECANCELED; } if (!block_job_should_pause(job)) { block_job_do_yield(job, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + ns); } - block_job_pause_point(job); + return block_job_pause_point(job); } void block_job_yield(BlockJob *job) @@ -906,13 +908,17 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } -void block_job_relax(BlockJob *job, int64_t delay_ns) +int block_job_relax(BlockJob *job, int64_t delay_ns) { + if (block_job_is_cancelled(job)) { + return -ECANCELED; + } + if (delay_ns || (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - \ job->last_enter_ns > SLICE_TIME)) { - block_job_sleep_ns(job, delay_ns); + return block_job_sleep_ns(job, delay_ns); } else { - block_job_pause_point(job); + return block_job_pause_point(job); } } diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 5f1520fab7..1ceb47e1e6 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -147,7 +147,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, * %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately * interrupt the wait. */ -void block_job_sleep_ns(BlockJob *job, int64_t ns); +int block_job_sleep_ns(BlockJob *job, int64_t ns); /** * block_job_yield: @@ -167,8 +167,10 @@ void block_job_yield(BlockJob *job); * 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. + * + * returns ECANCELED if the job has been canceled. */ -void block_job_relax(BlockJob *job, int64_t delay_ns); +int block_job_relax(BlockJob *job, int64_t delay_ns); /** * block_job_pause_all: @@ -217,7 +219,7 @@ bool block_job_is_cancelled(BlockJob *job); * Pause now if block_job_pause() has been called. Block jobs that perform * lots of I/O must call this between requests so that the job can be paused. */ -void coroutine_fn block_job_pause_point(BlockJob *job); +int coroutine_fn block_job_pause_point(BlockJob *job); /** * block_job_enter: From patchwork Fri Jan 19 20:58:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863809 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 3zNYFm6S3gz9s74 for ; Sat, 20 Jan 2018 08:03:24 +1100 (AEDT) Received: from localhost ([::1]:44756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdoo-0004e8-U2 for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:03:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdkv-0001rM-L9 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdku-00063l-SQ for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdks-00062V-N1; Fri, 19 Jan 2018 15:59:18 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C95125A59; Fri, 19 Jan 2018 20:59:17 +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 2D0C95C542; Fri, 19 Jan 2018 20:59:16 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:43 -0500 Message-Id: <20180119205847.7141-10-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 19 Jan 2018 20:59:17 +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 v2 09/13] block/backup: remove yield_and_check 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" This is a respin of the same functionality as mirror_throttle, so trash this and replace it with the generic version. yield_and_check returned true if canceled, false otherwise. block_job_relax returns -ECANCELED if canceled, 0 otherwise. Signed-off-by: John Snow --- block/backup.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/block/backup.c b/block/backup.c index b4204c0ee4..0624c3b322 100644 --- a/block/backup.c +++ b/block/backup.c @@ -334,29 +334,17 @@ static void backup_complete(BlockJob *job, void *opaque) g_free(data); } -static bool coroutine_fn yield_and_check(BackupBlockJob *job) +static uint64_t get_delay_ns(BackupBlockJob *job) { uint64_t delay_ns = 0; - if (block_job_is_cancelled(&job->common)) { - return true; - } - - /* we need to yield so that bdrv_drain_all() returns. - * (without, VM does not reboot) - */ if (job->common.speed) { delay_ns = ratelimit_calculate_delay(&job->limit, job->bytes_read); job->bytes_read = 0; } - block_job_relax(&job->common, delay_ns); - if (block_job_is_cancelled(&job->common)) { - return true; - } - - return false; + return delay_ns; } static int coroutine_fn backup_run_incremental(BackupBlockJob *job) @@ -369,7 +357,7 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) hbitmap_iter_init(&hbi, job->copy_bitmap, 0); while ((cluster = hbitmap_iter_next(&hbi)) != -1) { do { - if (yield_and_check(job)) { + if (block_job_relax(&job->common, get_delay_ns(job))) { return 0; } ret = backup_do_cow(job, cluster * job->cluster_size, @@ -465,7 +453,7 @@ static void coroutine_fn backup_run(void *opaque) bool error_is_read; int alloced = 0; - if (yield_and_check(job)) { + if (block_job_relax(&job->common, get_delay_ns(job))) { break; } From patchwork Fri Jan 19 20:58:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863815 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 3zNYNr60T7z9s74 for ; Sat, 20 Jan 2018 08:09:32 +1100 (AEDT) Received: from localhost ([::1]:44805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecduk-0001Xd-UA for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:09:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdl1-0001xX-Tm for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdl1-00066I-BF for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkv-00063h-BV; Fri, 19 Jan 2018 15:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73846C047B65; Fri, 19 Jan 2018 20:59: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 E9EA55C1B7; Fri, 19 Jan 2018 20:59:17 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:44 -0500 Message-Id: <20180119205847.7141-11-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 20:59: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 v2 10/13] block/mirror: condense cancellation and relax calls 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" We can count on the relax call to check cancellation for us, so condense these concurrent calls. Signed-off-by: John Snow --- block/mirror.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 3c73caed5e..a0e0044de2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -610,9 +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_relax(&s->common, 0); - - if (block_job_is_cancelled(&s->common)) { + if (block_job_relax(&s->common, 0)) { s->initial_zeroing_ongoing = false; return 0; } @@ -638,9 +636,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_relax(&s->common, 0); - - if (block_job_is_cancelled(&s->common)) { + if (block_job_relax(&s->common, 0)) { return 0; } From patchwork Fri Jan 19 20:58:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863816 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 3zNYNz2Mgbz9s74 for ; Sat, 20 Jan 2018 08:09:39 +1100 (AEDT) Received: from localhost ([::1]:44815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdur-0001jL-En for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:09:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdl3-0001z7-GF for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdl2-00066g-G5 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59926) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdkw-00064G-S6; Fri, 19 Jan 2018 15:59:23 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E329FA96F9; Fri, 19 Jan 2018 20:59: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 94D945C1B7; Fri, 19 Jan 2018 20:59:20 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:45 -0500 Message-Id: <20180119205847.7141-12-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 19 Jan 2018 20:59: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 v2 11/13] block/mirror: remove block_job_sleep_ns calls 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" We're attempting to slacken the mirror loop in three different places, but we can combine these three attempts. Combine the early loop call to block_job_pause_point with the two late-loop calls to block_job_sleep_ns. When delay_ns is 0 and it has not been SLICE_TIME since the last yield, block_job_relax is merely a call to block_job_pause_point, so this should be equivalent with the exception that if we have managed to not yield at all in the last SLICE_TIME ns, we will now do so. I am not sure that condition was possible, so this loop should be equivalent. Signed-off-by: John Snow --- block/mirror.c | 22 +++++++++++----------- block/trace-events | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index a0e0044de2..192e03694f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -761,7 +761,7 @@ static void coroutine_fn mirror_run(void *opaque) assert(!s->dbi); s->dbi = bdrv_dirty_iter_new(s->dirty_bitmap); for (;;) { - uint64_t delay_ns = 0; + static uint64_t delay_ns = 0; int64_t cnt, delta; bool should_complete; @@ -770,9 +770,16 @@ static void coroutine_fn mirror_run(void *opaque) goto immediate_exit; } - block_job_pause_point(&s->common); - cnt = bdrv_get_dirty_count(s->dirty_bitmap); + + trace_mirror_before_relax(s, cnt, s->synced, delay_ns); + if (block_job_relax(&s->common, delay_ns)) { + if (!s->synced) { + goto immediate_exit; + } + } + delay_ns = 0; + /* s->common.offset contains the number of bytes already processed so * far, cnt is the number of dirty bytes remaining and * s->bytes_in_flight is the number of bytes currently being @@ -849,15 +856,8 @@ static void coroutine_fn mirror_run(void *opaque) } ret = 0; - trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); - if (!s->synced) { - block_job_sleep_ns(&s->common, delay_ns); - if (block_job_is_cancelled(&s->common)) { - break; - } - } else if (!should_complete) { + if (s->synced && !should_complete) { delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0); - block_job_sleep_ns(&s->common, delay_ns); } } diff --git a/block/trace-events b/block/trace-events index 11c8d5f590..60f36f929a 100644 --- a/block/trace-events +++ b/block/trace-events @@ -27,7 +27,7 @@ mirror_start(void *bs, void *s, void *opaque) "bs %p s %p opaque %p" mirror_restart_iter(void *s, int64_t cnt) "s %p dirty count %"PRId64 mirror_before_flush(void *s) "s %p" mirror_before_drain(void *s, int64_t cnt) "s %p dirty count %"PRId64 -mirror_before_sleep(void *s, int64_t cnt, int synced, uint64_t delay_ns) "s %p dirty count %"PRId64" synced %d delay %"PRIu64"ns" +mirror_before_relax(void *s, int64_t cnt, int synced, uint64_t delay_ns) "s %p dirty count %"PRId64" synced %d delay %"PRIu64"ns" mirror_one_iteration(void *s, int64_t offset, uint64_t bytes) "s %p offset %" PRId64 " bytes %" PRIu64 mirror_iteration_done(void *s, int64_t offset, uint64_t bytes, int ret) "s %p offset %" PRId64 " bytes %" PRIu64 " ret %d" mirror_yield(void *s, int64_t cnt, int buf_free_count, int in_flight) "s %p dirty count %"PRId64" free buffers %d in_flight %d" From patchwork Fri Jan 19 20:58:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863813 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 3zNYKf1W4Tz9s75 for ; Sat, 20 Jan 2018 08:06:46 +1100 (AEDT) Received: from localhost ([::1]:44781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecds4-0007XQ-9U for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:06:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdl3-0001zK-Ig for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdl2-00066l-KK for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdky-00064n-Oi; Fri, 19 Jan 2018 15:59:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D08E84E334; Fri, 19 Jan 2018 20:59:23 +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 101485C1B7; Fri, 19 Jan 2018 20:59:21 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:46 -0500 Message-Id: <20180119205847.7141-13-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 19 Jan 2018 20:59:23 +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 v2 12/13] blockjob: privatize block_job_sleep_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" There's not currently any external caller of it. Except in tests, but we'll fix that here too. Replace usages in test cases with block_job_relax, which functions similarly enough to be used as a drop-in replacement. Very technically block_job_sleep_ns(job, 0) behaves differently from block_job_relax(job, 0) in that relax may resolve to a no-op, but this makes no difference in the test in which it is used. Signed-off-by: John Snow Reviewed-by: Max Reitz --- blockjob.c | 11 ++++++++++- include/block/blockjob_int.h | 11 ----------- tests/test-bdrv-drain.c | 2 +- tests/test-blockjob-txn.c | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/blockjob.c b/blockjob.c index b5a0cda412..40167d6896 100644 --- a/blockjob.c +++ b/blockjob.c @@ -876,7 +876,16 @@ bool block_job_is_cancelled(BlockJob *job) return job->cancelled; } -int block_job_sleep_ns(BlockJob *job, int64_t ns) +/** + * block_job_sleep_ns: + * @job: The job that calls the function. + * @ns: How many nanoseconds to stop for. + * + * Put the job to sleep (assuming that it wasn't canceled) for @ns + * %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately + * interrupt the wait. + */ +static int block_job_sleep_ns(BlockJob *job, int64_t ns) { assert(job->busy); diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 1ceb47e1e6..c4891a5a9b 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -138,17 +138,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, uint64_t shared_perm, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp); -/** - * block_job_sleep_ns: - * @job: The job that calls the function. - * @ns: How many nanoseconds to stop for. - * - * Put the job to sleep (assuming that it wasn't canceled) for @ns - * %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately - * interrupt the wait. - */ -int block_job_sleep_ns(BlockJob *job, int64_t ns); - /** * block_job_yield: * @job: The job that calls the function. diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index d760e2b243..5d47541b4c 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -506,7 +506,7 @@ static void coroutine_fn test_job_start(void *opaque) TestBlockJob *s = opaque; while (!s->should_complete) { - block_job_sleep_ns(&s->common, 100000); + block_job_relax(&s->common, 100000); } block_job_defer_to_main_loop(&s->common, test_job_completed, NULL); diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 3591c9617f..edcf0de6bd 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -44,7 +44,7 @@ static void coroutine_fn test_block_job_run(void *opaque) while (s->iterations--) { if (s->use_timer) { - block_job_sleep_ns(job, 0); + block_job_relax(job, 0); } else { block_job_yield(job); } From patchwork Fri Jan 19 20:58:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 863814 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 3zNYL44csQz9s74 for ; Sat, 20 Jan 2018 08:07:08 +1100 (AEDT) Received: from localhost ([::1]:44793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdsP-0007pu-Ji for incoming@patchwork.ozlabs.org; Fri, 19 Jan 2018 16:07:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecdl6-00022w-VN for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecdl5-000681-Uc for qemu-devel@nongnu.org; Fri, 19 Jan 2018 15:59:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecdl3-00066q-CI; Fri, 19 Jan 2018 15:59:29 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7669FC0860BE; Fri, 19 Jan 2018 20:59:28 +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 F17A45C1B7; Fri, 19 Jan 2018 20:59:23 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 19 Jan 2018 15:58:47 -0500 Message-Id: <20180119205847.7141-14-jsnow@redhat.com> In-Reply-To: <20180119205847.7141-1-jsnow@redhat.com> References: <20180119205847.7141-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 20:59:28 +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 v2 13/13] blockjob: remove block_job_pause_point from interface 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" Remove the last call in block/mirror, using relax instead. relax may do nothing if we are canceled, so allow iteration to return prematurely and allow mirror_run to handle the cancellation logic. This is a functional change to mirror that should have the effect of cancelled mirror jobs being able to respond to that request a little sooner instead of launching new requests. Signed-off-by: John Snow --- block/mirror.c | 4 +++- blockjob.c | 10 +++++++++- include/block/blockjob_int.h | 9 --------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 192e03694f..8e6b5b25a9 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -345,7 +345,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) mirror_wait_for_io(s); } - block_job_pause_point(&s->common); + if (block_job_relax(&s->common, 0)) { + return 0; + } /* Find the number of consective dirty chunks following the first dirty * one, and wait for in flight requests in them. */ diff --git a/blockjob.c b/blockjob.c index 40167d6896..27c13fdd08 100644 --- a/blockjob.c +++ b/blockjob.c @@ -60,6 +60,7 @@ static void __attribute__((__constructor__)) block_job_init(void) static void block_job_event_cancelled(BlockJob *job); static void block_job_event_completed(BlockJob *job, const char *msg); static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job)); +static int coroutine_fn block_job_pause_point(BlockJob *job); /* Transactional group of block jobs */ struct BlockJobTxn { @@ -793,7 +794,14 @@ static void block_job_do_yield(BlockJob *job, uint64_t ns) assert(job->busy); } -int coroutine_fn block_job_pause_point(BlockJob *job) +/** + * block_job_pause_point: + * @job: The job that is ready to pause. + * + * Pause now if block_job_pause() has been called. Block jobs that perform + * lots of I/O must call this between requests so that the job can be paused. + */ +static int coroutine_fn block_job_pause_point(BlockJob *job) { assert(job && block_job_started(job)); diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index c4891a5a9b..57327cbc5a 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -201,15 +201,6 @@ void block_job_completed(BlockJob *job, int ret); */ bool block_job_is_cancelled(BlockJob *job); -/** - * block_job_pause_point: - * @job: The job that is ready to pause. - * - * Pause now if block_job_pause() has been called. Block jobs that perform - * lots of I/O must call this between requests so that the job can be paused. - */ -int coroutine_fn block_job_pause_point(BlockJob *job); - /** * block_job_enter: * @job: The job to enter.