From patchwork Thu Aug 3 20:01:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9879809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 144B8603F4 for ; Thu, 3 Aug 2017 20:02:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117BE28923 for ; Thu, 3 Aug 2017 20:02:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04FAD28942; Thu, 3 Aug 2017 20:02:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C0172893F for ; Thu, 3 Aug 2017 20:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbdHCUCE (ORCPT ); Thu, 3 Aug 2017 16:02:04 -0400 Received: from mail-io0-f178.google.com ([209.85.223.178]:37605 "EHLO mail-io0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921AbdHCUCE (ORCPT ); Thu, 3 Aug 2017 16:02:04 -0400 Received: by mail-io0-f178.google.com with SMTP id c74so10994840iod.4 for ; Thu, 03 Aug 2017 13:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W9vfapFmzQ1crgScPxgvm8foVatMXjIPp/Ognvr2dpI=; b=RBDN96hxf+Qx/vwwGwX0KkLV6pV9ijJ5yJO/NDuEmK6dnZm+vGJCEpI5+j/ZldU9KF XktUCq7SFf67pdDr5g6VvS/gEWU03u/BuwgPUU4iGKSRmDBNeVf0fI8JcRjAt1zcN0qc Nmi3S7ueKYpP13CtnQsjjEGhdWH3uULg2Enxkd4DRERDweJQLdgtYD+BuDBh8TzNahVj eo89eLNVd0s93qXaQMDzsnrzn8TFpLMtvYDf/fvs+S3B3e+3yDBExzIK15UW8WhneaxP YDVbBBFRmLXmXdA+ryHqEl+o4TRXoHhIwf2p4cUdaIgCIlBi1OZ+EtklnPJSPNeb6HTb +bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W9vfapFmzQ1crgScPxgvm8foVatMXjIPp/Ognvr2dpI=; b=jBwMVVte1f9vxuhDsawU/tGwMDBEmKjX3OfnnBI12vz961lxVEDNpg497m5gOaJSWf U51IoTxHVt+9QXQnCpU806svTVFZ6WSZBdIgP+ducD4mAqbhmmPr74OO66IOUZw/AcKS UFE0N0L436qJfa8aS22dLiU772XxoN3wszSEOPMcPmq6WYc9ivUeN8XYXwtjxWHui5sd sJMxVBdn9QOPsbRNCAxUSiaD01IbP6wpB4IQ0+q2EqrVYRpPG9reZfW8cVRHnezlNWkC IqukxAZ1ZbJYEbTKJnkTpnwpyg9WnLHNjwc9ZpFeMH0ONKyQzQ9WiOZ9CNUsGyKjB7y7 L6Sw== X-Gm-Message-State: AHYfb5hTE+uGu81opi52msgm81pbdWMzvP3i0Abzd0mMgEN93dsrf4KK RJuQxwDKe+4YLjdK9b6n2w== X-Received: by 10.107.58.8 with SMTP id h8mr19984ioa.22.1501790523054; Thu, 03 Aug 2017 13:02:03 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id b79sm3780882itb.5.2017.08.03.13.02.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Aug 2017 13:02:02 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org Cc: brking@linux.vnet.ibm.com, Jens Axboe Subject: [PATCH 3/4] blk-mq: provide internal in-flight variant Date: Thu, 3 Aug 2017 14:01:55 -0600 Message-Id: <1501790516-6924-4-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501790516-6924-1-git-send-email-axboe@kernel.dk> References: <1501790516-6924-1-git-send-email-axboe@kernel.dk> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't have to inc/dec some counter, since we can just iterate the tags. That makes inc/dec a noop, but means we have to iterate busy tags to get an in-flight count. Signed-off-by: Jens Axboe Reviewed-by: Bart Van Assche --- block/blk-mq.c | 24 ++++++++++++++++++++++++ block/blk-mq.h | 2 ++ block/genhd.c | 29 +++++++++++++++++++++++++++++ include/linux/genhd.h | 25 +++---------------------- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 05dfa3f270ae..37035891e120 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -86,6 +86,30 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx, sbitmap_clear_bit(&hctx->ctx_map, ctx->index_hw); } +struct mq_inflight { + struct hd_struct *part; + unsigned int inflight; +}; + +static void blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx, + struct request *rq, void *priv, + bool reserved) +{ + struct mq_inflight *mi = priv; + + if (rq->part == mi->part) + mi->inflight++; +} + +unsigned int blk_mq_in_flight(struct request_queue *q, + struct hd_struct *part) +{ + struct mq_inflight mi = { .part = part, .inflight = 0 }; + + blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi); + return mi.inflight; +} + void blk_freeze_queue_start(struct request_queue *q) { int freeze_depth; diff --git a/block/blk-mq.h b/block/blk-mq.h index 1a06fdf9fd4d..cade1a512a01 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -138,4 +138,6 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx) return hctx->nr_ctx && hctx->tags; } +unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part); + #endif diff --git a/block/genhd.c b/block/genhd.c index f735af67a0c9..ad5dc567d57f 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -45,6 +45,35 @@ static void disk_add_events(struct gendisk *disk); static void disk_del_events(struct gendisk *disk); static void disk_release_events(struct gendisk *disk); +void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw) +{ + if (q->mq_ops) + return; + + atomic_inc(&part->in_flight[rw]); + if (part->partno) + atomic_inc(&part_to_disk(part)->part0.in_flight[rw]); +} + +void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw) +{ + if (q->mq_ops) + return; + + atomic_dec(&part->in_flight[rw]); + if (part->partno) + atomic_dec(&part_to_disk(part)->part0.in_flight[rw]); +} + +int part_in_flight(struct request_queue *q, struct hd_struct *part) +{ + if (q->mq_ops) + return blk_mq_in_flight(q, part); + + return atomic_read(&part->in_flight[0]) + + atomic_read(&part->in_flight[1]); +} + /** * disk_get_part - get partition * @disk: disk to look partition from diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 7f7427e00f9c..f2c5096b3a7e 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -362,28 +362,9 @@ static inline void free_part_stats(struct hd_struct *part) #define part_stat_sub(cpu, gendiskp, field, subnd) \ part_stat_add(cpu, gendiskp, field, -subnd) -static inline void part_inc_in_flight(struct request_queue *q, - struct hd_struct *part, int rw) -{ - atomic_inc(&part->in_flight[rw]); - if (part->partno) - atomic_inc(&part_to_disk(part)->part0.in_flight[rw]); -} - -static inline void part_dec_in_flight(struct request_queue *q, - struct hd_struct *part, int rw) -{ - atomic_dec(&part->in_flight[rw]); - if (part->partno) - atomic_dec(&part_to_disk(part)->part0.in_flight[rw]); -} - -static inline int part_in_flight(struct request_queue *q, - struct hd_struct *part) -{ - return atomic_read(&part->in_flight[0]) + - atomic_read(&part->in_flight[1]); -} +int part_in_flight(struct request_queue *q, struct hd_struct *part); +void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw); +void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw); static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk) {