Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
bd166ef1 JA |
2 | #ifndef BLK_MQ_SCHED_H |
3 | #define BLK_MQ_SCHED_H | |
4 | ||
2e9bc346 | 5 | #include "elevator.h" |
bd166ef1 | 6 | #include "blk-mq.h" |
bd166ef1 | 7 | |
d2a27964 | 8 | #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ) |
d97e594c | 9 | |
e4d750c9 | 10 | bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio, |
14ccb66b | 11 | unsigned int nr_segs, struct request **merged_request); |
179ae84f | 12 | bool blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio, |
14ccb66b | 13 | unsigned int nr_segs); |
fd2ef39c JK |
14 | bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq, |
15 | struct list_head *free); | |
7211aef8 | 16 | void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx); |
e9ea1596 | 17 | void __blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx); |
bd166ef1 JA |
18 | |
19 | void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx); | |
bd166ef1 | 20 | |
6917ff0b | 21 | int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e); |
54d5329d | 22 | void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e); |
1820f4f0 | 23 | void blk_mq_sched_free_rqs(struct request_queue *q); |
bd166ef1 | 24 | |
e9ea1596 PB |
25 | static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx) |
26 | { | |
27 | if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) | |
28 | __blk_mq_sched_restart(hctx); | |
29 | } | |
30 | ||
8addffd6 CH |
31 | static inline bool bio_mergeable(struct bio *bio) |
32 | { | |
33 | return !(bio->bi_opf & REQ_NOMERGE_FLAGS); | |
34 | } | |
35 | ||
bd166ef1 JA |
36 | static inline bool |
37 | blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq, | |
38 | struct bio *bio) | |
39 | { | |
dd6216bb | 40 | if (rq->rq_flags & RQF_USE_SCHED) { |
2ff0682d | 41 | struct elevator_queue *e = q->elevator; |
bd166ef1 | 42 | |
2ff0682d JA |
43 | if (e->type->ops.allow_merge) |
44 | return e->type->ops.allow_merge(q, rq, bio); | |
45 | } | |
bd166ef1 JA |
46 | return true; |
47 | } | |
48 | ||
ed88660a | 49 | static inline void blk_mq_sched_completed_request(struct request *rq, u64 now) |
bd166ef1 | 50 | { |
dd6216bb | 51 | if (rq->rq_flags & RQF_USE_SCHED) { |
2ff0682d | 52 | struct elevator_queue *e = rq->q->elevator; |
bd166ef1 | 53 | |
2ff0682d JA |
54 | if (e->type->ops.completed_request) |
55 | e->type->ops.completed_request(rq, now); | |
56 | } | |
bd166ef1 JA |
57 | } |
58 | ||
bd166ef1 JA |
59 | static inline void blk_mq_sched_requeue_request(struct request *rq) |
60 | { | |
dd6216bb | 61 | if (rq->rq_flags & RQF_USE_SCHED) { |
2ff0682d JA |
62 | struct request_queue *q = rq->q; |
63 | struct elevator_queue *e = q->elevator; | |
bd166ef1 | 64 | |
fdcab6cd | 65 | if (e->type->ops.requeue_request) |
2ff0682d JA |
66 | e->type->ops.requeue_request(rq); |
67 | } | |
bd166ef1 JA |
68 | } |
69 | ||
70 | static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx) | |
71 | { | |
72 | struct elevator_queue *e = hctx->queue->elevator; | |
73 | ||
f9cd4bfe JA |
74 | if (e && e->type->ops.has_work) |
75 | return e->type->ops.has_work(hctx); | |
bd166ef1 JA |
76 | |
77 | return false; | |
78 | } | |
79 | ||
bd166ef1 JA |
80 | static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx) |
81 | { | |
82 | return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); | |
83 | } | |
84 | ||
85 | #endif |