From patchwork Wed Mar 16 14:16:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8600951 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C646B9F6E1 for ; Wed, 16 Mar 2016 14:17:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0CA1202FE for ; Wed, 16 Mar 2016 14:17:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F02B8202EC for ; Wed, 16 Mar 2016 14:17:20 +0000 (UTC) Received: from localhost ([::1]:56591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCGG-0002oN-9O for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 10:17:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCG3-0002jn-DO for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agCG2-0005v8-2m for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38699) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCG1-0005v1-Qv for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:06 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 8C78AC049E15 for ; Wed, 16 Mar 2016 14:17:05 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GEGwbu001673; Wed, 16 Mar 2016 10:17:04 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 16 Mar 2016 15:16:44 +0100 Message-Id: <1458137817-15383-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1458137817-15383-1-git-send-email-pbonzini@redhat.com> References: <1458137817-15383-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 03/16] block: introduce bdrv_no_throttling_begin/end X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extract the handling of throttling from bdrv_flush_io_queue. Signed-off-by: Paolo Bonzini Reviewed-by: Fam Zheng --- block.c | 1 - block/io.c | 56 +++++++++++++++++++++++++++++------------------ block/throttle-groups.c | 4 ++++ include/block/block_int.h | 6 ++--- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/block.c b/block.c index 59a18a3..bbd7de6 100644 --- a/block.c +++ b/block.c @@ -2304,7 +2304,6 @@ static void swap_feature_fields(BlockDriverState *bs_top, assert(!bs_new->throttle_state); if (bs_top->throttle_state) { - assert(bs_top->io_limits_enabled); bdrv_io_limits_enable(bs_new, throttle_group_get_name(bs_top)); bdrv_io_limits_disable(bs_top); } diff --git a/block/io.c b/block/io.c index 5ee5032..272caac 100644 --- a/block/io.c +++ b/block/io.c @@ -69,28 +69,43 @@ void bdrv_set_io_limits(BlockDriverState *bs, throttle_group_config(bs, cfg); } -static void bdrv_start_throttled_reqs(BlockDriverState *bs) +static void bdrv_no_throttling_begin(BlockDriverState *bs) { - bool enabled = bs->io_limits_enabled; + BdrvChild *child; + + QLIST_FOREACH(child, &bs->children, next) { + bdrv_no_throttling_begin(child->bs); + } - bs->io_limits_enabled = false; - throttle_group_restart_bs(bs); - bs->io_limits_enabled = enabled; + if (bs->io_limits_disabled++ == 0) { + throttle_group_restart_bs(bs); + } +} + +static void bdrv_no_throttling_end(BlockDriverState *bs) +{ + BdrvChild *child; + + --bs->io_limits_disabled; + + QLIST_FOREACH(child, &bs->children, next) { + bdrv_no_throttling_end(child->bs); + } } void bdrv_io_limits_disable(BlockDriverState *bs) { - bs->io_limits_enabled = false; - bdrv_start_throttled_reqs(bs); + assert(bs->throttle_state); + bdrv_no_throttling_begin(bs); throttle_group_unregister_bs(bs); + bdrv_no_throttling_end(bs); } /* should be called before bdrv_set_io_limits if a limit is set */ void bdrv_io_limits_enable(BlockDriverState *bs, const char *group) { - assert(!bs->io_limits_enabled); + assert(!bs->throttle_state); throttle_group_register_bs(bs, group); - bs->io_limits_enabled = true; } void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group) @@ -255,6 +270,7 @@ void bdrv_drain(BlockDriverState *bs) { bool busy = true; + bdrv_no_throttling_begin(bs); bdrv_drain_recurse(bs); while (busy) { /* Keep iterating */ @@ -262,6 +278,7 @@ void bdrv_drain(BlockDriverState *bs) busy = bdrv_requests_pending(bs); busy |= aio_poll(bdrv_get_aio_context(bs), busy); } + bdrv_no_throttling_end(bs); } /* @@ -284,6 +301,7 @@ void bdrv_drain_all(void) if (bs->job) { block_job_pause(bs->job); } + bdrv_no_throttling_begin(bs); bdrv_drain_recurse(bs); aio_context_release(aio_context); @@ -325,6 +343,7 @@ void bdrv_drain_all(void) AioContext *aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); + bdrv_no_throttling_end(bs); if (bs->job) { block_job_resume(bs->job); } @@ -555,11 +574,7 @@ static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset, * will not fire; so the I/O throttling function has to be disabled here * if it has been enabled. */ - if (bs->io_limits_enabled) { - fprintf(stderr, "Disabling I/O throttling on '%s' due " - "to synchronous I/O.\n", bdrv_get_device_name(bs)); - bdrv_io_limits_disable(bs); - } + bdrv_no_throttling_begin(bs); if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ @@ -573,6 +588,8 @@ static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset, aio_poll(aio_context, true); } } + + bdrv_no_throttling_end(bs); return rwco.ret; } @@ -608,13 +625,11 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { - bool enabled; int ret; - enabled = bs->io_limits_enabled; - bs->io_limits_enabled = false; + bdrv_no_throttling_begin(bs); ret = bdrv_read(bs, sector_num, buf, nb_sectors); - bs->io_limits_enabled = enabled; + bdrv_no_throttling_end(bs); return ret; } @@ -952,7 +967,7 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs, } /* throttling disk I/O */ - if (bs->io_limits_enabled) { + if (bs->throttle_state) { throttle_group_co_io_limits_intercept(bs, bytes, false); } @@ -1294,7 +1309,7 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, } /* throttling disk I/O */ - if (bs->io_limits_enabled) { + if (bs->throttle_state) { throttle_group_co_io_limits_intercept(bs, bytes, true); } @@ -2749,7 +2764,6 @@ void bdrv_flush_io_queue(BlockDriverState *bs) } else if (bs->file) { bdrv_flush_io_queue(bs->file->bs); } - bdrv_start_throttled_reqs(bs); } void bdrv_drained_begin(BlockDriverState *bs) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 9f52d2b..b348886 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -219,6 +219,10 @@ static bool throttle_group_schedule_timer(BlockDriverState *bs, ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); bool must_wait; + if (bs->io_limits_disabled) { + return false; + } + /* Check if any of the timers in this group is already armed */ if (tg->any_timer_armed[is_write]) { return true; diff --git a/include/block/block_int.h b/include/block/block_int.h index dda5ba0..dac6d43 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -412,10 +412,10 @@ struct BlockDriverState { /* I/O throttling. * throttle_state tells us if this BDS has I/O limits configured. - * io_limits_enabled tells us if they are currently being - * enforced, but it can be temporarily set to false */ + * io_limits_disabled tells us if they are currently being enforced */ CoQueue throttled_reqs[2]; - bool io_limits_enabled; + unsigned int io_limits_disabled; + /* The following fields are protected by the ThrottleGroup lock. * See the ThrottleGroup documentation for details. */ ThrottleState *throttle_state;