From patchwork Fri Jul 27 22:56:18 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: 10547795 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 212BFA65F for ; Fri, 27 Jul 2018 22:56:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13AD62C693 for ; Fri, 27 Jul 2018 22:56:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 085132C736; Fri, 27 Jul 2018 22:56:25 +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 240822C699 for ; Fri, 27 Jul 2018 22:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388507AbeG1AUY (ORCPT ); Fri, 27 Jul 2018 20:20:24 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:29752 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731568AbeG1AUY (ORCPT ); Fri, 27 Jul 2018 20:20:24 -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=1532732183; x=1564268183; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=z94dgkc87GwITL/gAKcW27qG6FGvs+C9NWnV2/G0br0=; b=YrkMTW2g5CWJqI+PfavwCsIqC3DiL6bY7150mVNO2/wY2D70PN75ejic Km4yZfWqvvOupHCndL0g3psyYt0NIG5o+qqPm/42vtLZb9SjsDP0MRKYL /V7+Kg1ZR4kZHjdijZASnqAB5I83tAlgTt4hoGuRCJWDPaWt/iTP1vTaO 0nRc+EshiTX6WcjzgXX1NtZc+ToInFUzzhq0oCDy3c5cdMAIsiBghf8d7 xd404JBnI+DtJniPcD9asuAa7GThMjlCmTus4Vae+0D3t+vZ+HCGYBeBV z9EK4CNWmDIF+C10rThIk3bsVJV/8rpUnZnQRsk9LVYxWOltD+LxBupfW g==; X-IronPort-AV: E=Sophos;i="5.51,411,1526313600"; d="scan'208";a="85204235" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jul 2018 06:56:22 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 27 Jul 2018 15:44:24 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jul 2018 15:56:22 -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 v2 3/5] block: Split blk_add_timer() Date: Fri, 27 Jul 2018 15:56:18 -0700 Message-Id: <20180727225620.17855-4-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180727225620.17855-1-bart.vanassche@wdc.com> References: <20180727225620.17855-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 8e9beb4ddeb0..670f8960b88a 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)) { @@ -785,7 +785,7 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved) } } - 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 38992c098026..ac0255a70401 100644 --- a/block/blk-timeout.c +++ b/block/blk-timeout.c @@ -188,6 +188,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. @@ -199,7 +226,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); @@ -227,26 +253,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 *);