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.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Jens Axboe 2018-11-06 13:30:55 -07:00
Родитель 849a370016
Коммит 85f4d4b65f
3 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -38,7 +38,7 @@
#include "blk-mq-sched.h" #include "blk-mq-sched.h"
#include "blk-rq-qos.h" #include "blk-rq-qos.h"
static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie); static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
static void blk_mq_poll_stats_start(struct request_queue *q); static void blk_mq_poll_stats_start(struct request_queue *q);
static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb); static void blk_mq_poll_stats_fn(struct blk_stat_callback *cb);
@ -3305,7 +3305,7 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,
return true; return true;
} }
static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq) static int __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
{ {
struct request_queue *q = hctx->queue; struct request_queue *q = hctx->queue;
long state; long state;
@ -3318,7 +3318,7 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
* straight to the busy poll loop. * straight to the busy poll loop.
*/ */
if (blk_mq_poll_hybrid_sleep(q, hctx, rq)) if (blk_mq_poll_hybrid_sleep(q, hctx, rq))
return true; return 1;
hctx->poll_considered++; hctx->poll_considered++;
@ -3332,30 +3332,30 @@ static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
if (ret > 0) { if (ret > 0) {
hctx->poll_success++; hctx->poll_success++;
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
return true; return ret;
} }
if (signal_pending_state(state, current)) if (signal_pending_state(state, current))
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
if (current->state == TASK_RUNNING) if (current->state == TASK_RUNNING)
return true; return 1;
if (ret < 0) if (ret < 0)
break; break;
cpu_relax(); cpu_relax();
} }
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
return false; return 0;
} }
static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie) static int blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
{ {
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
struct request *rq; struct request *rq;
if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
return false; return 0;
hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)]; hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
if (!blk_qc_t_is_internal(cookie)) if (!blk_qc_t_is_internal(cookie))
@ -3369,7 +3369,7 @@ static bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
* so we should be safe with just the NULL check. * so we should be safe with just the NULL check.
*/ */
if (!rq) if (!rq)
return false; return 0;
} }
return __blk_mq_poll(hctx, rq); return __blk_mq_poll(hctx, rq);

Просмотреть файл

@ -220,11 +220,11 @@ static blk_qc_t nvme_ns_head_make_request(struct request_queue *q,
return ret; return ret;
} }
static bool nvme_ns_head_poll(struct request_queue *q, blk_qc_t qc) static int nvme_ns_head_poll(struct request_queue *q, blk_qc_t qc)
{ {
struct nvme_ns_head *head = q->queuedata; struct nvme_ns_head *head = q->queuedata;
struct nvme_ns *ns; struct nvme_ns *ns;
bool found = false; int found = 0;
int srcu_idx; int srcu_idx;
srcu_idx = srcu_read_lock(&head->srcu); srcu_idx = srcu_read_lock(&head->srcu);

Просмотреть файл

@ -283,7 +283,7 @@ static inline unsigned short req_get_ioprio(struct request *req)
struct blk_queue_ctx; struct blk_queue_ctx;
typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio); typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio);
typedef bool (poll_q_fn) (struct request_queue *q, blk_qc_t); typedef int (poll_q_fn) (struct request_queue *q, blk_qc_t);
struct bio_vec; struct bio_vec;
typedef int (dma_drain_needed_fn)(struct request *); typedef int (dma_drain_needed_fn)(struct request *);