From patchwork Wed Oct 5 16:51:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 9363239 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 264AC6077E for ; Wed, 5 Oct 2016 16:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 171DB285EF for ; Wed, 5 Oct 2016 16:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACAB285F2; Wed, 5 Oct 2016 16:40:38 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 9595B285EF for ; Wed, 5 Oct 2016 16:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754069AbcJEQkh (ORCPT ); Wed, 5 Oct 2016 12:40:37 -0400 Received: from mga06.intel.com ([134.134.136.31]:11644 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448AbcJEQkg (ORCPT ); Wed, 5 Oct 2016 12:40:36 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 05 Oct 2016 09:40:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,449,1473145200"; d="scan'208";a="16499144" Received: from unknown (HELO localhost.localdomain) ([10.232.112.96]) by fmsmga006.fm.intel.com with ESMTP; 05 Oct 2016 09:40:35 -0700 Date: Wed, 5 Oct 2016 12:51:27 -0400 From: Keith Busch To: Ming Lei Cc: linux-block , Jens Axboe , Christoph Hellwig Subject: Re: [PATCH] blk-mq: Return invalid cookie if bio was split Message-ID: <20161005165127.GA4812@localhost.localdomain> References: <20160926230030.GB24200@localhost.localdomain> <20160927172536.53a1315f@tom-ThinkPad-T450> <20161003220040.GA1259@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.0 (2016-08-17) 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 On Wed, Oct 05, 2016 at 11:19:39AM +0800, Ming Lei wrote: > But .poll() need to check if the specific request is completed or not, > then blk_poll() can set 'current' as RUNNING if it is completed. > > blk_poll(): > ... > 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; > } Right, but the task could be waiting on a whole lot more than just that one tag, so setting the task to running before knowing those all complete doesn't sound right. > I am glad to take a look the patch if you post it out. Here's what I got for block + nvme. It relies on all the requests to complete to set the task back to running. --- -- -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/blk-core.c b/block/blk-core.c index b993f88..3c1cfbf 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3342,6 +3342,8 @@ EXPORT_SYMBOL(blk_finish_plug); bool blk_poll(struct request_queue *q, blk_qc_t cookie) { struct blk_plug *plug; + struct blk_mq_hw_ctx *hctx; + unsigned int queue_num; long state; if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) || @@ -3353,27 +3355,15 @@ bool blk_poll(struct request_queue *q, blk_qc_t cookie) blk_flush_plug_list(plug, false); state = current->state; + queue_num = blk_qc_t_to_queue_num(cookie); + hctx = q->queue_hw_ctx[queue_num]; while (!need_resched()) { - unsigned int queue_num = blk_qc_t_to_queue_num(cookie); - struct blk_mq_hw_ctx *hctx = q->queue_hw_ctx[queue_num]; - 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; - } + q->mq_ops->poll(hctx); if (signal_pending_state(state, current)) set_current_state(TASK_RUNNING); - if (current->state == TASK_RUNNING) return true; - if (ret < 0) - break; cpu_relax(); } diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index befac5b..2e359e0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -649,7 +651,7 @@ static inline bool nvme_cqe_valid(struct nvme_queue *nvmeq, u16 head, return (le16_to_cpu(nvmeq->cqes[head].status) & 1) == phase; } -static void __nvme_process_cq(struct nvme_queue *nvmeq, unsigned int *tag) +static void nvme_process_cq(struct nvme_queue *nvmeq) { u16 head, phase; @@ -665,9 +667,6 @@ static void __nvme_process_cq(struct nvme_queue *nvmeq, unsigned int *tag) phase = !phase; } - if (tag && *tag == cqe.command_id) - *tag = -1; - if (unlikely(cqe.command_id >= nvmeq->q_depth)) { dev_warn(nvmeq->dev->ctrl.device, "invalid id %d completed on queue %d\n", @@ -711,11 +710,6 @@ static void __nvme_process_cq(struct nvme_queue *nvmeq, unsigned int *tag) nvmeq->cqe_seen = 1; } -static void nvme_process_cq(struct nvme_queue *nvmeq) -{ - __nvme_process_cq(nvmeq, NULL); -} - static irqreturn_t nvme_irq(int irq, void *data) { irqreturn_t result; @@ -736,20 +730,15 @@ static irqreturn_t nvme_irq_check(int irq, void *data) return IRQ_NONE; } -static int nvme_poll(struct blk_mq_hw_ctx *hctx, unsigned int tag) +static void nvme_poll(struct blk_mq_hw_ctx *hctx) { struct nvme_queue *nvmeq = hctx->driver_data; if (nvme_cqe_valid(nvmeq, nvmeq->cq_head, nvmeq->cq_phase)) { spin_lock_irq(&nvmeq->q_lock); - __nvme_process_cq(nvmeq, &tag); + nvme_process_cq(nvmeq); spin_unlock_irq(&nvmeq->q_lock); - - if (tag == -1) - return 1; } - - return 0; } static void nvme_pci_submit_async_event(struct nvme_ctrl *ctrl, int aer_idx) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 2498fdf..a723af9 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -100,7 +100,7 @@ typedef void (exit_request_fn)(void *, struct request *, unsigned int, typedef void (busy_iter_fn)(struct blk_mq_hw_ctx *, struct request *, void *, bool); typedef void (busy_tag_iter_fn)(struct request *, void *, bool); -typedef int (poll_fn)(struct blk_mq_hw_ctx *, unsigned int); +typedef void (poll_fn)(struct blk_mq_hw_ctx *); struct blk_mq_ops {