From patchwork Thu Mar 24 16:39:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8662571 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 0DF109F44D for ; Thu, 24 Mar 2016 16:39:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3132B203AD for ; Thu, 24 Mar 2016 16:39:54 +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 472BD203A0 for ; Thu, 24 Mar 2016 16:39:53 +0000 (UTC) Received: from localhost ([::1]:51792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aj8Ia-0001B9-N5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Mar 2016 12:39:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aj8IK-00011x-LB for qemu-devel@nongnu.org; Thu, 24 Mar 2016 12:39:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aj8IJ-0001X8-G6 for qemu-devel@nongnu.org; Thu, 24 Mar 2016 12:39:36 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aj8IJ-0001Wo-6M; Thu, 24 Mar 2016 12:39:35 -0400 Received: by mail-wm0-x244.google.com with SMTP id l68so14124862wml.3; Thu, 24 Mar 2016 09:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oV5Nr48s+QuCPOY/hxaeqwuHuQNJDhW4kZA5k2Vkjmg=; b=dGXAEeLAO2B0ciZIQnGTEJUU43pULvriDhOsTeIMxo0EyA08miJyrWCoHVzJf2G5kA Si/k9xr4wRQ8ZhZ41B7NVmKVz7g+6QR00RGSe9B/qZle4Rz46uyafy75QlzGnNiPtGpr r6rCWxcxkfTol7tuAaU1IFgZxHJr08s5AjASKCOgcvH+TICR6xuJ4eNXPftGadc8fggr o7UD8vKZoOKxrbrEU6MRbFDvDaQvJMpamgiVTypvLycqB2sMyurbsYDdNPiOmMSrw+3v 8QdS7SVmWUsdWf5vWVST/Gisn9tfLiDW0wfELvBfX7qgL19iWCHEfXY977uD6/Lpfrud gaHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oV5Nr48s+QuCPOY/hxaeqwuHuQNJDhW4kZA5k2Vkjmg=; b=aQzN3ndpo8Nt3ejz3N4GYC+jR7NHMO2FtudSpUxfONcEfQCglG8J8w1Rt8Au3lEubf vWq2pY7MefDnOtnrlrLelcdLGj9HRmcZOYeyGh1/np3AlZTLQWQxGfDTX8jMqaJ9OeqH NSCme9TRrgTrwym504GtSB+v0/o7EMS5pmoeH76kI7inEXfAhIGr5AH1iCcuSTMlUqmx uhD7IkEtOe3NT68hkb0XPAqwI75s332+3ZswZM9mbsEibXZRGFOnSiH7KqQficyYDU7Y CJsnCoyNdynlMUtUBleFKKuHBcN7jkaL0dm3l5yl2L998aC0Y7Zo1JBpJzE7za7AMGEk hDEw== X-Gm-Message-State: AD7BkJKCknleEV85pBbXHEi3TVw/VxqgI16RxRUw4yP62x6n+ScbYnzsmjmqYwLcsaiwAQ== X-Received: by 10.28.224.132 with SMTP id x126mr12122174wmg.88.1458837574535; Thu, 24 Mar 2016 09:39:34 -0700 (PDT) Received: from 640k.lan (94-39-161-17.adsl-ull.clienti.tiscali.it. [94.39.161.17]) by smtp.gmail.com with ESMTPSA id w125sm8508814wmw.18.2016.03.24.09.39.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Mar 2016 09:39:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 24 Mar 2016 17:39:23 +0100 Message-Id: <1458837566-108527-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1458837566-108527-1-git-send-email-pbonzini@redhat.com> References: <1458837566-108527-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH 4/7] 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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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. These new functions will soon become BdrvChildRole callbacks, as they can be generalized to "beginning of drain" and "end of drain". Signed-off-by: Paolo Bonzini Reviewed-by: Alberto Garcia --- v2->v3: rebase, drop recursion block.c | 1 - block/block-backend.c | 6 ++---- block/io.c | 30 ++++++++++++++++++------------ block/throttle-groups.c | 4 ++++ include/block/block_int.h | 9 ++++++--- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index b4107fc..9cc0eb4 100644 --- a/block.c +++ b/block.c @@ -2300,7 +2300,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/block-backend.c b/block/block-backend.c index dca21d1..51e9e49 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -800,7 +800,6 @@ int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors) { BlockDriverState *bs = blk_bs(blk); - bool enabled; int ret; ret = blk_check_request(blk, sector_num, nb_sectors); @@ -808,10 +807,9 @@ int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, return ret; } - enabled = bs->io_limits_enabled; - bs->io_limits_enabled = false; + bdrv_no_throttling_begin(bs); ret = blk_read(blk, sector_num, buf, nb_sectors); - bs->io_limits_enabled = enabled; + bdrv_no_throttling_end(bs); return ret; } diff --git a/block/io.c b/block/io.c index 93696df..516cfb9 100644 --- a/block/io.c +++ b/block/io.c @@ -63,28 +63,31 @@ void bdrv_set_io_limits(BlockDriverState *bs, throttle_group_config(bs, cfg); } -static void bdrv_start_throttled_reqs(BlockDriverState *bs) +void bdrv_no_throttling_begin(BlockDriverState *bs) { - bool enabled = bs->io_limits_enabled; + if (bs->io_limits_disabled++ == 0) { + throttle_group_restart_bs(bs); + } +} - bs->io_limits_enabled = false; - throttle_group_restart_bs(bs); - bs->io_limits_enabled = enabled; +void bdrv_no_throttling_end(BlockDriverState *bs) +{ + --bs->io_limits_disabled; } 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) @@ -249,6 +252,7 @@ void bdrv_drain(BlockDriverState *bs) { bool busy = true; + bdrv_no_throttling_begin(bs); bdrv_drain_recurse(bs); while (busy) { /* Keep iterating */ @@ -256,6 +260,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); } /* @@ -278,6 +283,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); @@ -319,6 +325,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); } @@ -921,7 +928,7 @@ 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); } @@ -1263,7 +1270,7 @@ 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); } @@ -2698,7 +2705,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 ba6e9ac..cfcbd96 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; @@ -722,4 +722,7 @@ void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); void blockdev_close_all_bdrv_states(void); +void bdrv_no_throttling_begin(BlockDriverState *bs); +void bdrv_no_throttling_end(BlockDriverState *bs); + #endif /* BLOCK_INT_H */