rt.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  1. /*
  2. * Real-Time Scheduling Class (mapped to the SCHED_FIFO and SCHED_RR
  3. * policies)
  4. */
  5. #include "sched.h"
  6. #include <linux/slab.h>
  7. int sched_rr_timeslice = RR_TIMESLICE;
  8. static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun);
  9. struct rt_bandwidth def_rt_bandwidth;
  10. static enum hrtimer_restart sched_rt_period_timer(struct hrtimer *timer)
  11. {
  12. struct rt_bandwidth *rt_b =
  13. container_of(timer, struct rt_bandwidth, rt_period_timer);
  14. ktime_t now;
  15. int overrun;
  16. int idle = 0;
  17. for (;;) {
  18. now = hrtimer_cb_get_time(timer);
  19. overrun = hrtimer_forward(timer, now, rt_b->rt_period);
  20. if (!overrun)
  21. break;
  22. idle = do_sched_rt_period_timer(rt_b, overrun);
  23. }
  24. return idle ? HRTIMER_NORESTART : HRTIMER_RESTART;
  25. }
  26. void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
  27. {
  28. rt_b->rt_period = ns_to_ktime(period);
  29. rt_b->rt_runtime = runtime;
  30. raw_spin_lock_init(&rt_b->rt_runtime_lock);
  31. hrtimer_init(&rt_b->rt_period_timer,
  32. CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  33. rt_b->rt_period_timer.function = sched_rt_period_timer;
  34. }
  35. static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
  36. {
  37. if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
  38. return;
  39. if (hrtimer_active(&rt_b->rt_period_timer))
  40. return;
  41. raw_spin_lock(&rt_b->rt_runtime_lock);
  42. start_bandwidth_timer(&rt_b->rt_period_timer, rt_b->rt_period);
  43. raw_spin_unlock(&rt_b->rt_runtime_lock);
  44. }
  45. void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq)
  46. {
  47. struct rt_prio_array *array;
  48. int i;
  49. array = &rt_rq->active;
  50. for (i = 0; i < MAX_RT_PRIO; i++) {
  51. INIT_LIST_HEAD(array->queue + i);
  52. __clear_bit(i, array->bitmap);
  53. }
  54. /* delimiter for bitsearch: */
  55. __set_bit(MAX_RT_PRIO, array->bitmap);
  56. #if defined CONFIG_SMP
  57. rt_rq->highest_prio.curr = MAX_RT_PRIO;
  58. rt_rq->highest_prio.next = MAX_RT_PRIO;
  59. rt_rq->rt_nr_migratory = 0;
  60. rt_rq->overloaded = 0;
  61. plist_head_init(&rt_rq->pushable_tasks);
  62. #endif
  63. rt_rq->rt_time = 0;
  64. rt_rq->rt_throttled = 0;
  65. rt_rq->rt_runtime = 0;
  66. raw_spin_lock_init(&rt_rq->rt_runtime_lock);
  67. }
  68. #ifdef CONFIG_RT_GROUP_SCHED
  69. static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b)
  70. {
  71. hrtimer_cancel(&rt_b->rt_period_timer);
  72. }
  73. #define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
  74. static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se)
  75. {
  76. #ifdef CONFIG_SCHED_DEBUG
  77. WARN_ON_ONCE(!rt_entity_is_task(rt_se));
  78. #endif
  79. return container_of(rt_se, struct task_struct, rt);
  80. }
  81. static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
  82. {
  83. return rt_rq->rq;
  84. }
  85. static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se)
  86. {
  87. return rt_se->rt_rq;
  88. }
  89. void free_rt_sched_group(struct task_group *tg)
  90. {
  91. int i;
  92. if (tg->rt_se)
  93. destroy_rt_bandwidth(&tg->rt_bandwidth);
  94. for_each_possible_cpu(i) {
  95. if (tg->rt_rq)
  96. kfree(tg->rt_rq[i]);
  97. if (tg->rt_se)
  98. kfree(tg->rt_se[i]);
  99. }
  100. kfree(tg->rt_rq);
  101. kfree(tg->rt_se);
  102. }
  103. void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
  104. struct sched_rt_entity *rt_se, int cpu,
  105. struct sched_rt_entity *parent)
  106. {
  107. struct rq *rq = cpu_rq(cpu);
  108. rt_rq->highest_prio.curr = MAX_RT_PRIO;
  109. rt_rq->rt_nr_boosted = 0;
  110. rt_rq->rq = rq;
  111. rt_rq->tg = tg;
  112. tg->rt_rq[cpu] = rt_rq;
  113. tg->rt_se[cpu] = rt_se;
  114. if (!rt_se)
  115. return;
  116. if (!parent)
  117. rt_se->rt_rq = &rq->rt;
  118. else
  119. rt_se->rt_rq = parent->my_q;
  120. rt_se->my_q = rt_rq;
  121. rt_se->parent = parent;
  122. INIT_LIST_HEAD(&rt_se->run_list);
  123. }
  124. int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
  125. {
  126. struct rt_rq *rt_rq;
  127. struct sched_rt_entity *rt_se;
  128. int i;
  129. tg->rt_rq = kzalloc(sizeof(rt_rq) * nr_cpu_ids, GFP_KERNEL);
  130. if (!tg->rt_rq)
  131. goto err;
  132. tg->rt_se = kzalloc(sizeof(rt_se) * nr_cpu_ids, GFP_KERNEL);
  133. if (!tg->rt_se)
  134. goto err;
  135. init_rt_bandwidth(&tg->rt_bandwidth,
  136. ktime_to_ns(def_rt_bandwidth.rt_period), 0);
  137. for_each_possible_cpu(i) {
  138. rt_rq = kzalloc_node(sizeof(struct rt_rq),
  139. GFP_KERNEL, cpu_to_node(i));
  140. if (!rt_rq)
  141. goto err;
  142. rt_se = kzalloc_node(sizeof(struct sched_rt_entity),
  143. GFP_KERNEL, cpu_to_node(i));
  144. if (!rt_se)
  145. goto err_free_rq;
  146. init_rt_rq(rt_rq, cpu_rq(i));
  147. rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime;
  148. init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]);
  149. }
  150. return 1;
  151. err_free_rq:
  152. kfree(rt_rq);
  153. err:
  154. return 0;
  155. }
  156. #else /* CONFIG_RT_GROUP_SCHED */
  157. #define rt_entity_is_task(rt_se) (1)
  158. static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se)
  159. {
  160. return container_of(rt_se, struct task_struct, rt);
  161. }
  162. static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
  163. {
  164. return container_of(rt_rq, struct rq, rt);
  165. }
  166. static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se)
  167. {
  168. struct task_struct *p = rt_task_of(rt_se);
  169. struct rq *rq = task_rq(p);
  170. return &rq->rt;
  171. }
  172. void free_rt_sched_group(struct task_group *tg) { }
  173. int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
  174. {
  175. return 1;
  176. }
  177. #endif /* CONFIG_RT_GROUP_SCHED */
  178. #ifdef CONFIG_SMP
  179. static inline int rt_overloaded(struct rq *rq)
  180. {
  181. return atomic_read(&rq->rd->rto_count);
  182. }
  183. static inline void rt_set_overload(struct rq *rq)
  184. {
  185. if (!rq->online)
  186. return;
  187. cpumask_set_cpu(rq->cpu, rq->rd->rto_mask);
  188. /*
  189. * Make sure the mask is visible before we set
  190. * the overload count. That is checked to determine
  191. * if we should look at the mask. It would be a shame
  192. * if we looked at the mask, but the mask was not
  193. * updated yet.
  194. *
  195. * Matched by the barrier in pull_rt_task().
  196. */
  197. smp_wmb();
  198. atomic_inc(&rq->rd->rto_count);
  199. }
  200. static inline void rt_clear_overload(struct rq *rq)
  201. {
  202. if (!rq->online)
  203. return;
  204. /* the order here really doesn't matter */
  205. atomic_dec(&rq->rd->rto_count);
  206. cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask);
  207. }
  208. static void update_rt_migration(struct rt_rq *rt_rq)
  209. {
  210. if (rt_rq->rt_nr_migratory && rt_rq->rt_nr_total > 1) {
  211. if (!rt_rq->overloaded) {
  212. rt_set_overload(rq_of_rt_rq(rt_rq));
  213. rt_rq->overloaded = 1;
  214. }
  215. } else if (rt_rq->overloaded) {
  216. rt_clear_overload(rq_of_rt_rq(rt_rq));
  217. rt_rq->overloaded = 0;
  218. }
  219. }
  220. static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  221. {
  222. struct task_struct *p;
  223. if (!rt_entity_is_task(rt_se))
  224. return;
  225. p = rt_task_of(rt_se);
  226. rt_rq = &rq_of_rt_rq(rt_rq)->rt;
  227. rt_rq->rt_nr_total++;
  228. if (p->nr_cpus_allowed > 1)
  229. rt_rq->rt_nr_migratory++;
  230. update_rt_migration(rt_rq);
  231. }
  232. static void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  233. {
  234. struct task_struct *p;
  235. if (!rt_entity_is_task(rt_se))
  236. return;
  237. p = rt_task_of(rt_se);
  238. rt_rq = &rq_of_rt_rq(rt_rq)->rt;
  239. rt_rq->rt_nr_total--;
  240. if (p->nr_cpus_allowed > 1)
  241. rt_rq->rt_nr_migratory--;
  242. update_rt_migration(rt_rq);
  243. }
  244. static inline int has_pushable_tasks(struct rq *rq)
  245. {
  246. return !plist_head_empty(&rq->rt.pushable_tasks);
  247. }
  248. static void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
  249. {
  250. plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
  251. plist_node_init(&p->pushable_tasks, p->prio);
  252. plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks);
  253. /* Update the highest prio pushable task */
  254. if (p->prio < rq->rt.highest_prio.next)
  255. rq->rt.highest_prio.next = p->prio;
  256. }
  257. static void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
  258. {
  259. plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
  260. /* Update the new highest prio pushable task */
  261. if (has_pushable_tasks(rq)) {
  262. p = plist_first_entry(&rq->rt.pushable_tasks,
  263. struct task_struct, pushable_tasks);
  264. rq->rt.highest_prio.next = p->prio;
  265. } else
  266. rq->rt.highest_prio.next = MAX_RT_PRIO;
  267. }
  268. #else
  269. static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
  270. {
  271. }
  272. static inline void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
  273. {
  274. }
  275. static inline
  276. void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  277. {
  278. }
  279. static inline
  280. void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  281. {
  282. }
  283. #endif /* CONFIG_SMP */
  284. static inline int on_rt_rq(struct sched_rt_entity *rt_se)
  285. {
  286. return !list_empty(&rt_se->run_list);
  287. }
  288. #ifdef CONFIG_RT_GROUP_SCHED
  289. static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
  290. {
  291. if (!rt_rq->tg)
  292. return RUNTIME_INF;
  293. return rt_rq->rt_runtime;
  294. }
  295. static inline u64 sched_rt_period(struct rt_rq *rt_rq)
  296. {
  297. return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period);
  298. }
  299. typedef struct task_group *rt_rq_iter_t;
  300. static inline struct task_group *next_task_group(struct task_group *tg)
  301. {
  302. do {
  303. tg = list_entry_rcu(tg->list.next,
  304. typeof(struct task_group), list);
  305. } while (&tg->list != &task_groups && task_group_is_autogroup(tg));
  306. if (&tg->list == &task_groups)
  307. tg = NULL;
  308. return tg;
  309. }
  310. #define for_each_rt_rq(rt_rq, iter, rq) \
  311. for (iter = container_of(&task_groups, typeof(*iter), list); \
  312. (iter = next_task_group(iter)) && \
  313. (rt_rq = iter->rt_rq[cpu_of(rq)]);)
  314. #define for_each_sched_rt_entity(rt_se) \
  315. for (; rt_se; rt_se = rt_se->parent)
  316. static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
  317. {
  318. return rt_se->my_q;
  319. }
  320. static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head);
  321. static void dequeue_rt_entity(struct sched_rt_entity *rt_se);
  322. static void sched_rt_rq_enqueue(struct rt_rq *rt_rq)
  323. {
  324. struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr;
  325. struct sched_rt_entity *rt_se;
  326. int cpu = cpu_of(rq_of_rt_rq(rt_rq));
  327. rt_se = rt_rq->tg->rt_se[cpu];
  328. if (rt_rq->rt_nr_running) {
  329. if (rt_se && !on_rt_rq(rt_se))
  330. enqueue_rt_entity(rt_se, false);
  331. if (rt_rq->highest_prio.curr < curr->prio)
  332. resched_task(curr);
  333. }
  334. }
  335. static void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
  336. {
  337. struct sched_rt_entity *rt_se;
  338. int cpu = cpu_of(rq_of_rt_rq(rt_rq));
  339. rt_se = rt_rq->tg->rt_se[cpu];
  340. if (rt_se && on_rt_rq(rt_se))
  341. dequeue_rt_entity(rt_se);
  342. }
  343. static inline int rt_rq_throttled(struct rt_rq *rt_rq)
  344. {
  345. return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted;
  346. }
  347. static int rt_se_boosted(struct sched_rt_entity *rt_se)
  348. {
  349. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  350. struct task_struct *p;
  351. if (rt_rq)
  352. return !!rt_rq->rt_nr_boosted;
  353. p = rt_task_of(rt_se);
  354. return p->prio != p->normal_prio;
  355. }
  356. #ifdef CONFIG_SMP
  357. static inline const struct cpumask *sched_rt_period_mask(void)
  358. {
  359. return this_rq()->rd->span;
  360. }
  361. #else
  362. static inline const struct cpumask *sched_rt_period_mask(void)
  363. {
  364. return cpu_online_mask;
  365. }
  366. #endif
  367. static inline
  368. struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
  369. {
  370. return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu];
  371. }
  372. static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
  373. {
  374. return &rt_rq->tg->rt_bandwidth;
  375. }
  376. #else /* !CONFIG_RT_GROUP_SCHED */
  377. static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
  378. {
  379. return rt_rq->rt_runtime;
  380. }
  381. static inline u64 sched_rt_period(struct rt_rq *rt_rq)
  382. {
  383. return ktime_to_ns(def_rt_bandwidth.rt_period);
  384. }
  385. typedef struct rt_rq *rt_rq_iter_t;
  386. #define for_each_rt_rq(rt_rq, iter, rq) \
  387. for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
  388. #define for_each_sched_rt_entity(rt_se) \
  389. for (; rt_se; rt_se = NULL)
  390. static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
  391. {
  392. return NULL;
  393. }
  394. static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq)
  395. {
  396. if (rt_rq->rt_nr_running)
  397. resched_task(rq_of_rt_rq(rt_rq)->curr);
  398. }
  399. static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
  400. {
  401. }
  402. static inline int rt_rq_throttled(struct rt_rq *rt_rq)
  403. {
  404. return rt_rq->rt_throttled;
  405. }
  406. static inline const struct cpumask *sched_rt_period_mask(void)
  407. {
  408. return cpu_online_mask;
  409. }
  410. static inline
  411. struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
  412. {
  413. return &cpu_rq(cpu)->rt;
  414. }
  415. static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
  416. {
  417. return &def_rt_bandwidth;
  418. }
  419. #endif /* CONFIG_RT_GROUP_SCHED */
  420. #ifdef CONFIG_SMP
  421. /*
  422. * We ran out of runtime, see if we can borrow some from our neighbours.
  423. */
  424. static int do_balance_runtime(struct rt_rq *rt_rq)
  425. {
  426. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  427. struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd;
  428. int i, weight, more = 0;
  429. u64 rt_period;
  430. weight = cpumask_weight(rd->span);
  431. raw_spin_lock(&rt_b->rt_runtime_lock);
  432. rt_period = ktime_to_ns(rt_b->rt_period);
  433. for_each_cpu(i, rd->span) {
  434. struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
  435. s64 diff;
  436. if (iter == rt_rq)
  437. continue;
  438. raw_spin_lock(&iter->rt_runtime_lock);
  439. /*
  440. * Either all rqs have inf runtime and there's nothing to steal
  441. * or __disable_runtime() below sets a specific rq to inf to
  442. * indicate its been disabled and disalow stealing.
  443. */
  444. if (iter->rt_runtime == RUNTIME_INF)
  445. goto next;
  446. /*
  447. * From runqueues with spare time, take 1/n part of their
  448. * spare time, but no more than our period.
  449. */
  450. diff = iter->rt_runtime - iter->rt_time;
  451. if (diff > 0) {
  452. diff = div_u64((u64)diff, weight);
  453. if (rt_rq->rt_runtime + diff > rt_period)
  454. diff = rt_period - rt_rq->rt_runtime;
  455. iter->rt_runtime -= diff;
  456. rt_rq->rt_runtime += diff;
  457. more = 1;
  458. if (rt_rq->rt_runtime == rt_period) {
  459. raw_spin_unlock(&iter->rt_runtime_lock);
  460. break;
  461. }
  462. }
  463. next:
  464. raw_spin_unlock(&iter->rt_runtime_lock);
  465. }
  466. raw_spin_unlock(&rt_b->rt_runtime_lock);
  467. return more;
  468. }
  469. /*
  470. * Ensure this RQ takes back all the runtime it lend to its neighbours.
  471. */
  472. static void __disable_runtime(struct rq *rq)
  473. {
  474. struct root_domain *rd = rq->rd;
  475. rt_rq_iter_t iter;
  476. struct rt_rq *rt_rq;
  477. if (unlikely(!scheduler_running))
  478. return;
  479. for_each_rt_rq(rt_rq, iter, rq) {
  480. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  481. s64 want;
  482. int i;
  483. raw_spin_lock(&rt_b->rt_runtime_lock);
  484. raw_spin_lock(&rt_rq->rt_runtime_lock);
  485. /*
  486. * Either we're all inf and nobody needs to borrow, or we're
  487. * already disabled and thus have nothing to do, or we have
  488. * exactly the right amount of runtime to take out.
  489. */
  490. if (rt_rq->rt_runtime == RUNTIME_INF ||
  491. rt_rq->rt_runtime == rt_b->rt_runtime)
  492. goto balanced;
  493. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  494. /*
  495. * Calculate the difference between what we started out with
  496. * and what we current have, that's the amount of runtime
  497. * we lend and now have to reclaim.
  498. */
  499. want = rt_b->rt_runtime - rt_rq->rt_runtime;
  500. /*
  501. * Greedy reclaim, take back as much as we can.
  502. */
  503. for_each_cpu(i, rd->span) {
  504. struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
  505. s64 diff;
  506. /*
  507. * Can't reclaim from ourselves or disabled runqueues.
  508. */
  509. if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF)
  510. continue;
  511. raw_spin_lock(&iter->rt_runtime_lock);
  512. if (want > 0) {
  513. diff = min_t(s64, iter->rt_runtime, want);
  514. iter->rt_runtime -= diff;
  515. want -= diff;
  516. } else {
  517. iter->rt_runtime -= want;
  518. want -= want;
  519. }
  520. raw_spin_unlock(&iter->rt_runtime_lock);
  521. if (!want)
  522. break;
  523. }
  524. raw_spin_lock(&rt_rq->rt_runtime_lock);
  525. /*
  526. * We cannot be left wanting - that would mean some runtime
  527. * leaked out of the system.
  528. */
  529. BUG_ON(want);
  530. balanced:
  531. /*
  532. * Disable all the borrow logic by pretending we have inf
  533. * runtime - in which case borrowing doesn't make sense.
  534. */
  535. rt_rq->rt_runtime = RUNTIME_INF;
  536. rt_rq->rt_throttled = 0;
  537. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  538. raw_spin_unlock(&rt_b->rt_runtime_lock);
  539. }
  540. }
  541. static void __enable_runtime(struct rq *rq)
  542. {
  543. rt_rq_iter_t iter;
  544. struct rt_rq *rt_rq;
  545. if (unlikely(!scheduler_running))
  546. return;
  547. /*
  548. * Reset each runqueue's bandwidth settings
  549. */
  550. for_each_rt_rq(rt_rq, iter, rq) {
  551. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  552. raw_spin_lock(&rt_b->rt_runtime_lock);
  553. raw_spin_lock(&rt_rq->rt_runtime_lock);
  554. rt_rq->rt_runtime = rt_b->rt_runtime;
  555. rt_rq->rt_time = 0;
  556. rt_rq->rt_throttled = 0;
  557. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  558. raw_spin_unlock(&rt_b->rt_runtime_lock);
  559. }
  560. }
  561. static int balance_runtime(struct rt_rq *rt_rq)
  562. {
  563. int more = 0;
  564. if (!sched_feat(RT_RUNTIME_SHARE))
  565. return more;
  566. if (rt_rq->rt_time > rt_rq->rt_runtime) {
  567. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  568. more = do_balance_runtime(rt_rq);
  569. raw_spin_lock(&rt_rq->rt_runtime_lock);
  570. }
  571. return more;
  572. }
  573. #else /* !CONFIG_SMP */
  574. static inline int balance_runtime(struct rt_rq *rt_rq)
  575. {
  576. return 0;
  577. }
  578. #endif /* CONFIG_SMP */
  579. static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
  580. {
  581. int i, idle = 1, throttled = 0;
  582. const struct cpumask *span;
  583. span = sched_rt_period_mask();
  584. #ifdef CONFIG_RT_GROUP_SCHED
  585. /*
  586. * FIXME: isolated CPUs should really leave the root task group,
  587. * whether they are isolcpus or were isolated via cpusets, lest
  588. * the timer run on a CPU which does not service all runqueues,
  589. * potentially leaving other CPUs indefinitely throttled. If
  590. * isolation is really required, the user will turn the throttle
  591. * off to kill the perturbations it causes anyway. Meanwhile,
  592. * this maintains functionality for boot and/or troubleshooting.
  593. */
  594. if (rt_b == &root_task_group.rt_bandwidth)
  595. span = cpu_online_mask;
  596. #endif
  597. for_each_cpu(i, span) {
  598. int enqueue = 0;
  599. struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
  600. struct rq *rq = rq_of_rt_rq(rt_rq);
  601. raw_spin_lock(&rq->lock);
  602. if (rt_rq->rt_time) {
  603. u64 runtime;
  604. raw_spin_lock(&rt_rq->rt_runtime_lock);
  605. if (rt_rq->rt_throttled)
  606. balance_runtime(rt_rq);
  607. runtime = rt_rq->rt_runtime;
  608. rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
  609. if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
  610. rt_rq->rt_throttled = 0;
  611. enqueue = 1;
  612. /*
  613. * Force a clock update if the CPU was idle,
  614. * lest wakeup -> unthrottle time accumulate.
  615. */
  616. if (rt_rq->rt_nr_running && rq->curr == rq->idle)
  617. rq->skip_clock_update = -1;
  618. }
  619. if (rt_rq->rt_time || rt_rq->rt_nr_running)
  620. idle = 0;
  621. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  622. } else if (rt_rq->rt_nr_running) {
  623. idle = 0;
  624. if (!rt_rq_throttled(rt_rq))
  625. enqueue = 1;
  626. }
  627. if (rt_rq->rt_throttled)
  628. throttled = 1;
  629. if (enqueue)
  630. sched_rt_rq_enqueue(rt_rq);
  631. raw_spin_unlock(&rq->lock);
  632. }
  633. if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF))
  634. return 1;
  635. return idle;
  636. }
  637. static inline int rt_se_prio(struct sched_rt_entity *rt_se)
  638. {
  639. #ifdef CONFIG_RT_GROUP_SCHED
  640. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  641. if (rt_rq)
  642. return rt_rq->highest_prio.curr;
  643. #endif
  644. return rt_task_of(rt_se)->prio;
  645. }
  646. static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
  647. {
  648. u64 runtime = sched_rt_runtime(rt_rq);
  649. if (rt_rq->rt_throttled)
  650. return rt_rq_throttled(rt_rq);
  651. if (runtime >= sched_rt_period(rt_rq))
  652. return 0;
  653. balance_runtime(rt_rq);
  654. runtime = sched_rt_runtime(rt_rq);
  655. if (runtime == RUNTIME_INF)
  656. return 0;
  657. if (rt_rq->rt_time > runtime) {
  658. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  659. /*
  660. * Don't actually throttle groups that have no runtime assigned
  661. * but accrue some time due to boosting.
  662. */
  663. if (likely(rt_b->rt_runtime)) {
  664. static bool once = false;
  665. rt_rq->rt_throttled = 1;
  666. if (!once) {
  667. once = true;
  668. printk_sched("sched: RT throttling activated\n");
  669. }
  670. } else {
  671. /*
  672. * In case we did anyway, make it go away,
  673. * replenishment is a joke, since it will replenish us
  674. * with exactly 0 ns.
  675. */
  676. rt_rq->rt_time = 0;
  677. }
  678. if (rt_rq_throttled(rt_rq)) {
  679. sched_rt_rq_dequeue(rt_rq);
  680. return 1;
  681. }
  682. }
  683. return 0;
  684. }
  685. /*
  686. * Update the current task's runtime statistics. Skip current tasks that
  687. * are not in our scheduling class.
  688. */
  689. static void update_curr_rt(struct rq *rq)
  690. {
  691. struct task_struct *curr = rq->curr;
  692. struct sched_rt_entity *rt_se = &curr->rt;
  693. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  694. u64 delta_exec;
  695. if (curr->sched_class != &rt_sched_class)
  696. return;
  697. delta_exec = rq_clock_task(rq) - curr->se.exec_start;
  698. if (unlikely((s64)delta_exec <= 0))
  699. return;
  700. schedstat_set(curr->se.statistics.exec_max,
  701. max(curr->se.statistics.exec_max, delta_exec));
  702. curr->se.sum_exec_runtime += delta_exec;
  703. account_group_exec_runtime(curr, delta_exec);
  704. curr->se.exec_start = rq_clock_task(rq);
  705. cpuacct_charge(curr, delta_exec);
  706. sched_rt_avg_update(rq, delta_exec);
  707. if (!rt_bandwidth_enabled())
  708. return;
  709. for_each_sched_rt_entity(rt_se) {
  710. rt_rq = rt_rq_of_se(rt_se);
  711. if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
  712. raw_spin_lock(&rt_rq->rt_runtime_lock);
  713. rt_rq->rt_time += delta_exec;
  714. if (sched_rt_runtime_exceeded(rt_rq))
  715. resched_task(curr);
  716. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  717. }
  718. }
  719. }
  720. #if defined CONFIG_SMP
  721. static void
  722. inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
  723. {
  724. struct rq *rq = rq_of_rt_rq(rt_rq);
  725. if (rq->online && prio < prev_prio)
  726. cpupri_set(&rq->rd->cpupri, rq->cpu, prio);
  727. }
  728. static void
  729. dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
  730. {
  731. struct rq *rq = rq_of_rt_rq(rt_rq);
  732. if (rq->online && rt_rq->highest_prio.curr != prev_prio)
  733. cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr);
  734. }
  735. #else /* CONFIG_SMP */
  736. static inline
  737. void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  738. static inline
  739. void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  740. #endif /* CONFIG_SMP */
  741. #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
  742. static void
  743. inc_rt_prio(struct rt_rq *rt_rq, int prio)
  744. {
  745. int prev_prio = rt_rq->highest_prio.curr;
  746. if (prio < prev_prio)
  747. rt_rq->highest_prio.curr = prio;
  748. inc_rt_prio_smp(rt_rq, prio, prev_prio);
  749. }
  750. static void
  751. dec_rt_prio(struct rt_rq *rt_rq, int prio)
  752. {
  753. int prev_prio = rt_rq->highest_prio.curr;
  754. if (rt_rq->rt_nr_running) {
  755. WARN_ON(prio < prev_prio);
  756. /*
  757. * This may have been our highest task, and therefore
  758. * we may have some recomputation to do
  759. */
  760. if (prio == prev_prio) {
  761. struct rt_prio_array *array = &rt_rq->active;
  762. rt_rq->highest_prio.curr =
  763. sched_find_first_bit(array->bitmap);
  764. }
  765. } else
  766. rt_rq->highest_prio.curr = MAX_RT_PRIO;
  767. dec_rt_prio_smp(rt_rq, prio, prev_prio);
  768. }
  769. #else
  770. static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {}
  771. static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {}
  772. #endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */
  773. #ifdef CONFIG_RT_GROUP_SCHED
  774. static void
  775. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  776. {
  777. if (rt_se_boosted(rt_se))
  778. rt_rq->rt_nr_boosted++;
  779. if (rt_rq->tg)
  780. start_rt_bandwidth(&rt_rq->tg->rt_bandwidth);
  781. }
  782. static void
  783. dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  784. {
  785. if (rt_se_boosted(rt_se))
  786. rt_rq->rt_nr_boosted--;
  787. WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted);
  788. }
  789. #else /* CONFIG_RT_GROUP_SCHED */
  790. static void
  791. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  792. {
  793. start_rt_bandwidth(&def_rt_bandwidth);
  794. }
  795. static inline
  796. void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {}
  797. #endif /* CONFIG_RT_GROUP_SCHED */
  798. static inline
  799. void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  800. {
  801. int prio = rt_se_prio(rt_se);
  802. WARN_ON(!rt_prio(prio));
  803. rt_rq->rt_nr_running++;
  804. inc_rt_prio(rt_rq, prio);
  805. inc_rt_migration(rt_se, rt_rq);
  806. inc_rt_group(rt_se, rt_rq);
  807. }
  808. static inline
  809. void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  810. {
  811. WARN_ON(!rt_prio(rt_se_prio(rt_se)));
  812. WARN_ON(!rt_rq->rt_nr_running);
  813. rt_rq->rt_nr_running--;
  814. dec_rt_prio(rt_rq, rt_se_prio(rt_se));
  815. dec_rt_migration(rt_se, rt_rq);
  816. dec_rt_group(rt_se, rt_rq);
  817. }
  818. static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  819. {
  820. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  821. struct rt_prio_array *array = &rt_rq->active;
  822. struct rt_rq *group_rq = group_rt_rq(rt_se);
  823. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  824. /*
  825. * Don't enqueue the group if its throttled, or when empty.
  826. * The latter is a consequence of the former when a child group
  827. * get throttled and the current group doesn't have any other
  828. * active members.
  829. */
  830. if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running))
  831. return;
  832. if (head)
  833. list_add(&rt_se->run_list, queue);
  834. else
  835. list_add_tail(&rt_se->run_list, queue);
  836. __set_bit(rt_se_prio(rt_se), array->bitmap);
  837. inc_rt_tasks(rt_se, rt_rq);
  838. }
  839. static void __dequeue_rt_entity(struct sched_rt_entity *rt_se)
  840. {
  841. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  842. struct rt_prio_array *array = &rt_rq->active;
  843. list_del_init(&rt_se->run_list);
  844. if (list_empty(array->queue + rt_se_prio(rt_se)))
  845. __clear_bit(rt_se_prio(rt_se), array->bitmap);
  846. dec_rt_tasks(rt_se, rt_rq);
  847. }
  848. /*
  849. * Because the prio of an upper entry depends on the lower
  850. * entries, we must remove entries top - down.
  851. */
  852. static void dequeue_rt_stack(struct sched_rt_entity *rt_se)
  853. {
  854. struct sched_rt_entity *back = NULL;
  855. for_each_sched_rt_entity(rt_se) {
  856. rt_se->back = back;
  857. back = rt_se;
  858. }
  859. for (rt_se = back; rt_se; rt_se = rt_se->back) {
  860. if (on_rt_rq(rt_se))
  861. __dequeue_rt_entity(rt_se);
  862. }
  863. }
  864. static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  865. {
  866. dequeue_rt_stack(rt_se);
  867. for_each_sched_rt_entity(rt_se)
  868. __enqueue_rt_entity(rt_se, head);
  869. }
  870. static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
  871. {
  872. dequeue_rt_stack(rt_se);
  873. for_each_sched_rt_entity(rt_se) {
  874. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  875. if (rt_rq && rt_rq->rt_nr_running)
  876. __enqueue_rt_entity(rt_se, false);
  877. }
  878. }
  879. /*
  880. * Adding/removing a task to/from a priority array:
  881. */
  882. static void
  883. enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  884. {
  885. struct sched_rt_entity *rt_se = &p->rt;
  886. if (flags & ENQUEUE_WAKEUP)
  887. rt_se->timeout = 0;
  888. enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
  889. if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
  890. enqueue_pushable_task(rq, p);
  891. inc_nr_running(rq);
  892. }
  893. static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  894. {
  895. struct sched_rt_entity *rt_se = &p->rt;
  896. update_curr_rt(rq);
  897. dequeue_rt_entity(rt_se);
  898. dequeue_pushable_task(rq, p);
  899. dec_nr_running(rq);
  900. }
  901. /*
  902. * Put task to the head or the end of the run list without the overhead of
  903. * dequeue followed by enqueue.
  904. */
  905. static void
  906. requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head)
  907. {
  908. if (on_rt_rq(rt_se)) {
  909. struct rt_prio_array *array = &rt_rq->active;
  910. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  911. if (head)
  912. list_move(&rt_se->run_list, queue);
  913. else
  914. list_move_tail(&rt_se->run_list, queue);
  915. }
  916. }
  917. static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
  918. {
  919. struct sched_rt_entity *rt_se = &p->rt;
  920. struct rt_rq *rt_rq;
  921. for_each_sched_rt_entity(rt_se) {
  922. rt_rq = rt_rq_of_se(rt_se);
  923. requeue_rt_entity(rt_rq, rt_se, head);
  924. }
  925. }
  926. static void yield_task_rt(struct rq *rq)
  927. {
  928. requeue_task_rt(rq, rq->curr, 0);
  929. }
  930. #ifdef CONFIG_SMP
  931. static int find_lowest_rq(struct task_struct *task);
  932. static int
  933. select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags)
  934. {
  935. struct task_struct *curr;
  936. struct rq *rq;
  937. if (p->nr_cpus_allowed == 1)
  938. goto out;
  939. /* For anything but wake ups, just return the task_cpu */
  940. if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
  941. goto out;
  942. rq = cpu_rq(cpu);
  943. rcu_read_lock();
  944. curr = ACCESS_ONCE(rq->curr); /* unlocked access */
  945. /*
  946. * If the current task on @p's runqueue is an RT task, then
  947. * try to see if we can wake this RT task up on another
  948. * runqueue. Otherwise simply start this RT task
  949. * on its current runqueue.
  950. *
  951. * We want to avoid overloading runqueues. If the woken
  952. * task is a higher priority, then it will stay on this CPU
  953. * and the lower prio task should be moved to another CPU.
  954. * Even though this will probably make the lower prio task
  955. * lose its cache, we do not want to bounce a higher task
  956. * around just because it gave up its CPU, perhaps for a
  957. * lock?
  958. *
  959. * For equal prio tasks, we just let the scheduler sort it out.
  960. *
  961. * Otherwise, just let it ride on the affined RQ and the
  962. * post-schedule router will push the preempted task away
  963. *
  964. * This test is optimistic, if we get it wrong the load-balancer
  965. * will have to sort it out.
  966. */
  967. if (curr && unlikely(rt_task(curr)) &&
  968. (curr->nr_cpus_allowed < 2 ||
  969. curr->prio <= p->prio)) {
  970. int target = find_lowest_rq(p);
  971. if (target != -1)
  972. cpu = target;
  973. }
  974. rcu_read_unlock();
  975. out:
  976. return cpu;
  977. }
  978. static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
  979. {
  980. if (rq->curr->nr_cpus_allowed == 1)
  981. return;
  982. if (p->nr_cpus_allowed != 1
  983. && cpupri_find(&rq->rd->cpupri, p, NULL))
  984. return;
  985. if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
  986. return;
  987. /*
  988. * There appears to be other cpus that can accept
  989. * current and none to run 'p', so lets reschedule
  990. * to try and push current away:
  991. */
  992. requeue_task_rt(rq, p, 1);
  993. resched_task(rq->curr);
  994. }
  995. #endif /* CONFIG_SMP */
  996. /*
  997. * Preempt the current task with a newly woken task if needed:
  998. */
  999. static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags)
  1000. {
  1001. if (p->prio < rq->curr->prio) {
  1002. resched_task(rq->curr);
  1003. return;
  1004. }
  1005. #ifdef CONFIG_SMP
  1006. /*
  1007. * If:
  1008. *
  1009. * - the newly woken task is of equal priority to the current task
  1010. * - the newly woken task is non-migratable while current is migratable
  1011. * - current will be preempted on the next reschedule
  1012. *
  1013. * we should check to see if current can readily move to a different
  1014. * cpu. If so, we will reschedule to allow the push logic to try
  1015. * to move current somewhere else, making room for our non-migratable
  1016. * task.
  1017. */
  1018. if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr))
  1019. check_preempt_equal_prio(rq, p);
  1020. #endif
  1021. }
  1022. static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq,
  1023. struct rt_rq *rt_rq)
  1024. {
  1025. struct rt_prio_array *array = &rt_rq->active;
  1026. struct sched_rt_entity *next = NULL;
  1027. struct list_head *queue;
  1028. int idx;
  1029. idx = sched_find_first_bit(array->bitmap);
  1030. BUG_ON(idx >= MAX_RT_PRIO);
  1031. queue = array->queue + idx;
  1032. next = list_entry(queue->next, struct sched_rt_entity, run_list);
  1033. return next;
  1034. }
  1035. static struct task_struct *_pick_next_task_rt(struct rq *rq)
  1036. {
  1037. struct sched_rt_entity *rt_se;
  1038. struct task_struct *p;
  1039. struct rt_rq *rt_rq;
  1040. rt_rq = &rq->rt;
  1041. if (!rt_rq->rt_nr_running)
  1042. return NULL;
  1043. if (rt_rq_throttled(rt_rq))
  1044. return NULL;
  1045. do {
  1046. rt_se = pick_next_rt_entity(rq, rt_rq);
  1047. BUG_ON(!rt_se);
  1048. rt_rq = group_rt_rq(rt_se);
  1049. } while (rt_rq);
  1050. p = rt_task_of(rt_se);
  1051. p->se.exec_start = rq_clock_task(rq);
  1052. return p;
  1053. }
  1054. static struct task_struct *pick_next_task_rt(struct rq *rq)
  1055. {
  1056. struct task_struct *p = _pick_next_task_rt(rq);
  1057. /* The running task is never eligible for pushing */
  1058. if (p)
  1059. dequeue_pushable_task(rq, p);
  1060. #ifdef CONFIG_SMP
  1061. /*
  1062. * We detect this state here so that we can avoid taking the RQ
  1063. * lock again later if there is no need to push
  1064. */
  1065. rq->post_schedule = has_pushable_tasks(rq);
  1066. #endif
  1067. return p;
  1068. }
  1069. static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
  1070. {
  1071. update_curr_rt(rq);
  1072. /*
  1073. * The previous task needs to be made eligible for pushing
  1074. * if it is still active
  1075. */
  1076. if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
  1077. enqueue_pushable_task(rq, p);
  1078. }
  1079. #ifdef CONFIG_SMP
  1080. /* Only try algorithms three times */
  1081. #define RT_MAX_TRIES 3
  1082. static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
  1083. {
  1084. if (!task_running(rq, p) &&
  1085. cpumask_test_cpu(cpu, tsk_cpus_allowed(p)))
  1086. return 1;
  1087. return 0;
  1088. }
  1089. /*
  1090. * Return the highest pushable rq's task, which is suitable to be executed
  1091. * on the cpu, NULL otherwise
  1092. */
  1093. static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu)
  1094. {
  1095. struct plist_head *head = &rq->rt.pushable_tasks;
  1096. struct task_struct *p;
  1097. if (!has_pushable_tasks(rq))
  1098. return NULL;
  1099. plist_for_each_entry(p, head, pushable_tasks) {
  1100. if (pick_rt_task(rq, p, cpu))
  1101. return p;
  1102. }
  1103. return NULL;
  1104. }
  1105. static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask);
  1106. static int find_lowest_rq(struct task_struct *task)
  1107. {
  1108. struct sched_domain *sd;
  1109. struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask);
  1110. int this_cpu = smp_processor_id();
  1111. int cpu = task_cpu(task);
  1112. /* Make sure the mask is initialized first */
  1113. if (unlikely(!lowest_mask))
  1114. return -1;
  1115. if (task->nr_cpus_allowed == 1)
  1116. return -1; /* No other targets possible */
  1117. if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
  1118. return -1; /* No targets found */
  1119. /*
  1120. * At this point we have built a mask of cpus representing the
  1121. * lowest priority tasks in the system. Now we want to elect
  1122. * the best one based on our affinity and topology.
  1123. *
  1124. * We prioritize the last cpu that the task executed on since
  1125. * it is most likely cache-hot in that location.
  1126. */
  1127. if (cpumask_test_cpu(cpu, lowest_mask))
  1128. return cpu;
  1129. /*
  1130. * Otherwise, we consult the sched_domains span maps to figure
  1131. * out which cpu is logically closest to our hot cache data.
  1132. */
  1133. if (!cpumask_test_cpu(this_cpu, lowest_mask))
  1134. this_cpu = -1; /* Skip this_cpu opt if not among lowest */
  1135. rcu_read_lock();
  1136. for_each_domain(cpu, sd) {
  1137. if (sd->flags & SD_WAKE_AFFINE) {
  1138. int best_cpu;
  1139. /*
  1140. * "this_cpu" is cheaper to preempt than a
  1141. * remote processor.
  1142. */
  1143. if (this_cpu != -1 &&
  1144. cpumask_test_cpu(this_cpu, sched_domain_span(sd))) {
  1145. rcu_read_unlock();
  1146. return this_cpu;
  1147. }
  1148. best_cpu = cpumask_first_and(lowest_mask,
  1149. sched_domain_span(sd));
  1150. if (best_cpu < nr_cpu_ids) {
  1151. rcu_read_unlock();
  1152. return best_cpu;
  1153. }
  1154. }
  1155. }
  1156. rcu_read_unlock();
  1157. /*
  1158. * And finally, if there were no matches within the domains
  1159. * just give the caller *something* to work with from the compatible
  1160. * locations.
  1161. */
  1162. if (this_cpu != -1)
  1163. return this_cpu;
  1164. cpu = cpumask_any(lowest_mask);
  1165. if (cpu < nr_cpu_ids)
  1166. return cpu;
  1167. return -1;
  1168. }
  1169. /* Will lock the rq it finds */
  1170. static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
  1171. {
  1172. struct rq *lowest_rq = NULL;
  1173. int tries;
  1174. int cpu;
  1175. for (tries = 0; tries < RT_MAX_TRIES; tries++) {
  1176. cpu = find_lowest_rq(task);
  1177. if ((cpu == -1) || (cpu == rq->cpu))
  1178. break;
  1179. lowest_rq = cpu_rq(cpu);
  1180. /* if the prio of this runqueue changed, try again */
  1181. if (double_lock_balance(rq, lowest_rq)) {
  1182. /*
  1183. * We had to unlock the run queue. In
  1184. * the mean time, task could have
  1185. * migrated already or had its affinity changed.
  1186. * Also make sure that it wasn't scheduled on its rq.
  1187. */
  1188. if (unlikely(task_rq(task) != rq ||
  1189. !cpumask_test_cpu(lowest_rq->cpu,
  1190. tsk_cpus_allowed(task)) ||
  1191. task_running(rq, task) ||
  1192. !task->on_rq)) {
  1193. double_unlock_balance(rq, lowest_rq);
  1194. lowest_rq = NULL;
  1195. break;
  1196. }
  1197. }
  1198. /* If this rq is still suitable use it. */
  1199. if (lowest_rq->rt.highest_prio.curr > task->prio)
  1200. break;
  1201. /* try again */
  1202. double_unlock_balance(rq, lowest_rq);
  1203. lowest_rq = NULL;
  1204. }
  1205. return lowest_rq;
  1206. }
  1207. static struct task_struct *pick_next_pushable_task(struct rq *rq)
  1208. {
  1209. struct task_struct *p;
  1210. if (!has_pushable_tasks(rq))
  1211. return NULL;
  1212. p = plist_first_entry(&rq->rt.pushable_tasks,
  1213. struct task_struct, pushable_tasks);
  1214. BUG_ON(rq->cpu != task_cpu(p));
  1215. BUG_ON(task_current(rq, p));
  1216. BUG_ON(p->nr_cpus_allowed <= 1);
  1217. BUG_ON(!p->on_rq);
  1218. BUG_ON(!rt_task(p));
  1219. return p;
  1220. }
  1221. /*
  1222. * If the current CPU has more than one RT task, see if the non
  1223. * running task can migrate over to a CPU that is running a task
  1224. * of lesser priority.
  1225. */
  1226. static int push_rt_task(struct rq *rq)
  1227. {
  1228. struct task_struct *next_task;
  1229. struct rq *lowest_rq;
  1230. int ret = 0;
  1231. if (!rq->rt.overloaded)
  1232. return 0;
  1233. next_task = pick_next_pushable_task(rq);
  1234. if (!next_task)
  1235. return 0;
  1236. retry:
  1237. if (unlikely(next_task == rq->curr)) {
  1238. WARN_ON(1);
  1239. return 0;
  1240. }
  1241. /*
  1242. * It's possible that the next_task slipped in of
  1243. * higher priority than current. If that's the case
  1244. * just reschedule current.
  1245. */
  1246. if (unlikely(next_task->prio < rq->curr->prio)) {
  1247. resched_task(rq->curr);
  1248. return 0;
  1249. }
  1250. /* We might release rq lock */
  1251. get_task_struct(next_task);
  1252. /* find_lock_lowest_rq locks the rq if found */
  1253. lowest_rq = find_lock_lowest_rq(next_task, rq);
  1254. if (!lowest_rq) {
  1255. struct task_struct *task;
  1256. /*
  1257. * find_lock_lowest_rq releases rq->lock
  1258. * so it is possible that next_task has migrated.
  1259. *
  1260. * We need to make sure that the task is still on the same
  1261. * run-queue and is also still the next task eligible for
  1262. * pushing.
  1263. */
  1264. task = pick_next_pushable_task(rq);
  1265. if (task_cpu(next_task) == rq->cpu && task == next_task) {
  1266. /*
  1267. * The task hasn't migrated, and is still the next
  1268. * eligible task, but we failed to find a run-queue
  1269. * to push it to. Do not retry in this case, since
  1270. * other cpus will pull from us when ready.
  1271. */
  1272. goto out;
  1273. }
  1274. if (!task)
  1275. /* No more tasks, just exit */
  1276. goto out;
  1277. /*
  1278. * Something has shifted, try again.
  1279. */
  1280. put_task_struct(next_task);
  1281. next_task = task;
  1282. goto retry;
  1283. }
  1284. deactivate_task(rq, next_task, 0);
  1285. set_task_cpu(next_task, lowest_rq->cpu);
  1286. activate_task(lowest_rq, next_task, 0);
  1287. ret = 1;
  1288. resched_task(lowest_rq->curr);
  1289. double_unlock_balance(rq, lowest_rq);
  1290. out:
  1291. put_task_struct(next_task);
  1292. return ret;
  1293. }
  1294. static void push_rt_tasks(struct rq *rq)
  1295. {
  1296. /* push_rt_task will return true if it moved an RT */
  1297. while (push_rt_task(rq))
  1298. ;
  1299. }
  1300. static int pull_rt_task(struct rq *this_rq)
  1301. {
  1302. int this_cpu = this_rq->cpu, ret = 0, cpu;
  1303. struct task_struct *p;
  1304. struct rq *src_rq;
  1305. if (likely(!rt_overloaded(this_rq)))
  1306. return 0;
  1307. /*
  1308. * Match the barrier from rt_set_overloaded; this guarantees that if we
  1309. * see overloaded we must also see the rto_mask bit.
  1310. */
  1311. smp_rmb();
  1312. for_each_cpu(cpu, this_rq->rd->rto_mask) {
  1313. if (this_cpu == cpu)
  1314. continue;
  1315. src_rq = cpu_rq(cpu);
  1316. /*
  1317. * Don't bother taking the src_rq->lock if the next highest
  1318. * task is known to be lower-priority than our current task.
  1319. * This may look racy, but if this value is about to go
  1320. * logically higher, the src_rq will push this task away.
  1321. * And if its going logically lower, we do not care
  1322. */
  1323. if (src_rq->rt.highest_prio.next >=
  1324. this_rq->rt.highest_prio.curr)
  1325. continue;
  1326. /*
  1327. * We can potentially drop this_rq's lock in
  1328. * double_lock_balance, and another CPU could
  1329. * alter this_rq
  1330. */
  1331. double_lock_balance(this_rq, src_rq);
  1332. /*
  1333. * We can pull only a task, which is pushable
  1334. * on its rq, and no others.
  1335. */
  1336. p = pick_highest_pushable_task(src_rq, this_cpu);
  1337. /*
  1338. * Do we have an RT task that preempts
  1339. * the to-be-scheduled task?
  1340. */
  1341. if (p && (p->prio < this_rq->rt.highest_prio.curr)) {
  1342. WARN_ON(p == src_rq->curr);
  1343. WARN_ON(!p->on_rq);
  1344. /*
  1345. * There's a chance that p is higher in priority
  1346. * than what's currently running on its cpu.
  1347. * This is just that p is wakeing up and hasn't
  1348. * had a chance to schedule. We only pull
  1349. * p if it is lower in priority than the
  1350. * current task on the run queue
  1351. */
  1352. if (p->prio < src_rq->curr->prio)
  1353. goto skip;
  1354. ret = 1;
  1355. deactivate_task(src_rq, p, 0);
  1356. set_task_cpu(p, this_cpu);
  1357. activate_task(this_rq, p, 0);
  1358. /*
  1359. * We continue with the search, just in
  1360. * case there's an even higher prio task
  1361. * in another runqueue. (low likelihood
  1362. * but possible)
  1363. */
  1364. }
  1365. skip:
  1366. double_unlock_balance(this_rq, src_rq);
  1367. }
  1368. return ret;
  1369. }
  1370. static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
  1371. {
  1372. /* Try to pull RT tasks here if we lower this rq's prio */
  1373. if (rq->rt.highest_prio.curr > prev->prio)
  1374. pull_rt_task(rq);
  1375. }
  1376. static void post_schedule_rt(struct rq *rq)
  1377. {
  1378. push_rt_tasks(rq);
  1379. }
  1380. /*
  1381. * If we are not running and we are not going to reschedule soon, we should
  1382. * try to push tasks away now
  1383. */
  1384. static void task_woken_rt(struct rq *rq, struct task_struct *p)
  1385. {
  1386. if (!task_running(rq, p) &&
  1387. !test_tsk_need_resched(rq->curr) &&
  1388. has_pushable_tasks(rq) &&
  1389. p->nr_cpus_allowed > 1 &&
  1390. rt_task(rq->curr) &&
  1391. (rq->curr->nr_cpus_allowed < 2 ||
  1392. rq->curr->prio <= p->prio))
  1393. push_rt_tasks(rq);
  1394. }
  1395. static void set_cpus_allowed_rt(struct task_struct *p,
  1396. const struct cpumask *new_mask)
  1397. {
  1398. struct rq *rq;
  1399. int weight;
  1400. BUG_ON(!rt_task(p));
  1401. if (!p->on_rq)
  1402. return;
  1403. weight = cpumask_weight(new_mask);
  1404. /*
  1405. * Only update if the process changes its state from whether it
  1406. * can migrate or not.
  1407. */
  1408. if ((p->nr_cpus_allowed > 1) == (weight > 1))
  1409. return;
  1410. rq = task_rq(p);
  1411. /*
  1412. * The process used to be able to migrate OR it can now migrate
  1413. */
  1414. if (weight <= 1) {
  1415. if (!task_current(rq, p))
  1416. dequeue_pushable_task(rq, p);
  1417. BUG_ON(!rq->rt.rt_nr_migratory);
  1418. rq->rt.rt_nr_migratory--;
  1419. } else {
  1420. if (!task_current(rq, p))
  1421. enqueue_pushable_task(rq, p);
  1422. rq->rt.rt_nr_migratory++;
  1423. }
  1424. update_rt_migration(&rq->rt);
  1425. }
  1426. /* Assumes rq->lock is held */
  1427. static void rq_online_rt(struct rq *rq)
  1428. {
  1429. if (rq->rt.overloaded)
  1430. rt_set_overload(rq);
  1431. __enable_runtime(rq);
  1432. cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
  1433. }
  1434. /* Assumes rq->lock is held */
  1435. static void rq_offline_rt(struct rq *rq)
  1436. {
  1437. if (rq->rt.overloaded)
  1438. rt_clear_overload(rq);
  1439. __disable_runtime(rq);
  1440. cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
  1441. }
  1442. /*
  1443. * When switch from the rt queue, we bring ourselves to a position
  1444. * that we might want to pull RT tasks from other runqueues.
  1445. */
  1446. static void switched_from_rt(struct rq *rq, struct task_struct *p)
  1447. {
  1448. /*
  1449. * If there are other RT tasks then we will reschedule
  1450. * and the scheduling of the other RT tasks will handle
  1451. * the balancing. But if we are the last RT task
  1452. * we may need to handle the pulling of RT tasks
  1453. * now.
  1454. */
  1455. if (!p->on_rq || rq->rt.rt_nr_running)
  1456. return;
  1457. if (pull_rt_task(rq))
  1458. resched_task(rq->curr);
  1459. }
  1460. void init_sched_rt_class(void)
  1461. {
  1462. unsigned int i;
  1463. for_each_possible_cpu(i) {
  1464. zalloc_cpumask_var_node(&per_cpu(local_cpu_mask, i),
  1465. GFP_KERNEL, cpu_to_node(i));
  1466. }
  1467. }
  1468. #endif /* CONFIG_SMP */
  1469. /*
  1470. * When switching a task to RT, we may overload the runqueue
  1471. * with RT tasks. In this case we try to push them off to
  1472. * other runqueues.
  1473. */
  1474. static void switched_to_rt(struct rq *rq, struct task_struct *p)
  1475. {
  1476. int check_resched = 1;
  1477. /*
  1478. * If we are already running, then there's nothing
  1479. * that needs to be done. But if we are not running
  1480. * we may need to preempt the current running task.
  1481. * If that current running task is also an RT task
  1482. * then see if we can move to another run queue.
  1483. */
  1484. if (p->on_rq && rq->curr != p) {
  1485. #ifdef CONFIG_SMP
  1486. if (rq->rt.overloaded && push_rt_task(rq) &&
  1487. /* Don't resched if we changed runqueues */
  1488. rq != task_rq(p))
  1489. check_resched = 0;
  1490. #endif /* CONFIG_SMP */
  1491. if (check_resched && p->prio < rq->curr->prio)
  1492. resched_task(rq->curr);
  1493. }
  1494. }
  1495. /*
  1496. * Priority of the task has changed. This may cause
  1497. * us to initiate a push or pull.
  1498. */
  1499. static void
  1500. prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio)
  1501. {
  1502. if (!p->on_rq)
  1503. return;
  1504. if (rq->curr == p) {
  1505. #ifdef CONFIG_SMP
  1506. /*
  1507. * If our priority decreases while running, we
  1508. * may need to pull tasks to this runqueue.
  1509. */
  1510. if (oldprio < p->prio)
  1511. pull_rt_task(rq);
  1512. /*
  1513. * If there's a higher priority task waiting to run
  1514. * then reschedule. Note, the above pull_rt_task
  1515. * can release the rq lock and p could migrate.
  1516. * Only reschedule if p is still on the same runqueue.
  1517. */
  1518. if (p->prio > rq->rt.highest_prio.curr && rq->curr == p)
  1519. resched_task(p);
  1520. #else
  1521. /* For UP simply resched on drop of prio */
  1522. if (oldprio < p->prio)
  1523. resched_task(p);
  1524. #endif /* CONFIG_SMP */
  1525. } else {
  1526. /*
  1527. * This task is not running, but if it is
  1528. * greater than the current running task
  1529. * then reschedule.
  1530. */
  1531. if (p->prio < rq->curr->prio)
  1532. resched_task(rq->curr);
  1533. }
  1534. }
  1535. static void watchdog(struct rq *rq, struct task_struct *p)
  1536. {
  1537. unsigned long soft, hard;
  1538. /* max may change after cur was read, this will be fixed next tick */
  1539. soft = task_rlimit(p, RLIMIT_RTTIME);
  1540. hard = task_rlimit_max(p, RLIMIT_RTTIME);
  1541. if (soft != RLIM_INFINITY) {
  1542. unsigned long next;
  1543. if (p->rt.watchdog_stamp != jiffies) {
  1544. p->rt.timeout++;
  1545. p->rt.watchdog_stamp = jiffies;
  1546. }
  1547. next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
  1548. if (p->rt.timeout > next)
  1549. p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
  1550. }
  1551. }
  1552. static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
  1553. {
  1554. struct sched_rt_entity *rt_se = &p->rt;
  1555. update_curr_rt(rq);
  1556. watchdog(rq, p);
  1557. /*
  1558. * RR tasks need a special form of timeslice management.
  1559. * FIFO tasks have no timeslices.
  1560. */
  1561. if (p->policy != SCHED_RR)
  1562. return;
  1563. if (--p->rt.time_slice)
  1564. return;
  1565. p->rt.time_slice = sched_rr_timeslice;
  1566. /*
  1567. * Requeue to the end of queue if we (and all of our ancestors) are not
  1568. * the only element on the queue
  1569. */
  1570. for_each_sched_rt_entity(rt_se) {
  1571. if (rt_se->run_list.prev != rt_se->run_list.next) {
  1572. requeue_task_rt(rq, p, 0);
  1573. set_tsk_need_resched(p);
  1574. return;
  1575. }
  1576. }
  1577. }
  1578. static void set_curr_task_rt(struct rq *rq)
  1579. {
  1580. struct task_struct *p = rq->curr;
  1581. p->se.exec_start = rq_clock_task(rq);
  1582. /* The running task is never eligible for pushing */
  1583. dequeue_pushable_task(rq, p);
  1584. }
  1585. static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)
  1586. {
  1587. /*
  1588. * Time slice is 0 for SCHED_FIFO tasks
  1589. */
  1590. if (task->policy == SCHED_RR)
  1591. return sched_rr_timeslice;
  1592. else
  1593. return 0;
  1594. }
  1595. const struct sched_class rt_sched_class = {
  1596. .next = &fair_sched_class,
  1597. .enqueue_task = enqueue_task_rt,
  1598. .dequeue_task = dequeue_task_rt,
  1599. .yield_task = yield_task_rt,
  1600. .check_preempt_curr = check_preempt_curr_rt,
  1601. .pick_next_task = pick_next_task_rt,
  1602. .put_prev_task = put_prev_task_rt,
  1603. #ifdef CONFIG_SMP
  1604. .select_task_rq = select_task_rq_rt,
  1605. .set_cpus_allowed = set_cpus_allowed_rt,
  1606. .rq_online = rq_online_rt,
  1607. .rq_offline = rq_offline_rt,
  1608. .pre_schedule = pre_schedule_rt,
  1609. .post_schedule = post_schedule_rt,
  1610. .task_woken = task_woken_rt,
  1611. .switched_from = switched_from_rt,
  1612. #endif
  1613. .set_curr_task = set_curr_task_rt,
  1614. .task_tick = task_tick_rt,
  1615. .get_rr_interval = get_rr_interval_rt,
  1616. .prio_changed = prio_changed_rt,
  1617. .switched_to = switched_to_rt,
  1618. };
  1619. #ifdef CONFIG_SCHED_DEBUG
  1620. extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
  1621. void print_rt_stats(struct seq_file *m, int cpu)
  1622. {
  1623. rt_rq_iter_t iter;
  1624. struct rt_rq *rt_rq;
  1625. rcu_read_lock();
  1626. for_each_rt_rq(rt_rq, iter, cpu_rq(cpu))
  1627. print_rt_rq(m, cpu, rt_rq);
  1628. rcu_read_unlock();
  1629. }
  1630. #endif /* CONFIG_SCHED_DEBUG */