From patchwork Fri Apr 22 17:42:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8914751 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 2142A9F1D3 for ; Fri, 22 Apr 2016 17:45:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FB41201C8 for ; Fri, 22 Apr 2016 17:45:20 +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 81DBF201C0 for ; Fri, 22 Apr 2016 17:45:19 +0000 (UTC) Received: from localhost ([::1]:36980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atf8o-0008MC-QQ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Apr 2016 13:45:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atf6g-00030s-KB for qemu-devel@nongnu.org; Fri, 22 Apr 2016 13:43:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atf6f-0006Yx-EQ for qemu-devel@nongnu.org; Fri, 22 Apr 2016 13:43:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atf6d-0006YJ-0c; Fri, 22 Apr 2016 13:43:03 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DF5CC05E16B; Fri, 22 Apr 2016 17:43:02 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-64.ams2.redhat.com [10.36.116.64]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3MHgiPT021616; Fri, 22 Apr 2016 13:43:00 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 22 Apr 2016 19:42:35 +0200 Message-Id: <1461346962-4676-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1461346962-4676-1-git-send-email-kwolf@redhat.com> References: <1461346962-4676-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 06/13] block: Move actual I/O throttling to BlockBackend 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, berto@igalia.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Kevin Wolf Reviewed-by: Alberto Garcia --- block/block-backend.c | 10 ++++++++++ block/io.c | 10 ---------- block/throttle-groups.c | 5 ++--- include/block/throttle-groups.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 087e60a..b1a176e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -716,6 +716,11 @@ static int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, return ret; } + /* throttling disk I/O */ + if (blk->public.throttle_state) { + throttle_group_co_io_limits_intercept(blk, bytes, false); + } + return bdrv_co_do_preadv(blk_bs(blk), offset, bytes, qiov, flags); } @@ -730,6 +735,11 @@ static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, return ret; } + /* throttling disk I/O */ + if (blk->public.throttle_state) { + throttle_group_co_io_limits_intercept(blk, bytes, true); + } + if (!blk->enable_write_cache) { flags |= BDRV_REQ_FUA; } diff --git a/block/io.c b/block/io.c index 34d1bf6..ccc6a76 100644 --- a/block/io.c +++ b/block/io.c @@ -1007,11 +1007,6 @@ int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs, flags |= BDRV_REQ_COPY_ON_READ; } - /* throttling disk I/O */ - if (bs->blk && blk_get_public(bs->blk)->throttle_state) { - throttle_group_co_io_limits_intercept(bs, bytes, false); - } - /* Align read if necessary by padding qiov */ if (offset & (align - 1)) { head_buf = qemu_blockalign(bs, align); @@ -1357,11 +1352,6 @@ int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, return ret; } - /* throttling disk I/O */ - if (bs->blk && blk_get_public(bs->blk)->throttle_state) { - throttle_group_co_io_limits_intercept(bs, bytes, true); - } - /* * Align write if necessary by performing a read-modify-write cycle. * Pad qiov with the read parts and be sure to have a tracked request not diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 5bd5c3b..6e6939e 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -284,18 +284,17 @@ static void schedule_next_request(BlockBackend *blk, bool is_write) * if necessary, and schedule the next request using a round robin * algorithm. * - * @bs: the current BlockDriverState + * @blk: the current BlockBackend * @bytes: the number of bytes for this I/O * @is_write: the type of operation (read/write) */ -void coroutine_fn throttle_group_co_io_limits_intercept(BlockDriverState *bs, +void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, unsigned int bytes, bool is_write) { bool must_wait; BlockBackend *token; - BlockBackend *blk = bs->blk; BlockBackendPublic *blkp = blk_get_public(blk); ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h index 840ba44..ac42248 100644 --- a/include/block/throttle-groups.h +++ b/include/block/throttle-groups.h @@ -40,7 +40,7 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname); void throttle_group_unregister_blk(BlockBackend *blk); void throttle_group_restart_blk(BlockBackend *blk); -void coroutine_fn throttle_group_co_io_limits_intercept(BlockDriverState *bs, +void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, unsigned int bytes, bool is_write);