Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef BLK_MQ_SCHED_H
0003 #define BLK_MQ_SCHED_H
0004 
0005 #include "elevator.h"
0006 #include "blk-mq.h"
0007 #include "blk-mq-tag.h"
0008 
0009 #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ)
0010 
0011 bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
0012         unsigned int nr_segs, struct request **merged_request);
0013 bool blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio,
0014         unsigned int nr_segs);
0015 bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq,
0016                    struct list_head *free);
0017 void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx);
0018 void __blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);
0019 
0020 void blk_mq_sched_insert_request(struct request *rq, bool at_head,
0021                  bool run_queue, bool async);
0022 void blk_mq_sched_insert_requests(struct blk_mq_hw_ctx *hctx,
0023                   struct blk_mq_ctx *ctx,
0024                   struct list_head *list, bool run_queue_async);
0025 
0026 void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
0027 
0028 int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
0029 void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
0030 void blk_mq_sched_free_rqs(struct request_queue *q);
0031 
0032 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
0033 {
0034     if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
0035         __blk_mq_sched_restart(hctx);
0036 }
0037 
0038 static inline bool bio_mergeable(struct bio *bio)
0039 {
0040     return !(bio->bi_opf & REQ_NOMERGE_FLAGS);
0041 }
0042 
0043 static inline bool
0044 blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
0045              struct bio *bio)
0046 {
0047     if (rq->rq_flags & RQF_ELV) {
0048         struct elevator_queue *e = q->elevator;
0049 
0050         if (e->type->ops.allow_merge)
0051             return e->type->ops.allow_merge(q, rq, bio);
0052     }
0053     return true;
0054 }
0055 
0056 static inline void blk_mq_sched_completed_request(struct request *rq, u64 now)
0057 {
0058     if (rq->rq_flags & RQF_ELV) {
0059         struct elevator_queue *e = rq->q->elevator;
0060 
0061         if (e->type->ops.completed_request)
0062             e->type->ops.completed_request(rq, now);
0063     }
0064 }
0065 
0066 static inline void blk_mq_sched_requeue_request(struct request *rq)
0067 {
0068     if (rq->rq_flags & RQF_ELV) {
0069         struct request_queue *q = rq->q;
0070         struct elevator_queue *e = q->elevator;
0071 
0072         if ((rq->rq_flags & RQF_ELVPRIV) && e->type->ops.requeue_request)
0073             e->type->ops.requeue_request(rq);
0074     }
0075 }
0076 
0077 static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
0078 {
0079     struct elevator_queue *e = hctx->queue->elevator;
0080 
0081     if (e && e->type->ops.has_work)
0082         return e->type->ops.has_work(hctx);
0083 
0084     return false;
0085 }
0086 
0087 static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
0088 {
0089     return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
0090 }
0091 
0092 #endif