From patchwork Tue Nov 1 21:05:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9408041 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 0899C60234 for ; Tue, 1 Nov 2016 21:06:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0B0329A50 for ; Tue, 1 Nov 2016 21:06:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E59FA29A9C; Tue, 1 Nov 2016 21:06:23 +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 94E2E29A50 for ; Tue, 1 Nov 2016 21:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932218AbcKAVFj (ORCPT ); Tue, 1 Nov 2016 17:05:39 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:53992 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754283AbcKAVFi (ORCPT ); Tue, 1 Nov 2016 17:05:38 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.17/8.16.0.17) with SMTP id uA1L48N6016828; Tue, 1 Nov 2016 14:05:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=yK6rIn0BgxW3JItLMBRTnPkA7m8OK8r2oIFZbs77URg=; b=qSbJz/3Pcw1q8oCBacuoYQ3nUZLjQcZbcoSQz+cPKrMk0bkxDcDmpELBUw8Qjyi51QN+ HBrVgFa3LGAMMtL6t6g9qpWPW198Ivs1j7pm/2KH5uHsPU3imrFhy+oFzrwrfUqYm0AI 4JaSgE+o78CNMh9GbeL+ZlN5bXJoIz/MB58= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 26f12b92ms-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 01 Nov 2016 14:05:35 -0700 Received: from x1.hil-sfehihf.abq.wayport.net (192.168.54.13) by mail.thefacebook.com (192.168.16.20) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 1 Nov 2016 14:05:33 -0700 From: Jens Axboe To: , , CC: , Jens Axboe Subject: [PATCH 2/4] block: move poll code to blk-mq Date: Tue, 1 Nov 2016 15:05:23 -0600 Message-ID: <1478034325-28232-3-git-send-email-axboe@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478034325-28232-1-git-send-email-axboe@fb.com> References: <1478034325-28232-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-01_07:, , signatures=0 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 The poll code is blk-mq specific, let's move it to blk-mq.c. This is a prep patch for improving the polling code. Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig --- block/blk-core.c | 36 +++++------------------------------- block/blk-mq.c | 33 +++++++++++++++++++++++++++++++++ block/blk-mq.h | 2 ++ 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index ca77c725b4e5..7728562d77d9 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3293,47 +3293,21 @@ EXPORT_SYMBOL(blk_finish_plug); bool blk_poll(struct request_queue *q, blk_qc_t cookie) { - struct blk_plug *plug; - long state; - unsigned int queue_num; struct blk_mq_hw_ctx *hctx; + struct blk_plug *plug; + struct request *rq; if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) || !test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) return false; - queue_num = blk_qc_t_to_queue_num(cookie); - hctx = q->queue_hw_ctx[queue_num]; - hctx->poll_considered++; - plug = current->plug; if (plug) blk_flush_plug_list(plug, false); - state = current->state; - while (!need_resched()) { - int ret; - - hctx->poll_invoked++; - - ret = q->mq_ops->poll(hctx, blk_qc_t_to_tag(cookie)); - if (ret > 0) { - hctx->poll_success++; - set_current_state(TASK_RUNNING); - return true; - } - - if (signal_pending_state(state, current)) - set_current_state(TASK_RUNNING); - - if (current->state == TASK_RUNNING) - return true; - if (ret < 0) - break; - cpu_relax(); - } - - return false; + hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)]; + rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie)); + return blk_mq_poll(hctx, rq); } EXPORT_SYMBOL_GPL(blk_poll); diff --git a/block/blk-mq.c b/block/blk-mq.c index 4555a76d22a7..4ef35588c299 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2352,6 +2352,39 @@ void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues) } EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues); +bool blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) +{ + struct request_queue *q = hctx->queue; + long state; + + hctx->poll_considered++; + + state = current->state; + while (!need_resched()) { + int ret; + + hctx->poll_invoked++; + + ret = q->mq_ops->poll(hctx, rq->tag); + if (ret > 0) { + hctx->poll_success++; + set_current_state(TASK_RUNNING); + return true; + } + + if (signal_pending_state(state, current)) + set_current_state(TASK_RUNNING); + + if (current->state == TASK_RUNNING) + return true; + if (ret < 0) + break; + cpu_relax(); + } + + return false; +} + void blk_mq_disable_hotplug(void) { mutex_lock(&all_q_mutex); diff --git a/block/blk-mq.h b/block/blk-mq.h index 8cf16cb69f64..79ea86e0ed49 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -61,6 +61,8 @@ extern void blk_mq_rq_timed_out(struct request *req, bool reserved); void blk_mq_release(struct request_queue *q); +extern bool blk_mq_poll(struct blk_mq_hw_ctx *, struct request *); + static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q, unsigned int cpu) {