From patchwork Mon Jan 8 19:15:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 10150425 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 3716D601A1 for ; Mon, 8 Jan 2018 19:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F51928688 for ; Mon, 8 Jan 2018 19:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3260C286A4; Mon, 8 Jan 2018 19:19:28 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 99CF228688 for ; Mon, 8 Jan 2018 19:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756413AbeAHTTO (ORCPT ); Mon, 8 Jan 2018 14:19:14 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:34646 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932372AbeAHTPv (ORCPT ); Mon, 8 Jan 2018 14:15:51 -0500 Received: by mail-qt0-f196.google.com with SMTP id 33so14968249qtv.1; Mon, 08 Jan 2018 11:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=W77FrbD6Nu8OeRV3aXIPA7Y6OZUtb5C17blZsYxS9kc=; b=NQlsykemOug1M8Vftvow9pgxzEil8Gocr9H43HlOSItd9cGTsap4wyss/TwQGJUsGQ B9mb2tfFbo1H7bgGskc/eDocup5TCkg0hqMs2WyPwQtkMk/08ma0YDAVkfh3lQvY3miK 8qeJ8b3A+UjZH7aWhpLGn1qCh/V+kcu1lWsK6jBen9qAUyw4sa3t80wP+o7iYIvhJNIy IIaIIAQvJUuEz0U8IpIOLRRuHRgjIDtZbVXucilR3gkZv/oEIx9KF7WqzaopIPeSsMYs NtxDi49W6LhKetImq8iCqLbwP5I/hgW3F2LWcgMjfeb7uTRAe1b1u46XGEEzN+45Q1Kh c1Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=W77FrbD6Nu8OeRV3aXIPA7Y6OZUtb5C17blZsYxS9kc=; b=ZkbpB+oadaa1n88dTBrgEemNQj0GUMdSOwYQBwaOCgSEe9ZNzE5wsZ+4pk2aW5ufkO llEveuwBU9G4RlkErGqajfyNpgOjy2msHNyGr1rSd4iOF0e17YnR9ffOZw1AYzi7kNAl nGYUWRV7HM4f7tgXf+cUDcG8QiXJOEwg0F5B5q3ywIWOPsolFj/U9LJWDVT5VLjufAac D/3oCxBBBancaG6GVX+gIhnQjvkSUDj6sromYMLgx3SWr7msrmKLuzWCXLlOntc6mXsM Nsg74a9sR1W0eevw8CpHK4/8k7RtsbwllcoKdL2yvSZe3jzk+BYfozvs4c5mg6snaFZA /1yw== X-Gm-Message-State: AKwxytdHTy/CMjcKFyVgXfXD+e/BdvEgER6YNNZxwktyANDiE0WOb+vN gwwk1Szbz2QKH89PTymJiys= X-Google-Smtp-Source: ACJfBovMfNkURHwYIODghQvz3ai06EDbOnD0Tmd2Fw0j4qTXy/DbNlfrtqOmHNqxwQvF3L5oKgMYcA== X-Received: by 10.200.43.141 with SMTP id m13mr17776502qtm.72.1515438950369; Mon, 08 Jan 2018 11:15:50 -0800 (PST) Received: from localhost (dhcp-ec-8-6b-ed-7a-cf.cpe.echoes.net. [72.28.5.223]) by smtp.gmail.com with ESMTPSA id j7sm7778363qth.31.2018.01.08.11.15.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 11:15:49 -0800 (PST) From: Tejun Heo To: jack@suse.cz, axboe@kernel.dk, clm@fb.com, jbacik@fb.com Cc: kernel-team@fb.com, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, peterz@infradead.org, jianchao.w.wang@oracle.com, Bart.VanAssche@wdc.com, linux-block@vger.kernel.org, Tejun Heo Subject: [PATCH 1/8] blk-mq: move hctx lock/unlock into a helper Date: Mon, 8 Jan 2018 11:15:35 -0800 Message-Id: <20180108191542.379478-2-tj@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180108191542.379478-1-tj@kernel.org> References: <20180108191542.379478-1-tj@kernel.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jens Axboe Move the RCU vs SRCU logic into lock/unlock helpers, which makes the actual functional bits within the locked region much easier to read. tj: Reordered in front of timeout revamp patches and added the missing blk_mq_run_hw_queue() conversion. Signed-off-by: Jens Axboe Signed-off-by: Tejun Heo Reviewed-by: Bart Van Assche --- block/blk-mq.c | 66 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 111e1aa..ddc9261 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -557,6 +557,22 @@ static void __blk_mq_complete_request(struct request *rq) put_cpu(); } +static void hctx_unlock(struct blk_mq_hw_ctx *hctx, int srcu_idx) +{ + if (!(hctx->flags & BLK_MQ_F_BLOCKING)) + rcu_read_unlock(); + else + srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx); +} + +static void hctx_lock(struct blk_mq_hw_ctx *hctx, int *srcu_idx) +{ + if (!(hctx->flags & BLK_MQ_F_BLOCKING)) + rcu_read_lock(); + else + *srcu_idx = srcu_read_lock(hctx->queue_rq_srcu); +} + /** * blk_mq_complete_request - end I/O on a request * @rq: the request being processed @@ -1214,17 +1230,11 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx) */ WARN_ON_ONCE(in_interrupt()); - if (!(hctx->flags & BLK_MQ_F_BLOCKING)) { - rcu_read_lock(); - blk_mq_sched_dispatch_requests(hctx); - rcu_read_unlock(); - } else { - might_sleep(); + might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING); - srcu_idx = srcu_read_lock(hctx->queue_rq_srcu); - blk_mq_sched_dispatch_requests(hctx); - srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx); - } + hctx_lock(hctx, &srcu_idx); + blk_mq_sched_dispatch_requests(hctx); + hctx_unlock(hctx, srcu_idx); } /* @@ -1296,17 +1306,10 @@ bool blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async) * And queue will be rerun in blk_mq_unquiesce_queue() if it is * quiesced. */ - if (!(hctx->flags & BLK_MQ_F_BLOCKING)) { - rcu_read_lock(); - need_run = !blk_queue_quiesced(hctx->queue) && - blk_mq_hctx_has_pending(hctx); - rcu_read_unlock(); - } else { - srcu_idx = srcu_read_lock(hctx->queue_rq_srcu); - need_run = !blk_queue_quiesced(hctx->queue) && - blk_mq_hctx_has_pending(hctx); - srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx); - } + hctx_lock(hctx, &srcu_idx); + need_run = !blk_queue_quiesced(hctx->queue) && + blk_mq_hctx_has_pending(hctx); + hctx_unlock(hctx, srcu_idx); if (need_run) { __blk_mq_delay_run_hw_queue(hctx, async, 0); @@ -1618,7 +1621,7 @@ static blk_qc_t request_to_qc_t(struct blk_mq_hw_ctx *hctx, struct request *rq) static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, struct request *rq, - blk_qc_t *cookie, bool may_sleep) + blk_qc_t *cookie) { struct request_queue *q = rq->q; struct blk_mq_queue_data bd = { @@ -1668,25 +1671,20 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, } insert: - blk_mq_sched_insert_request(rq, false, run_queue, false, may_sleep); + blk_mq_sched_insert_request(rq, false, run_queue, false, + hctx->flags & BLK_MQ_F_BLOCKING); } static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, struct request *rq, blk_qc_t *cookie) { - if (!(hctx->flags & BLK_MQ_F_BLOCKING)) { - rcu_read_lock(); - __blk_mq_try_issue_directly(hctx, rq, cookie, false); - rcu_read_unlock(); - } else { - unsigned int srcu_idx; + int srcu_idx; - might_sleep(); + might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING); - srcu_idx = srcu_read_lock(hctx->queue_rq_srcu); - __blk_mq_try_issue_directly(hctx, rq, cookie, true); - srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx); - } + hctx_lock(hctx, &srcu_idx); + __blk_mq_try_issue_directly(hctx, rq, cookie); + hctx_unlock(hctx, srcu_idx); } static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)