bfq-cgroup.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * cgroups support for the BFQ I/O scheduler.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/blkdev.h>
  17. #include <linux/cgroup.h>
  18. #include <linux/elevator.h>
  19. #include <linux/ktime.h>
  20. #include <linux/rbtree.h>
  21. #include <linux/ioprio.h>
  22. #include <linux/sbitmap.h>
  23. #include <linux/delay.h>
  24. #include "bfq-iosched.h"
  25. #ifdef CONFIG_BFQ_GROUP_IOSCHED
  26. /* bfqg stats flags */
  27. enum bfqg_stats_flags {
  28. BFQG_stats_waiting = 0,
  29. BFQG_stats_idling,
  30. BFQG_stats_empty,
  31. };
  32. #define BFQG_FLAG_FNS(name) \
  33. static void bfqg_stats_mark_##name(struct bfqg_stats *stats) \
  34. { \
  35. stats->flags |= (1 << BFQG_stats_##name); \
  36. } \
  37. static void bfqg_stats_clear_##name(struct bfqg_stats *stats) \
  38. { \
  39. stats->flags &= ~(1 << BFQG_stats_##name); \
  40. } \
  41. static int bfqg_stats_##name(struct bfqg_stats *stats) \
  42. { \
  43. return (stats->flags & (1 << BFQG_stats_##name)) != 0; \
  44. } \
  45. BFQG_FLAG_FNS(waiting)
  46. BFQG_FLAG_FNS(idling)
  47. BFQG_FLAG_FNS(empty)
  48. #undef BFQG_FLAG_FNS
  49. /* This should be called with the scheduler lock held. */
  50. static void bfqg_stats_update_group_wait_time(struct bfqg_stats *stats)
  51. {
  52. unsigned long long now;
  53. if (!bfqg_stats_waiting(stats))
  54. return;
  55. now = sched_clock();
  56. if (time_after64(now, stats->start_group_wait_time))
  57. blkg_stat_add(&stats->group_wait_time,
  58. now - stats->start_group_wait_time);
  59. bfqg_stats_clear_waiting(stats);
  60. }
  61. /* This should be called with the scheduler lock held. */
  62. static void bfqg_stats_set_start_group_wait_time(struct bfq_group *bfqg,
  63. struct bfq_group *curr_bfqg)
  64. {
  65. struct bfqg_stats *stats = &bfqg->stats;
  66. if (bfqg_stats_waiting(stats))
  67. return;
  68. if (bfqg == curr_bfqg)
  69. return;
  70. stats->start_group_wait_time = sched_clock();
  71. bfqg_stats_mark_waiting(stats);
  72. }
  73. /* This should be called with the scheduler lock held. */
  74. static void bfqg_stats_end_empty_time(struct bfqg_stats *stats)
  75. {
  76. unsigned long long now;
  77. if (!bfqg_stats_empty(stats))
  78. return;
  79. now = sched_clock();
  80. if (time_after64(now, stats->start_empty_time))
  81. blkg_stat_add(&stats->empty_time,
  82. now - stats->start_empty_time);
  83. bfqg_stats_clear_empty(stats);
  84. }
  85. void bfqg_stats_update_dequeue(struct bfq_group *bfqg)
  86. {
  87. blkg_stat_add(&bfqg->stats.dequeue, 1);
  88. }
  89. void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg)
  90. {
  91. struct bfqg_stats *stats = &bfqg->stats;
  92. if (blkg_rwstat_total(&stats->queued))
  93. return;
  94. /*
  95. * group is already marked empty. This can happen if bfqq got new
  96. * request in parent group and moved to this group while being added
  97. * to service tree. Just ignore the event and move on.
  98. */
  99. if (bfqg_stats_empty(stats))
  100. return;
  101. stats->start_empty_time = sched_clock();
  102. bfqg_stats_mark_empty(stats);
  103. }
  104. void bfqg_stats_update_idle_time(struct bfq_group *bfqg)
  105. {
  106. struct bfqg_stats *stats = &bfqg->stats;
  107. if (bfqg_stats_idling(stats)) {
  108. unsigned long long now = sched_clock();
  109. if (time_after64(now, stats->start_idle_time))
  110. blkg_stat_add(&stats->idle_time,
  111. now - stats->start_idle_time);
  112. bfqg_stats_clear_idling(stats);
  113. }
  114. }
  115. void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg)
  116. {
  117. struct bfqg_stats *stats = &bfqg->stats;
  118. stats->start_idle_time = sched_clock();
  119. bfqg_stats_mark_idling(stats);
  120. }
  121. void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg)
  122. {
  123. struct bfqg_stats *stats = &bfqg->stats;
  124. blkg_stat_add(&stats->avg_queue_size_sum,
  125. blkg_rwstat_total(&stats->queued));
  126. blkg_stat_add(&stats->avg_queue_size_samples, 1);
  127. bfqg_stats_update_group_wait_time(stats);
  128. }
  129. /*
  130. * blk-cgroup policy-related handlers
  131. * The following functions help in converting between blk-cgroup
  132. * internal structures and BFQ-specific structures.
  133. */
  134. static struct bfq_group *pd_to_bfqg(struct blkg_policy_data *pd)
  135. {
  136. return pd ? container_of(pd, struct bfq_group, pd) : NULL;
  137. }
  138. struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg)
  139. {
  140. return pd_to_blkg(&bfqg->pd);
  141. }
  142. static struct bfq_group *blkg_to_bfqg(struct blkcg_gq *blkg)
  143. {
  144. return pd_to_bfqg(blkg_to_pd(blkg, &blkcg_policy_bfq));
  145. }
  146. /*
  147. * bfq_group handlers
  148. * The following functions help in navigating the bfq_group hierarchy
  149. * by allowing to find the parent of a bfq_group or the bfq_group
  150. * associated to a bfq_queue.
  151. */
  152. static struct bfq_group *bfqg_parent(struct bfq_group *bfqg)
  153. {
  154. struct blkcg_gq *pblkg = bfqg_to_blkg(bfqg)->parent;
  155. return pblkg ? blkg_to_bfqg(pblkg) : NULL;
  156. }
  157. struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
  158. {
  159. struct bfq_entity *group_entity = bfqq->entity.parent;
  160. return group_entity ? container_of(group_entity, struct bfq_group,
  161. entity) :
  162. bfqq->bfqd->root_group;
  163. }
  164. /*
  165. * The following two functions handle get and put of a bfq_group by
  166. * wrapping the related blk-cgroup hooks.
  167. */
  168. static void bfqg_get(struct bfq_group *bfqg)
  169. {
  170. bfqg->ref++;
  171. }
  172. static void bfqg_put(struct bfq_group *bfqg)
  173. {
  174. bfqg->ref--;
  175. if (bfqg->ref == 0)
  176. kfree(bfqg);
  177. }
  178. static void bfqg_and_blkg_get(struct bfq_group *bfqg)
  179. {
  180. /* see comments in bfq_bic_update_cgroup for why refcounting bfqg */
  181. bfqg_get(bfqg);
  182. blkg_get(bfqg_to_blkg(bfqg));
  183. }
  184. void bfqg_and_blkg_put(struct bfq_group *bfqg)
  185. {
  186. blkg_put(bfqg_to_blkg(bfqg));
  187. bfqg_put(bfqg);
  188. }
  189. void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
  190. unsigned int op)
  191. {
  192. blkg_rwstat_add(&bfqg->stats.queued, op, 1);
  193. bfqg_stats_end_empty_time(&bfqg->stats);
  194. if (!(bfqq == ((struct bfq_data *)bfqg->bfqd)->in_service_queue))
  195. bfqg_stats_set_start_group_wait_time(bfqg, bfqq_group(bfqq));
  196. }
  197. void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op)
  198. {
  199. blkg_rwstat_add(&bfqg->stats.queued, op, -1);
  200. }
  201. void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op)
  202. {
  203. blkg_rwstat_add(&bfqg->stats.merged, op, 1);
  204. }
  205. void bfqg_stats_update_completion(struct bfq_group *bfqg, uint64_t start_time,
  206. uint64_t io_start_time, unsigned int op)
  207. {
  208. struct bfqg_stats *stats = &bfqg->stats;
  209. unsigned long long now = sched_clock();
  210. if (time_after64(now, io_start_time))
  211. blkg_rwstat_add(&stats->service_time, op,
  212. now - io_start_time);
  213. if (time_after64(io_start_time, start_time))
  214. blkg_rwstat_add(&stats->wait_time, op,
  215. io_start_time - start_time);
  216. }
  217. /* @stats = 0 */
  218. static void bfqg_stats_reset(struct bfqg_stats *stats)
  219. {
  220. /* queued stats shouldn't be cleared */
  221. blkg_rwstat_reset(&stats->merged);
  222. blkg_rwstat_reset(&stats->service_time);
  223. blkg_rwstat_reset(&stats->wait_time);
  224. blkg_stat_reset(&stats->time);
  225. blkg_stat_reset(&stats->avg_queue_size_sum);
  226. blkg_stat_reset(&stats->avg_queue_size_samples);
  227. blkg_stat_reset(&stats->dequeue);
  228. blkg_stat_reset(&stats->group_wait_time);
  229. blkg_stat_reset(&stats->idle_time);
  230. blkg_stat_reset(&stats->empty_time);
  231. }
  232. /* @to += @from */
  233. static void bfqg_stats_add_aux(struct bfqg_stats *to, struct bfqg_stats *from)
  234. {
  235. if (!to || !from)
  236. return;
  237. /* queued stats shouldn't be cleared */
  238. blkg_rwstat_add_aux(&to->merged, &from->merged);
  239. blkg_rwstat_add_aux(&to->service_time, &from->service_time);
  240. blkg_rwstat_add_aux(&to->wait_time, &from->wait_time);
  241. blkg_stat_add_aux(&from->time, &from->time);
  242. blkg_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
  243. blkg_stat_add_aux(&to->avg_queue_size_samples,
  244. &from->avg_queue_size_samples);
  245. blkg_stat_add_aux(&to->dequeue, &from->dequeue);
  246. blkg_stat_add_aux(&to->group_wait_time, &from->group_wait_time);
  247. blkg_stat_add_aux(&to->idle_time, &from->idle_time);
  248. blkg_stat_add_aux(&to->empty_time, &from->empty_time);
  249. }
  250. /*
  251. * Transfer @bfqg's stats to its parent's aux counts so that the ancestors'
  252. * recursive stats can still account for the amount used by this bfqg after
  253. * it's gone.
  254. */
  255. static void bfqg_stats_xfer_dead(struct bfq_group *bfqg)
  256. {
  257. struct bfq_group *parent;
  258. if (!bfqg) /* root_group */
  259. return;
  260. parent = bfqg_parent(bfqg);
  261. lockdep_assert_held(bfqg_to_blkg(bfqg)->q->queue_lock);
  262. if (unlikely(!parent))
  263. return;
  264. bfqg_stats_add_aux(&parent->stats, &bfqg->stats);
  265. bfqg_stats_reset(&bfqg->stats);
  266. }
  267. void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
  268. {
  269. struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
  270. entity->weight = entity->new_weight;
  271. entity->orig_weight = entity->new_weight;
  272. if (bfqq) {
  273. bfqq->ioprio = bfqq->new_ioprio;
  274. bfqq->ioprio_class = bfqq->new_ioprio_class;
  275. /*
  276. * Make sure that bfqg and its associated blkg do not
  277. * disappear before entity.
  278. */
  279. bfqg_and_blkg_get(bfqg);
  280. }
  281. entity->parent = bfqg->my_entity; /* NULL for root group */
  282. entity->sched_data = &bfqg->sched_data;
  283. }
  284. static void bfqg_stats_exit(struct bfqg_stats *stats)
  285. {
  286. blkg_rwstat_exit(&stats->merged);
  287. blkg_rwstat_exit(&stats->service_time);
  288. blkg_rwstat_exit(&stats->wait_time);
  289. blkg_rwstat_exit(&stats->queued);
  290. blkg_stat_exit(&stats->time);
  291. blkg_stat_exit(&stats->avg_queue_size_sum);
  292. blkg_stat_exit(&stats->avg_queue_size_samples);
  293. blkg_stat_exit(&stats->dequeue);
  294. blkg_stat_exit(&stats->group_wait_time);
  295. blkg_stat_exit(&stats->idle_time);
  296. blkg_stat_exit(&stats->empty_time);
  297. }
  298. static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
  299. {
  300. if (blkg_rwstat_init(&stats->merged, gfp) ||
  301. blkg_rwstat_init(&stats->service_time, gfp) ||
  302. blkg_rwstat_init(&stats->wait_time, gfp) ||
  303. blkg_rwstat_init(&stats->queued, gfp) ||
  304. blkg_stat_init(&stats->time, gfp) ||
  305. blkg_stat_init(&stats->avg_queue_size_sum, gfp) ||
  306. blkg_stat_init(&stats->avg_queue_size_samples, gfp) ||
  307. blkg_stat_init(&stats->dequeue, gfp) ||
  308. blkg_stat_init(&stats->group_wait_time, gfp) ||
  309. blkg_stat_init(&stats->idle_time, gfp) ||
  310. blkg_stat_init(&stats->empty_time, gfp)) {
  311. bfqg_stats_exit(stats);
  312. return -ENOMEM;
  313. }
  314. return 0;
  315. }
  316. static struct bfq_group_data *cpd_to_bfqgd(struct blkcg_policy_data *cpd)
  317. {
  318. return cpd ? container_of(cpd, struct bfq_group_data, pd) : NULL;
  319. }
  320. static struct bfq_group_data *blkcg_to_bfqgd(struct blkcg *blkcg)
  321. {
  322. return cpd_to_bfqgd(blkcg_to_cpd(blkcg, &blkcg_policy_bfq));
  323. }
  324. static struct blkcg_policy_data *bfq_cpd_alloc(gfp_t gfp)
  325. {
  326. struct bfq_group_data *bgd;
  327. bgd = kzalloc(sizeof(*bgd), gfp);
  328. if (!bgd)
  329. return NULL;
  330. return &bgd->pd;
  331. }
  332. static void bfq_cpd_init(struct blkcg_policy_data *cpd)
  333. {
  334. struct bfq_group_data *d = cpd_to_bfqgd(cpd);
  335. d->weight = cgroup_subsys_on_dfl(io_cgrp_subsys) ?
  336. CGROUP_WEIGHT_DFL : BFQ_WEIGHT_LEGACY_DFL;
  337. }
  338. static void bfq_cpd_free(struct blkcg_policy_data *cpd)
  339. {
  340. kfree(cpd_to_bfqgd(cpd));
  341. }
  342. static struct blkg_policy_data *bfq_pd_alloc(gfp_t gfp, int node)
  343. {
  344. struct bfq_group *bfqg;
  345. bfqg = kzalloc_node(sizeof(*bfqg), gfp, node);
  346. if (!bfqg)
  347. return NULL;
  348. if (bfqg_stats_init(&bfqg->stats, gfp)) {
  349. kfree(bfqg);
  350. return NULL;
  351. }
  352. /* see comments in bfq_bic_update_cgroup for why refcounting */
  353. bfqg_get(bfqg);
  354. return &bfqg->pd;
  355. }
  356. static void bfq_pd_init(struct blkg_policy_data *pd)
  357. {
  358. struct blkcg_gq *blkg = pd_to_blkg(pd);
  359. struct bfq_group *bfqg = blkg_to_bfqg(blkg);
  360. struct bfq_data *bfqd = blkg->q->elevator->elevator_data;
  361. struct bfq_entity *entity = &bfqg->entity;
  362. struct bfq_group_data *d = blkcg_to_bfqgd(blkg->blkcg);
  363. entity->orig_weight = entity->weight = entity->new_weight = d->weight;
  364. entity->my_sched_data = &bfqg->sched_data;
  365. bfqg->my_entity = entity; /*
  366. * the root_group's will be set to NULL
  367. * in bfq_init_queue()
  368. */
  369. bfqg->bfqd = bfqd;
  370. bfqg->active_entities = 0;
  371. bfqg->rq_pos_tree = RB_ROOT;
  372. }
  373. static void bfq_pd_free(struct blkg_policy_data *pd)
  374. {
  375. struct bfq_group *bfqg = pd_to_bfqg(pd);
  376. bfqg_stats_exit(&bfqg->stats);
  377. bfqg_put(bfqg);
  378. }
  379. static void bfq_pd_reset_stats(struct blkg_policy_data *pd)
  380. {
  381. struct bfq_group *bfqg = pd_to_bfqg(pd);
  382. bfqg_stats_reset(&bfqg->stats);
  383. }
  384. static void bfq_group_set_parent(struct bfq_group *bfqg,
  385. struct bfq_group *parent)
  386. {
  387. struct bfq_entity *entity;
  388. entity = &bfqg->entity;
  389. entity->parent = parent->my_entity;
  390. entity->sched_data = &parent->sched_data;
  391. }
  392. static struct bfq_group *bfq_lookup_bfqg(struct bfq_data *bfqd,
  393. struct blkcg *blkcg)
  394. {
  395. struct blkcg_gq *blkg;
  396. blkg = blkg_lookup(blkcg, bfqd->queue);
  397. if (likely(blkg))
  398. return blkg_to_bfqg(blkg);
  399. return NULL;
  400. }
  401. struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
  402. struct blkcg *blkcg)
  403. {
  404. struct bfq_group *bfqg, *parent;
  405. struct bfq_entity *entity;
  406. bfqg = bfq_lookup_bfqg(bfqd, blkcg);
  407. if (unlikely(!bfqg))
  408. return NULL;
  409. /*
  410. * Update chain of bfq_groups as we might be handling a leaf group
  411. * which, along with some of its relatives, has not been hooked yet
  412. * to the private hierarchy of BFQ.
  413. */
  414. entity = &bfqg->entity;
  415. for_each_entity(entity) {
  416. struct bfq_group *curr_bfqg = container_of(entity,
  417. struct bfq_group, entity);
  418. if (curr_bfqg != bfqd->root_group) {
  419. parent = bfqg_parent(curr_bfqg);
  420. if (!parent)
  421. parent = bfqd->root_group;
  422. bfq_group_set_parent(curr_bfqg, parent);
  423. }
  424. }
  425. return bfqg;
  426. }
  427. /**
  428. * bfq_bfqq_move - migrate @bfqq to @bfqg.
  429. * @bfqd: queue descriptor.
  430. * @bfqq: the queue to move.
  431. * @bfqg: the group to move to.
  432. *
  433. * Move @bfqq to @bfqg, deactivating it from its old group and reactivating
  434. * it on the new one. Avoid putting the entity on the old group idle tree.
  435. *
  436. * Must be called under the scheduler lock, to make sure that the blkg
  437. * owning @bfqg does not disappear (see comments in
  438. * bfq_bic_update_cgroup on guaranteeing the consistency of blkg
  439. * objects).
  440. */
  441. void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  442. struct bfq_group *bfqg)
  443. {
  444. struct bfq_entity *entity = &bfqq->entity;
  445. /* If bfqq is empty, then bfq_bfqq_expire also invokes
  446. * bfq_del_bfqq_busy, thereby removing bfqq and its entity
  447. * from data structures related to current group. Otherwise we
  448. * need to remove bfqq explicitly with bfq_deactivate_bfqq, as
  449. * we do below.
  450. */
  451. if (bfqq == bfqd->in_service_queue)
  452. bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
  453. false, BFQQE_PREEMPTED);
  454. if (bfq_bfqq_busy(bfqq))
  455. bfq_deactivate_bfqq(bfqd, bfqq, false, false);
  456. else if (entity->on_st)
  457. bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
  458. bfqg_and_blkg_put(bfqq_group(bfqq));
  459. entity->parent = bfqg->my_entity;
  460. entity->sched_data = &bfqg->sched_data;
  461. /* pin down bfqg and its associated blkg */
  462. bfqg_and_blkg_get(bfqg);
  463. if (bfq_bfqq_busy(bfqq)) {
  464. bfq_pos_tree_add_move(bfqd, bfqq);
  465. bfq_activate_bfqq(bfqd, bfqq);
  466. }
  467. if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
  468. bfq_schedule_dispatch(bfqd);
  469. }
  470. /**
  471. * __bfq_bic_change_cgroup - move @bic to @cgroup.
  472. * @bfqd: the queue descriptor.
  473. * @bic: the bic to move.
  474. * @blkcg: the blk-cgroup to move to.
  475. *
  476. * Move bic to blkcg, assuming that bfqd->lock is held; which makes
  477. * sure that the reference to cgroup is valid across the call (see
  478. * comments in bfq_bic_update_cgroup on this issue)
  479. *
  480. * NOTE: an alternative approach might have been to store the current
  481. * cgroup in bfqq and getting a reference to it, reducing the lookup
  482. * time here, at the price of slightly more complex code.
  483. */
  484. static struct bfq_group *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
  485. struct bfq_io_cq *bic,
  486. struct blkcg *blkcg)
  487. {
  488. struct bfq_queue *async_bfqq = bic_to_bfqq(bic, 0);
  489. struct bfq_queue *sync_bfqq = bic_to_bfqq(bic, 1);
  490. struct bfq_group *bfqg;
  491. struct bfq_entity *entity;
  492. bfqg = bfq_find_set_group(bfqd, blkcg);
  493. if (unlikely(!bfqg))
  494. bfqg = bfqd->root_group;
  495. if (async_bfqq) {
  496. entity = &async_bfqq->entity;
  497. if (entity->sched_data != &bfqg->sched_data) {
  498. bic_set_bfqq(bic, NULL, 0);
  499. bfq_log_bfqq(bfqd, async_bfqq,
  500. "bic_change_group: %p %d",
  501. async_bfqq, async_bfqq->ref);
  502. bfq_put_queue(async_bfqq);
  503. }
  504. }
  505. if (sync_bfqq) {
  506. entity = &sync_bfqq->entity;
  507. if (entity->sched_data != &bfqg->sched_data)
  508. bfq_bfqq_move(bfqd, sync_bfqq, bfqg);
  509. }
  510. return bfqg;
  511. }
  512. void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio)
  513. {
  514. struct bfq_data *bfqd = bic_to_bfqd(bic);
  515. struct bfq_group *bfqg = NULL;
  516. uint64_t serial_nr;
  517. rcu_read_lock();
  518. serial_nr = bio_blkcg(bio)->css.serial_nr;
  519. /*
  520. * Check whether blkcg has changed. The condition may trigger
  521. * spuriously on a newly created cic but there's no harm.
  522. */
  523. if (unlikely(!bfqd) || likely(bic->blkcg_serial_nr == serial_nr))
  524. goto out;
  525. bfqg = __bfq_bic_change_cgroup(bfqd, bic, bio_blkcg(bio));
  526. /*
  527. * Update blkg_path for bfq_log_* functions. We cache this
  528. * path, and update it here, for the following
  529. * reasons. Operations on blkg objects in blk-cgroup are
  530. * protected with the request_queue lock, and not with the
  531. * lock that protects the instances of this scheduler
  532. * (bfqd->lock). This exposes BFQ to the following sort of
  533. * race.
  534. *
  535. * The blkg_lookup performed in bfq_get_queue, protected
  536. * through rcu, may happen to return the address of a copy of
  537. * the original blkg. If this is the case, then the
  538. * bfqg_and_blkg_get performed in bfq_get_queue, to pin down
  539. * the blkg, is useless: it does not prevent blk-cgroup code
  540. * from destroying both the original blkg and all objects
  541. * directly or indirectly referred by the copy of the
  542. * blkg.
  543. *
  544. * On the bright side, destroy operations on a blkg invoke, as
  545. * a first step, hooks of the scheduler associated with the
  546. * blkg. And these hooks are executed with bfqd->lock held for
  547. * BFQ. As a consequence, for any blkg associated with the
  548. * request queue this instance of the scheduler is attached
  549. * to, we are guaranteed that such a blkg is not destroyed, and
  550. * that all the pointers it contains are consistent, while we
  551. * are holding bfqd->lock. A blkg_lookup performed with
  552. * bfqd->lock held then returns a fully consistent blkg, which
  553. * remains consistent until this lock is held.
  554. *
  555. * Thanks to the last fact, and to the fact that: (1) bfqg has
  556. * been obtained through a blkg_lookup in the above
  557. * assignment, and (2) bfqd->lock is being held, here we can
  558. * safely use the policy data for the involved blkg (i.e., the
  559. * field bfqg->pd) to get to the blkg associated with bfqg,
  560. * and then we can safely use any field of blkg. After we
  561. * release bfqd->lock, even just getting blkg through this
  562. * bfqg may cause dangling references to be traversed, as
  563. * bfqg->pd may not exist any more.
  564. *
  565. * In view of the above facts, here we cache, in the bfqg, any
  566. * blkg data we may need for this bic, and for its associated
  567. * bfq_queue. As of now, we need to cache only the path of the
  568. * blkg, which is used in the bfq_log_* functions.
  569. *
  570. * Finally, note that bfqg itself needs to be protected from
  571. * destruction on the blkg_free of the original blkg (which
  572. * invokes bfq_pd_free). We use an additional private
  573. * refcounter for bfqg, to let it disappear only after no
  574. * bfq_queue refers to it any longer.
  575. */
  576. blkg_path(bfqg_to_blkg(bfqg), bfqg->blkg_path, sizeof(bfqg->blkg_path));
  577. bic->blkcg_serial_nr = serial_nr;
  578. out:
  579. rcu_read_unlock();
  580. }
  581. /**
  582. * bfq_flush_idle_tree - deactivate any entity on the idle tree of @st.
  583. * @st: the service tree being flushed.
  584. */
  585. static void bfq_flush_idle_tree(struct bfq_service_tree *st)
  586. {
  587. struct bfq_entity *entity = st->first_idle;
  588. for (; entity ; entity = st->first_idle)
  589. __bfq_deactivate_entity(entity, false);
  590. }
  591. /**
  592. * bfq_reparent_leaf_entity - move leaf entity to the root_group.
  593. * @bfqd: the device data structure with the root group.
  594. * @entity: the entity to move.
  595. */
  596. static void bfq_reparent_leaf_entity(struct bfq_data *bfqd,
  597. struct bfq_entity *entity)
  598. {
  599. struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
  600. bfq_bfqq_move(bfqd, bfqq, bfqd->root_group);
  601. }
  602. /**
  603. * bfq_reparent_active_entities - move to the root group all active
  604. * entities.
  605. * @bfqd: the device data structure with the root group.
  606. * @bfqg: the group to move from.
  607. * @st: the service tree with the entities.
  608. */
  609. static void bfq_reparent_active_entities(struct bfq_data *bfqd,
  610. struct bfq_group *bfqg,
  611. struct bfq_service_tree *st)
  612. {
  613. struct rb_root *active = &st->active;
  614. struct bfq_entity *entity = NULL;
  615. if (!RB_EMPTY_ROOT(&st->active))
  616. entity = bfq_entity_of(rb_first(active));
  617. for (; entity ; entity = bfq_entity_of(rb_first(active)))
  618. bfq_reparent_leaf_entity(bfqd, entity);
  619. if (bfqg->sched_data.in_service_entity)
  620. bfq_reparent_leaf_entity(bfqd,
  621. bfqg->sched_data.in_service_entity);
  622. }
  623. /**
  624. * bfq_pd_offline - deactivate the entity associated with @pd,
  625. * and reparent its children entities.
  626. * @pd: descriptor of the policy going offline.
  627. *
  628. * blkio already grabs the queue_lock for us, so no need to use
  629. * RCU-based magic
  630. */
  631. static void bfq_pd_offline(struct blkg_policy_data *pd)
  632. {
  633. struct bfq_service_tree *st;
  634. struct bfq_group *bfqg = pd_to_bfqg(pd);
  635. struct bfq_data *bfqd = bfqg->bfqd;
  636. struct bfq_entity *entity = bfqg->my_entity;
  637. unsigned long flags;
  638. int i;
  639. spin_lock_irqsave(&bfqd->lock, flags);
  640. if (!entity) /* root group */
  641. goto put_async_queues;
  642. /*
  643. * Empty all service_trees belonging to this group before
  644. * deactivating the group itself.
  645. */
  646. for (i = 0; i < BFQ_IOPRIO_CLASSES; i++) {
  647. st = bfqg->sched_data.service_tree + i;
  648. /*
  649. * The idle tree may still contain bfq_queues belonging
  650. * to exited task because they never migrated to a different
  651. * cgroup from the one being destroyed now.
  652. */
  653. bfq_flush_idle_tree(st);
  654. /*
  655. * It may happen that some queues are still active
  656. * (busy) upon group destruction (if the corresponding
  657. * processes have been forced to terminate). We move
  658. * all the leaf entities corresponding to these queues
  659. * to the root_group.
  660. * Also, it may happen that the group has an entity
  661. * in service, which is disconnected from the active
  662. * tree: it must be moved, too.
  663. * There is no need to put the sync queues, as the
  664. * scheduler has taken no reference.
  665. */
  666. bfq_reparent_active_entities(bfqd, bfqg, st);
  667. }
  668. __bfq_deactivate_entity(entity, false);
  669. put_async_queues:
  670. bfq_put_async_queues(bfqd, bfqg);
  671. spin_unlock_irqrestore(&bfqd->lock, flags);
  672. /*
  673. * @blkg is going offline and will be ignored by
  674. * blkg_[rw]stat_recursive_sum(). Transfer stats to the parent so
  675. * that they don't get lost. If IOs complete after this point, the
  676. * stats for them will be lost. Oh well...
  677. */
  678. bfqg_stats_xfer_dead(bfqg);
  679. }
  680. void bfq_end_wr_async(struct bfq_data *bfqd)
  681. {
  682. struct blkcg_gq *blkg;
  683. list_for_each_entry(blkg, &bfqd->queue->blkg_list, q_node) {
  684. struct bfq_group *bfqg = blkg_to_bfqg(blkg);
  685. bfq_end_wr_async_queues(bfqd, bfqg);
  686. }
  687. bfq_end_wr_async_queues(bfqd, bfqd->root_group);
  688. }
  689. static int bfq_io_show_weight(struct seq_file *sf, void *v)
  690. {
  691. struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
  692. struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
  693. unsigned int val = 0;
  694. if (bfqgd)
  695. val = bfqgd->weight;
  696. seq_printf(sf, "%u\n", val);
  697. return 0;
  698. }
  699. static int bfq_io_set_weight_legacy(struct cgroup_subsys_state *css,
  700. struct cftype *cftype,
  701. u64 val)
  702. {
  703. struct blkcg *blkcg = css_to_blkcg(css);
  704. struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
  705. struct blkcg_gq *blkg;
  706. int ret = -ERANGE;
  707. if (val < BFQ_MIN_WEIGHT || val > BFQ_MAX_WEIGHT)
  708. return ret;
  709. ret = 0;
  710. spin_lock_irq(&blkcg->lock);
  711. bfqgd->weight = (unsigned short)val;
  712. hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
  713. struct bfq_group *bfqg = blkg_to_bfqg(blkg);
  714. if (!bfqg)
  715. continue;
  716. /*
  717. * Setting the prio_changed flag of the entity
  718. * to 1 with new_weight == weight would re-set
  719. * the value of the weight to its ioprio mapping.
  720. * Set the flag only if necessary.
  721. */
  722. if ((unsigned short)val != bfqg->entity.new_weight) {
  723. bfqg->entity.new_weight = (unsigned short)val;
  724. /*
  725. * Make sure that the above new value has been
  726. * stored in bfqg->entity.new_weight before
  727. * setting the prio_changed flag. In fact,
  728. * this flag may be read asynchronously (in
  729. * critical sections protected by a different
  730. * lock than that held here), and finding this
  731. * flag set may cause the execution of the code
  732. * for updating parameters whose value may
  733. * depend also on bfqg->entity.new_weight (in
  734. * __bfq_entity_update_weight_prio).
  735. * This barrier makes sure that the new value
  736. * of bfqg->entity.new_weight is correctly
  737. * seen in that code.
  738. */
  739. smp_wmb();
  740. bfqg->entity.prio_changed = 1;
  741. }
  742. }
  743. spin_unlock_irq(&blkcg->lock);
  744. return ret;
  745. }
  746. static ssize_t bfq_io_set_weight(struct kernfs_open_file *of,
  747. char *buf, size_t nbytes,
  748. loff_t off)
  749. {
  750. u64 weight;
  751. /* First unsigned long found in the file is used */
  752. int ret = kstrtoull(strim(buf), 0, &weight);
  753. if (ret)
  754. return ret;
  755. ret = bfq_io_set_weight_legacy(of_css(of), NULL, weight);
  756. return ret ?: nbytes;
  757. }
  758. static int bfqg_print_stat(struct seq_file *sf, void *v)
  759. {
  760. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_stat,
  761. &blkcg_policy_bfq, seq_cft(sf)->private, false);
  762. return 0;
  763. }
  764. static int bfqg_print_rwstat(struct seq_file *sf, void *v)
  765. {
  766. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_rwstat,
  767. &blkcg_policy_bfq, seq_cft(sf)->private, true);
  768. return 0;
  769. }
  770. static u64 bfqg_prfill_stat_recursive(struct seq_file *sf,
  771. struct blkg_policy_data *pd, int off)
  772. {
  773. u64 sum = blkg_stat_recursive_sum(pd_to_blkg(pd),
  774. &blkcg_policy_bfq, off);
  775. return __blkg_prfill_u64(sf, pd, sum);
  776. }
  777. static u64 bfqg_prfill_rwstat_recursive(struct seq_file *sf,
  778. struct blkg_policy_data *pd, int off)
  779. {
  780. struct blkg_rwstat sum = blkg_rwstat_recursive_sum(pd_to_blkg(pd),
  781. &blkcg_policy_bfq,
  782. off);
  783. return __blkg_prfill_rwstat(sf, pd, &sum);
  784. }
  785. static int bfqg_print_stat_recursive(struct seq_file *sf, void *v)
  786. {
  787. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  788. bfqg_prfill_stat_recursive, &blkcg_policy_bfq,
  789. seq_cft(sf)->private, false);
  790. return 0;
  791. }
  792. static int bfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
  793. {
  794. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  795. bfqg_prfill_rwstat_recursive, &blkcg_policy_bfq,
  796. seq_cft(sf)->private, true);
  797. return 0;
  798. }
  799. static u64 bfqg_prfill_sectors(struct seq_file *sf, struct blkg_policy_data *pd,
  800. int off)
  801. {
  802. u64 sum = blkg_rwstat_total(&pd->blkg->stat_bytes);
  803. return __blkg_prfill_u64(sf, pd, sum >> 9);
  804. }
  805. static int bfqg_print_stat_sectors(struct seq_file *sf, void *v)
  806. {
  807. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  808. bfqg_prfill_sectors, &blkcg_policy_bfq, 0, false);
  809. return 0;
  810. }
  811. static u64 bfqg_prfill_sectors_recursive(struct seq_file *sf,
  812. struct blkg_policy_data *pd, int off)
  813. {
  814. struct blkg_rwstat tmp = blkg_rwstat_recursive_sum(pd->blkg, NULL,
  815. offsetof(struct blkcg_gq, stat_bytes));
  816. u64 sum = atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_READ]) +
  817. atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_WRITE]);
  818. return __blkg_prfill_u64(sf, pd, sum >> 9);
  819. }
  820. static int bfqg_print_stat_sectors_recursive(struct seq_file *sf, void *v)
  821. {
  822. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  823. bfqg_prfill_sectors_recursive, &blkcg_policy_bfq, 0,
  824. false);
  825. return 0;
  826. }
  827. static u64 bfqg_prfill_avg_queue_size(struct seq_file *sf,
  828. struct blkg_policy_data *pd, int off)
  829. {
  830. struct bfq_group *bfqg = pd_to_bfqg(pd);
  831. u64 samples = blkg_stat_read(&bfqg->stats.avg_queue_size_samples);
  832. u64 v = 0;
  833. if (samples) {
  834. v = blkg_stat_read(&bfqg->stats.avg_queue_size_sum);
  835. v = div64_u64(v, samples);
  836. }
  837. __blkg_prfill_u64(sf, pd, v);
  838. return 0;
  839. }
  840. /* print avg_queue_size */
  841. static int bfqg_print_avg_queue_size(struct seq_file *sf, void *v)
  842. {
  843. blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  844. bfqg_prfill_avg_queue_size, &blkcg_policy_bfq,
  845. 0, false);
  846. return 0;
  847. }
  848. struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
  849. {
  850. int ret;
  851. ret = blkcg_activate_policy(bfqd->queue, &blkcg_policy_bfq);
  852. if (ret)
  853. return NULL;
  854. return blkg_to_bfqg(bfqd->queue->root_blkg);
  855. }
  856. struct blkcg_policy blkcg_policy_bfq = {
  857. .dfl_cftypes = bfq_blkg_files,
  858. .legacy_cftypes = bfq_blkcg_legacy_files,
  859. .cpd_alloc_fn = bfq_cpd_alloc,
  860. .cpd_init_fn = bfq_cpd_init,
  861. .cpd_bind_fn = bfq_cpd_init,
  862. .cpd_free_fn = bfq_cpd_free,
  863. .pd_alloc_fn = bfq_pd_alloc,
  864. .pd_init_fn = bfq_pd_init,
  865. .pd_offline_fn = bfq_pd_offline,
  866. .pd_free_fn = bfq_pd_free,
  867. .pd_reset_stats_fn = bfq_pd_reset_stats,
  868. };
  869. struct cftype bfq_blkcg_legacy_files[] = {
  870. {
  871. .name = "bfq.weight",
  872. .flags = CFTYPE_NOT_ON_ROOT,
  873. .seq_show = bfq_io_show_weight,
  874. .write_u64 = bfq_io_set_weight_legacy,
  875. },
  876. /* statistics, covers only the tasks in the bfqg */
  877. {
  878. .name = "bfq.time",
  879. .private = offsetof(struct bfq_group, stats.time),
  880. .seq_show = bfqg_print_stat,
  881. },
  882. {
  883. .name = "bfq.sectors",
  884. .seq_show = bfqg_print_stat_sectors,
  885. },
  886. {
  887. .name = "bfq.io_service_bytes",
  888. .private = (unsigned long)&blkcg_policy_bfq,
  889. .seq_show = blkg_print_stat_bytes,
  890. },
  891. {
  892. .name = "bfq.io_serviced",
  893. .private = (unsigned long)&blkcg_policy_bfq,
  894. .seq_show = blkg_print_stat_ios,
  895. },
  896. {
  897. .name = "bfq.io_service_time",
  898. .private = offsetof(struct bfq_group, stats.service_time),
  899. .seq_show = bfqg_print_rwstat,
  900. },
  901. {
  902. .name = "bfq.io_wait_time",
  903. .private = offsetof(struct bfq_group, stats.wait_time),
  904. .seq_show = bfqg_print_rwstat,
  905. },
  906. {
  907. .name = "bfq.io_merged",
  908. .private = offsetof(struct bfq_group, stats.merged),
  909. .seq_show = bfqg_print_rwstat,
  910. },
  911. {
  912. .name = "bfq.io_queued",
  913. .private = offsetof(struct bfq_group, stats.queued),
  914. .seq_show = bfqg_print_rwstat,
  915. },
  916. /* the same statictics which cover the bfqg and its descendants */
  917. {
  918. .name = "bfq.time_recursive",
  919. .private = offsetof(struct bfq_group, stats.time),
  920. .seq_show = bfqg_print_stat_recursive,
  921. },
  922. {
  923. .name = "bfq.sectors_recursive",
  924. .seq_show = bfqg_print_stat_sectors_recursive,
  925. },
  926. {
  927. .name = "bfq.io_service_bytes_recursive",
  928. .private = (unsigned long)&blkcg_policy_bfq,
  929. .seq_show = blkg_print_stat_bytes_recursive,
  930. },
  931. {
  932. .name = "bfq.io_serviced_recursive",
  933. .private = (unsigned long)&blkcg_policy_bfq,
  934. .seq_show = blkg_print_stat_ios_recursive,
  935. },
  936. {
  937. .name = "bfq.io_service_time_recursive",
  938. .private = offsetof(struct bfq_group, stats.service_time),
  939. .seq_show = bfqg_print_rwstat_recursive,
  940. },
  941. {
  942. .name = "bfq.io_wait_time_recursive",
  943. .private = offsetof(struct bfq_group, stats.wait_time),
  944. .seq_show = bfqg_print_rwstat_recursive,
  945. },
  946. {
  947. .name = "bfq.io_merged_recursive",
  948. .private = offsetof(struct bfq_group, stats.merged),
  949. .seq_show = bfqg_print_rwstat_recursive,
  950. },
  951. {
  952. .name = "bfq.io_queued_recursive",
  953. .private = offsetof(struct bfq_group, stats.queued),
  954. .seq_show = bfqg_print_rwstat_recursive,
  955. },
  956. {
  957. .name = "bfq.avg_queue_size",
  958. .seq_show = bfqg_print_avg_queue_size,
  959. },
  960. {
  961. .name = "bfq.group_wait_time",
  962. .private = offsetof(struct bfq_group, stats.group_wait_time),
  963. .seq_show = bfqg_print_stat,
  964. },
  965. {
  966. .name = "bfq.idle_time",
  967. .private = offsetof(struct bfq_group, stats.idle_time),
  968. .seq_show = bfqg_print_stat,
  969. },
  970. {
  971. .name = "bfq.empty_time",
  972. .private = offsetof(struct bfq_group, stats.empty_time),
  973. .seq_show = bfqg_print_stat,
  974. },
  975. {
  976. .name = "bfq.dequeue",
  977. .private = offsetof(struct bfq_group, stats.dequeue),
  978. .seq_show = bfqg_print_stat,
  979. },
  980. { } /* terminate */
  981. };
  982. struct cftype bfq_blkg_files[] = {
  983. {
  984. .name = "bfq.weight",
  985. .flags = CFTYPE_NOT_ON_ROOT,
  986. .seq_show = bfq_io_show_weight,
  987. .write = bfq_io_set_weight,
  988. },
  989. {} /* terminate */
  990. };
  991. #else /* CONFIG_BFQ_GROUP_IOSCHED */
  992. void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
  993. unsigned int op) { }
  994. void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op) { }
  995. void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op) { }
  996. void bfqg_stats_update_completion(struct bfq_group *bfqg, uint64_t start_time,
  997. uint64_t io_start_time, unsigned int op) { }
  998. void bfqg_stats_update_dequeue(struct bfq_group *bfqg) { }
  999. void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg) { }
  1000. void bfqg_stats_update_idle_time(struct bfq_group *bfqg) { }
  1001. void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg) { }
  1002. void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg) { }
  1003. void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  1004. struct bfq_group *bfqg) {}
  1005. void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
  1006. {
  1007. struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
  1008. entity->weight = entity->new_weight;
  1009. entity->orig_weight = entity->new_weight;
  1010. if (bfqq) {
  1011. bfqq->ioprio = bfqq->new_ioprio;
  1012. bfqq->ioprio_class = bfqq->new_ioprio_class;
  1013. }
  1014. entity->sched_data = &bfqg->sched_data;
  1015. }
  1016. void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) {}
  1017. void bfq_end_wr_async(struct bfq_data *bfqd)
  1018. {
  1019. bfq_end_wr_async_queues(bfqd, bfqd->root_group);
  1020. }
  1021. struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, struct blkcg *blkcg)
  1022. {
  1023. return bfqd->root_group;
  1024. }
  1025. struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
  1026. {
  1027. return bfqq->bfqd->root_group;
  1028. }
  1029. struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
  1030. {
  1031. struct bfq_group *bfqg;
  1032. int i;
  1033. bfqg = kmalloc_node(sizeof(*bfqg), GFP_KERNEL | __GFP_ZERO, node);
  1034. if (!bfqg)
  1035. return NULL;
  1036. for (i = 0; i < BFQ_IOPRIO_CLASSES; i++)
  1037. bfqg->sched_data.service_tree[i] = BFQ_SERVICE_TREE_INIT;
  1038. return bfqg;
  1039. }
  1040. #endif /* CONFIG_BFQ_GROUP_IOSCHED */