summaryrefslogtreecommitdiff
path: root/block/blk-mq.h
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2021-12-03 16:15:31 +0300
committerJens Axboe <axboe@kernel.dk>2021-12-04 00:51:29 +0300
commit2a904d00855f94cb85751e45fa494f225d44ae0d (patch)
tree0bcc141b19e61b4d536115e274c68da183ae9ff2 /block/blk-mq.h
parent0a467d0fdd9594fbb449ebc93852533332c528fd (diff)
downloadlinux-2a904d00855f94cb85751e45fa494f225d44ae0d.tar.xz
blk-mq: remove hctx_lock and hctx_unlock
Remove hctx_lock and hctx_unlock, and add one helper of blk_mq_run_dispatch_ops() to run code block defined in dispatch_ops with rcu/srcu read held. Compared with hctx_lock()/hctx_unlock(): 1) remove 2 branch to 1, so we just need to check (hctx->flags & BLK_MQ_F_BLOCKING) once when running one dispatch_ops 2) srcu_idx needn't to be touched in case of non-blocking 3) might_sleep_if() can be moved to the blocking branch Also put the added blk_mq_run_dispatch_ops() in private header, so that the following patch can use it out of blk-mq.c. Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20211203131534.3668411-2-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-mq.h')
-rw-r--r--block/blk-mq.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/block/blk-mq.h b/block/blk-mq.h
index d516c7a46f57..e4c396204928 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -374,5 +374,21 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
return __blk_mq_active_requests(hctx) < depth;
}
+/* run the code block in @dispatch_ops with rcu/srcu read lock held */
+#define blk_mq_run_dispatch_ops(hctx, dispatch_ops) \
+do { \
+ if (!((hctx)->flags & BLK_MQ_F_BLOCKING)) { \
+ rcu_read_lock(); \
+ (dispatch_ops); \
+ rcu_read_unlock(); \
+ } else { \
+ int srcu_idx; \
+ \
+ might_sleep(); \
+ srcu_idx = srcu_read_lock((hctx)->srcu); \
+ (dispatch_ops); \
+ srcu_read_unlock((hctx)->srcu, srcu_idx); \
+ } \
+} while (0)
#endif