History

blk-mq: when polling for IO, look for any completion

If we want to support async IO polling, then we have to allow finding completions that aren't just for the one we are looking for. Always pass in -1 to the mq_ops->poll() helper, and have that return how many events were found in this poll loop.

Jens Axboe committed 7 years ago

Commit 1052b8a1 parent 1db49095 files · +70 −69Browse files

Unified · Split

5 files
  1. block/blk-core.c +11 −2
  2. block/blk-mq.c +36 −35
  3. drivers/nvme/host/pci.c +7 −7
  4. drivers/nvme/host/rdma.c +15 −24
  5. include/linux/blkdev.h +1 −1
block/blk-core.c+11−2
@@ -1273,10 +1273,19 @@ blk_qc_t submit_bio(struct bio *bio) · 1272 unmodified lines
12731273 }
12741274 EXPORT_SYMBOL(submit_bio);
12751275
1276−bool blk_poll(struct request_queue *q, blk_qc_t cookie)
1276+/**
1277+ * blk_poll - poll for IO completions
1278+ * @q: the queue
1279+ * @cookie: cookie passed back at IO submission time
1280+ *
1281+ * Description:
1282+ * Poll for completions on the passed in queue. Returns number of
1283+ * completed entries found.
1284+ */
1285+int blk_poll(struct request_queue *q, blk_qc_t cookie)
12771286 {
12781287 if (!q->poll_fn || !blk_qc_t_valid(cookie))
1279− return false;
1288+ return 0;
12801289
12811290 if (current->plug)
12821291 blk_flush_plug_list(current->plug, false);
block/blk-mq.c+36−35
@@ -3285,15 +3285,12 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, · 3284 unmodified lines
32853285 return false;
32863286
32873287 /*
3288− * poll_nsec can be:
3288+ * If we get here, hybrid polling is enabled. Hence poll_nsec can be:
32893289 *
3290− * -1: don't ever hybrid sleep
32913290 * 0: use half of prev avg
32923291 * >0: use this specific value
32933292 */
3294− if (q->poll_nsec == -1)
3295− return false;
3296− else if (q->poll_nsec > 0)
3293+ if (q->poll_nsec > 0)
32973294 nsecs = q->poll_nsec;
32983295 else
32993296 nsecs = blk_mq_poll_nsecs(q, hctx, rq);
@@ -3330,11 +3327,41 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, · 30 unmodified lines
33303327 return true;
33313328 }
33323329
3333−static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
3330+static bool blk_mq_poll_hybrid(struct request_queue *q,
3331+ struct blk_mq_hw_ctx *hctx, blk_qc_t cookie)
33343332 {
3335− struct request_queue *q = hctx->queue;
3333+ struct request *rq;
3334+
3335+ if (q->poll_nsec == -1)
3336+ return false;
3337+
3338+ if (!blk_qc_t_is_internal(cookie))
3339+ rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
3340+ else {
3341+ rq = blk_mq_tag_to_rq(hctx->sched_tags, blk_qc_t_to_tag(cookie));
3342+ /*
3343+ * With scheduling, if the request has completed, we'll
3344+ * get a NULL return here, as we clear the sched tag when
3345+ * that happens. The request still remains valid, like always,
3346+ * so we should be safe with just the NULL check.
3347+ */
3348+ if (!rq)
3349+ return false;
3350+ }
3351+
3352+ return blk_mq_poll_hybrid_sleep(q, hctx, rq);
3353+}
3354+
3355+static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
3356+{
3357+ struct blk_mq_hw_ctx *hctx;
33363358 long state;
33373359
3360+ if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
3361+ return 0;
3362+
3363+ hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
3364+
33383365 /*
33393366 * If we sleep, have the caller restart the poll loop to reset
33403367 * the state. Like for the other success return cases, the
@@ -3342,7 +3369,7 @@ static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 1 unmodified line
33423369 * the IO isn't complete, we'll get called again and will go
33433370 * straight to the busy poll loop.
33443371 */
3345− if (blk_mq_poll_hybrid_sleep(q, hctx, rq))
3372+ if (blk_mq_poll_hybrid(q, hctx, cookie))
33463373 return 1;
33473374
33483375 hctx->poll_considered++;
@@ -3353,7 +3380,7 @@ static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 4 unmodified lines
33533380
33543381 hctx->poll_invoked++;
33553382
3356− ret = q->mq_ops->poll(hctx, rq->tag);
3383+ ret = q->mq_ops->poll(hctx, -1U);
33573384 if (ret > 0) {
33583385 hctx->poll_success++;
33593386 __set_current_state(TASK_RUNNING);
@@ -3374,32 +3401,6 @@ static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 14 unmodified lines
33743401 return 0;
33753402 }
33763403
3377−static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
3378−{
3379− struct blk_mq_hw_ctx *hctx;
3380− struct request *rq;
3381−
3382− if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
3383− return 0;
3384−
3385− hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
3386− if (!blk_qc_t_is_internal(cookie))
3387− rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
3388− else {
3389− rq = blk_mq_tag_to_rq(hctx->sched_tags, blk_qc_t_to_tag(cookie));
3390− /*
3391− * With scheduling, if the request has completed, we'll
3392− * get a NULL return here, as we clear the sched tag when
3393− * that happens. The request still remains valid, like always,
3394− * so we should be safe with just the NULL check.
3395− */
3396− if (!rq)
3397− return 0;
3398− }
3399−
3400− return __blk_mq_poll(hctx, rq);
3401−}
3402−
34033404 unsigned int blk_mq_rq_cpu(struct request *rq)
34043405 {
34053406 return rq->mq_ctx->cpu;
drivers/nvme/host/pci.c+7−7
@@ -1012,15 +1012,15 @@ static inline void nvme_update_cq_head(struct nvme_queue *nvmeq) · 1011 unmodified lines
10121012 }
10131013 }
10141014
1015−static inline bool nvme_process_cq(struct nvme_queue *nvmeq, u16 *start,
1016− u16 *end, int tag)
1015+static inline int nvme_process_cq(struct nvme_queue *nvmeq, u16 *start,
1016+ u16 *end, unsigned int tag)
10171017 {
1018− bool found = false;
1018+ int found = 0;
10191019
10201020 *start = nvmeq->cq_head;
1021− while (!found && nvme_cqe_pending(nvmeq)) {
1022− if (nvmeq->cqes[nvmeq->cq_head].command_id == tag)
1023− found = true;
1021+ while (nvme_cqe_pending(nvmeq)) {
1022+ if (tag == -1U || nvmeq->cqes[nvmeq->cq_head].command_id == tag)
1023+ found++;
10241024 nvme_update_cq_head(nvmeq);
10251025 }
10261026 *end = nvmeq->cq_head;
@@ -1062,7 +1062,7 @@ static irqreturn_t nvme_irq_check(int irq, void *data) · 35 unmodified lines
10621062 static int __nvme_poll(struct nvme_queue *nvmeq, unsigned int tag)
10631063 {
10641064 u16 start, end;
1065− bool found;
1065+ int found;
10661066
10671067 if (!nvme_cqe_pending(nvmeq))
10681068 return 0;
drivers/nvme/host/rdma.c+15−24
@@ -1409,12 +1409,11 @@ static void nvme_rdma_submit_async_event(struct nvme_ctrl *arg) · 1408 unmodified lines
14091409 WARN_ON_ONCE(ret);
14101410 }
14111411
1412−static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue,
1413− struct nvme_completion *cqe, struct ib_wc *wc, int tag)
1412+static void nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue,
1413+ struct nvme_completion *cqe, struct ib_wc *wc)
14141414 {
14151415 struct request *rq;
14161416 struct nvme_rdma_request *req;
1417− int ret = 0;
14181417
14191418 rq = blk_mq_tag_to_rq(nvme_rdma_tagset(queue), cqe->command_id);
14201419 if (!rq) {
@@ -1422,7 +1421,7 @@ static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue, · 1 unmodified line
14221421 "tag 0x%x on QP %#x not found\n",
14231422 cqe->command_id, queue->qp->qp_num);
14241423 nvme_rdma_error_recovery(queue->ctrl);
1425− return ret;
1424+ return;
14261425 }
14271426 req = blk_mq_rq_to_pdu(rq);
14281427
@@ -1437,6 +1436,8 @@ static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue, · 8 unmodified lines
14371436 nvme_rdma_error_recovery(queue->ctrl);
14381437 }
14391438 } else if (req->mr) {
1439+ int ret;
1440+
14401441 ret = nvme_rdma_inv_rkey(queue, req);
14411442 if (unlikely(ret < 0)) {
14421443 dev_err(queue->ctrl->ctrl.device,
@@ -1445,19 +1446,14 @@ static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue *queue, · 2 unmodified lines
14451446 nvme_rdma_error_recovery(queue->ctrl);
14461447 }
14471448 /* the local invalidation completion will end the request */
1448− return 0;
1449+ return;
14491450 }
14501451
1451− if (refcount_dec_and_test(&req->ref)) {
1452− if (rq->tag == tag)
1453− ret = 1;
1452+ if (refcount_dec_and_test(&req->ref))
14541453 nvme_end_request(rq, req->status, req->result);
1455− }
1456−
1457− return ret;
14581454 }
14591455
1460−static int __nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc, int tag)
1456+static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc)
14611457 {
14621458 struct nvme_rdma_qe *qe =
14631459 container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe);
@@ -1465,11 +1461,10 @@ static int __nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc, int tag) · 1 unmodified line
14651461 struct ib_device *ibdev = queue->device->dev;
14661462 struct nvme_completion *cqe = qe->data;
14671463 const size_t len = sizeof(struct nvme_completion);
1468− int ret = 0;
14691464
14701465 if (unlikely(wc->status != IB_WC_SUCCESS)) {
14711466 nvme_rdma_wr_error(cq, wc, "RECV");
1472− return 0;
1467+ return;
14731468 }
14741469
14751470 ib_dma_sync_single_for_cpu(ibdev, qe->dma, len, DMA_FROM_DEVICE);
@@ -1484,16 +1479,10 @@ static int __nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc, int tag) · 8 unmodified lines
14841479 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status,
14851480 &cqe->result);
14861481 else
1487− ret = nvme_rdma_process_nvme_rsp(queue, cqe, wc, tag);
1482+ nvme_rdma_process_nvme_rsp(queue, cqe, wc);
14881483 ib_dma_sync_single_for_device(ibdev, qe->dma, len, DMA_FROM_DEVICE);
14891484
14901485 nvme_rdma_post_recv(queue, qe);
1491− return ret;
1492−}
1493−
1494−static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc)
1495−{
1496− __nvme_rdma_recv_done(cq, wc, -1);
14971486 }
14981487
14991488 static int nvme_rdma_conn_established(struct nvme_rdma_queue *queue)
@@ -1758,10 +1747,12 @@ static int nvme_rdma_poll(struct blk_mq_hw_ctx *hctx, unsigned int tag) · 258 unmodified lines
17581747 struct ib_cqe *cqe = wc.wr_cqe;
17591748
17601749 if (cqe) {
1761− if (cqe->done == nvme_rdma_recv_done)
1762− found |= __nvme_rdma_recv_done(cq, &wc, tag);
1763− else
1750+ if (cqe->done == nvme_rdma_recv_done) {
1751+ nvme_rdma_recv_done(cq, &wc);
1752+ found++;
1753+ } else {
17641754 cqe->done(cq, &wc);
1755+ }
17651756 }
17661757 }
17671758
include/linux/blkdev.h+1−1
@@ -867,7 +867,7 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, · 866 unmodified lines
867867 int blk_status_to_errno(blk_status_t status);
868868 blk_status_t errno_to_blk_status(int errno);
869869
870−bool blk_poll(struct request_queue *q, blk_qc_t cookie);
870+int blk_poll(struct request_queue *q, blk_qc_t cookie);
871871
872872 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
873873 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t