[PATCH V2 10/20] blk-mq-sched: introduce helpers for query, change busy state

Ming Lei
2017-08-05T06:57:52Z

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-mq-sched.c | 6 +++---
block/blk-mq.c | 4 ++--
block/blk-mq.h | 15 +++++++++++++++
3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 18d997679d7d..9fae76275acf 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -181,7 +181,7 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
* effect.
*/
if (list_empty_careful(&hctx->dispatch))
- clear_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+ blk_mq_hctx_clear_dispatch_busy(hctx);
}

/*
@@ -189,7 +189,7 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
* will be run to try to make progress, so it is always
* safe to check the state here.
*/
- if (test_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state))
+ if (blk_mq_hctx_is_dispatch_busy(hctx))
return;

if (!has_sched_dispatch) {
@@ -342,7 +342,7 @@ static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
* the dispatch list.
*/
spin_lock(&hctx->lock);
- set_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+ blk_mq_hctx_set_dispatch_busy(hctx);
list_add(&rq->queuelist, &hctx->dispatch);
spin_unlock(&hctx->lock);
return true;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b535587570b8..11042aa0501d 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1105,7 +1105,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list)
* DISPATCH_BUSY won't be cleared until all requests
* in hctx->dispatch are dispatched successfully
*/
- set_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+ blk_mq_hctx_set_dispatch_busy(hctx);
list_splice_init(list, &hctx->dispatch);
spin_unlock(&hctx->lock);

@@ -1883,7 +1883,7 @@ static int blk_mq_hctx_notify_dead(unsigned int cpu, struct hlist_node *node)
return 0;

spin_lock(&hctx->lock);
- set_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+ blk_mq_hctx_set_dispatch_busy(hctx);
list_splice_tail_init(&tmp, &hctx->dispatch);
spin_unlock(&hctx->lock);

diff --git a/block/blk-mq.h b/block/blk-mq.h
index 260b608af336..cadc0c83a140 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -136,4 +136,19 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)
return hctx->nr_ctx && hctx->tags;
}

+static inline bool blk_mq_hctx_is_dispatch_busy(struct blk_mq_hw_ctx *hctx)
+{
+ return test_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+}
+
+static inline void blk_mq_hctx_set_dispatch_busy(struct blk_mq_hw_ctx *hctx)
+{
+ set_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+}
+
+static inline void blk_mq_hctx_clear_dispatch_busy(struct blk_mq_hw_ctx *hctx)
+{
+ clear_bit(BLK_MQ_S_DISPATCH_BUSY, &hctx->state);
+}
+
#endif
--
2.9.4