From patchwork Thu Apr 7 16:33:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 607514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3qgpCM3PF8z9t4h for ; Fri, 8 Apr 2016 02:37:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=K0J2L8KE; dkim-atps=neutral Received: from localhost ([::1]:51325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCvV-00072P-FI for incoming@patchwork.ozlabs.org; Thu, 07 Apr 2016 12:37:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCsN-0001MM-Rf for qemu-devel@nongnu.org; Thu, 07 Apr 2016 12:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoCsM-0005kl-6k for qemu-devel@nongnu.org; Thu, 07 Apr 2016 12:33:47 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCsL-0005kV-Sv; Thu, 07 Apr 2016 12:33:46 -0400 Received: by mail-wm0-x243.google.com with SMTP id l6so5684499wml.3; Thu, 07 Apr 2016 09:33:45 -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=L/zgZ6ngBfy40rCO9igAVknQcNcBtrpa3kLztBWfVjM=; b=K0J2L8KE7TSymXqIpgxEk3LckQy3Vdvu8eggkoJ7pVja1KLmGCq9q8xeZlSR0BTCZ4 9Wzlz8x9lByxO5bx2kw9Ob3Cv3yt76ycD4Mafh/SF2I7uCG79yqzich9kjiWvZ9oLfSZ KONiXfQIVQ+8wU79RE2X8TF/uke7qojYSZeSBEzK2tvpVvdgCD/nb2IEzDvUO0U8N4I5 jmAHG0e2ST9JDhYzSnWes/CVfGJRpPjOV1l46PUfwhNjxiIxWloO86rqsATObOoinpTz DvdnKRhMMYXOX1Mnc9rd8H6KKZ+6QaudSa6w/jxddMvpDSx5qVEcmQ9Ax8GyIkOLM6SZ xa3A== 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=L/zgZ6ngBfy40rCO9igAVknQcNcBtrpa3kLztBWfVjM=; b=mi6bEiOpG4G0LcDw2mAFnTPa/++mFnFYNmneoSvUPEg9vq1J+x1hQduSC/DyM0+5NU PIHknArK42RMsZZETm87LahewFZtBbdg7rQGjjf+tvJcA3B3ruDQpVRZwH21PtJWgk3u zTHAmBFJ7tq7qruhvM3YpGkSuwcH+nq3Cd4mHqlvasDAc6lQjL7ebkoAUkTW7Kb79DDD gsX+Fl6L4H6r9lo55SirbwITAT8QzJfEfGmekd3D+ZoOXSxmCTreQo0U2JdtTsVQrS90 F+cNp6TNlgCbOuFWpn0Jyk5ZkTcIofD18QF6cQjb/ys88UUEArs98x6AEs2PHebMaGls NYlA== X-Gm-Message-State: AD7BkJJLXaBVahmqb5Eb5CJmAFl6B+O6+Zu0tDnWBv3oxKrMPUc/aSa0XPTQdSeRNP9NHA== X-Received: by 10.28.105.5 with SMTP id e5mr5307950wmc.87.1460046825275; Thu, 07 Apr 2016 09:33:45 -0700 (PDT) Received: from 640k.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id hh8sm9218862wjc.42.2016.04.07.09.33.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Apr 2016 09:33:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Apr 2016 18:33:33 +0200 Message-Id: <1460046816-102846-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1460046816-102846-1-git-send-email-pbonzini@redhat.com> References: <1460046816-102846-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::243 Cc: kwolf@redhat.com, berto@igalia.com, famz@redhat.com, qemu-block@nongnu.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v4 5/8] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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". Reviewed-by: Alberto Garcia Signed-off-by: Paolo Bonzini --- v3->v4: added assertion in bdrv_no_throttling_end [Berto] block.c | 1 - block/block-backend.c | 6 ++---- block/io.c | 33 +++++++++++++++++++++------------ block/throttle-groups.c | 4 ++++ include/block/block_int.h | 9 ++++++--- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index d4939b4..6cbad0e 100644 --- a/block.c +++ b/block.c @@ -2261,7 +2261,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 d74f670..435856c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -794,7 +794,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); @@ -802,10 +801,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 15bc956..fbcf954 100644 --- a/block/io.c +++ b/block/io.c @@ -65,28 +65,32 @@ 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) +{ + assert(bs->io_limits_disabled); + --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) @@ -302,18 +306,22 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) */ void coroutine_fn bdrv_co_drain(BlockDriverState *bs) { + bdrv_no_throttling_begin(bs); bdrv_drain_recurse(bs); bdrv_co_yield_to_drain(bs); + bdrv_no_throttling_end(bs); } void bdrv_drain(BlockDriverState *bs) { + bdrv_no_throttling_begin(bs); bdrv_drain_recurse(bs); if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs); } else { bdrv_drain_poll(bs); } + bdrv_no_throttling_end(bs); } /* @@ -336,6 +344,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); @@ -377,6 +386,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); } @@ -980,7 +990,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); } @@ -1330,7 +1340,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); } @@ -2772,7 +2782,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 b796f6b..9ac063a 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 10d8759..ed9314b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -424,10 +424,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; @@ -713,6 +713,9 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const BdrvChildRole *child_role); void bdrv_root_unref_child(BdrvChild *child); +void bdrv_no_throttling_begin(BlockDriverState *bs); +void bdrv_no_throttling_end(BlockDriverState *bs); + void blk_dev_change_media_cb(BlockBackend *blk, bool load); bool blk_dev_has_removable_media(BlockBackend *blk); bool blk_dev_has_tray(BlockBackend *blk);