bfq-iosched.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. /*
  369. * Same purpose as the previous fields for the values of the
  370. * field keeping the queue's belonging to a large burst
  371. */
  372. bool saved_in_large_burst;
  373. /*
  374. * True if the queue belonged to a burst list before its merge
  375. * with another cooperating queue.
  376. */
  377. bool was_in_burst_list;
  378. /*
  379. * Save the weight when a merge occurs, to be able
  380. * to restore it in case of split. If the weight is not
  381. * correctly resumed when the queue is recycled,
  382. * then the weight of the recycled queue could differ
  383. * from the weight of the original queue.
  384. */
  385. unsigned int saved_weight;
  386. u64 saved_io_start_time;
  387. u64 saved_tot_idle_time;
  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. struct bfq_ttime saved_ttime;
  396. unsigned int saved_wr_cur_max_time;
  397. /* Save also injection state */
  398. unsigned int saved_inject_limit;
  399. unsigned long saved_decrease_time_jif;
  400. u64 saved_last_serv_time_ns;
  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 async_depths[2][2];
  712. /*
  713. * Number of independent actuators. This is equal to 1 in
  714. * case of single-actuator drives.
  715. */
  716. unsigned int num_actuators;
  717. /*
  718. * Disk independent access ranges for each actuator
  719. * in this device.
  720. */
  721. sector_t sector[BFQ_MAX_ACTUATORS];
  722. sector_t nr_sectors[BFQ_MAX_ACTUATORS];
  723. struct blk_independent_access_range ia_ranges[BFQ_MAX_ACTUATORS];
  724. /*
  725. * If the number of I/O requests queued in the device for a
  726. * given actuator is below next threshold, then the actuator
  727. * is deemed as underutilized. If this condition is found to
  728. * hold for some actuator upon a dispatch, but (i) the
  729. * in-service queue does not contain I/O for that actuator,
  730. * while (ii) some other queue does contain I/O for that
  731. * actuator, then the head I/O request of the latter queue is
  732. * returned (injected), instead of the head request of the
  733. * currently in-service queue.
  734. *
  735. * We set the threshold, empirically, to the minimum possible
  736. * value for which an actuator is fully utilized, or close to
  737. * be fully utilized. By doing so, injected I/O 'steals' as
  738. * few drive-queue slots as possibile to the in-service
  739. * queue. This reduces as much as possible the probability
  740. * that the service of I/O from the in-service bfq_queue gets
  741. * delayed because of slot exhaustion, i.e., because all the
  742. * slots of the drive queue are filled with I/O injected from
  743. * other queues (NCQ provides for 32 slots).
  744. */
  745. unsigned int actuator_load_threshold;
  746. };
  747. enum bfqq_state_flags {
  748. BFQQF_just_created = 0, /* queue just allocated */
  749. BFQQF_busy, /* has requests or is in service */
  750. BFQQF_wait_request, /* waiting for a request */
  751. BFQQF_non_blocking_wait_rq, /*
  752. * waiting for a request
  753. * without idling the device
  754. */
  755. BFQQF_fifo_expire, /* FIFO checked in this slice */
  756. BFQQF_has_short_ttime, /* queue has a short think time */
  757. BFQQF_sync, /* synchronous queue */
  758. BFQQF_IO_bound, /*
  759. * bfqq has timed-out at least once
  760. * having consumed at most 2/10 of
  761. * its budget
  762. */
  763. BFQQF_in_large_burst, /*
  764. * bfqq activated in a large burst,
  765. * see comments to bfq_handle_burst.
  766. */
  767. BFQQF_softrt_update, /*
  768. * may need softrt-next-start
  769. * update
  770. */
  771. BFQQF_coop, /* bfqq is shared */
  772. BFQQF_split_coop, /* shared bfqq will be split */
  773. };
  774. #define BFQ_BFQQ_FNS(name) \
  775. void bfq_mark_bfqq_##name(struct bfq_queue *bfqq); \
  776. void bfq_clear_bfqq_##name(struct bfq_queue *bfqq); \
  777. int bfq_bfqq_##name(const struct bfq_queue *bfqq);
  778. BFQ_BFQQ_FNS(just_created);
  779. BFQ_BFQQ_FNS(busy);
  780. BFQ_BFQQ_FNS(wait_request);
  781. BFQ_BFQQ_FNS(non_blocking_wait_rq);
  782. BFQ_BFQQ_FNS(fifo_expire);
  783. BFQ_BFQQ_FNS(has_short_ttime);
  784. BFQ_BFQQ_FNS(sync);
  785. BFQ_BFQQ_FNS(IO_bound);
  786. BFQ_BFQQ_FNS(in_large_burst);
  787. BFQ_BFQQ_FNS(coop);
  788. BFQ_BFQQ_FNS(split_coop);
  789. BFQ_BFQQ_FNS(softrt_update);
  790. #undef BFQ_BFQQ_FNS
  791. /* Expiration reasons. */
  792. enum bfqq_expiration {
  793. BFQQE_TOO_IDLE = 0, /*
  794. * queue has been idling for
  795. * too long
  796. */
  797. BFQQE_BUDGET_TIMEOUT, /* budget took too long to be used */
  798. BFQQE_BUDGET_EXHAUSTED, /* budget consumed */
  799. BFQQE_NO_MORE_REQUESTS, /* the queue has no more requests */
  800. BFQQE_PREEMPTED /* preemption in progress */
  801. };
  802. struct bfq_stat {
  803. struct percpu_counter cpu_cnt;
  804. atomic64_t aux_cnt;
  805. };
  806. struct bfqg_stats {
  807. /* basic stats */
  808. struct blkg_rwstat bytes;
  809. struct blkg_rwstat ios;
  810. #ifdef CONFIG_BFQ_CGROUP_DEBUG
  811. /* number of ios merged */
  812. struct blkg_rwstat merged;
  813. /* total time spent on device in ns, may not be accurate w/ queueing */
  814. struct blkg_rwstat service_time;
  815. /* total time spent waiting in scheduler queue in ns */
  816. struct blkg_rwstat wait_time;
  817. /* number of IOs queued up */
  818. struct blkg_rwstat queued;
  819. /* total disk time and nr sectors dispatched by this group */
  820. struct bfq_stat time;
  821. /* sum of number of ios queued across all samples */
  822. struct bfq_stat avg_queue_size_sum;
  823. /* count of samples taken for average */
  824. struct bfq_stat avg_queue_size_samples;
  825. /* how many times this group has been removed from service tree */
  826. struct bfq_stat dequeue;
  827. /* total time spent waiting for it to be assigned a timeslice. */
  828. struct bfq_stat group_wait_time;
  829. /* time spent idling for this blkcg_gq */
  830. struct bfq_stat idle_time;
  831. /* total time with empty current active q with other requests queued */
  832. struct bfq_stat empty_time;
  833. /* fields after this shouldn't be cleared on stat reset */
  834. u64 start_group_wait_time;
  835. u64 start_idle_time;
  836. u64 start_empty_time;
  837. uint16_t flags;
  838. #endif /* CONFIG_BFQ_CGROUP_DEBUG */
  839. };
  840. #ifdef CONFIG_BFQ_GROUP_IOSCHED
  841. /*
  842. * struct bfq_group_data - per-blkcg storage for the blkio subsystem.
  843. *
  844. * @ps: @blkcg_policy_storage that this structure inherits
  845. * @weight: weight of the bfq_group
  846. */
  847. struct bfq_group_data {
  848. /* must be the first member */
  849. struct blkcg_policy_data pd;
  850. unsigned int weight;
  851. };
  852. /**
  853. * struct bfq_group - per (device, cgroup) data structure.
  854. * @entity: schedulable entity to insert into the parent group sched_data.
  855. * @sched_data: own sched_data, to contain child entities (they may be
  856. * both bfq_queues and bfq_groups).
  857. * @bfqd: the bfq_data for the device this group acts upon.
  858. * @async_bfqq: array of async queues for all the tasks belonging to
  859. * the group, one queue per ioprio value per ioprio_class,
  860. * except for the idle class that has only one queue.
  861. * @async_idle_bfqq: async queue for the idle class (ioprio is ignored).
  862. * @my_entity: pointer to @entity, %NULL for the toplevel group; used
  863. * to avoid too many special cases during group creation/
  864. * migration.
  865. * @stats: stats for this bfqg.
  866. * @active_entities: number of active entities belonging to the group;
  867. * unused for the root group. Used to know whether there
  868. * are groups with more than one active @bfq_entity
  869. * (see the comments to the function
  870. * bfq_better_to_idle()).
  871. * @rq_pos_tree: rbtree sorted by next_request position, used when
  872. * determining if two or more queues have interleaving
  873. * requests (see bfq_find_close_cooperator()).
  874. *
  875. * Each (device, cgroup) pair has its own bfq_group, i.e., for each cgroup
  876. * there is a set of bfq_groups, each one collecting the lower-level
  877. * entities belonging to the group that are acting on the same device.
  878. *
  879. * Locking works as follows:
  880. * o @bfqd is protected by the queue lock, RCU is used to access it
  881. * from the readers.
  882. * o All the other fields are protected by the @bfqd queue lock.
  883. */
  884. struct bfq_group {
  885. /* must be the first member */
  886. struct blkg_policy_data pd;
  887. /* reference counter (see comments in bfq_bic_update_cgroup) */
  888. refcount_t ref;
  889. struct bfq_entity entity;
  890. struct bfq_sched_data sched_data;
  891. struct bfq_data *bfqd;
  892. struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS][BFQ_MAX_ACTUATORS];
  893. struct bfq_queue *async_idle_bfqq[BFQ_MAX_ACTUATORS];
  894. struct bfq_entity *my_entity;
  895. int active_entities;
  896. int num_queues_with_pending_reqs;
  897. struct rb_root rq_pos_tree;
  898. struct bfqg_stats stats;
  899. };
  900. #else
  901. struct bfq_group {
  902. struct bfq_entity entity;
  903. struct bfq_sched_data sched_data;
  904. struct bfq_queue *async_bfqq[2][IOPRIO_NR_LEVELS][BFQ_MAX_ACTUATORS];
  905. struct bfq_queue *async_idle_bfqq[BFQ_MAX_ACTUATORS];
  906. struct rb_root rq_pos_tree;
  907. };
  908. #endif
  909. /* --------------- main algorithm interface ----------------- */
  910. #define BFQ_SERVICE_TREE_INIT ((struct bfq_service_tree) \
  911. { RB_ROOT, RB_ROOT, NULL, NULL, 0, 0 })
  912. extern const int bfq_timeout;
  913. struct bfq_queue *bic_to_bfqq(struct bfq_io_cq *bic, bool is_sync,
  914. unsigned int actuator_idx);
  915. void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync,
  916. unsigned int actuator_idx);
  917. struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic);
  918. void bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq);
  919. void bfq_weights_tree_add(struct bfq_queue *bfqq);
  920. void bfq_weights_tree_remove(struct bfq_queue *bfqq);
  921. void bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  922. bool compensate, enum bfqq_expiration reason);
  923. void bfq_put_queue(struct bfq_queue *bfqq);
  924. void bfq_put_cooperator(struct bfq_queue *bfqq);
  925. void bfq_end_wr_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
  926. void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq);
  927. void bfq_schedule_dispatch(struct bfq_data *bfqd);
  928. void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
  929. /* ------------ end of main algorithm interface -------------- */
  930. /* ---------------- cgroups-support interface ---------------- */
  931. void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq);
  932. void bfqg_stats_update_io_remove(struct bfq_group *bfqg, blk_opf_t opf);
  933. void bfqg_stats_update_io_merged(struct bfq_group *bfqg, blk_opf_t opf);
  934. void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
  935. u64 io_start_time_ns, blk_opf_t opf);
  936. void bfqg_stats_update_dequeue(struct bfq_group *bfqg);
  937. void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg);
  938. void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  939. struct bfq_group *bfqg);
  940. #ifdef CONFIG_BFQ_CGROUP_DEBUG
  941. void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
  942. blk_opf_t opf);
  943. void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg);
  944. void bfqg_stats_update_idle_time(struct bfq_group *bfqg);
  945. void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg);
  946. #endif
  947. void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg);
  948. void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio);
  949. void bfq_end_wr_async(struct bfq_data *bfqd);
  950. struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio);
  951. struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg);
  952. struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
  953. struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node);
  954. void bfqg_and_blkg_put(struct bfq_group *bfqg);
  955. #ifdef CONFIG_BFQ_GROUP_IOSCHED
  956. extern struct cftype bfq_blkcg_legacy_files[];
  957. extern struct cftype bfq_blkg_files[];
  958. extern struct blkcg_policy blkcg_policy_bfq;
  959. #endif
  960. /* ------------- end of cgroups-support interface ------------- */
  961. /* - interface of the internal hierarchical B-WF2Q+ scheduler - */
  962. #ifdef CONFIG_BFQ_GROUP_IOSCHED
  963. /* both next loops stop at one of the child entities of the root group */
  964. #define for_each_entity(entity) \
  965. for (; entity ; entity = entity->parent)
  966. /*
  967. * For each iteration, compute parent in advance, so as to be safe if
  968. * entity is deallocated during the iteration. Such a deallocation may
  969. * happen as a consequence of a bfq_put_queue that frees the bfq_queue
  970. * containing entity.
  971. */
  972. #define for_each_entity_safe(entity, parent) \
  973. for (; entity && ({ parent = entity->parent; 1; }); entity = parent)
  974. #else /* CONFIG_BFQ_GROUP_IOSCHED */
  975. /*
  976. * Next two macros are fake loops when cgroups support is not
  977. * enabled. I fact, in such a case, there is only one level to go up
  978. * (to reach the root group).
  979. */
  980. #define for_each_entity(entity) \
  981. for (; entity ; entity = NULL)
  982. #define for_each_entity_safe(entity, parent) \
  983. for (parent = NULL; entity ; entity = parent)
  984. #endif /* CONFIG_BFQ_GROUP_IOSCHED */
  985. struct bfq_queue *bfq_entity_to_bfqq(struct bfq_entity *entity);
  986. unsigned int bfq_tot_busy_queues(struct bfq_data *bfqd);
  987. struct bfq_service_tree *bfq_entity_service_tree(struct bfq_entity *entity);
  988. struct bfq_entity *bfq_entity_of(struct rb_node *node);
  989. unsigned short bfq_ioprio_to_weight(int ioprio);
  990. void bfq_put_idle_entity(struct bfq_service_tree *st,
  991. struct bfq_entity *entity);
  992. struct bfq_service_tree *
  993. __bfq_entity_update_weight_prio(struct bfq_service_tree *old_st,
  994. struct bfq_entity *entity,
  995. bool update_class_too);
  996. void bfq_bfqq_served(struct bfq_queue *bfqq, int served);
  997. void bfq_bfqq_charge_time(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  998. unsigned long time_ms);
  999. bool __bfq_deactivate_entity(struct bfq_entity *entity,
  1000. bool ins_into_idle_tree);
  1001. bool next_queue_may_preempt(struct bfq_data *bfqd);
  1002. struct bfq_queue *bfq_get_next_queue(struct bfq_data *bfqd);
  1003. bool __bfq_bfqd_reset_in_service(struct bfq_data *bfqd);
  1004. void bfq_deactivate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  1005. bool ins_into_idle_tree, bool expiration);
  1006. void bfq_activate_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq);
  1007. void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  1008. bool expiration);
  1009. void bfq_del_bfqq_busy(struct bfq_queue *bfqq, bool expiration);
  1010. void bfq_add_bfqq_busy(struct bfq_queue *bfqq);
  1011. void bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq);
  1012. void bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq);
  1013. void bfq_reassign_last_bfqq(struct bfq_queue *cur_bfqq,
  1014. struct bfq_queue *new_bfqq);
  1015. /* --------------- end of interface of B-WF2Q+ ---------------- */
  1016. /* Logging facilities. */
  1017. static inline void bfq_bfqq_name(struct bfq_queue *bfqq, char *str, int len)
  1018. {
  1019. char type = bfq_bfqq_sync(bfqq) ? 'S' : 'A';
  1020. if (bfqq->pid != -1)
  1021. snprintf(str, len, "bfq%d%c", bfqq->pid, type);
  1022. else
  1023. snprintf(str, len, "bfqSHARED-%c", type);
  1024. }
  1025. #ifdef CONFIG_BFQ_GROUP_IOSCHED
  1026. struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
  1027. #define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do { \
  1028. char pid_str[MAX_BFQQ_NAME_LENGTH]; \
  1029. if (likely(!blk_trace_note_message_enabled((bfqd)->queue))) \
  1030. break; \
  1031. bfq_bfqq_name((bfqq), pid_str, MAX_BFQQ_NAME_LENGTH); \
  1032. blk_add_cgroup_trace_msg((bfqd)->queue, \
  1033. &bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css, \
  1034. "%s " fmt, pid_str, ##args); \
  1035. } while (0)
  1036. #else /* CONFIG_BFQ_GROUP_IOSCHED */
  1037. #define bfq_log_bfqq(bfqd, bfqq, fmt, args...) do { \
  1038. char pid_str[MAX_BFQQ_NAME_LENGTH]; \
  1039. if (likely(!blk_trace_note_message_enabled((bfqd)->queue))) \
  1040. break; \
  1041. bfq_bfqq_name((bfqq), pid_str, MAX_BFQQ_NAME_LENGTH); \
  1042. blk_add_trace_msg((bfqd)->queue, "%s " fmt, pid_str, ##args); \
  1043. } while (0)
  1044. #endif /* CONFIG_BFQ_GROUP_IOSCHED */
  1045. #define bfq_log(bfqd, fmt, args...) \
  1046. blk_add_trace_msg((bfqd)->queue, "bfq " fmt, ##args)
  1047. #endif /* _BFQ_H */