Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Christoph Hellwig | 2e9bc34 | 2021-09-20 14:33:23 +0200 | [diff] [blame] | 2 | #ifndef _ELEVATOR_H |
| 3 | #define _ELEVATOR_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
Jens Axboe | 4a893e8 | 2006-07-22 15:37:43 +0200 | [diff] [blame] | 5 | #include <linux/percpu.h> |
Sasha Levin | 242d98f | 2012-12-17 10:01:27 -0500 | [diff] [blame] | 6 | #include <linux/hashtable.h> |
Jens Axboe | 4a893e8 | 2006-07-22 15:37:43 +0200 | [diff] [blame] | 7 | |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 8 | struct io_cq; |
Jianpeng Ma | d50235b | 2013-07-03 13:25:24 +0200 | [diff] [blame] | 9 | struct elevator_type; |
Omar Sandoval | d332ce0 | 2017-05-04 08:24:40 -0600 | [diff] [blame] | 10 | struct blk_mq_debugfs_attr; |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 11 | |
Christoph Hellwig | 34fe7c0 | 2017-02-08 14:46:48 +0100 | [diff] [blame] | 12 | /* |
| 13 | * Return values from elevator merger |
| 14 | */ |
| 15 | enum elv_merge { |
| 16 | ELEVATOR_NO_MERGE = 0, |
| 17 | ELEVATOR_FRONT_MERGE = 1, |
| 18 | ELEVATOR_BACK_MERGE = 2, |
Christoph Hellwig | 1e73973 | 2017-02-08 14:46:49 +0100 | [diff] [blame] | 19 | ELEVATOR_DISCARD_MERGE = 3, |
Christoph Hellwig | 34fe7c0 | 2017-02-08 14:46:48 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 22 | struct blk_mq_alloc_data; |
| 23 | struct blk_mq_hw_ctx; |
| 24 | |
| 25 | struct elevator_mq_ops { |
| 26 | int (*init_sched)(struct request_queue *, struct elevator_type *); |
| 27 | void (*exit_sched)(struct elevator_queue *); |
Omar Sandoval | ee056f9 | 2017-04-05 12:01:34 -0700 | [diff] [blame] | 28 | int (*init_hctx)(struct blk_mq_hw_ctx *, unsigned int); |
| 29 | void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int); |
Jens Axboe | 77f1e0a | 2019-01-18 10:34:16 -0700 | [diff] [blame] | 30 | void (*depth_updated)(struct blk_mq_hw_ctx *); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 31 | |
| 32 | bool (*allow_merge)(struct request_queue *, struct request *, struct bio *); |
Omar Sandoval | efed9a3 | 2021-05-10 17:05:35 -0700 | [diff] [blame] | 33 | bool (*bio_merge)(struct request_queue *, struct bio *, unsigned int); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 34 | int (*request_merge)(struct request_queue *q, struct request **, struct bio *); |
Christoph Hellwig | 34fe7c0 | 2017-02-08 14:46:48 +0100 | [diff] [blame] | 35 | void (*request_merged)(struct request_queue *, struct request *, enum elv_merge); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 36 | void (*requests_merged)(struct request_queue *, struct request *, struct request *); |
Christoph Hellwig | 5bbf4e5 | 2017-06-16 18:15:26 +0200 | [diff] [blame] | 37 | void (*limit_depth)(unsigned int, struct blk_mq_alloc_data *); |
Christoph Hellwig | 5d9c305 | 2020-05-29 15:53:08 +0200 | [diff] [blame] | 38 | void (*prepare_request)(struct request *); |
Christoph Hellwig | 7b9e936 | 2017-06-16 18:15:21 +0200 | [diff] [blame] | 39 | void (*finish_request)(struct request *); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 40 | void (*insert_requests)(struct blk_mq_hw_ctx *, struct list_head *, bool); |
Jens Axboe | c13660a | 2017-01-26 12:40:07 -0700 | [diff] [blame] | 41 | struct request *(*dispatch_request)(struct blk_mq_hw_ctx *); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 42 | bool (*has_work)(struct blk_mq_hw_ctx *); |
Omar Sandoval | ed88660 | 2018-09-27 15:55:51 -0700 | [diff] [blame] | 43 | void (*completed_request)(struct request *, u64); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 44 | void (*requeue_request)(struct request *); |
| 45 | struct request *(*former_request)(struct request_queue *, struct request *); |
| 46 | struct request *(*next_request)(struct request_queue *, struct request *); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 47 | void (*init_icq)(struct io_cq *); |
| 48 | void (*exit_icq)(struct io_cq *); |
| 49 | }; |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ELV_NAME_MAX (16) |
| 52 | |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 53 | struct elv_fs_entry { |
| 54 | struct attribute attr; |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 55 | ssize_t (*show)(struct elevator_queue *, char *); |
| 56 | ssize_t (*store)(struct elevator_queue *, const char *, size_t); |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 57 | }; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* |
| 60 | * identifies an elevator type, such as AS or deadline |
| 61 | */ |
| 62 | struct elevator_type |
| 63 | { |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 64 | /* managed by elevator core */ |
| 65 | struct kmem_cache *icq_cache; |
| 66 | |
| 67 | /* fields provided by elevator implementation */ |
Jens Axboe | f9cd4bf | 2018-11-01 16:41:41 -0600 | [diff] [blame] | 68 | struct elevator_mq_ops ops; |
Jens Axboe | a1ce35f | 2018-10-29 10:23:51 -0600 | [diff] [blame] | 69 | |
Tejun Heo | f1f8cc9 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 70 | size_t icq_size; /* see iocontext.h */ |
| 71 | size_t icq_align; /* ditto */ |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 72 | struct elv_fs_entry *elevator_attrs; |
Damien Le Moal | 9305d5d | 2019-07-11 00:57:41 +0900 | [diff] [blame] | 73 | const char *elevator_name; |
Jens Axboe | 8ac0d9a | 2017-10-25 12:35:02 -0600 | [diff] [blame] | 74 | const char *elevator_alias; |
Damien Le Moal | 68c43f1 | 2019-09-05 18:51:31 +0900 | [diff] [blame] | 75 | const unsigned int elevator_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | struct module *elevator_owner; |
Omar Sandoval | d332ce0 | 2017-05-04 08:24:40 -0600 | [diff] [blame] | 77 | #ifdef CONFIG_BLK_DEBUG_FS |
| 78 | const struct blk_mq_debugfs_attr *queue_debugfs_attrs; |
| 79 | const struct blk_mq_debugfs_attr *hctx_debugfs_attrs; |
| 80 | #endif |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 81 | |
| 82 | /* managed by elevator core */ |
Eric Biggers | 9bd2bbc | 2017-06-02 20:35:51 -0700 | [diff] [blame] | 83 | char icq_cache_name[ELV_NAME_MAX + 6]; /* elvname + "_io_cq" */ |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 84 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Sasha Levin | 242d98f | 2012-12-17 10:01:27 -0500 | [diff] [blame] | 87 | #define ELV_HASH_BITS 6 |
| 88 | |
Jens Axboe | 70b3ea0 | 2016-12-07 08:43:31 -0700 | [diff] [blame] | 89 | void elv_rqhash_del(struct request_queue *q, struct request *rq); |
| 90 | void elv_rqhash_add(struct request_queue *q, struct request *rq); |
| 91 | void elv_rqhash_reposition(struct request_queue *q, struct request *rq); |
| 92 | struct request *elv_rqhash_find(struct request_queue *q, sector_t offset); |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* |
Adrian Bunk | 5406958 | 2006-01-10 00:09:36 +0100 | [diff] [blame] | 95 | * each queue has an elevator_queue associated with it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ |
| 97 | struct elevator_queue |
| 98 | { |
Tejun Heo | 22f746e | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 99 | struct elevator_type *type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | void *elevator_data; |
| 101 | struct kobject kobj; |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 102 | struct mutex sysfs_lock; |
Jens Axboe | 430c62f | 2010-10-07 09:35:16 +0200 | [diff] [blame] | 103 | unsigned int registered:1; |
Sasha Levin | 242d98f | 2012-12-17 10:01:27 -0500 | [diff] [blame] | 104 | DECLARE_HASHTABLE(hash, ELV_HASH_BITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* |
| 108 | * block elevator interface |
| 109 | */ |
Christoph Hellwig | 34fe7c0 | 2017-02-08 14:46:48 +0100 | [diff] [blame] | 110 | extern enum elv_merge elv_merge(struct request_queue *, struct request **, |
| 111 | struct bio *); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 112 | extern void elv_merge_requests(struct request_queue *, struct request *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | struct request *); |
Christoph Hellwig | 34fe7c0 | 2017-02-08 14:46:48 +0100 | [diff] [blame] | 114 | extern void elv_merged_request(struct request_queue *, struct request *, |
| 115 | enum elv_merge); |
Jan Kara | fd2ef39 | 2021-06-23 11:36:34 +0200 | [diff] [blame] | 116 | extern bool elv_attempt_insert_merge(struct request_queue *, struct request *, |
| 117 | struct list_head *); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 118 | extern struct request *elv_former_request(struct request_queue *, struct request *); |
| 119 | extern struct request *elv_latter_request(struct request_queue *, struct request *); |
Christoph Hellwig | 26a9750 | 2021-06-02 09:53:17 +0300 | [diff] [blame] | 120 | void elevator_init_mq(struct request_queue *q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * io scheduler registration |
| 124 | */ |
Jens Axboe | e567bf7 | 2014-06-22 16:32:48 -0600 | [diff] [blame] | 125 | extern int elv_register(struct elevator_type *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | extern void elv_unregister(struct elevator_type *); |
| 127 | |
| 128 | /* |
| 129 | * io scheduler sysfs switching |
| 130 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 131 | extern ssize_t elv_iosched_show(struct request_queue *, char *); |
| 132 | extern ssize_t elv_iosched_store(struct request_queue *, const char *, size_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Tahsin Erdogan | 72ef799 | 2016-07-07 11:48:22 -0700 | [diff] [blame] | 134 | extern bool elv_bio_merge_ok(struct request *, struct bio *); |
Jianpeng Ma | d50235b | 2013-07-03 13:25:24 +0200 | [diff] [blame] | 135 | extern struct elevator_queue *elevator_alloc(struct request_queue *, |
| 136 | struct elevator_type *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 139 | * Helper functions. |
| 140 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 141 | extern struct request *elv_rb_former_request(struct request_queue *, struct request *); |
| 142 | extern struct request *elv_rb_latter_request(struct request_queue *, struct request *); |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * rb support functions. |
| 146 | */ |
Jeff Moyer | 796d511 | 2011-06-02 21:19:05 +0200 | [diff] [blame] | 147 | extern void elv_rb_add(struct rb_root *, struct request *); |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 148 | extern void elv_rb_del(struct rb_root *, struct request *); |
| 149 | extern struct request *elv_rb_find(struct rb_root *, sector_t); |
| 150 | |
| 151 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | * Insertion selection |
| 153 | */ |
| 154 | #define ELEVATOR_INSERT_FRONT 1 |
| 155 | #define ELEVATOR_INSERT_BACK 2 |
| 156 | #define ELEVATOR_INSERT_SORT 3 |
Tejun Heo | 797e7db | 2006-01-06 09:51:03 +0100 | [diff] [blame] | 157 | #define ELEVATOR_INSERT_REQUEUE 4 |
Tejun Heo | ae1b153 | 2011-01-25 12:43:54 +0100 | [diff] [blame] | 158 | #define ELEVATOR_INSERT_FLUSH 5 |
Jens Axboe | 5e84ea3 | 2011-03-21 10:14:27 +0100 | [diff] [blame] | 159 | #define ELEVATOR_INSERT_SORT_MERGE 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Jens Axboe | 2e662b6 | 2006-07-13 11:55:04 +0200 | [diff] [blame] | 161 | #define rb_entry_rq(node) rb_entry((node), struct request, rb_node) |
Jens Axboe | 1b47f53 | 2005-10-20 16:37:00 +0200 | [diff] [blame] | 162 | |
Jens Axboe | 1fbfdfc | 2006-07-11 21:49:15 +0200 | [diff] [blame] | 163 | #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist) |
Frederic Weisbecker | d9a74df | 2014-02-24 16:39:53 +0100 | [diff] [blame] | 164 | #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist) |
Jens Axboe | 1fbfdfc | 2006-07-11 21:49:15 +0200 | [diff] [blame] | 165 | |
Christoph Hellwig | 2e9bc34 | 2021-09-20 14:33:23 +0200 | [diff] [blame] | 166 | #endif /* _ELEVATOR_H */ |