Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * ROW (Read Over Write) I/O scheduler. |
| 3 | * |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 4 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 and |
| 8 | * only version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | /* See Documentation/block/row-iosched.txt */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/blkdev.h> |
| 21 | #include <linux/elevator.h> |
| 22 | #include <linux/bio.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/compiler.h> |
| 27 | #include <linux/blktrace_api.h> |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 28 | #include <linux/hrtimer.h> |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * enum row_queue_prio - Priorities of the ROW queues |
| 32 | * |
| 33 | * This enum defines the priorities (and the number of queues) |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 34 | * the requests will be distributed to. The higher priority - |
| 35 | * the bigger is the "bus time" (or the dispatch quantum) given |
| 36 | * to that queue. |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 37 | * ROWQ_PRIO_HIGH_READ - is the higher priority queue. |
| 38 | * |
| 39 | */ |
| 40 | enum row_queue_prio { |
| 41 | ROWQ_PRIO_HIGH_READ = 0, |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 42 | ROWQ_PRIO_HIGH_SWRITE, |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 43 | ROWQ_PRIO_REG_READ, |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 44 | ROWQ_PRIO_REG_SWRITE, |
| 45 | ROWQ_PRIO_REG_WRITE, |
| 46 | ROWQ_PRIO_LOW_READ, |
| 47 | ROWQ_PRIO_LOW_SWRITE, |
| 48 | ROWQ_MAX_PRIO, |
| 49 | }; |
| 50 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 51 | /* |
| 52 | * The following indexes define the distribution of ROW queues according to |
| 53 | * priorities. Each index defines the first queue in that priority group. |
| 54 | */ |
| 55 | #define ROWQ_HIGH_PRIO_IDX ROWQ_PRIO_HIGH_READ |
| 56 | #define ROWQ_REG_PRIO_IDX ROWQ_PRIO_REG_READ |
| 57 | #define ROWQ_LOW_PRIO_IDX ROWQ_PRIO_LOW_READ |
| 58 | |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 59 | /** |
| 60 | * struct row_queue_params - ROW queue parameters |
| 61 | * @idling_enabled: Flag indicating whether idling is enable on |
| 62 | * the queue |
| 63 | * @quantum: Number of requests to be dispatched from this queue |
| 64 | * in a dispatch cycle |
| 65 | * @is_urgent: Flags indicating whether the queue can notify on |
| 66 | * urgent requests |
| 67 | * |
| 68 | */ |
| 69 | struct row_queue_params { |
| 70 | bool idling_enabled; |
| 71 | int quantum; |
| 72 | bool is_urgent; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 73 | }; |
| 74 | |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 75 | /* |
| 76 | * This array holds the default values of the different configurables |
| 77 | * for each ROW queue. Each row of the array holds the following values: |
| 78 | * {idling_enabled, quantum, is_urgent} |
| 79 | * Each row corresponds to a queue with the same index (according to |
| 80 | * enum row_queue_prio) |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 81 | * Note: The quantums are valid inside their priority type. For example: |
| 82 | * For every 10 high priority read requests, 1 high priority sync |
| 83 | * write will be dispatched. |
| 84 | * For every 100 regular read requests 1 regular write request will |
| 85 | * be dispatched. |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 86 | */ |
| 87 | static const struct row_queue_params row_queues_def[] = { |
| 88 | /* idling_enabled, quantum, is_urgent */ |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 89 | {true, 10, true}, /* ROWQ_PRIO_HIGH_READ */ |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 90 | {false, 1, false}, /* ROWQ_PRIO_HIGH_SWRITE */ |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 91 | {true, 100, true}, /* ROWQ_PRIO_REG_READ */ |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 92 | {false, 1, false}, /* ROWQ_PRIO_REG_SWRITE */ |
| 93 | {false, 1, false}, /* ROWQ_PRIO_REG_WRITE */ |
| 94 | {false, 1, false}, /* ROWQ_PRIO_LOW_READ */ |
| 95 | {false, 1, false} /* ROWQ_PRIO_LOW_SWRITE */ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 96 | }; |
| 97 | |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 98 | /* Default values for idling on read queues (in msec) */ |
| 99 | #define ROW_IDLE_TIME_MSEC 5 |
Lee Susman | d243909 | 2013-06-23 16:27:40 +0300 | [diff] [blame] | 100 | #define ROW_READ_FREQ_MSEC 5 |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * struct rowq_idling_data - parameters for idling on the queue |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 104 | * @last_insert_time: time the last request was inserted |
| 105 | * to the queue |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 106 | * @begin_idling: flag indicating wether we should idle |
| 107 | * |
| 108 | */ |
| 109 | struct rowq_idling_data { |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 110 | ktime_t last_insert_time; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 111 | bool begin_idling; |
| 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * struct row_queue - requests grouping structure |
| 116 | * @rdata: parent row_data structure |
| 117 | * @fifo: fifo of requests |
| 118 | * @prio: queue priority (enum row_queue_prio) |
| 119 | * @nr_dispatched: number of requests already dispatched in |
| 120 | * the current dispatch cycle |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 121 | * @nr_req: number of requests in queue |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 122 | * @dispatch quantum: number of requests this queue may |
| 123 | * dispatch in a dispatch cycle |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 124 | * @idle_data: data for idling on queues |
| 125 | * |
| 126 | */ |
| 127 | struct row_queue { |
| 128 | struct row_data *rdata; |
| 129 | struct list_head fifo; |
| 130 | enum row_queue_prio prio; |
| 131 | |
| 132 | unsigned int nr_dispatched; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 133 | |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 134 | unsigned int nr_req; |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 135 | int disp_quantum; |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 136 | |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 137 | /* used only for READ queues */ |
| 138 | struct rowq_idling_data idle_data; |
| 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * struct idling_data - data for idling on empty rqueue |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 143 | * @idle_time_ms: idling duration (msec) |
| 144 | * @freq_ms: min time between two requests that |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 145 | * triger idling (msec) |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 146 | * @hr_timer: idling timer |
| 147 | * @idle_work: the work to be scheduled when idling timer expires |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 148 | * @idling_queue_idx: index of the queues we're idling on |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 149 | * |
| 150 | */ |
| 151 | struct idling_data { |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 152 | s64 idle_time_ms; |
| 153 | s64 freq_ms; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 154 | |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 155 | struct hrtimer hr_timer; |
| 156 | struct work_struct idle_work; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 157 | enum row_queue_prio idling_queue_idx; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | /** |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 161 | * struct starvation_data - data for starvation management |
| 162 | * @starvation_limit: number of times this priority class |
| 163 | * can tolerate being starved |
| 164 | * @starvation_counter: number of requests from higher |
| 165 | * priority classes that were dispatched while this |
| 166 | * priority request were pending |
| 167 | * |
| 168 | */ |
| 169 | struct starvation_data { |
| 170 | int starvation_limit; |
| 171 | int starvation_counter; |
| 172 | }; |
| 173 | |
| 174 | /** |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 175 | * struct row_queue - Per block device rqueue structure |
| 176 | * @dispatch_queue: dispatch rqueue |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 177 | * @row_queues: array of priority request queues |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 178 | * @rd_idle_data: data for idling after READ request |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 179 | * @nr_reqs: nr_reqs[0] holds the number of all READ requests in |
| 180 | * scheduler, nr_reqs[1] holds the number of all WRITE |
| 181 | * requests in scheduler |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 182 | * @urgent_in_flight: flag indicating that there is an urgent |
| 183 | * request that was dispatched to driver and is yet to |
| 184 | * complete. |
| 185 | * @pending_urgent_rq: pointer to the pending urgent request |
| 186 | * @last_served_ioprio_class: I/O priority class that was last dispatched from |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 187 | * @reg_prio_starvation: starvation data for REGULAR priority queues |
| 188 | * @low_prio_starvation: starvation data for LOW priority queues |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 189 | * @cycle_flags: used for marking unserved queueus |
| 190 | * |
| 191 | */ |
| 192 | struct row_data { |
| 193 | struct request_queue *dispatch_queue; |
| 194 | |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 195 | struct row_queue row_queues[ROWQ_MAX_PRIO]; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 196 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 197 | struct idling_data rd_idle_data; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 198 | unsigned int nr_reqs[2]; |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 199 | bool urgent_in_flight; |
| 200 | struct request *pending_urgent_rq; |
| 201 | int last_served_ioprio_class; |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 202 | |
Maya Erez | 7fd5fad | 2013-04-14 15:19:52 +0300 | [diff] [blame] | 203 | #define ROW_REG_STARVATION_TOLLERANCE 5000 |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 204 | struct starvation_data reg_prio_starvation; |
Maya Erez | 7fd5fad | 2013-04-14 15:19:52 +0300 | [diff] [blame] | 205 | #define ROW_LOW_STARVATION_TOLLERANCE 10000 |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 206 | struct starvation_data low_prio_starvation; |
| 207 | |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 208 | unsigned int cycle_flags; |
| 209 | }; |
| 210 | |
| 211 | #define RQ_ROWQ(rq) ((struct row_queue *) ((rq)->elv.priv[0])) |
| 212 | |
| 213 | #define row_log(q, fmt, args...) \ |
| 214 | blk_add_trace_msg(q, "%s():" fmt , __func__, ##args) |
| 215 | #define row_log_rowq(rdata, rowq_id, fmt, args...) \ |
| 216 | blk_add_trace_msg(rdata->dispatch_queue, "rowq%d " fmt, \ |
| 217 | rowq_id, ##args) |
| 218 | |
| 219 | static inline void row_mark_rowq_unserved(struct row_data *rd, |
| 220 | enum row_queue_prio qnum) |
| 221 | { |
| 222 | rd->cycle_flags |= (1 << qnum); |
| 223 | } |
| 224 | |
| 225 | static inline void row_clear_rowq_unserved(struct row_data *rd, |
| 226 | enum row_queue_prio qnum) |
| 227 | { |
| 228 | rd->cycle_flags &= ~(1 << qnum); |
| 229 | } |
| 230 | |
| 231 | static inline int row_rowq_unserved(struct row_data *rd, |
| 232 | enum row_queue_prio qnum) |
| 233 | { |
| 234 | return rd->cycle_flags & (1 << qnum); |
| 235 | } |
| 236 | |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 237 | static inline void __maybe_unused row_dump_queues_stat(struct row_data *rd) |
| 238 | { |
| 239 | int i; |
| 240 | |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 241 | row_log(rd->dispatch_queue, " Queues status:"); |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 242 | for (i = 0; i < ROWQ_MAX_PRIO; i++) |
| 243 | row_log(rd->dispatch_queue, |
| 244 | "queue%d: dispatched= %d, nr_req=%d", i, |
| 245 | rd->row_queues[i].nr_dispatched, |
| 246 | rd->row_queues[i].nr_req); |
| 247 | } |
| 248 | |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 249 | /******************** Static helper functions ***********************/ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 250 | static void kick_queue(struct work_struct *work) |
| 251 | { |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 252 | struct idling_data *read_data = |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 253 | container_of(work, struct idling_data, idle_work); |
| 254 | struct row_data *rd = |
| 255 | container_of(read_data, struct row_data, rd_idle_data); |
| 256 | |
| 257 | blk_run_queue(rd->dispatch_queue); |
| 258 | } |
| 259 | |
| 260 | |
| 261 | static enum hrtimer_restart row_idle_hrtimer_fn(struct hrtimer *hr_timer) |
| 262 | { |
| 263 | struct idling_data *read_data = |
| 264 | container_of(hr_timer, struct idling_data, hr_timer); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 265 | struct row_data *rd = |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 266 | container_of(read_data, struct row_data, rd_idle_data); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 267 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 268 | row_log_rowq(rd, rd->rd_idle_data.idling_queue_idx, |
| 269 | "Performing delayed work"); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 270 | /* Mark idling process as done */ |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 271 | rd->row_queues[rd->rd_idle_data.idling_queue_idx]. |
| 272 | idle_data.begin_idling = false; |
| 273 | rd->rd_idle_data.idling_queue_idx = ROWQ_MAX_PRIO; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 274 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 275 | if (!rd->nr_reqs[READ] && !rd->nr_reqs[WRITE]) |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 276 | row_log(rd->dispatch_queue, "No requests in scheduler"); |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 277 | else |
| 278 | kblockd_schedule_work(rd->dispatch_queue, |
| 279 | &read_data->idle_work); |
| 280 | return HRTIMER_NORESTART; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 281 | } |
| 282 | |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 283 | /* |
| 284 | * row_regular_req_pending() - Check if there are REGULAR priority requests |
| 285 | * Pending in scheduler |
| 286 | * @rd: pointer to struct row_data |
| 287 | * |
| 288 | * Returns True if there are REGULAR priority requests in scheduler queues. |
| 289 | * False, otherwise. |
| 290 | */ |
| 291 | static inline bool row_regular_req_pending(struct row_data *rd) |
| 292 | { |
| 293 | int i; |
| 294 | |
| 295 | for (i = ROWQ_REG_PRIO_IDX; i < ROWQ_LOW_PRIO_IDX; i++) |
| 296 | if (!list_empty(&rd->row_queues[i].fifo)) |
| 297 | return true; |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * row_low_req_pending() - Check if there are LOW priority requests |
| 303 | * Pending in scheduler |
| 304 | * @rd: pointer to struct row_data |
| 305 | * |
| 306 | * Returns True if there are LOW priority requests in scheduler queues. |
| 307 | * False, otherwise. |
| 308 | */ |
| 309 | static inline bool row_low_req_pending(struct row_data *rd) |
| 310 | { |
| 311 | int i; |
| 312 | |
| 313 | for (i = ROWQ_LOW_PRIO_IDX; i < ROWQ_MAX_PRIO; i++) |
| 314 | if (!list_empty(&rd->row_queues[i].fifo)) |
| 315 | return true; |
| 316 | return false; |
| 317 | } |
| 318 | |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 319 | /******************* Elevator callback functions *********************/ |
| 320 | |
| 321 | /* |
| 322 | * row_add_request() - Add request to the scheduler |
| 323 | * @q: requests queue |
| 324 | * @rq: request to add |
| 325 | * |
| 326 | */ |
| 327 | static void row_add_request(struct request_queue *q, |
| 328 | struct request *rq) |
| 329 | { |
| 330 | struct row_data *rd = (struct row_data *)q->elevator->elevator_data; |
| 331 | struct row_queue *rqueue = RQ_ROWQ(rq); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 332 | s64 diff_ms; |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 333 | bool queue_was_empty = list_empty(&rqueue->fifo); |
Lee Susman | d243909 | 2013-06-23 16:27:40 +0300 | [diff] [blame] | 334 | unsigned long bv_page_flags = 0; |
| 335 | |
| 336 | if (rq->bio && rq->bio->bi_io_vec && rq->bio->bi_io_vec->bv_page) |
| 337 | bv_page_flags = rq->bio->bi_io_vec->bv_page->flags; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 338 | |
| 339 | list_add_tail(&rq->queuelist, &rqueue->fifo); |
| 340 | rd->nr_reqs[rq_data_dir(rq)]++; |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 341 | rqueue->nr_req++; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 342 | rq_set_fifo_time(rq, jiffies); /* for statistics*/ |
| 343 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 344 | if (rq->cmd_flags & REQ_URGENT) { |
| 345 | WARN_ON(1); |
| 346 | blk_dump_rq_flags(rq, ""); |
| 347 | rq->cmd_flags &= ~REQ_URGENT; |
| 348 | } |
| 349 | |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 350 | if (row_queues_def[rqueue->prio].idling_enabled) { |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 351 | if (rd->rd_idle_data.idling_queue_idx == rqueue->prio && |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 352 | hrtimer_active(&rd->rd_idle_data.hr_timer)) { |
Tatyana Brokhman | a1d6f9e | 2013-07-02 14:43:13 +0300 | [diff] [blame] | 353 | if (hrtimer_try_to_cancel( |
| 354 | &rd->rd_idle_data.hr_timer) >= 0) { |
| 355 | row_log_rowq(rd, rqueue->prio, |
| 356 | "Canceled delayed work on %d", |
| 357 | rd->rd_idle_data.idling_queue_idx); |
| 358 | rd->rd_idle_data.idling_queue_idx = |
| 359 | ROWQ_MAX_PRIO; |
| 360 | } |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 361 | } |
| 362 | diff_ms = ktime_to_ms(ktime_sub(ktime_get(), |
| 363 | rqueue->idle_data.last_insert_time)); |
| 364 | if (unlikely(diff_ms < 0)) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 365 | pr_err("%s(): time delta error: diff_ms < 0", |
| 366 | __func__); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 367 | rqueue->idle_data.begin_idling = false; |
| 368 | return; |
| 369 | } |
Lee Susman | d243909 | 2013-06-23 16:27:40 +0300 | [diff] [blame] | 370 | |
| 371 | if ((bv_page_flags & (1L << PG_readahead)) || |
| 372 | (diff_ms < rd->rd_idle_data.freq_ms)) { |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 373 | rqueue->idle_data.begin_idling = true; |
| 374 | row_log_rowq(rd, rqueue->prio, "Enable idling"); |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 375 | } else { |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 376 | rqueue->idle_data.begin_idling = false; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 377 | row_log_rowq(rd, rqueue->prio, "Disable idling (%ldms)", |
| 378 | (long)diff_ms); |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 379 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 380 | |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 381 | rqueue->idle_data.last_insert_time = ktime_get(); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 382 | } |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 383 | if (row_queues_def[rqueue->prio].is_urgent && |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 384 | !rd->pending_urgent_rq && !rd->urgent_in_flight) { |
| 385 | /* Handle High Priority queues */ |
| 386 | if (rqueue->prio < ROWQ_REG_PRIO_IDX && |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 387 | rd->last_served_ioprio_class != IOPRIO_CLASS_RT && |
| 388 | queue_was_empty) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 389 | row_log_rowq(rd, rqueue->prio, |
| 390 | "added (high prio) urgent request"); |
| 391 | rq->cmd_flags |= REQ_URGENT; |
| 392 | rd->pending_urgent_rq = rq; |
| 393 | } else if (row_rowq_unserved(rd, rqueue->prio)) { |
| 394 | /* Handle Regular priotity queues */ |
| 395 | row_log_rowq(rd, rqueue->prio, |
| 396 | "added urgent request (total on queue=%d)", |
| 397 | rqueue->nr_req); |
| 398 | rq->cmd_flags |= REQ_URGENT; |
| 399 | WARN_ON(rqueue->nr_req > 1); |
| 400 | rd->pending_urgent_rq = rq; |
| 401 | } |
Tatyana Brokhman | 0ef8143 | 2012-12-20 19:23:58 +0200 | [diff] [blame] | 402 | } else |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 403 | row_log_rowq(rd, rqueue->prio, |
| 404 | "added request (total on queue=%d)", rqueue->nr_req); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 405 | } |
| 406 | |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 407 | /** |
| 408 | * row_reinsert_req() - Reinsert request back to the scheduler |
| 409 | * @q: requests queue |
| 410 | * @rq: request to add |
| 411 | * |
| 412 | * Reinsert the given request back to the queue it was |
| 413 | * dispatched from as if it was never dispatched. |
| 414 | * |
| 415 | * Returns 0 on success, error code otherwise |
| 416 | */ |
| 417 | static int row_reinsert_req(struct request_queue *q, |
| 418 | struct request *rq) |
| 419 | { |
| 420 | struct row_data *rd = q->elevator->elevator_data; |
| 421 | struct row_queue *rqueue = RQ_ROWQ(rq); |
| 422 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 423 | if (!rqueue || rqueue->prio >= ROWQ_MAX_PRIO) |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 424 | return -EIO; |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 425 | |
| 426 | list_add(&rq->queuelist, &rqueue->fifo); |
| 427 | rd->nr_reqs[rq_data_dir(rq)]++; |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 428 | rqueue->nr_req++; |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 429 | |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 430 | row_log_rowq(rd, rqueue->prio, |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 431 | "%s request reinserted (total on queue=%d)", |
| 432 | (rq_data_dir(rq) == READ ? "READ" : "write"), rqueue->nr_req); |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 433 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 434 | if (rq->cmd_flags & REQ_URGENT) { |
| 435 | /* |
| 436 | * It's not compliant with the design to re-insert |
| 437 | * urgent requests. We want to be able to track this |
| 438 | * down. |
| 439 | */ |
| 440 | WARN_ON(1); |
| 441 | if (!rd->urgent_in_flight) { |
| 442 | pr_err("%s(): no urgent in flight", __func__); |
| 443 | } else { |
| 444 | rd->urgent_in_flight = false; |
| 445 | pr_err("%s(): reinserting URGENT %s req", |
| 446 | __func__, |
| 447 | (rq_data_dir(rq) == READ ? "READ" : "WRITE")); |
| 448 | if (rd->pending_urgent_rq) { |
| 449 | pr_err("%s(): urgent rq is pending", |
| 450 | __func__); |
| 451 | rd->pending_urgent_rq->cmd_flags &= ~REQ_URGENT; |
| 452 | } |
| 453 | rd->pending_urgent_rq = rq; |
| 454 | } |
| 455 | } |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 456 | return 0; |
| 457 | } |
| 458 | |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 459 | static void row_completed_req(struct request_queue *q, struct request *rq) |
| 460 | { |
| 461 | struct row_data *rd = q->elevator->elevator_data; |
| 462 | |
| 463 | if (rq->cmd_flags & REQ_URGENT) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 464 | if (!rd->urgent_in_flight) { |
| 465 | WARN_ON(1); |
| 466 | pr_err("%s(): URGENT req but urgent_in_flight = F", |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 467 | __func__); |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 468 | } |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 469 | rd->urgent_in_flight = false; |
| 470 | rq->cmd_flags &= ~REQ_URGENT; |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 471 | } |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 472 | row_log(q, "completed %s %s req.", |
| 473 | (rq->cmd_flags & REQ_URGENT ? "URGENT" : "regular"), |
| 474 | (rq_data_dir(rq) == READ ? "READ" : "WRITE")); |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 477 | /** |
Tatyana Brokhman | 0ef8143 | 2012-12-20 19:23:58 +0200 | [diff] [blame] | 478 | * row_urgent_pending() - Return TRUE if there is an urgent |
| 479 | * request on scheduler |
| 480 | * @q: requests queue |
| 481 | */ |
| 482 | static bool row_urgent_pending(struct request_queue *q) |
| 483 | { |
| 484 | struct row_data *rd = q->elevator->elevator_data; |
Tatyana Brokhman | 0ef8143 | 2012-12-20 19:23:58 +0200 | [diff] [blame] | 485 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 486 | if (rd->urgent_in_flight) { |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 487 | row_log(rd->dispatch_queue, "%d urgent requests in flight", |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 488 | rd->urgent_in_flight); |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 489 | return false; |
| 490 | } |
| 491 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 492 | if (rd->pending_urgent_rq) { |
| 493 | row_log(rd->dispatch_queue, "Urgent request pending"); |
| 494 | return true; |
| 495 | } |
Shashank Babu Chinta Venkata | 3df69bf | 2013-02-26 17:33:55 -0800 | [diff] [blame] | 496 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 497 | row_log(rd->dispatch_queue, "no urgent request pending/in flight"); |
Tatyana Brokhman | 0ef8143 | 2012-12-20 19:23:58 +0200 | [diff] [blame] | 498 | return false; |
| 499 | } |
| 500 | |
| 501 | /** |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 502 | * row_remove_request() - Remove given request from scheduler |
| 503 | * @q: requests queue |
| 504 | * @rq: request to remove |
| 505 | * |
| 506 | */ |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 507 | static void row_remove_request(struct row_data *rd, |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 508 | struct request *rq) |
| 509 | { |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 510 | struct row_queue *rqueue = RQ_ROWQ(rq); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 511 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 512 | list_del_init(&(rq)->queuelist); |
| 513 | if (rd->pending_urgent_rq == rq) |
| 514 | rd->pending_urgent_rq = NULL; |
| 515 | else |
| 516 | BUG_ON(rq->cmd_flags & REQ_URGENT); |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 517 | rqueue->nr_req--; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 518 | rd->nr_reqs[rq_data_dir(rq)]--; |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * row_dispatch_insert() - move request to dispatch queue |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 523 | * @rd: pointer to struct row_data |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 524 | * @rq: the request to dispatch |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 525 | * |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 526 | * This function moves the given request to the dispatch queue |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 527 | * |
| 528 | */ |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 529 | static void row_dispatch_insert(struct row_data *rd, struct request *rq) |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 530 | { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 531 | struct row_queue *rqueue = RQ_ROWQ(rq); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 532 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 533 | row_remove_request(rd, rq); |
| 534 | elv_dispatch_sort(rd->dispatch_queue, rq); |
| 535 | if (rq->cmd_flags & REQ_URGENT) { |
| 536 | WARN_ON(rd->urgent_in_flight); |
| 537 | rd->urgent_in_flight = true; |
| 538 | } |
| 539 | rqueue->nr_dispatched++; |
| 540 | row_clear_rowq_unserved(rd, rqueue->prio); |
| 541 | row_log_rowq(rd, rqueue->prio, |
| 542 | " Dispatched request %p nr_disp = %d", rq, |
| 543 | rqueue->nr_dispatched); |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 544 | if (rqueue->prio < ROWQ_REG_PRIO_IDX) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 545 | rd->last_served_ioprio_class = IOPRIO_CLASS_RT; |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 546 | if (row_regular_req_pending(rd)) |
| 547 | rd->reg_prio_starvation.starvation_counter++; |
| 548 | if (row_low_req_pending(rd)) |
| 549 | rd->low_prio_starvation.starvation_counter++; |
| 550 | } else if (rqueue->prio < ROWQ_LOW_PRIO_IDX) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 551 | rd->last_served_ioprio_class = IOPRIO_CLASS_BE; |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 552 | rd->reg_prio_starvation.starvation_counter = 0; |
| 553 | if (row_low_req_pending(rd)) |
| 554 | rd->low_prio_starvation.starvation_counter++; |
| 555 | } else { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 556 | rd->last_served_ioprio_class = IOPRIO_CLASS_IDLE; |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 557 | rd->low_prio_starvation.starvation_counter = 0; |
| 558 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /* |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 562 | * row_get_ioprio_class_to_serve() - Return the next I/O priority |
| 563 | * class to dispatch requests from |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 564 | * @rd: pointer to struct row_data |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 565 | * @force: flag indicating if forced dispatch |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 566 | * |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 567 | * This function returns the next I/O priority class to serve |
| 568 | * {IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE}. |
| 569 | * If there are no more requests in scheduler or if we're idling on some queue |
| 570 | * IOPRIO_CLASS_NONE will be returned. |
| 571 | * If idling is scheduled on a lower priority queue than the one that needs |
| 572 | * to be served, it will be canceled. |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 573 | * |
| 574 | */ |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 575 | static int row_get_ioprio_class_to_serve(struct row_data *rd, int force) |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 576 | { |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 577 | int i; |
| 578 | int ret = IOPRIO_CLASS_NONE; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 579 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 580 | if (!rd->nr_reqs[READ] && !rd->nr_reqs[WRITE]) { |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 581 | row_log(rd->dispatch_queue, "No more requests in scheduler"); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 582 | goto check_idling; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 583 | } |
| 584 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 585 | /* First, go over the high priority queues */ |
| 586 | for (i = 0; i < ROWQ_REG_PRIO_IDX; i++) { |
| 587 | if (!list_empty(&rd->row_queues[i].fifo)) { |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 588 | if (hrtimer_active(&rd->rd_idle_data.hr_timer)) { |
Tatyana Brokhman | a1d6f9e | 2013-07-02 14:43:13 +0300 | [diff] [blame] | 589 | if (hrtimer_try_to_cancel( |
| 590 | &rd->rd_idle_data.hr_timer) >= 0) { |
| 591 | row_log(rd->dispatch_queue, |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 592 | "Canceling delayed work on %d. RT pending", |
Tatyana Brokhman | a1d6f9e | 2013-07-02 14:43:13 +0300 | [diff] [blame] | 593 | rd->rd_idle_data.idling_queue_idx); |
| 594 | rd->rd_idle_data.idling_queue_idx = |
| 595 | ROWQ_MAX_PRIO; |
| 596 | } |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 597 | } |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 598 | |
| 599 | if (row_regular_req_pending(rd) && |
| 600 | (rd->reg_prio_starvation.starvation_counter >= |
| 601 | rd->reg_prio_starvation.starvation_limit)) |
| 602 | ret = IOPRIO_CLASS_BE; |
| 603 | else if (row_low_req_pending(rd) && |
| 604 | (rd->low_prio_starvation.starvation_counter >= |
| 605 | rd->low_prio_starvation.starvation_limit)) |
| 606 | ret = IOPRIO_CLASS_IDLE; |
| 607 | else |
| 608 | ret = IOPRIO_CLASS_RT; |
| 609 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 610 | goto done; |
| 611 | } |
| 612 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 613 | |
| 614 | /* |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 615 | * At the moment idling is implemented only for READ queues. |
| 616 | * If enabled on WRITE, this needs updating |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 617 | */ |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 618 | if (hrtimer_active(&rd->rd_idle_data.hr_timer)) { |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 619 | row_log(rd->dispatch_queue, "Delayed work pending. Exiting"); |
| 620 | goto done; |
| 621 | } |
| 622 | check_idling: |
| 623 | /* Check for (high priority) idling and enable if needed */ |
| 624 | for (i = 0; i < ROWQ_REG_PRIO_IDX && !force; i++) { |
| 625 | if (rd->row_queues[i].idle_data.begin_idling && |
| 626 | row_queues_def[i].idling_enabled) |
| 627 | goto initiate_idling; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 628 | } |
| 629 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 630 | /* Regular priority queues */ |
| 631 | for (i = ROWQ_REG_PRIO_IDX; i < ROWQ_LOW_PRIO_IDX; i++) { |
| 632 | if (list_empty(&rd->row_queues[i].fifo)) { |
| 633 | /* We can idle only if this is not a forced dispatch */ |
| 634 | if (rd->row_queues[i].idle_data.begin_idling && |
| 635 | !force && row_queues_def[i].idling_enabled) |
| 636 | goto initiate_idling; |
| 637 | } else { |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 638 | if (row_low_req_pending(rd) && |
| 639 | (rd->low_prio_starvation.starvation_counter >= |
| 640 | rd->low_prio_starvation.starvation_limit)) |
| 641 | ret = IOPRIO_CLASS_IDLE; |
| 642 | else |
| 643 | ret = IOPRIO_CLASS_BE; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 644 | goto done; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | if (rd->nr_reqs[READ] || rd->nr_reqs[WRITE]) |
| 649 | ret = IOPRIO_CLASS_IDLE; |
| 650 | goto done; |
| 651 | |
| 652 | initiate_idling: |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 653 | hrtimer_start(&rd->rd_idle_data.hr_timer, |
| 654 | ktime_set(0, rd->rd_idle_data.idle_time_ms * NSEC_PER_MSEC), |
| 655 | HRTIMER_MODE_REL); |
| 656 | |
| 657 | rd->rd_idle_data.idling_queue_idx = i; |
| 658 | row_log_rowq(rd, i, "Scheduled delayed work on %d. exiting", i); |
| 659 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 660 | done: |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static void row_restart_cycle(struct row_data *rd, |
| 665 | int start_idx, int end_idx) |
| 666 | { |
| 667 | int i; |
| 668 | |
| 669 | row_dump_queues_stat(rd); |
| 670 | for (i = start_idx; i < end_idx; i++) { |
| 671 | if (rd->row_queues[i].nr_dispatched < |
| 672 | rd->row_queues[i].disp_quantum) |
| 673 | row_mark_rowq_unserved(rd, i); |
| 674 | rd->row_queues[i].nr_dispatched = 0; |
| 675 | } |
| 676 | row_log(rd->dispatch_queue, "Restarting cycle for class @ %d-%d", |
| 677 | start_idx, end_idx); |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * row_get_next_queue() - selects the next queue to dispatch from |
| 682 | * @q: requests queue |
| 683 | * @rd: pointer to struct row_data |
| 684 | * @start_idx/end_idx: indexes in the row_queues array to select a queue |
| 685 | * from. |
| 686 | * |
| 687 | * Return index of the queues to dispatch from. Error code if fails. |
| 688 | * |
| 689 | */ |
| 690 | static int row_get_next_queue(struct request_queue *q, struct row_data *rd, |
| 691 | int start_idx, int end_idx) |
| 692 | { |
| 693 | int i = start_idx; |
| 694 | bool restart = true; |
| 695 | int ret = -EIO; |
| 696 | |
| 697 | do { |
| 698 | if (list_empty(&rd->row_queues[i].fifo) || |
| 699 | rd->row_queues[i].nr_dispatched >= |
| 700 | rd->row_queues[i].disp_quantum) { |
| 701 | i++; |
| 702 | if (i == end_idx && restart) { |
| 703 | /* Restart cycle for this priority class */ |
| 704 | row_restart_cycle(rd, start_idx, end_idx); |
| 705 | i = start_idx; |
| 706 | restart = false; |
| 707 | } |
| 708 | } else { |
| 709 | ret = i; |
| 710 | break; |
| 711 | } |
| 712 | } while (i < end_idx); |
| 713 | |
| 714 | return ret; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /* |
| 718 | * row_dispatch_requests() - selects the next request to dispatch |
| 719 | * @q: requests queue |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 720 | * @force: flag indicating if forced dispatch |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 721 | * |
| 722 | * Return 0 if no requests were moved to the dispatch queue. |
| 723 | * 1 otherwise |
| 724 | * |
| 725 | */ |
| 726 | static int row_dispatch_requests(struct request_queue *q, int force) |
| 727 | { |
| 728 | struct row_data *rd = (struct row_data *)q->elevator->elevator_data; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 729 | int ret = 0, currq, ioprio_class_to_serve, start_idx, end_idx; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 730 | |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 731 | if (force && hrtimer_active(&rd->rd_idle_data.hr_timer)) { |
Tatyana Brokhman | a1d6f9e | 2013-07-02 14:43:13 +0300 | [diff] [blame] | 732 | if (hrtimer_try_to_cancel(&rd->rd_idle_data.hr_timer) >= 0) { |
| 733 | row_log(rd->dispatch_queue, |
| 734 | "Canceled delayed work on %d - forced dispatch", |
| 735 | rd->rd_idle_data.idling_queue_idx); |
| 736 | rd->rd_idle_data.idling_queue_idx = ROWQ_MAX_PRIO; |
| 737 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 738 | } |
| 739 | |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 740 | if (rd->pending_urgent_rq) { |
| 741 | row_log(rd->dispatch_queue, "dispatching urgent request"); |
| 742 | row_dispatch_insert(rd, rd->pending_urgent_rq); |
| 743 | ret = 1; |
| 744 | goto done; |
| 745 | } |
| 746 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 747 | ioprio_class_to_serve = row_get_ioprio_class_to_serve(rd, force); |
| 748 | row_log(rd->dispatch_queue, "Dispatching from %d priority class", |
| 749 | ioprio_class_to_serve); |
| 750 | |
| 751 | switch (ioprio_class_to_serve) { |
| 752 | case IOPRIO_CLASS_NONE: |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 753 | rd->last_served_ioprio_class = IOPRIO_CLASS_NONE; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 754 | goto done; |
| 755 | case IOPRIO_CLASS_RT: |
| 756 | start_idx = ROWQ_HIGH_PRIO_IDX; |
| 757 | end_idx = ROWQ_REG_PRIO_IDX; |
| 758 | break; |
| 759 | case IOPRIO_CLASS_BE: |
| 760 | start_idx = ROWQ_REG_PRIO_IDX; |
| 761 | end_idx = ROWQ_LOW_PRIO_IDX; |
| 762 | break; |
| 763 | case IOPRIO_CLASS_IDLE: |
| 764 | start_idx = ROWQ_LOW_PRIO_IDX; |
| 765 | end_idx = ROWQ_MAX_PRIO; |
| 766 | break; |
| 767 | default: |
| 768 | pr_err("%s(): Invalid I/O priority class", __func__); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 769 | goto done; |
| 770 | } |
| 771 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 772 | currq = row_get_next_queue(q, rd, start_idx, end_idx); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 773 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 774 | /* Dispatch */ |
| 775 | if (currq >= 0) { |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 776 | row_dispatch_insert(rd, |
| 777 | rq_entry_fifo(rd->row_queues[currq].fifo.next)); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 778 | ret = 1; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 779 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 780 | done: |
| 781 | return ret; |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * row_init_queue() - Init scheduler data structures |
| 786 | * @q: requests queue |
| 787 | * |
| 788 | * Return pointer to struct row_data to be saved in elevator for |
| 789 | * this dispatch queue |
| 790 | * |
| 791 | */ |
| 792 | static void *row_init_queue(struct request_queue *q) |
| 793 | { |
| 794 | |
| 795 | struct row_data *rdata; |
| 796 | int i; |
| 797 | |
| 798 | rdata = kmalloc_node(sizeof(*rdata), |
| 799 | GFP_KERNEL | __GFP_ZERO, q->node); |
| 800 | if (!rdata) |
| 801 | return NULL; |
| 802 | |
Tatyana Brokhman | 522778f | 2013-01-24 16:17:27 +0200 | [diff] [blame] | 803 | memset(rdata, 0, sizeof(*rdata)); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 804 | for (i = 0; i < ROWQ_MAX_PRIO; i++) { |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 805 | INIT_LIST_HEAD(&rdata->row_queues[i].fifo); |
Tatyana Brokhman | 9375bcc | 2013-01-12 16:23:18 +0200 | [diff] [blame] | 806 | rdata->row_queues[i].disp_quantum = row_queues_def[i].quantum; |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 807 | rdata->row_queues[i].rdata = rdata; |
| 808 | rdata->row_queues[i].prio = i; |
| 809 | rdata->row_queues[i].idle_data.begin_idling = false; |
| 810 | rdata->row_queues[i].idle_data.last_insert_time = |
Tatyana Brokhman | bfb04f6 | 2012-12-06 13:17:19 +0200 | [diff] [blame] | 811 | ktime_set(0, 0); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 812 | } |
| 813 | |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 814 | rdata->reg_prio_starvation.starvation_limit = |
| 815 | ROW_REG_STARVATION_TOLLERANCE; |
| 816 | rdata->low_prio_starvation.starvation_limit = |
| 817 | ROW_LOW_STARVATION_TOLLERANCE; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 818 | /* |
| 819 | * Currently idling is enabled only for READ queues. If we want to |
| 820 | * enable it for write queues also, note that idling frequency will |
| 821 | * be the same in both cases |
| 822 | */ |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 823 | rdata->rd_idle_data.idle_time_ms = ROW_IDLE_TIME_MSEC; |
| 824 | rdata->rd_idle_data.freq_ms = ROW_READ_FREQ_MSEC; |
| 825 | hrtimer_init(&rdata->rd_idle_data.hr_timer, |
| 826 | CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 827 | rdata->rd_idle_data.hr_timer.function = &row_idle_hrtimer_fn; |
| 828 | |
| 829 | INIT_WORK(&rdata->rd_idle_data.idle_work, kick_queue); |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 830 | rdata->last_served_ioprio_class = IOPRIO_CLASS_NONE; |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 831 | rdata->rd_idle_data.idling_queue_idx = ROWQ_MAX_PRIO; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 832 | rdata->dispatch_queue = q; |
| 833 | |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 834 | return rdata; |
| 835 | } |
| 836 | |
| 837 | /* |
| 838 | * row_exit_queue() - called on unloading the RAW scheduler |
| 839 | * @e: poiner to struct elevator_queue |
| 840 | * |
| 841 | */ |
| 842 | static void row_exit_queue(struct elevator_queue *e) |
| 843 | { |
| 844 | struct row_data *rd = (struct row_data *)e->elevator_data; |
| 845 | int i; |
| 846 | |
| 847 | for (i = 0; i < ROWQ_MAX_PRIO; i++) |
Tatyana Brokhman | 8a970bc | 2013-01-12 16:21:12 +0200 | [diff] [blame] | 848 | BUG_ON(!list_empty(&rd->row_queues[i].fifo)); |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 849 | if (hrtimer_cancel(&rd->rd_idle_data.hr_timer)) |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 850 | pr_err("%s(): idle timer was active!", __func__); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 851 | rd->rd_idle_data.idling_queue_idx = ROWQ_MAX_PRIO; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 852 | kfree(rd); |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * row_merged_requests() - Called when 2 requests are merged |
| 857 | * @q: requests queue |
| 858 | * @rq: request the two requests were merged into |
| 859 | * @next: request that was merged |
| 860 | */ |
| 861 | static void row_merged_requests(struct request_queue *q, struct request *rq, |
| 862 | struct request *next) |
| 863 | { |
| 864 | struct row_queue *rqueue = RQ_ROWQ(next); |
| 865 | |
| 866 | list_del_init(&next->queuelist); |
Tatyana Brokhman | bd56be3 | 2013-01-13 22:04:59 +0200 | [diff] [blame] | 867 | rqueue->nr_req--; |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 868 | if (rqueue->rdata->pending_urgent_rq == next) { |
| 869 | pr_err("\n\nROW_WARNING: merging pending urgent!"); |
| 870 | rqueue->rdata->pending_urgent_rq = rq; |
| 871 | rq->cmd_flags |= REQ_URGENT; |
| 872 | WARN_ON(!(next->cmd_flags & REQ_URGENT)); |
| 873 | next->cmd_flags &= ~REQ_URGENT; |
| 874 | } |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 875 | rqueue->rdata->nr_reqs[rq_data_dir(rq)]--; |
| 876 | } |
| 877 | |
| 878 | /* |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 879 | * row_get_queue_prio() - Get queue priority for a given request |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 880 | * |
| 881 | * This is a helping function which purpose is to determine what |
| 882 | * ROW queue the given request should be added to (and |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 883 | * dispatched from later on) |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 884 | * |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 885 | */ |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 886 | static enum row_queue_prio row_get_queue_prio(struct request *rq, |
| 887 | struct row_data *rd) |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 888 | { |
| 889 | const int data_dir = rq_data_dir(rq); |
| 890 | const bool is_sync = rq_is_sync(rq); |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 891 | enum row_queue_prio q_type = ROWQ_MAX_PRIO; |
| 892 | int ioprio_class = IOPRIO_PRIO_CLASS(rq->elv.icq->ioc->ioprio); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 893 | |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 894 | switch (ioprio_class) { |
| 895 | case IOPRIO_CLASS_RT: |
| 896 | if (data_dir == READ) |
| 897 | q_type = ROWQ_PRIO_HIGH_READ; |
| 898 | else if (is_sync) |
| 899 | q_type = ROWQ_PRIO_HIGH_SWRITE; |
| 900 | else { |
| 901 | pr_err("%s:%s(): got a simple write from RT_CLASS. How???", |
| 902 | rq->rq_disk->disk_name, __func__); |
| 903 | q_type = ROWQ_PRIO_REG_WRITE; |
| 904 | } |
| 905 | break; |
| 906 | case IOPRIO_CLASS_IDLE: |
| 907 | if (data_dir == READ) |
| 908 | q_type = ROWQ_PRIO_LOW_READ; |
| 909 | else if (is_sync) |
| 910 | q_type = ROWQ_PRIO_LOW_SWRITE; |
| 911 | else { |
| 912 | pr_err("%s:%s(): got a simple write from IDLE_CLASS. How???", |
| 913 | rq->rq_disk->disk_name, __func__); |
| 914 | q_type = ROWQ_PRIO_REG_WRITE; |
| 915 | } |
| 916 | break; |
| 917 | case IOPRIO_CLASS_NONE: |
| 918 | case IOPRIO_CLASS_BE: |
| 919 | default: |
| 920 | if (data_dir == READ) |
| 921 | q_type = ROWQ_PRIO_REG_READ; |
| 922 | else if (is_sync) |
| 923 | q_type = ROWQ_PRIO_REG_SWRITE; |
| 924 | else |
| 925 | q_type = ROWQ_PRIO_REG_WRITE; |
| 926 | break; |
| 927 | } |
| 928 | |
| 929 | return q_type; |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /* |
| 933 | * row_set_request() - Set ROW data structures associated with this request. |
| 934 | * @q: requests queue |
| 935 | * @rq: pointer to the request |
| 936 | * @gfp_mask: ignored |
| 937 | * |
| 938 | */ |
| 939 | static int |
| 940 | row_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask) |
| 941 | { |
| 942 | struct row_data *rd = (struct row_data *)q->elevator->elevator_data; |
| 943 | unsigned long flags; |
| 944 | |
| 945 | spin_lock_irqsave(q->queue_lock, flags); |
| 946 | rq->elv.priv[0] = |
Tatyana Brokhman | fe6fd2f | 2013-03-12 21:17:18 +0200 | [diff] [blame] | 947 | (void *)(&rd->row_queues[row_get_queue_prio(rq, rd)]); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 948 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | /********** Helping sysfs functions/defenitions for ROW attributes ******/ |
| 954 | static ssize_t row_var_show(int var, char *page) |
| 955 | { |
| 956 | return snprintf(page, 100, "%d\n", var); |
| 957 | } |
| 958 | |
| 959 | static ssize_t row_var_store(int *var, const char *page, size_t count) |
| 960 | { |
| 961 | int err; |
| 962 | err = kstrtoul(page, 10, (unsigned long *)var); |
| 963 | |
| 964 | return count; |
| 965 | } |
| 966 | |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 967 | #define SHOW_FUNCTION(__FUNC, __VAR) \ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 968 | static ssize_t __FUNC(struct elevator_queue *e, char *page) \ |
| 969 | { \ |
| 970 | struct row_data *rowd = e->elevator_data; \ |
| 971 | int __data = __VAR; \ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 972 | return row_var_show(__data, (page)); \ |
| 973 | } |
| 974 | SHOW_FUNCTION(row_hp_read_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 975 | rowd->row_queues[ROWQ_PRIO_HIGH_READ].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 976 | SHOW_FUNCTION(row_rp_read_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 977 | rowd->row_queues[ROWQ_PRIO_REG_READ].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 978 | SHOW_FUNCTION(row_hp_swrite_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 979 | rowd->row_queues[ROWQ_PRIO_HIGH_SWRITE].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 980 | SHOW_FUNCTION(row_rp_swrite_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 981 | rowd->row_queues[ROWQ_PRIO_REG_SWRITE].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 982 | SHOW_FUNCTION(row_rp_write_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 983 | rowd->row_queues[ROWQ_PRIO_REG_WRITE].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 984 | SHOW_FUNCTION(row_lp_read_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 985 | rowd->row_queues[ROWQ_PRIO_LOW_READ].disp_quantum); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 986 | SHOW_FUNCTION(row_lp_swrite_quantum_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 987 | rowd->row_queues[ROWQ_PRIO_LOW_SWRITE].disp_quantum); |
| 988 | SHOW_FUNCTION(row_rd_idle_data_show, rowd->rd_idle_data.idle_time_ms); |
| 989 | SHOW_FUNCTION(row_rd_idle_data_freq_show, rowd->rd_idle_data.freq_ms); |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 990 | SHOW_FUNCTION(row_reg_starv_limit_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 991 | rowd->reg_prio_starvation.starvation_limit); |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 992 | SHOW_FUNCTION(row_low_starv_limit_show, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 993 | rowd->low_prio_starvation.starvation_limit); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 994 | #undef SHOW_FUNCTION |
| 995 | |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 996 | #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX) \ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 997 | static ssize_t __FUNC(struct elevator_queue *e, \ |
| 998 | const char *page, size_t count) \ |
| 999 | { \ |
| 1000 | struct row_data *rowd = e->elevator_data; \ |
| 1001 | int __data; \ |
| 1002 | int ret = row_var_store(&__data, (page), count); \ |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1003 | if (__data < (MIN)) \ |
| 1004 | __data = (MIN); \ |
| 1005 | else if (__data > (MAX)) \ |
| 1006 | __data = (MAX); \ |
| 1007 | *(__PTR) = __data; \ |
| 1008 | return ret; \ |
| 1009 | } |
| 1010 | STORE_FUNCTION(row_hp_read_quantum_store, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1011 | &rowd->row_queues[ROWQ_PRIO_HIGH_READ].disp_quantum, 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1012 | STORE_FUNCTION(row_rp_read_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1013 | &rowd->row_queues[ROWQ_PRIO_REG_READ].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1014 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1015 | STORE_FUNCTION(row_hp_swrite_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1016 | &rowd->row_queues[ROWQ_PRIO_HIGH_SWRITE].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1017 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1018 | STORE_FUNCTION(row_rp_swrite_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1019 | &rowd->row_queues[ROWQ_PRIO_REG_SWRITE].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1020 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1021 | STORE_FUNCTION(row_rp_write_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1022 | &rowd->row_queues[ROWQ_PRIO_REG_WRITE].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1023 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1024 | STORE_FUNCTION(row_lp_read_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1025 | &rowd->row_queues[ROWQ_PRIO_LOW_READ].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1026 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1027 | STORE_FUNCTION(row_lp_swrite_quantum_store, |
Tatyana Brokhman | 0a0345a | 2012-10-15 20:50:54 +0200 | [diff] [blame] | 1028 | &rowd->row_queues[ROWQ_PRIO_LOW_SWRITE].disp_quantum, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1029 | 1, INT_MAX); |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 1030 | STORE_FUNCTION(row_rd_idle_data_store, &rowd->rd_idle_data.idle_time_ms, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1031 | 1, INT_MAX); |
Tatyana Brokhman | ce1a8ed | 2013-01-17 20:56:07 +0200 | [diff] [blame] | 1032 | STORE_FUNCTION(row_rd_idle_data_freq_store, &rowd->rd_idle_data.freq_ms, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1033 | 1, INT_MAX); |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 1034 | STORE_FUNCTION(row_reg_starv_limit_store, |
| 1035 | &rowd->reg_prio_starvation.starvation_limit, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1036 | 1, INT_MAX); |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 1037 | STORE_FUNCTION(row_low_starv_limit_store, |
| 1038 | &rowd->low_prio_starvation.starvation_limit, |
Tatyana Brokhman | e9aab61 | 2013-03-21 11:04:02 +0200 | [diff] [blame] | 1039 | 1, INT_MAX); |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1040 | |
| 1041 | #undef STORE_FUNCTION |
| 1042 | |
| 1043 | #define ROW_ATTR(name) \ |
| 1044 | __ATTR(name, S_IRUGO|S_IWUSR, row_##name##_show, \ |
| 1045 | row_##name##_store) |
| 1046 | |
| 1047 | static struct elv_fs_entry row_attrs[] = { |
| 1048 | ROW_ATTR(hp_read_quantum), |
| 1049 | ROW_ATTR(rp_read_quantum), |
| 1050 | ROW_ATTR(hp_swrite_quantum), |
| 1051 | ROW_ATTR(rp_swrite_quantum), |
| 1052 | ROW_ATTR(rp_write_quantum), |
| 1053 | ROW_ATTR(lp_read_quantum), |
| 1054 | ROW_ATTR(lp_swrite_quantum), |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 1055 | ROW_ATTR(rd_idle_data), |
| 1056 | ROW_ATTR(rd_idle_data_freq), |
Tatyana Brokhman | eec4947 | 2013-03-21 13:02:07 +0200 | [diff] [blame] | 1057 | ROW_ATTR(reg_starv_limit), |
| 1058 | ROW_ATTR(low_starv_limit), |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1059 | __ATTR_NULL |
| 1060 | }; |
| 1061 | |
| 1062 | static struct elevator_type iosched_row = { |
| 1063 | .ops = { |
| 1064 | .elevator_merge_req_fn = row_merged_requests, |
| 1065 | .elevator_dispatch_fn = row_dispatch_requests, |
| 1066 | .elevator_add_req_fn = row_add_request, |
Tatyana Brokhman | b7bf9ac | 2012-10-30 08:33:06 +0200 | [diff] [blame] | 1067 | .elevator_reinsert_req_fn = row_reinsert_req, |
Tatyana Brokhman | 0ef8143 | 2012-12-20 19:23:58 +0200 | [diff] [blame] | 1068 | .elevator_is_urgent_fn = row_urgent_pending, |
Tatyana Brokhman | 4c3c3cc | 2013-01-24 15:08:40 +0200 | [diff] [blame] | 1069 | .elevator_completed_req_fn = row_completed_req, |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1070 | .elevator_former_req_fn = elv_rb_former_request, |
| 1071 | .elevator_latter_req_fn = elv_rb_latter_request, |
| 1072 | .elevator_set_req_fn = row_set_request, |
| 1073 | .elevator_init_fn = row_init_queue, |
| 1074 | .elevator_exit_fn = row_exit_queue, |
| 1075 | }, |
Tatyana Brokhman | db7c153 | 2013-01-23 17:15:49 +0200 | [diff] [blame] | 1076 | .icq_size = sizeof(struct io_cq), |
| 1077 | .icq_align = __alignof__(struct io_cq), |
Tatyana Brokhman | 1634906 | 2012-09-20 10:46:10 +0300 | [diff] [blame] | 1078 | .elevator_attrs = row_attrs, |
| 1079 | .elevator_name = "row", |
| 1080 | .elevator_owner = THIS_MODULE, |
| 1081 | }; |
| 1082 | |
| 1083 | static int __init row_init(void) |
| 1084 | { |
| 1085 | elv_register(&iosched_row); |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | static void __exit row_exit(void) |
| 1090 | { |
| 1091 | elv_unregister(&iosched_row); |
| 1092 | } |
| 1093 | |
| 1094 | module_init(row_init); |
| 1095 | module_exit(row_exit); |
| 1096 | |
| 1097 | MODULE_LICENSE("GPLv2"); |
| 1098 | MODULE_DESCRIPTION("Read Over Write IO scheduler"); |