@@ -102,13 +102,12 @@ static bool blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
!e->type->ops.mq.has_work(hctx))
break;
- if (q->mq_ops->get_budget && !q->mq_ops->get_budget(hctx))
+ if (!blk_mq_get_dispatch_budget(hctx))
return true;
rq = e->type->ops.mq.dispatch_request(hctx);
if (!rq) {
- if (q->mq_ops->put_budget)
- q->mq_ops->put_budget(hctx);
+ blk_mq_put_dispatch_budget(hctx, true);
break;
}
list_add(&rq->queuelist, &rq_list);
@@ -140,13 +139,12 @@ static bool blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
if (!sbitmap_any_bit_set(&hctx->ctx_map))
break;
- if (q->mq_ops->get_budget && !q->mq_ops->get_budget(hctx))
+ if (!blk_mq_get_dispatch_budget(hctx))
return true;
rq = blk_mq_dequeue_from_ctx(hctx, ctx);
if (!rq) {
- if (q->mq_ops->put_budget)
- q->mq_ops->put_budget(hctx);
+ blk_mq_put_dispatch_budget(hctx, true);
break;
}
list_add(&rq->queuelist, &rq_list);
@@ -1087,14 +1087,6 @@ static bool blk_mq_dispatch_wait_add(struct blk_mq_hw_ctx *hctx)
return true;
}
-static void blk_mq_put_budget(struct blk_mq_hw_ctx *hctx, bool got_budget)
-{
- struct request_queue *q = hctx->queue;
-
- if (q->mq_ops->put_budget && got_budget)
- q->mq_ops->put_budget(hctx);
-}
-
bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
bool got_budget)
{
@@ -1125,7 +1117,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
* rerun the hardware queue when a tag is freed.
*/
if (!blk_mq_dispatch_wait_add(hctx)) {
- blk_mq_put_budget(hctx, got_budget);
+ blk_mq_put_dispatch_budget(hctx, got_budget);
break;
}
@@ -1135,16 +1127,13 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
* hardware queue to the wait queue.
*/
if (!blk_mq_get_driver_tag(rq, &hctx, false)) {
- blk_mq_put_budget(hctx, got_budget);
+ blk_mq_put_dispatch_budget(hctx, got_budget);
break;
}
}
- if (!got_budget) {
- if (q->mq_ops->get_budget &&
- !q->mq_ops->get_budget(hctx))
- break;
- }
+ if (!got_budget && !blk_mq_get_dispatch_budget(hctx))
+ break;
list_del_init(&rq->queuelist);
@@ -1642,7 +1631,7 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
if (!blk_mq_get_driver_tag(rq, NULL, false))
goto insert;
- if (q->mq_ops->get_budget && !q->mq_ops->get_budget(hctx)) {
+ if (!blk_mq_get_dispatch_budget(hctx)) {
blk_mq_put_driver_tag(rq);
goto insert;
}
@@ -139,4 +139,23 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)
void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2]);
+static inline bool blk_mq_get_dispatch_budget(struct blk_mq_hw_ctx *hctx)
+{
+ struct request_queue *q = hctx->queue;
+
+ if (!q->mq_ops->get_budget)
+ return true;
+
+ return q->mq_ops->get_budget(hctx);
+}
+
+static inline void blk_mq_put_dispatch_budget(struct blk_mq_hw_ctx *hctx,
+ bool got_budget)
+{
+ struct request_queue *q = hctx->queue;
+
+ if (got_budget && q->mq_ops->put_budget)
+ q->mq_ops->put_budget(hctx);
+}
+
#endif