Commit | Line | Data |
---|---|---|
a497ee34 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
ea25da48 PV |
2 | /* |
3 | * Header file for the BFQ I/O scheduler: data structures and | |
4 | * prototypes of interface functions among BFQ components. | |
ea25da48 PV |
5 | */ |
6 | #ifndef _BFQ_H | |
7 | #define _BFQ_H | |
8 | ||
9 | #include <linux/blktrace_api.h> | |
10 | #include <linux/hrtimer.h> | |
ea25da48 | 11 | |
1d156646 TH |
12 | #include "blk-cgroup-rwstat.h" |
13 | ||
ea25da48 PV |
14 | #define BFQ_IOPRIO_CLASSES 3 |
15 | #define BFQ_CL_IDLE_TIMEOUT (HZ/5) | |
16 | ||
17 | #define BFQ_MIN_WEIGHT 1 | |
18 | #define BFQ_MAX_WEIGHT 1000 | |
19 | #define BFQ_WEIGHT_CONVERSION_COEFF 10 | |
20 | ||
21 | #define BFQ_DEFAULT_QUEUE_IOPRIO 4 | |
22 | ||
23 | #define BFQ_WEIGHT_LEGACY_DFL 100 | |
24 | #define BFQ_DEFAULT_GRP_IOPRIO 0 | |
25 | #define BFQ_DEFAULT_GRP_CLASS IOPRIO_CLASS_BE | |
26 | ||
582f04e1 | 27 | #define MAX_BFQQ_NAME_LENGTH 16 |
1e66413c | 28 | |
ea25da48 PV |
29 | /* |
30 | * Soft real-time applications are extremely more latency sensitive | |
31 | * than interactive ones. Over-raise the weight of the former to | |
32 | * privilege them against the latter. | |
33 | */ | |
34 | #define BFQ_SOFTRT_WEIGHT_FACTOR 100 | |
35 | ||
9778369a PV |
36 | /* |
37 | * Maximum number of actuators supported. This constant is used simply | |
38 | * to define the size of the static array that will contain | |
39 | * per-actuator data. The current value is hopefully a good upper | |
40 | * bound to the possible number of actuators of any actual drive. | |
41 | */ | |
42 | #define BFQ_MAX_ACTUATORS 8 | |
43 | ||
ea25da48 PV |
44 | struct bfq_entity; |
45 | ||
46 | /** | |
47 | * struct bfq_service_tree - per ioprio_class service tree. | |
48 | * | |
49 | * Each service tree represents a B-WF2Q+ scheduler on its own. Each | |
50 | * ioprio_class has its own independent scheduler, and so its own | |
51 | * bfq_service_tree. All the fields are protected by the queue lock | |
52 | * of the containing bfqd. | |
53 | */ | |
54 | struct bfq_service_tree { | |
55 | /* tree for active entities (i.e., those backlogged) */ | |
56 | struct rb_root active; | |
38c91407 | 57 | /* tree for idle entities (i.e., not backlogged, with V < F_i)*/ |
ea25da48 PV |
58 | struct rb_root idle; |
59 | ||
60 | /* idle entity with minimum F_i */ | |
61 | struct bfq_entity *first_idle; | |
62 | /* idle entity with maximum F_i */ | |
63 | struct bfq_entity *last_idle; | |
64 | ||
65 | /* scheduler virtual time */ | |
66 | u64 vtime; | |
67 | /* scheduler weight sum; active and idle entities contribute to it */ | |
68 | unsigned long wsum; | |
69 | }; | |
70 | ||
71 | /** | |
72 | * struct bfq_sched_data - multi-class scheduler. | |
73 | * | |
74 | * bfq_sched_data is the basic scheduler queue. It supports three | |
75 | * ioprio_classes, and can be used either as a toplevel queue or as an | |
46d556e6 | 76 | * intermediate queue in a hierarchical setup. |
ea25da48 PV |
77 | * |
78 | * The supported ioprio_classes are the same as in CFQ, in descending | |
79 | * priority order, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE. | |
80 | * Requests from higher priority queues are served before all the | |
81 | * requests from lower priority queues; among requests of the same | |
82 | * queue requests are served according to B-WF2Q+. | |
46d556e6 PV |
83 | * |
84 | * The schedule is implemented by the service trees, plus the field | |
85 | * @next_in_service, which points to the entity on the active trees | |
86 | * that will be served next, if 1) no changes in the schedule occurs | |
87 | * before the current in-service entity is expired, 2) the in-service | |
88 | * queue becomes idle when it expires, and 3) if the entity pointed by | |
89 | * in_service_entity is not a queue, then the in-service child entity | |
90 | * of the entity pointed by in_service_entity becomes idle on | |
91 | * expiration. This peculiar definition allows for the following | |
92 | * optimization, not yet exploited: while a given entity is still in | |
93 | * service, we already know which is the best candidate for next | |
636b8fe8 | 94 | * service among the other active entities in the same parent |
46d556e6 PV |
95 | * entity. We can then quickly compare the timestamps of the |
96 | * in-service entity with those of such best candidate. | |
97 | * | |
98 | * All fields are protected by the lock of the containing bfqd. | |
ea25da48 PV |
99 | */ |
100 | struct bfq_sched_data { | |
101 | /* entity in service */ | |
102 | struct bfq_entity *in_service_entity; | |
103 | /* head-of-line entity (see comments above) */ | |
104 | struct bfq_entity *next_in_service; | |
105 | /* array of service trees, one per ioprio_class */ | |
106 | struct bfq_service_tree service_tree[BFQ_IOPRIO_CLASSES]; | |
107 | /* last time CLASS_IDLE was served */ | |
108 | unsigned long bfq_class_idle_last_service; | |
109 | ||
110 | }; | |
111 | ||
112 | /** | |
2d29c9f8 | 113 | * struct bfq_weight_counter - counter of the number of all active queues |
ea25da48 PV |
114 | * with a given weight. |
115 | */ | |
116 | struct bfq_weight_counter { | |
2d29c9f8 FM |
117 | unsigned int weight; /* weight of the queues this counter refers to */ |
118 | unsigned int num_active; /* nr of active queues with this weight */ | |
ea25da48 | 119 | /* |
2d29c9f8 | 120 | * Weights tree member (see bfq_data's @queue_weights_tree) |
ea25da48 PV |
121 | */ |
122 | struct rb_node weights_node; | |
123 | }; | |
124 | ||
125 | /** | |
126 | * struct bfq_entity - schedulable entity. | |
127 | * | |
128 | * A bfq_entity is used to represent either a bfq_queue (leaf node in the | |
129 | * cgroup hierarchy) or a bfq_group into the upper level scheduler. Each | |
130 | * entity belongs to the sched_data of the parent group in the cgroup | |
131 | * hierarchy. Non-leaf entities have also their own sched_data, stored | |
132 | * in @my_sched_data. | |
133 | * | |
134 | * Each entity stores independently its priority values; this would | |
135 | * allow different weights on different devices, but this | |
136 | * functionality is not exported to userspace by now. Priorities and | |
137 | * weights are updated lazily, first storing the new values into the | |
138 | * new_* fields, then setting the @prio_changed flag. As soon as | |
139 | * there is a transition in the entity state that allows the priority | |
140 | * update to take place the effective and the requested priority | |
141 | * values are synchronized. | |
142 | * | |
143 | * Unless cgroups are used, the weight value is calculated from the | |
144 | * ioprio to export the same interface as CFQ. When dealing with | |
636b8fe8 | 145 | * "well-behaved" queues (i.e., queues that do not spend too much |
ea25da48 PV |
146 | * time to consume their budget and have true sequential behavior, and |
147 | * when there are no external factors breaking anticipation) the | |
148 | * relative weights at each level of the cgroups hierarchy should be | |
149 | * guaranteed. All the fields are protected by the queue lock of the | |
150 | * containing bfqd. | |
151 | */ | |
152 | struct bfq_entity { | |
153 | /* service_tree member */ | |
154 | struct rb_node rb_node; | |
ea25da48 PV |
155 | |
156 | /* | |
157 | * Flag, true if the entity is on a tree (either the active or | |
158 | * the idle one of its service_tree) or is in service. | |
159 | */ | |
33a16a98 | 160 | bool on_st_or_in_serv; |
ea25da48 PV |
161 | |
162 | /* B-WF2Q+ start and finish timestamps [sectors/weight] */ | |
163 | u64 start, finish; | |
164 | ||
165 | /* tree the entity is enqueued into; %NULL if not on a tree */ | |
166 | struct rb_root *tree; | |
167 | ||
168 | /* | |
169 | * minimum start time of the (active) subtree rooted at this | |
170 | * entity; used for O(log N) lookups into active trees | |
171 | */ | |
172 | u64 min_start; | |
173 | ||
174 | /* amount of service received during the last service slot */ | |
175 | int service; | |
176 | ||
177 | /* budget, used also to calculate F_i: F_i = S_i + @budget / @weight */ | |
178 | int budget; | |
179 | ||
98f04499 JK |
180 | /* Number of requests allocated in the subtree of this entity */ |
181 | int allocated; | |
182 | ||
795fe54c FZ |
183 | /* device weight, if non-zero, it overrides the default weight of |
184 | * bfq_group_data */ | |
185 | int dev_weight; | |
ea25da48 PV |
186 | /* weight of the queue */ |
187 | int weight; | |
188 | /* next weight if a change is in progress */ | |
189 | int new_weight; | |
190 | ||
191 | /* original weight, used to implement weight boosting */ | |
192 | int orig_weight; | |
193 | ||
194 | /* parent entity, for hierarchical scheduling */ | |
195 | struct bfq_entity *parent; | |
196 | ||
197 | /* | |
198 | * For non-leaf nodes in the hierarchy, the associated | |
199 | * scheduler queue, %NULL on leaf nodes. | |
200 | */ | |
201 | struct bfq_sched_data *my_sched_data; | |
202 | /* the scheduler queue this entity belongs to */ | |
203 | struct bfq_sched_data *sched_data; | |
204 | ||
205 | /* flag, set to request a weight, ioprio or ioprio_class change */ | |
206 | int prio_changed; | |
ba7aeae5 | 207 | |
1eb20620 | 208 | #ifdef CONFIG_BFQ_GROUP_IOSCHED |
ba7aeae5 PV |
209 | /* flag, set if the entity is counted in groups_with_pending_reqs */ |
210 | bool in_groups_with_pending_reqs; | |
1eb20620 | 211 | #endif |
430a67f9 PV |
212 | |
213 | /* last child queue of entity created (for non-leaf entities) */ | |
214 | struct bfq_queue *last_bfqq_created; | |
ea25da48 PV |
215 | }; |
216 | ||
217 | struct bfq_group; | |
218 | ||
219 | /** | |
220 | * struct bfq_ttime - per process thinktime stats. | |
221 | */ | |
222 | struct bfq_ttime { | |
223 | /* completion time of the last request */ | |
224 | u64 last_end_request; | |
225 | ||
226 | /* total process thinktime */ | |
227 | u64 ttime_total; | |
228 | /* number of thinktime samples */ | |
229 | unsigned long ttime_samples; | |
230 | /* average process thinktime */ | |
231 | u64 ttime_mean; | |
232 | }; | |
233 | ||
234 | /** | |
235 | * struct bfq_queue - leaf schedulable entity. | |
236 | * | |
237 | * A bfq_queue is a leaf request queue; it can be associated with an | |
9778369a PV |
238 | * io_context or more, if it is async or shared between cooperating |
239 | * processes. Besides, it contains I/O requests for only one actuator | |
240 | * (an io_context is associated with a different bfq_queue for each | |
241 | * actuator it generates I/O for). @cgroup holds a reference to the | |
242 | * cgroup, to be sure that it does not disappear while a bfqq still | |
243 | * references it (mostly to avoid races between request issuing and | |
244 | * task migration followed by cgroup destruction). All the fields are | |
245 | * protected by the queue lock of the containing bfqd. | |
ea25da48 PV |
246 | */ |
247 | struct bfq_queue { | |
248 | /* reference counter */ | |
249 | int ref; | |
430a67f9 PV |
250 | /* counter of references from other queues for delayed stable merge */ |
251 | int stable_ref; | |
ea25da48 PV |
252 | /* parent bfq_data */ |
253 | struct bfq_data *bfqd; | |
254 | ||
255 | /* current ioprio and ioprio class */ | |
256 | unsigned short ioprio, ioprio_class; | |
257 | /* next ioprio and ioprio class if a change is in progress */ | |
258 | unsigned short new_ioprio, new_ioprio_class; | |
259 | ||
2341d662 PV |
260 | /* last total-service-time sample, see bfq_update_inject_limit() */ |
261 | u64 last_serv_time_ns; | |
262 | /* limit for request injection */ | |
263 | unsigned int inject_limit; | |
264 | /* last time the inject limit has been decreased, in jiffies */ | |
265 | unsigned long decrease_time_jif; | |
266 | ||
ea25da48 PV |
267 | /* |
268 | * Shared bfq_queue if queue is cooperating with one or more | |
269 | * other queues. | |
270 | */ | |
271 | struct bfq_queue *new_bfqq; | |
272 | /* request-position tree member (see bfq_group's @rq_pos_tree) */ | |
273 | struct rb_node pos_node; | |
274 | /* request-position tree root (see bfq_group's @rq_pos_tree) */ | |
275 | struct rb_root *pos_root; | |
276 | ||
277 | /* sorted list of pending requests */ | |
278 | struct rb_root sort_list; | |
279 | /* if fifo isn't expired, next request to serve */ | |
280 | struct request *next_rq; | |
281 | /* number of sync and async requests queued */ | |
282 | int queued[2]; | |
ea25da48 PV |
283 | /* number of pending metadata requests */ |
284 | int meta_pending; | |
285 | /* fifo list of requests in sort_list */ | |
286 | struct list_head fifo; | |
287 | ||
288 | /* entity representing this queue in the scheduler */ | |
289 | struct bfq_entity entity; | |
290 | ||
2d29c9f8 FM |
291 | /* pointer to the weight counter associated with this entity */ |
292 | struct bfq_weight_counter *weight_counter; | |
293 | ||
ea25da48 PV |
294 | /* maximum budget allowed from the feedback mechanism */ |
295 | int max_budget; | |
296 | /* budget expiration (in jiffies) */ | |
297 | unsigned long budget_timeout; | |
298 | ||
299 | /* number of requests on the dispatch list or inside driver */ | |
300 | int dispatched; | |
301 | ||
302 | /* status flags */ | |
303 | unsigned long flags; | |
304 | ||
305 | /* node for active/idle bfqq list inside parent bfqd */ | |
306 | struct list_head bfqq_list; | |
307 | ||
308 | /* associated @bfq_ttime struct */ | |
309 | struct bfq_ttime ttime; | |
310 | ||
eb2fd80f PV |
311 | /* when bfqq started to do I/O within the last observation window */ |
312 | u64 io_start_time; | |
313 | /* how long bfqq has remained empty during the last observ. window */ | |
314 | u64 tot_idle_time; | |
315 | ||
ea25da48 PV |
316 | /* bit vector: a 1 for each seeky requests in history */ |
317 | u32 seek_history; | |
318 | ||
319 | /* node for the device's burst list */ | |
320 | struct hlist_node burst_list_node; | |
321 | ||
322 | /* position of the last request enqueued */ | |
323 | sector_t last_request_pos; | |
324 | ||
325 | /* Number of consecutive pairs of request completion and | |
326 | * arrival, such that the queue becomes idle after the | |
327 | * completion, but the next request arrives within an idle | |
328 | * time slice; used only if the queue's IO_bound flag has been | |
329 | * cleared. | |
330 | */ | |
331 | unsigned int requests_within_timer; | |
332 | ||
333 | /* pid of the process owning the queue, used for logging purposes */ | |
334 | pid_t pid; | |
335 | ||
336 | /* | |
337 | * Pointer to the bfq_io_cq owning the bfq_queue, set to %NULL | |
338 | * if the queue is shared. | |
339 | */ | |
340 | struct bfq_io_cq *bic; | |
341 | ||
342 | /* current maximum weight-raising time for this queue */ | |
343 | unsigned long wr_cur_max_time; | |
344 | /* | |
345 | * Minimum time instant such that, only if a new request is | |
346 | * enqueued after this time instant in an idle @bfq_queue with | |
347 | * no outstanding requests, then the task associated with the | |
348 | * queue it is deemed as soft real-time (see the comments on | |
349 | * the function bfq_bfqq_softrt_next_start()) | |
350 | */ | |
351 | unsigned long soft_rt_next_start; | |
352 | /* | |
353 | * Start time of the current weight-raising period if | |
354 | * the @bfq-queue is being weight-raised, otherwise | |
355 | * finish time of the last weight-raising period. | |
356 | */ | |
357 | unsigned long last_wr_start_finish; | |
358 | /* factor by which the weight of this queue is multiplied */ | |
359 | unsigned int wr_coeff; | |
360 | /* | |
361 | * Time of the last transition of the @bfq_queue from idle to | |
362 | * backlogged. | |
363 | */ | |
364 | unsigned long last_idle_bklogged; | |
365 | /* | |
366 | * Cumulative service received from the @bfq_queue since the | |
367 | * last transition from idle to backlogged. | |
368 | */ | |
369 | unsigned long service_from_backlogged; | |
8a8747dc PV |
370 | /* |
371 | * Cumulative service received from the @bfq_queue since its | |
372 | * last transition to weight-raised state. | |
373 | */ | |
374 | unsigned long service_from_wr; | |
ea25da48 PV |
375 | |
376 | /* | |
377 | * Value of wr start time when switching to soft rt | |
378 | */ | |
379 | unsigned long wr_start_at_switch_to_srt; | |
380 | ||
381 | unsigned long split_time; /* time of last split */ | |
7b8fa3b9 PV |
382 | |
383 | unsigned long first_IO_time; /* time of first I/O for this queue */ | |
430a67f9 PV |
384 | unsigned long creation_time; /* when this queue is created */ |
385 | ||
13a857a4 PV |
386 | /* |
387 | * Pointer to the waker queue for this queue, i.e., to the | |
388 | * queue Q such that this queue happens to get new I/O right | |
389 | * after some I/O request of Q is completed. For details, see | |
390 | * the comments on the choice of the queue for injection in | |
391 | * bfq_select_queue(). | |
392 | */ | |
393 | struct bfq_queue *waker_bfqq; | |
71217df3 PV |
394 | /* pointer to the curr. tentative waker queue, see bfq_check_waker() */ |
395 | struct bfq_queue *tentative_waker_bfqq; | |
396 | /* number of times the same tentative waker has been detected */ | |
397 | unsigned int num_waker_detections; | |
1f18b700 JK |
398 | /* time when we started considering this waker */ |
399 | u64 waker_detection_started; | |
71217df3 | 400 | |
13a857a4 PV |
401 | /* node for woken_list, see below */ |
402 | struct hlist_node woken_list_node; | |
403 | /* | |
404 | * Head of the list of the woken queues for this queue, i.e., | |
405 | * of the list of the queues for which this queue is a waker | |
406 | * queue. This list is used to reset the waker_bfqq pointer in | |
407 | * the woken queues when this queue exits. | |
408 | */ | |
409 | struct hlist_head woken_list; | |
9778369a PV |
410 | |
411 | /* index of the actuator this queue is associated with */ | |
412 | unsigned int actuator_idx; | |
ea25da48 PV |
413 | }; |
414 | ||
415 | /** | |
416 | * struct bfq_io_cq - per (request_queue, io_context) structure. | |
417 | */ | |
418 | struct bfq_io_cq { | |
419 | /* associated io_cq structure */ | |
420 | struct io_cq icq; /* must be the first member */ | |
9778369a PV |
421 | /* |
422 | * Matrix of associated process queues: first row for async | |
423 | * queues, second row sync queues. Each row contains one | |
424 | * column for each actuator. An I/O request generated by the | |
425 | * process is inserted into the queue pointed by bfqq[i][j] if | |
426 | * the request is to be served by the j-th actuator of the | |
427 | * drive, where i==0 or i==1, depending on whether the request | |
428 | * is async or sync. So there is a distinct queue for each | |
429 | * actuator. | |
430 | */ | |
431 | struct bfq_queue *bfqq[2][BFQ_MAX_ACTUATORS]; | |
ea25da48 PV |
432 | /* per (request_queue, blkcg) ioprio */ |
433 | int ioprio; | |
434 | #ifdef CONFIG_BFQ_GROUP_IOSCHED | |
435 | uint64_t blkcg_serial_nr; /* the current blkcg serial */ | |
436 | #endif | |
437 | /* | |
d5be3fef PV |
438 | * Snapshot of the has_short_time flag before merging; taken |
439 | * to remember its value while the queue is merged, so as to | |
440 | * be able to restore it in case of split. | |
ea25da48 | 441 | */ |
d5be3fef | 442 | bool saved_has_short_ttime; |
ea25da48 PV |
443 | /* |
444 | * Same purpose as the previous two fields for the I/O bound | |
445 | * classification of a queue. | |
446 | */ | |
447 | bool saved_IO_bound; | |
448 | ||
eb2fd80f PV |
449 | u64 saved_io_start_time; |
450 | u64 saved_tot_idle_time; | |
451 | ||
ea25da48 PV |
452 | /* |
453 | * Same purpose as the previous fields for the value of the | |
454 | * field keeping the queue's belonging to a large burst | |
455 | */ | |
456 | bool saved_in_large_burst; | |
457 | /* | |
458 | * True if the queue belonged to a burst list before its merge | |
459 | * with another cooperating queue. | |
460 | */ | |
461 | bool was_in_burst_list; | |
462 | ||
fffca087 FP |
463 | /* |
464 | * Save the weight when a merge occurs, to be able | |
465 | * to restore it in case of split. If the weight is not | |
466 | * correctly resumed when the queue is recycled, | |
467 | * then the weight of the recycled queue could differ | |
468 | * from the weight of the original queue. | |
469 | */ | |
470 | unsigned int saved_weight; | |
471 | ||
ea25da48 PV |
472 | /* |
473 | * Similar to previous fields: save wr information. | |
474 | */ | |
475 | unsigned long saved_wr_coeff; | |
476 | unsigned long saved_last_wr_start_finish; | |
e673914d | 477 | unsigned long saved_service_from_wr; |
ea25da48 PV |
478 | unsigned long saved_wr_start_at_switch_to_srt; |
479 | unsigned int saved_wr_cur_max_time; | |
480 | struct bfq_ttime saved_ttime; | |
5a5436b9 PV |
481 | |
482 | /* Save also injection state */ | |
483 | u64 saved_last_serv_time_ns; | |
484 | unsigned int saved_inject_limit; | |
485 | unsigned long saved_decrease_time_jif; | |
430a67f9 PV |
486 | |
487 | /* candidate queue for a stable merge (due to close creation time) */ | |
488 | struct bfq_queue *stable_merge_bfqq; | |
489 | ||
490 | bool stably_merged; /* non splittable if true */ | |
f9506673 | 491 | unsigned int requests; /* Number of requests this process has in flight */ |
ea25da48 PV |
492 | }; |
493 | ||
ea25da48 PV |
494 | /** |
495 | * struct bfq_data - per-device data structure. | |
496 | * | |
497 | * All the fields are protected by @lock. | |
498 | */ | |
499 | struct bfq_data { | |
500 | /* device request queue */ | |
501 | struct request_queue *queue; | |
502 | /* dispatch queue */ | |
503 | struct list_head dispatch; | |
504 | ||
505 | /* root bfq_group for the device */ | |
506 | struct bfq_group *root_group; | |
507 | ||
508 | /* | |
509 | * rbtree of weight counters of @bfq_queues, sorted by | |
510 | * weight. Used to keep track of whether all @bfq_queues have | |
511 | * the same weight. The tree contains one counter for each | |
512 | * distinct weight associated to some active and not | |
513 | * weight-raised @bfq_queue (see the comments to the functions | |
514 | * bfq_weights_tree_[add|remove] for further details). | |
515 | */ | |
fb53ac6c | 516 | struct rb_root_cached queue_weights_tree; |
ba7aeae5 | 517 | |
1eb20620 | 518 | #ifdef CONFIG_BFQ_GROUP_IOSCHED |
ea25da48 | 519 | /* |
71f8ca77 | 520 | * Number of groups with at least one process that |
ba7aeae5 PV |
521 | * has at least one request waiting for completion. Note that |
522 | * this accounts for also requests already dispatched, but not | |
523 | * yet completed. Therefore this number of groups may differ | |
524 | * (be larger) than the number of active groups, as a group is | |
525 | * considered active only if its corresponding entity has | |
71f8ca77 | 526 | * queues with at least one request queued. This |
ba7aeae5 PV |
527 | * number is used to decide whether a scenario is symmetric. |
528 | * For a detailed explanation see comments on the computation | |
529 | * of the variable asymmetric_scenario in the function | |
530 | * bfq_better_to_idle(). | |
531 | * | |
532 | * However, it is hard to compute this number exactly, for | |
71f8ca77 YK |
533 | * groups with multiple processes. Consider a group |
534 | * that is inactive, i.e., that has no process with | |
ba7aeae5 PV |
535 | * pending I/O inside BFQ queues. Then suppose that |
536 | * num_groups_with_pending_reqs is still accounting for this | |
71f8ca77 | 537 | * group, because the group has processes with some |
ba7aeae5 PV |
538 | * I/O request still in flight. num_groups_with_pending_reqs |
539 | * should be decremented when the in-flight request of the | |
71f8ca77 | 540 | * last process is finally completed (assuming that |
ba7aeae5 PV |
541 | * nothing else has changed for the group in the meantime, in |
542 | * terms of composition of the group and active/inactive state of child | |
543 | * groups and processes). To accomplish this, an additional | |
544 | * pending-request counter must be added to entities, and must | |
545 | * be updated correctly. To avoid this additional field and operations, | |
546 | * we resort to the following tradeoff between simplicity and | |
547 | * accuracy: for an inactive group that is still counted in | |
548 | * num_groups_with_pending_reqs, we decrement | |
71f8ca77 | 549 | * num_groups_with_pending_reqs when the first |
ba7aeae5 PV |
550 | * process of the group remains with no request waiting for |
551 | * completion. | |
552 | * | |
553 | * Even this simpler decrement strategy requires a little | |
554 | * carefulness: to avoid multiple decrements, we flag a group, | |
555 | * more precisely an entity representing a group, as still | |
556 | * counted in num_groups_with_pending_reqs when it becomes | |
71f8ca77 | 557 | * inactive. Then, when the first queue of the |
ba7aeae5 PV |
558 | * entity remains with no request waiting for completion, |
559 | * num_groups_with_pending_reqs is decremented, and this flag | |
560 | * is reset. After this flag is reset for the entity, | |
561 | * num_groups_with_pending_reqs won't be decremented any | |
71f8ca77 | 562 | * longer in case a new queue of the entity remains |
ba7aeae5 | 563 | * with no request waiting for completion. |
ea25da48 | 564 | */ |
ba7aeae5 | 565 | unsigned int num_groups_with_pending_reqs; |
1eb20620 | 566 | #endif |
ea25da48 PV |
567 | |
568 | /* | |
73d58118 PV |
569 | * Per-class (RT, BE, IDLE) number of bfq_queues containing |
570 | * requests (including the queue in service, even if it is | |
571 | * idling). | |
ea25da48 | 572 | */ |
73d58118 | 573 | unsigned int busy_queues[3]; |
ea25da48 PV |
574 | /* number of weight-raised busy @bfq_queues */ |
575 | int wr_busy_queues; | |
576 | /* number of queued requests */ | |
577 | int queued; | |
578 | /* number of requests dispatched and waiting for completion */ | |
579 | int rq_in_driver; | |
580 | ||
8cacc5ab PV |
581 | /* true if the device is non rotational and performs queueing */ |
582 | bool nonrot_with_queueing; | |
583 | ||
ea25da48 PV |
584 | /* |
585 | * Maximum number of requests in driver in the last | |
586 | * @hw_tag_samples completed requests. | |
587 | */ | |
588 | int max_rq_in_driver; | |
589 | /* number of samples used to calculate hw_tag */ | |
590 | int hw_tag_samples; | |
591 | /* flag set to one if the driver is showing a queueing behavior */ | |
592 | int hw_tag; | |
593 | ||
594 | /* number of budgets assigned */ | |
595 | int budgets_assigned; | |
596 | ||
597 | /* | |
598 | * Timer set when idling (waiting) for the next request from | |
599 | * the queue in service. | |
600 | */ | |
601 | struct hrtimer idle_slice_timer; | |
602 | ||
603 | /* bfq_queue in service */ | |
604 | struct bfq_queue *in_service_queue; | |
605 | ||
606 | /* on-disk position of the last served request */ | |
607 | sector_t last_position; | |
608 | ||
058fdecc PV |
609 | /* position of the last served request for the in-service queue */ |
610 | sector_t in_serv_last_pos; | |
611 | ||
ea25da48 PV |
612 | /* time of last request completion (ns) */ |
613 | u64 last_completion; | |
614 | ||
13a857a4 PV |
615 | /* bfqq owning the last completed rq */ |
616 | struct bfq_queue *last_completed_rq_bfqq; | |
617 | ||
430a67f9 PV |
618 | /* last bfqq created, among those in the root group */ |
619 | struct bfq_queue *last_bfqq_created; | |
620 | ||
2341d662 PV |
621 | /* time of last transition from empty to non-empty (ns) */ |
622 | u64 last_empty_occupied_ns; | |
623 | ||
624 | /* | |
625 | * Flag set to activate the sampling of the total service time | |
626 | * of a just-arrived first I/O request (see | |
627 | * bfq_update_inject_limit()). This will cause the setting of | |
628 | * waited_rq when the request is finally dispatched. | |
629 | */ | |
630 | bool wait_dispatch; | |
631 | /* | |
632 | * If set, then bfq_update_inject_limit() is invoked when | |
633 | * waited_rq is eventually completed. | |
634 | */ | |
635 | struct request *waited_rq; | |
636 | /* | |
637 | * True if some request has been injected during the last service hole. | |
638 | */ | |
639 | bool rqs_injected; | |
640 | ||
ea25da48 PV |
641 | /* time of first rq dispatch in current observation interval (ns) */ |
642 | u64 first_dispatch; | |
643 | /* time of last rq dispatch in current observation interval (ns) */ | |
644 | u64 last_dispatch; | |
645 | ||
646 | /* beginning of the last budget */ | |
647 | ktime_t last_budget_start; | |
648 | /* beginning of the last idle slice */ | |
649 | ktime_t last_idling_start; | |
2341d662 | 650 | unsigned long last_idling_start_jiffies; |
ea25da48 PV |
651 | |
652 | /* number of samples in current observation interval */ | |
653 | int peak_rate_samples; | |
654 | /* num of samples of seq dispatches in current observation interval */ | |
655 | u32 sequential_samples; | |
656 | /* total num of sectors transferred in current observation interval */ | |
657 | u64 tot_sectors_dispatched; | |
658 | /* max rq size seen during current observation interval (sectors) */ | |
659 | u32 last_rq_max_size; | |
660 | /* time elapsed from first dispatch in current observ. interval (us) */ | |
661 | u64 delta_from_first; | |
662 | /* | |
663 | * Current estimate of the device peak rate, measured in | |
bc56e2ca | 664 | * [(sectors/usec) / 2^BFQ_RATE_SHIFT]. The left-shift by |
ea25da48 PV |
665 | * BFQ_RATE_SHIFT is performed to increase precision in |
666 | * fixed-point calculations. | |
667 | */ | |
668 | u32 peak_rate; | |
669 | ||
670 | /* maximum budget allotted to a bfq_queue before rescheduling */ | |
671 | int bfq_max_budget; | |
672 | ||
673 | /* list of all the bfq_queues active on the device */ | |
674 | struct list_head active_list; | |
675 | /* list of all the bfq_queues idle on the device */ | |
676 | struct list_head idle_list; | |
677 | ||
678 | /* | |
679 | * Timeout for async/sync requests; when it fires, requests | |
680 | * are served in fifo order. | |
681 | */ | |
682 | u64 bfq_fifo_expire[2]; | |
683 | /* weight of backward seeks wrt forward ones */ | |
684 | unsigned int bfq_back_penalty; | |
685 | /* maximum allowed backward seek */ | |
686 | unsigned int bfq_back_max; | |
687 | /* maximum idling time */ | |
688 | u32 bfq_slice_idle; | |
689 | ||
690 | /* user-configured max budget value (0 for auto-tuning) */ | |
691 | int bfq_user_max_budget; | |
692 | /* | |
693 | * Timeout for bfq_queues to consume their budget; used to | |
694 | * prevent seeky queues from imposing long latencies to | |
695 | * sequential or quasi-sequential ones (this also implies that | |
696 | * seeky queues cannot receive guarantees in the service | |
697 | * domain; after a timeout they are charged for the time they | |
698 | * have been in service, to preserve fairness among them, but | |
699 | * without service-domain guarantees). | |
700 | */ | |
701 | unsigned int bfq_timeout; | |
702 | ||
ea25da48 PV |
703 | /* |
704 | * Force device idling whenever needed to provide accurate | |
705 | * service guarantees, without caring about throughput | |
706 | * issues. CAVEAT: this may even increase latencies, in case | |
707 | * of useless idling for processes that did stop doing I/O. | |
708 | */ | |
709 | bool strict_guarantees; | |
710 | ||
711 | /* | |
712 | * Last time at which a queue entered the current burst of | |
713 | * queues being activated shortly after each other; for more | |
714 | * details about this and the following parameters related to | |
715 | * a burst of activations, see the comments on the function | |
716 | * bfq_handle_burst. | |
717 | */ | |
718 | unsigned long last_ins_in_burst; | |
719 | /* | |
720 | * Reference time interval used to decide whether a queue has | |
721 | * been activated shortly after @last_ins_in_burst. | |
722 | */ | |
723 | unsigned long bfq_burst_interval; | |
724 | /* number of queues in the current burst of queue activations */ | |
725 | int burst_size; | |
726 | ||
727 | /* common parent entity for the queues in the burst */ | |
728 | struct bfq_entity *burst_parent_entity; | |
729 | /* Maximum burst size above which the current queue-activation | |
730 | * burst is deemed as 'large'. | |
731 | */ | |
732 | unsigned long bfq_large_burst_thresh; | |
733 | /* true if a large queue-activation burst is in progress */ | |
734 | bool large_burst; | |
735 | /* | |
736 | * Head of the burst list (as for the above fields, more | |
737 | * details in the comments on the function bfq_handle_burst). | |
738 | */ | |
739 | struct hlist_head burst_list; | |
740 | ||
741 | /* if set to true, low-latency heuristics are enabled */ | |
742 | bool low_latency; | |
743 | /* | |
744 | * Maximum factor by which the weight of a weight-raised queue | |
745 | * is multiplied. | |
746 | */ | |
747 | unsigned int bfq_wr_coeff; | |
748 | /* maximum duration of a weight-raising period (jiffies) */ | |
749 | unsigned int bfq_wr_max_time; | |
750 | ||
751 | /* Maximum weight-raising duration for soft real-time processes */ | |
752 | unsigned int bfq_wr_rt_max_time; | |
753 | /* | |
754 | * Minimum idle period after which weight-raising may be | |
755 | * reactivated for a queue (in jiffies). | |
756 | */ | |
757 | unsigned int bfq_wr_min_idle_time; | |
758 | /* | |
759 | * Minimum period between request arrivals after which | |
760 | * weight-raising may be reactivated for an already busy async | |
761 | * queue (in jiffies). | |
762 | */ | |
763 | unsigned long bfq_wr_min_inter_arr_async; | |
764 | ||
765 | /* Max service-rate for a soft real-time queue, in sectors/sec */ | |
766 | unsigned int bfq_wr_max_softrt_rate; | |
767 | /* | |
e24f1c24 PV |
768 | * Cached value of the product ref_rate*ref_wr_duration, used |
769 | * for computing the maximum duration of weight raising | |
770 | * automatically. | |
ea25da48 | 771 | */ |
e24f1c24 | 772 | u64 rate_dur_prod; |
ea25da48 PV |
773 | |
774 | /* fallback dummy bfqq for extreme OOM conditions */ | |
775 | struct bfq_queue oom_bfqq; | |
776 | ||
777 | spinlock_t lock; | |
778 | ||
779 | /* | |
780 | * bic associated with the task issuing current bio for | |
781 | * merging. This and the next field are used as a support to | |
782 | * be able to perform the bic lookup, needed by bio-merge | |
783 | * functions, before the scheduler lock is taken, and thus | |
784 | * avoid taking the request-queue lock while the scheduler | |
785 | * lock is being held. | |
786 | */ | |
787 | struct bfq_io_cq *bio_bic; | |
788 | /* bfqq associated with the task issuing current bio for merging */ | |
789 | struct bfq_queue *bio_bfqq; | |
a52a69ea | 790 | |
a52a69ea PV |
791 | /* |
792 | * Depth limits used in bfq_limit_depth (see comments on the | |
793 | * function) | |
794 | */ | |
795 | unsigned int word_depths[2][2]; | |
44dfa279 | 796 | unsigned int full_depth_shift; |
9778369a PV |
797 | |
798 | /* | |
799 | * Number of independent actuators. This is equal to 1 in | |
800 | * case of single-actuator drives. | |
801 | */ | |
802 | unsigned int num_actuators; | |
803 | ||
ea25da48 PV |
804 | }; |
805 | ||
806 | enum bfqq_state_flags { | |
807 | BFQQF_just_created = 0, /* queue just allocated */ | |
808 | BFQQF_busy, /* has requests or is in service */ | |
809 | BFQQF_wait_request, /* waiting for a request */ | |
810 | BFQQF_non_blocking_wait_rq, /* | |
811 | * waiting for a request | |
812 | * without idling the device | |
813 | */ | |
814 | BFQQF_fifo_expire, /* FIFO checked in this slice */ | |
d5be3fef | 815 | BFQQF_has_short_ttime, /* queue has a short think time */ |
ea25da48 PV |
816 | BFQQF_sync, /* synchronous queue */ |
817 | BFQQF_IO_bound, /* | |
818 | * bfqq has timed-out at least once | |
819 | * having consumed at most 2/10 of | |
820 | * its budget | |
821 | */ | |
822 | BFQQF_in_large_burst, /* | |
823 | * bfqq activated in a large burst, | |
824 | * see comments to bfq_handle_burst. | |
825 | */ | |
826 | BFQQF_softrt_update, /* | |
827 | * may need softrt-next-start | |
828 | * update | |
829 | */ | |
830 | BFQQF_coop, /* bfqq is shared */ | |
13a857a4 | 831 | BFQQF_split_coop, /* shared bfqq will be split */ |
ea25da48 PV |
832 | }; |
833 | ||
834 | #define BFQ_BFQQ_FNS(name) \ | |
835 | void bfq_mark_bfqq_##name(struct bfq_queue *bfqq); \ | |
836 | void bfq_clear_bfqq_##name(struct bfq_queue *bfqq); \ | |
837 | int bfq_bfqq_##name(const struct bfq_queue *bfqq); | |
838 | ||
839 | BFQ_BFQQ_FNS(just_created); | |
840 | BFQ_BFQQ_FNS(busy); | |
841 | BFQ_BFQQ_FNS(wait_request); | |
842 | BFQ_BFQQ_FNS(non_blocking_wait_rq); | |
843 | BFQ_BFQQ_FNS(fifo_expire); | |
d5be3fef | 844 | BFQ_BFQQ_FNS(has_short_ttime); |
ea25da48 PV |
845 | BFQ_BFQQ_FNS(sync); |
846 | BFQ_BFQQ_FNS(IO_bound); | |
847 | BFQ_BFQQ_FNS(in_large_burst); | |
848 | BFQ_BFQQ_FNS(coop); | |
849 | BFQ_BFQQ_FNS(split_coop); | |
850 | BFQ_BFQQ_FNS(softrt_update); | |
851 | #undef BFQ_BFQQ_FNS | |
852 | ||
853 | /* Expiration reasons. */ | |
854 | enum bfqq_expiration { | |
855 | BFQQE_TOO_IDLE = 0, /* | |
856 | * queue has been idling for | |
857 | * too long | |
858 | */ | |
859 | BFQQE_BUDGET_TIMEOUT, /* budget took too long to be used */ | |
860 | BFQQE_BUDGET_EXHAUSTED, /* budget consumed */ | |
861 | BFQQE_NO_MORE_REQUESTS, /* the queue has no more requests */ | |
862 | BFQQE_PREEMPTED /* preemption in progress */ | |
863 | }; | |
864 | ||
c0ce79dc CH |
865 | struct bfq_stat { |
866 | struct percpu_counter cpu_cnt; | |
867 | atomic64_t aux_cnt; | |
868 | }; | |
869 | ||
ea25da48 | 870 | struct bfqg_stats { |
fd41e603 TH |
871 | /* basic stats */ |
872 | struct blkg_rwstat bytes; | |
873 | struct blkg_rwstat ios; | |
8060c47b | 874 | #ifdef CONFIG_BFQ_CGROUP_DEBUG |
ea25da48 PV |
875 | /* number of ios merged */ |
876 | struct blkg_rwstat merged; | |
877 | /* total time spent on device in ns, may not be accurate w/ queueing */ | |
878 | struct blkg_rwstat service_time; | |
879 | /* total time spent waiting in scheduler queue in ns */ | |
880 | struct blkg_rwstat wait_time; | |
881 | /* number of IOs queued up */ | |
882 | struct blkg_rwstat queued; | |
883 | /* total disk time and nr sectors dispatched by this group */ | |
c0ce79dc | 884 | struct bfq_stat time; |
ea25da48 | 885 | /* sum of number of ios queued across all samples */ |
c0ce79dc | 886 | struct bfq_stat avg_queue_size_sum; |
ea25da48 | 887 | /* count of samples taken for average */ |
c0ce79dc | 888 | struct bfq_stat avg_queue_size_samples; |
ea25da48 | 889 | /* how many times this group has been removed from service tree */ |
c0ce79dc | 890 | struct bfq_stat dequeue; |
ea25da48 | 891 | /* total time spent waiting for it to be assigned a timeslice. */ |
c0ce79dc | 892 | struct bfq_stat group_wait_time; |
ea25da48 | 893 | /* time spent idling for this blkcg_gq */ |
c0ce79dc | 894 | struct bfq_stat idle_time; |
ea25da48 | 895 | /* total time with empty current active q with other requests queued */ |
c0ce79dc | 896 | struct bfq_stat empty_time; |
ea25da48 | 897 | /* fields after this shouldn't be cleared on stat reset */ |
84c7afce OS |
898 | u64 start_group_wait_time; |
899 | u64 start_idle_time; | |
900 | u64 start_empty_time; | |
ea25da48 | 901 | uint16_t flags; |
8060c47b | 902 | #endif /* CONFIG_BFQ_CGROUP_DEBUG */ |
ea25da48 PV |
903 | }; |
904 | ||
905 | #ifdef CONFIG_BFQ_GROUP_IOSCHED | |
906 | ||
907 | /* | |
908 | * struct bfq_group_data - per-blkcg storage for the blkio subsystem. | |
909 | * | |
910 | * @ps: @blkcg_policy_storage that this structure inherits | |
911 | * @weight: weight of the bfq_group | |
912 | */ | |
913 | struct bfq_group_data { | |
914 | /* must be the first member */ | |
915 | struct blkcg_policy_data pd; | |
916 | ||
917 | unsigned int weight; | |
918 | }; | |
919 | ||
920 | /** | |
921 | * struct bfq_group - per (device, cgroup) data structure. | |
922 | * @entity: schedulable entity to insert into the parent group sched_data. | |
923 | * @sched_data: own sched_data, to contain child entities (they may be | |
924 | * both bfq_queues and bfq_groups). | |
925 | * @bfqd: the bfq_data for the device this group acts upon. | |
926 | * @async_bfqq: array of async queues for all the tasks belonging to | |
927 | * the group, one queue per ioprio value per ioprio_class, | |
928 | * except for the idle class that has only one queue. | |
929 | * @async_idle_bfqq: async queue for the idle class (ioprio is ignored). | |
930 | * @my_entity: pointer to @entity, %NULL for the toplevel group; used | |
931 | * to avoid too many special cases during group creation/ | |
932 | * migration. | |
933 | * @stats: stats for this bfqg. | |
934 | * @active_entities: number of active entities belonging to the group; | |
935 | * unused for the root group. Used to know whether there | |
936 | * are groups with more than one active @bfq_entity | |
937 | * (see the comments to the function | |
938 | * bfq_bfqq_may_idle()). | |
939 | * @rq_pos_tree: rbtree sorted by next_request position, used when | |
940 | * determining if two or more queues have interleaving | |
941 | * requests (see bfq_find_close_cooperator()). | |
942 | * | |
943 | * Each (device, cgroup) pair has its own bfq_group, i.e., for each cgroup | |
944 | * there is a set of bfq_groups, each one collecting the lower-level | |
945 | * entities belonging to the group that are acting on the same device. | |
946 | * | |
947 | * Locking works as follows: | |
948 | * o @bfqd is protected by the queue lock, RCU is used to access it | |
949 | * from the readers. | |
950 | * o All the other fields are protected by the @bfqd queue lock. | |
951 | */ | |
952 | struct bfq_group { | |
953 | /* must be the first member */ | |
954 | struct blkg_policy_data pd; | |
955 | ||
8f9bebc3 PV |
956 | /* cached path for this blkg (see comments in bfq_bic_update_cgroup) */ |
957 | char blkg_path[128]; | |
958 | ||
959 | /* reference counter (see comments in bfq_bic_update_cgroup) */ | |
216f7647 | 960 | refcount_t ref; |
09f87186 JK |
961 | /* Is bfq_group still online? */ |
962 | bool online; | |
8f9bebc3 | 963 | |
ea25da48 PV |
964 | struct bfq_entity entity; |
965 | struct bfq_sched_data sched_data; | |
966 | ||
aa625117 | 967 | struct bfq_data *bfqd; |
ea25da48 | 968 | |
202bc942 | 969 | struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS]; |
ea25da48 PV |
970 | struct bfq_queue *async_idle_bfqq; |
971 | ||
972 | struct bfq_entity *my_entity; | |
973 | ||
974 | int active_entities; | |
60a6e10c | 975 | int num_queues_with_pending_reqs; |
ea25da48 PV |
976 | |
977 | struct rb_root rq_pos_tree; | |
978 | ||
979 | struct bfqg_stats stats; | |
980 | }; | |
981 | ||
982 | #else | |
983 | struct bfq_group { | |
4d8340d0 | 984 | struct bfq_entity entity; |
ea25da48 PV |
985 | struct bfq_sched_data sched_data; |
986 | ||
202bc942 | 987 | struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS]; |
ea25da48 PV |
988 | struct bfq_queue *async_idle_bfqq; |
989 | ||
990 | struct rb_root rq_pos_tree; | |
991 | }; | |
992 | #endif | |
993 | ||
ea25da48 PV |
994 | /* --------------- main algorithm interface ----------------- */ |
995 | ||
996 | #define BFQ_SERVICE_TREE_INIT ((struct bfq_service_tree) \ | |
997 | { RB_ROOT, RB_ROOT, NULL, NULL, 0, 0 }) | |
998 | ||
999 | extern const int bfq_timeout; | |
1000 | ||
9778369a PV |
1001 | struct bfq_queue *bic_to_bfqq(struct bfq_io_cq *bic, bool is_sync, |
1002 | unsigned int actuator_idx); | |
1003 | void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync, | |
1004 | unsigned int actuator_idx); | |
ea25da48 | 1005 | struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic); |
ea25da48 | 1006 | void bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq); |
afdba146 | 1007 | void bfq_weights_tree_add(struct bfq_queue *bfqq); |
afdba146 | 1008 | void bfq_weights_tree_remove(struct bfq_queue *bfqq); |
ea25da48 PV |
1009 | void bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, |
1010 | bool compensate, enum bfqq_expiration reason); | |
1011 | void bfq_put_queue(struct bfq_queue *bfqq); | |
3bc5e683 | 1012 | void bfq_put_cooperator(struct bfq_queue *bfqq); |
ea25da48 | 1013 | void bfq_end_wr_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg); |
c8997736 | 1014 | void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq); |
ea25da48 PV |
1015 | void bfq_schedule_dispatch(struct bfq_data *bfqd); |
1016 | void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg); | |
1017 | ||
1018 | /* ------------ end of main algorithm interface -------------- */ | |
1019 | ||
1020 | /* ---------------- cgroups-support interface ---------------- */ | |
1021 | ||
fd41e603 | 1022 | void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq); |
dc469ba2 BVA |
1023 | void bfqg_stats_update_io_remove(struct bfq_group *bfqg, blk_opf_t opf); |
1024 | void bfqg_stats_update_io_merged(struct bfq_group *bfqg, blk_opf_t opf); | |
84c7afce | 1025 | void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns, |
dc469ba2 | 1026 | u64 io_start_time_ns, blk_opf_t opf); |
ea25da48 | 1027 | void bfqg_stats_update_dequeue(struct bfq_group *bfqg); |
ea25da48 | 1028 | void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg); |
ea25da48 PV |
1029 | void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, |
1030 | struct bfq_group *bfqg); | |
1031 | ||
c2090eab YK |
1032 | #ifdef CONFIG_BFQ_CGROUP_DEBUG |
1033 | void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq, | |
1034 | blk_opf_t opf); | |
1035 | void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg); | |
1036 | void bfqg_stats_update_idle_time(struct bfq_group *bfqg); | |
1037 | void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg); | |
1038 | #endif | |
1039 | ||
ea25da48 PV |
1040 | void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg); |
1041 | void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio); | |
1042 | void bfq_end_wr_async(struct bfq_data *bfqd); | |
4e54a249 | 1043 | struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio); |
ea25da48 PV |
1044 | struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg); |
1045 | struct bfq_group *bfqq_group(struct bfq_queue *bfqq); | |
1046 | struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node); | |
8f9bebc3 | 1047 | void bfqg_and_blkg_put(struct bfq_group *bfqg); |
ea25da48 PV |
1048 | |
1049 | #ifdef CONFIG_BFQ_GROUP_IOSCHED | |
659b3394 JA |
1050 | extern struct cftype bfq_blkcg_legacy_files[]; |
1051 | extern struct cftype bfq_blkg_files[]; | |
ea25da48 PV |
1052 | extern struct blkcg_policy blkcg_policy_bfq; |
1053 | #endif | |
1054 | ||
1055 | /* ------------- end of cgroups-support interface ------------- */ | |
1056 | ||
1057 | /* - interface of the internal hierarchical B-WF2Q+ scheduler - */ | |
1058 | ||
1059 | #ifdef CONFIG_BFQ_GROUP_IOSCHED | |
1060 | /* both next loops stop at one of the child entities of the root group */ | |
1061 | #define for_each_entity(entity) \ | |
1062 | for (; entity ; entity = entity->parent) | |
1063 | ||
1064 | /* | |
1065 | * For each iteration, compute parent in advance, so as to be safe if | |
1066 | * entity is deallocated during the iteration. Such a deallocation may | |
1067 | * happen as a consequence of a bfq_put_queue that frees the bfq_queue | |
1068 | * containing entity. | |
1069 | */ | |
1070 | #define for_each_entity_safe(entity, parent) \ | |
1071 | for (; entity && ({ parent = entity->parent; 1; }); entity = parent) | |
1072 | ||
1073 | #else /* CONFIG_BFQ_GROUP_IOSCHED */ | |
1074 | /* | |
1075 | * Next two macros are fake loops when cgroups support is not | |
1076 | * enabled. I fact, in such a case, there is only one level to go up | |
1077 | * (to reach the root group). | |
1078 | */ | |
1079 | #define for_each_entity(entity) \ | |
1080 | for (; entity ; entity = NULL) | |
1081 | ||
1082 | #define for_each_entity_safe(entity, parent) \ | |
1083 | for (parent = NULL; entity ; entity = parent) | |
1084 | #endif /* CONFIG_BFQ_GROUP_IOSCHED */ | |
1085 | ||
ea25da48 | 1086 | struct bfq_queue *bfq_entity_to_bfqq(struct bfq_entity *entity); |
73d58118 | 1087 | unsigned int bfq_tot_busy_queues(struct bfq_data *bfqd); |
ea25da48 PV |
1088 | struct bfq_service_tree *bfq_entity_service_tree(struct bfq_entity *entity); |
1089 | struct bfq_entity *bfq_entity_of(struct rb_node *node); | |
1090 | unsigned short bfq_ioprio_to_weight(int ioprio); | |
1091 | void bfq_put_idle_entity(struct bfq_service_tree *st, | |
1092 | struct bfq_entity *entity); | |
1093 | struct bfq_service_tree * | |
1094 | __bfq_entity_update_weight_prio(struct bfq_service_tree *old_st, | |
431b17f9 PV |
1095 | struct bfq_entity *entity, |
1096 | bool update_class_too); | |
ea25da48 PV |
1097 | void bfq_bfqq_served(struct bfq_queue *bfqq, int served); |
1098 | void bfq_bfqq_charge_time(struct bfq_data *bfqd, struct bfq_queue *bfqq, | |
1099 | unsigned long time_ms); | |
1100 | bool __bfq_deactivate_entity(struct bfq_entity *entity, | |
1101 | bool ins_into_idle_tree); | |
1102 | bool next_queue_may_preempt(struct bfq_data *bfqd); | |
1103 | struct bfq_queue *bfq_get_next_queue(struct bfq_data *bfqd); | |
eed47d19 | 1104 | bool __bfq_bfqd_reset_in_service(struct bfq_data *bfqd); |
ea25da48 PV |
1105 | void bfq_deactivate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, |
1106 | bool ins_into_idle_tree, bool expiration); | |
1107 | void bfq_activate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq); | |
80294c3b PV |
1108 | void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, |
1109 | bool expiration); | |
d322f355 YK |
1110 | void bfq_del_bfqq_busy(struct bfq_queue *bfqq, bool expiration); |
1111 | void bfq_add_bfqq_busy(struct bfq_queue *bfqq); | |
3d89bd12 YK |
1112 | void bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq); |
1113 | void bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq); | |
ea25da48 PV |
1114 | |
1115 | /* --------------- end of interface of B-WF2Q+ ---------------- */ | |
1116 | ||
1117 | /* Logging facilities. */ | |
582f04e1 | 1118 | static inline void bfq_bfqq_name(struct bfq_queue *bfqq, char *str, int len) |
1e66413c | 1119 | { |
582f04e1 JK |
1120 | char type = bfq_bfqq_sync(bfqq) ? 'S' : 'A'; |
1121 | ||
1122 | if (bfqq->pid != -1) | |
1123 | snprintf(str, len, "bfq%d%c", bfqq->pid, type); | |
1e66413c | 1124 | else |
582f04e1 | 1125 | snprintf(str, len, "bfqSHARED-%c", type); |
1e66413c FP |
1126 | } |
1127 | ||
ea25da48 PV |
1128 | #ifdef CONFIG_BFQ_GROUP_IOSCHED |
1129 | struct bfq_group *bfqq_group(struct bfq_queue *bfqq); | |
1130 | ||
1131 | #define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do { \ | |
582f04e1 | 1132 | char pid_str[MAX_BFQQ_NAME_LENGTH]; \ |
40d47c15 DM |
1133 | if (likely(!blk_trace_note_message_enabled((bfqd)->queue))) \ |
1134 | break; \ | |
582f04e1 | 1135 | bfq_bfqq_name((bfqq), pid_str, MAX_BFQQ_NAME_LENGTH); \ |
35fe6d76 | 1136 | blk_add_cgroup_trace_msg((bfqd)->queue, \ |
f4a6a61c | 1137 | &bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css, \ |
582f04e1 | 1138 | "%s " fmt, pid_str, ##args); \ |
ea25da48 PV |
1139 | } while (0) |
1140 | ||
35fe6d76 SL |
1141 | #define bfq_log_bfqg(bfqd, bfqg, fmt, args...) do { \ |
1142 | blk_add_cgroup_trace_msg((bfqd)->queue, \ | |
f4a6a61c | 1143 | &bfqg_to_blkg(bfqg)->blkcg->css, fmt, ##args); \ |
35fe6d76 | 1144 | } while (0) |
ea25da48 PV |
1145 | |
1146 | #else /* CONFIG_BFQ_GROUP_IOSCHED */ | |
1147 | ||
1e66413c | 1148 | #define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do { \ |
582f04e1 | 1149 | char pid_str[MAX_BFQQ_NAME_LENGTH]; \ |
40d47c15 DM |
1150 | if (likely(!blk_trace_note_message_enabled((bfqd)->queue))) \ |
1151 | break; \ | |
582f04e1 JK |
1152 | bfq_bfqq_name((bfqq), pid_str, MAX_BFQQ_NAME_LENGTH); \ |
1153 | blk_add_trace_msg((bfqd)->queue, "%s " fmt, pid_str, ##args); \ | |
1e66413c | 1154 | } while (0) |
ea25da48 PV |
1155 | #define bfq_log_bfqg(bfqd, bfqg, fmt, args...) do {} while (0) |
1156 | ||
1157 | #endif /* CONFIG_BFQ_GROUP_IOSCHED */ | |
1158 | ||
1159 | #define bfq_log(bfqd, fmt, args...) \ | |
1160 | blk_add_trace_msg((bfqd)->queue, "bfq " fmt, ##args) | |
1161 | ||
1162 | #endif /* _BFQ_H */ |