History

block: have ->poll_fn() return number of entries polled

We currently only really support sync poll, ie poll with 1 IO in flight. This prepares us for supporting async poll. Note that the returned value isn't necessarily 100% accurate. If poll races with IRQ completion, we assume that the fact that the task is now runnable means we found at least one entry. In reality it could be more than 1, or not even 1. This is fine, the caller will just need to take this into account.

Jens Axboe committed 8 years ago

Commit 85f4d4b1 parent 849a3703 files · +12 −12Browse files

Unified · Split

3 files
  1. block/blk-mq.c +9 −9
  2. drivers/nvme/host/multipath.c +2 −2
  3. include/linux/blkdev.h +1 −1
block/blk-mq.c+9−9
@@ -38,7 +38,7 @@ · 37 unmodified lines
38#include "blk-mq-sched.h"38#include "blk-mq-sched.h"
39#include "blk-rq-qos.h"39#include "blk-rq-qos.h"
40 40
41static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie);41static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
42static void blk_mq_poll_stats_start(struct request_queue *q);42static void blk_mq_poll_stats_start(struct request_queue *q);
43static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb);43static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb);
44 44
@@ -3305,7 +3305,7 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, · 3260 unmodified lines
3305 return true;3305 return true;
3306}3306}
3307 3307
3308static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)3308static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
3309{3309{
3310 struct request_queue *q = hctx->queue;3310 struct request_queue *q = hctx->queue;
3311 long state;3311 long state;
@@ -3318,7 +3318,7 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 6 unmodified lines
3318 * straight to the busy poll loop.3318 * straight to the busy poll loop.
3319 */3319 */
3320 if (blk_mq_poll_hybrid_sleep(q, hctx, rq))3320 if (blk_mq_poll_hybrid_sleep(q, hctx, rq))
3321 return true;3321 return 1;
3322 3322
3323 hctx->poll_considered++;3323 hctx->poll_considered++;
3324 3324
@@ -3332,30 +3332,30 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) · 7 unmodified lines
3332 if (ret > 0) {3332 if (ret > 0) {
3333 hctx->poll_success++;3333 hctx->poll_success++;
3334 __set_current_state(TASK_RUNNING);3334 __set_current_state(TASK_RUNNING);
3335 return true;3335 return ret;
3336 }3336 }
3337 3337
3338 if (signal_pending_state(state, current))3338 if (signal_pending_state(state, current))
3339 __set_current_state(TASK_RUNNING);3339 __set_current_state(TASK_RUNNING);
3340 3340
3341 if (current->state == TASK_RUNNING)3341 if (current->state == TASK_RUNNING)
3342 return true;3342 return 1;
3343 if (ret < 0)3343 if (ret < 0)
3344 break;3344 break;
3345 cpu_relax();3345 cpu_relax();
3346 }3346 }
3347 3347
3348 __set_current_state(TASK_RUNNING);3348 __set_current_state(TASK_RUNNING);
3349 return false;3349 return 0;
3350}3350}
3351 3351
3352static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)3352static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
3353{3353{
3354 struct blk_mq_hw_ctx *hctx;3354 struct blk_mq_hw_ctx *hctx;
3355 struct request *rq;3355 struct request *rq;
3356 3356
3357 if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))3357 if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
3358 return false;3358 return 0;
3359 3359
3360 hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];3360 hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
3361 if (!blk_qc_t_is_internal(cookie))3361 if (!blk_qc_t_is_internal(cookie))
@@ -3369,7 +3369,7 @@ static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie) · 7 unmodified lines
3369 * so we should be safe with just the NULL check.3369 * so we should be safe with just the NULL check.
3370 */3370 */
3371 if (!rq)3371 if (!rq)
3372 return false;3372 return 0;
3373 }3373 }
3374 3374
3375 return __blk_mq_poll(hctx, rq);3375 return __blk_mq_poll(hctx, rq);
drivers/nvme/host/multipath.c+2−2
@@ -220,11 +220,11 @@ static blk_qc_t nvme_ns_head_make_request(struct request_queue *q, · 219 unmodified lines
220 return ret;220 return ret;
221}221}
222 222
223static bool nvme_ns_head_poll(struct request_queue *q, blk_qc_t qc)223static int nvme_ns_head_poll(struct request_queue *q, blk_qc_t qc)
224{224{
225 struct nvme_ns_head *head = q->queuedata;225 struct nvme_ns_head *head = q->queuedata;
226 struct nvme_ns *ns;226 struct nvme_ns *ns;
227 bool found = false;227 int found = 0;
228 int srcu_idx;228 int srcu_idx;
229 229
230 srcu_idx = srcu_read_lock(&head->srcu);230 srcu_idx = srcu_read_lock(&head->srcu);
include/linux/blkdev.h+1−1
@@ -283,7 +283,7 @@ static inline unsigned short req_get_ioprio(struct request *req) · 282 unmodified lines
283struct blk_queue_ctx;283struct blk_queue_ctx;
284 284
285typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio);285typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio);
286typedef bool (poll_q_fn) (struct request_queue *q, blk_qc_t);286typedef int (poll_q_fn) (struct request_queue *q, blk_qc_t);
287 287
288struct bio_vec;288struct bio_vec;
289typedef int (dma_drain_needed_fn)(struct request *);289typedef int (dma_drain_needed_fn)(struct request *);