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