From patchwork Tue Sep 18 20:58:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10604875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FE636CB for ; Tue, 18 Sep 2018 20:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21422BEAA for ; Tue, 18 Sep 2018 20:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5A382BEAC; Tue, 18 Sep 2018 20:59:46 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 717592BEAB for ; Tue, 18 Sep 2018 20:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729873AbeISCeH (ORCPT ); Tue, 18 Sep 2018 22:34:07 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:50203 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729902AbeISCeH (ORCPT ); Tue, 18 Sep 2018 22:34:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=XUKZkxqZnfuA7Kmsljv2AqNev93+v94huV7zjHkTg1Y=; b=txvmxKfhmVa5 aUGTINVHIQ6EfTJaOwl5yHLYMC35Eu0oFy75DQnd5yvk5I01jJRb6lMo9lpW+vXIyBR00XvN7bvVt n27yv54RiBvScCf1pNvPrOXtjfE9sMgClxIW6xssAgb1uK59YM8GOlLE3nCPqffZxXswe5opHfBTG GDiR3KQWBk4VXlYFHHfb6RxsWCHNuDhQagsRinnXI0SEutauCTDULVch4Ftm7y6LNkfqRb68QRC1L KoGmatnfBUQAQ22pMWAJWDOJ2tRRWXuBabtyrR+39+KHvrX1AGIXc6oz5LNL8CnTMZ0lQupiRHEoN hwJmFwg1n/8Lyi2EFpB9xA==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1g2N5i-000FVv-61; Tue, 18 Sep 2018 22:59:26 +0200 Received: from asus.hsd1.ca.comcast.net (c-174-62-111-89.hsd1.ca.comcast.net [174.62.111.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 9B2B2C0906; Tue, 18 Sep 2018 22:59:22 +0200 (CEST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v8 2/8] blk-mq: Introduce blk_mq_queue_rq_iter() Date: Tue, 18 Sep 2018 13:58:57 -0700 Message-Id: <20180918205903.15516-3-bvanassche@acm.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180918205903.15516-1-bvanassche@acm.org> References: <20180918205903.15516-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExper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HAQY75TBNNMBbDdWXJeGq06L50X2Qy2upyaP8j1NfwLSMzMWgFsmE0+Xlz1pRXWhjh9fdbl44I0 Df1nN63Cw5XairzMoRO+2yR7pt9JqCP5X+u3uDCejVE4UNDPNRgrf1AeViSeIVnMBBfBRBZgCikv OAMF/4pY8933x+uRyQECoIXFluPJGyJ2ePcQWk+3dNZU5rZYaF7U3qSQORcYm+eIaK9fUWr9RAN1 9ssFeollKTUEleC/aMh59YF7hUbm4nn1f8ypkbDQ8N7mh/jFPxqiQ662IrNcVOfW X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This function will be used in the patch "Make blk_get_request() block for non-PM requests while suspended". Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Ming Lei Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- block/blk-mq-tag.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-tag.h | 2 ++ 2 files changed, 46 insertions(+) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index ef3acb4a80e0..cf8537017f78 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -374,6 +374,50 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn, rcu_read_unlock(); } +/* + * Call @fn(rq, @priv, reserved) for each request associated with request + * queue @q or any queue that it shares tags with and that has been assigned a + * tag. 'reserved' indicates whether or not 'rq' is a reserved request. In + * contrast to blk_mq_queue_tag_busy_iter(), if an I/O scheduler has been + * associated with @q, this function also iterates over requests that have + * been assigned a scheduler tag but that have not yet been assigned a driver + * tag. + */ +void blk_mq_queue_rq_iter(struct request_queue *q, busy_iter_fn *fn, void *priv) +{ + struct blk_mq_hw_ctx *hctx; + int i; + + /* + * __blk_mq_update_nr_hw_queues will update the nr_hw_queues and + * queue_hw_ctx after freeze the queue. So we could use q_usage_counter + * to avoid race with it. __blk_mq_update_nr_hw_queues will users + * synchronize_rcu to ensure all of the users go out of the critical + * section below and see zeroed q_usage_counter. + */ + rcu_read_lock(); + if (percpu_ref_is_zero(&q->q_usage_counter)) { + rcu_read_unlock(); + return; + } + + queue_for_each_hw_ctx(q, hctx, i) { + struct blk_mq_tags *tags = hctx->sched_tags ? : hctx->tags; + + /* + * If no software queues are currently mapped to this + * hardware queue, there's nothing to check + */ + if (!blk_mq_hw_queue_mapped(hctx)) + continue; + + if (tags->nr_reserved_tags) + bt_for_each(hctx, &tags->breserved_tags, fn, priv, true); + bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false); + } + rcu_read_unlock(); +} + static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth, bool round_robin, int node) { diff --git a/block/blk-mq-tag.h b/block/blk-mq-tag.h index 61deab0b5a5a..25e62997ed6c 100644 --- a/block/blk-mq-tag.h +++ b/block/blk-mq-tag.h @@ -35,6 +35,8 @@ extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx, extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool); void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn, void *priv); +void blk_mq_queue_rq_iter(struct request_queue *q, busy_iter_fn *fn, + void *priv); static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt, struct blk_mq_hw_ctx *hctx)