From patchwork Fri Jul 27 16:20:40 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: 10547419 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 0132C112B for ; Fri, 27 Jul 2018 16:20:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E56682C196 for ; Fri, 27 Jul 2018 16:20:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3DEB2C1B6; Fri, 27 Jul 2018 16:20:45 +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 41B382C19D for ; Fri, 27 Jul 2018 16:20:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730698AbeG0RnU (ORCPT ); Fri, 27 Jul 2018 13:43:20 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:15076 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730852AbeG0RnU (ORCPT ); Fri, 27 Jul 2018 13:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1532708445; x=1564244445; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Qe5qUjuSSBxYS3IFQCyNN6FhbDH0ni0dDwkReESS2mo=; b=K7WmnLENBqr5sWgXrct3dRxtmrxuWxQYfYTsCNWP4DQl6ZYRAKAM+vdG VzSqwfzoVA1UvWazcfJghEXQdUdF5RG/EL5ydI6ccsctrE7gy0f1dqD4h TB/54/q2N7trqA18kJDDDopEjvo6m6djOcuz/9RrcGKOoQeYIP/uAsWZD vydSRvIREVT9JymcbEo+HuB1wEd4lIsgGq7/mEY34bVXRvdvRLUc1DSEd BnCV9WoF3fGTfbndEkQmXgQQW0EoWSsl8CTvhwqclYtGI6X0oAoUkk8kz Hl7G91JI+bvtOu2n7xaaUyjPUhA4K7ApAHNUkdXiXQkAoelkjhZAkYCFq Q==; X-IronPort-AV: E=Sophos;i="5.51,410,1526313600"; d="scan'208";a="86000771" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Jul 2018 00:20:44 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 27 Jul 2018 09:09:16 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jul 2018 09:20:42 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Keith Busch , Jianchao Wang , Ming Lei Subject: [PATCH 3/5] block: Split blk_add_timer() Date: Fri, 27 Jul 2018 09:20:40 -0700 Message-Id: <20180727162042.13425-4-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180727162042.13425-1-bart.vanassche@wdc.com> References: <20180727162042.13425-1-bart.vanassche@wdc.com> 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 Split blk_add_timer() as follows: - Introduce the helper function __blk_add_timer() that performs the tasks that apply both to the legacy block layer core and to blk-mq. - Duplicate the remaining blk_add_timer() function into the new function blk_mq_add_timer(). - Change the blk_mq_timer() calls into blk_mq_add_timer() calls in blk-mq code. This patch does not change any functionality. Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Keith Busch Cc: Jianchao Wang Cc: Ming Lei --- block/blk-mq.c | 4 +-- block/blk-timeout.c | 81 +++++++++++++++++++++++++++++++++++---------- block/blk.h | 1 + 3 files changed, 66 insertions(+), 20 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 96e1a7f25875..1b49973629f6 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -644,7 +644,7 @@ void blk_mq_start_request(struct request *rq) WARN_ON_ONCE(blk_mq_rq_state(rq) != MQ_RQ_IDLE); - blk_add_timer(rq); + blk_mq_add_timer(rq); WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT); if (q->dma_drain_size && blk_rq_bytes(rq)) { @@ -779,7 +779,7 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved) WARN_ON_ONCE(ret != BLK_EH_RESET_TIMER); } - blk_add_timer(req); + blk_mq_add_timer(req); } static bool blk_mq_req_expired(struct request *rq, unsigned long *next) diff --git a/block/blk-timeout.c b/block/blk-timeout.c index 37df7f8f8516..527670f2f985 100644 --- a/block/blk-timeout.c +++ b/block/blk-timeout.c @@ -181,6 +181,33 @@ unsigned long blk_rq_timeout(unsigned long timeout) return timeout; } +static void __blk_add_timer(struct request *req, unsigned long deadline) +{ + struct request_queue *q = req->q; + unsigned long expiry; + + /* + * If the timer isn't already pending or this timeout is earlier + * than an existing one, modify the timer. Round up to next nearest + * second. + */ + expiry = blk_rq_timeout(round_jiffies_up(deadline)); + if (!timer_pending(&q->timeout) || + time_before(expiry, q->timeout.expires)) { + unsigned long diff = q->timeout.expires - expiry; + + /* + * Due to added timer slack to group timers, the timer + * will often be a little in front of what we asked for. + * So apply some tolerance here too, otherwise we keep + * modifying the timer because expires for value X + * will be X + something. + */ + if (!timer_pending(&q->timeout) || (diff >= HZ / 2)) + mod_timer(&q->timeout, expiry); + } +} + /** * blk_add_timer - Start timeout timer for a single request * @req: request that is about to start running. @@ -192,7 +219,6 @@ unsigned long blk_rq_timeout(unsigned long timeout) void blk_add_timer(struct request *req) { struct request_queue *q = req->q; - unsigned long expiry; if (!q->mq_ops) lockdep_assert_held(q->queue_lock); @@ -220,26 +246,45 @@ void blk_add_timer(struct request *req) if (!q->mq_ops) list_add_tail(&req->timeout_list, &req->q->timeout_list); + __blk_add_timer(req, blk_rq_deadline(req)); +} + +/** + * blk_mq_add_timer - set the deadline for a single request + * @req: request for which to set the deadline. + * + * Sets the deadline of a request. The caller must guarantee that the request + * state won't be modified while this function is in progress. + */ +void blk_mq_add_timer(struct request *req) +{ + struct request_queue *q = req->q; + + if (!q->mq_ops) + lockdep_assert_held(q->queue_lock); + + /* blk-mq has its own handler, so we don't need ->rq_timed_out_fn */ + if (!q->mq_ops && !q->rq_timed_out_fn) + return; + + BUG_ON(!list_empty(&req->timeout_list)); + /* - * If the timer isn't already pending or this timeout is earlier - * than an existing one, modify the timer. Round up to next nearest - * second. + * Some LLDs, like scsi, peek at the timeout to prevent a + * command from being retried forever. */ - expiry = blk_rq_timeout(round_jiffies_up(blk_rq_deadline(req))); + if (!req->timeout) + req->timeout = q->rq_timeout; - if (!timer_pending(&q->timeout) || - time_before(expiry, q->timeout.expires)) { - unsigned long diff = q->timeout.expires - expiry; + req->rq_flags &= ~RQF_TIMED_OUT; + blk_rq_set_deadline(req, jiffies + req->timeout); - /* - * Due to added timer slack to group timers, the timer - * will often be a little in front of what we asked for. - * So apply some tolerance here too, otherwise we keep - * modifying the timer because expires for value X - * will be X + something. - */ - if (!timer_pending(&q->timeout) || (diff >= HZ / 2)) - mod_timer(&q->timeout, expiry); - } + /* + * Only the non-mq case needs to add the request to a protected list. + * For the mq case we simply scan the tag map. + */ + if (!q->mq_ops) + list_add_tail(&req->timeout_list, &req->q->timeout_list); + __blk_add_timer(req, blk_rq_deadline(req)); } diff --git a/block/blk.h b/block/blk.h index 69b14cd2bb22..6adae8f94279 100644 --- a/block/blk.h +++ b/block/blk.h @@ -170,6 +170,7 @@ static inline bool bio_integrity_endio(struct bio *bio) void blk_timeout_work(struct work_struct *work); unsigned long blk_rq_timeout(unsigned long timeout); void blk_add_timer(struct request *req); +void blk_mq_add_timer(struct request *req); void blk_delete_timer(struct request *);