bfq-iosched.h 40 KB

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