rt.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  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. bool sched_rt_bandwidth_account(struct rt_rq *rt_rq)
  421. {
  422. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  423. return (hrtimer_active(&rt_b->rt_period_timer) ||
  424. rt_rq->rt_time < rt_b->rt_runtime);
  425. }
  426. #ifdef CONFIG_SMP
  427. /*
  428. * We ran out of runtime, see if we can borrow some from our neighbours.
  429. */
  430. static int do_balance_runtime(struct rt_rq *rt_rq)
  431. {
  432. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  433. struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd;
  434. int i, weight, more = 0;
  435. u64 rt_period;
  436. weight = cpumask_weight(rd->span);
  437. raw_spin_lock(&rt_b->rt_runtime_lock);
  438. rt_period = ktime_to_ns(rt_b->rt_period);
  439. for_each_cpu(i, rd->span) {
  440. struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
  441. s64 diff;
  442. if (iter == rt_rq)
  443. continue;
  444. raw_spin_lock(&iter->rt_runtime_lock);
  445. /*
  446. * Either all rqs have inf runtime and there's nothing to steal
  447. * or __disable_runtime() below sets a specific rq to inf to
  448. * indicate its been disabled and disalow stealing.
  449. */
  450. if (iter->rt_runtime == RUNTIME_INF)
  451. goto next;
  452. /*
  453. * From runqueues with spare time, take 1/n part of their
  454. * spare time, but no more than our period.
  455. */
  456. diff = iter->rt_runtime - iter->rt_time;
  457. if (diff > 0) {
  458. diff = div_u64((u64)diff, weight);
  459. if (rt_rq->rt_runtime + diff > rt_period)
  460. diff = rt_period - rt_rq->rt_runtime;
  461. iter->rt_runtime -= diff;
  462. rt_rq->rt_runtime += diff;
  463. more = 1;
  464. if (rt_rq->rt_runtime == rt_period) {
  465. raw_spin_unlock(&iter->rt_runtime_lock);
  466. break;
  467. }
  468. }
  469. next:
  470. raw_spin_unlock(&iter->rt_runtime_lock);
  471. }
  472. raw_spin_unlock(&rt_b->rt_runtime_lock);
  473. return more;
  474. }
  475. /*
  476. * Ensure this RQ takes back all the runtime it lend to its neighbours.
  477. */
  478. static void __disable_runtime(struct rq *rq)
  479. {
  480. struct root_domain *rd = rq->rd;
  481. rt_rq_iter_t iter;
  482. struct rt_rq *rt_rq;
  483. if (unlikely(!scheduler_running))
  484. return;
  485. for_each_rt_rq(rt_rq, iter, rq) {
  486. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  487. s64 want;
  488. int i;
  489. raw_spin_lock(&rt_b->rt_runtime_lock);
  490. raw_spin_lock(&rt_rq->rt_runtime_lock);
  491. /*
  492. * Either we're all inf and nobody needs to borrow, or we're
  493. * already disabled and thus have nothing to do, or we have
  494. * exactly the right amount of runtime to take out.
  495. */
  496. if (rt_rq->rt_runtime == RUNTIME_INF ||
  497. rt_rq->rt_runtime == rt_b->rt_runtime)
  498. goto balanced;
  499. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  500. /*
  501. * Calculate the difference between what we started out with
  502. * and what we current have, that's the amount of runtime
  503. * we lend and now have to reclaim.
  504. */
  505. want = rt_b->rt_runtime - rt_rq->rt_runtime;
  506. /*
  507. * Greedy reclaim, take back as much as we can.
  508. */
  509. for_each_cpu(i, rd->span) {
  510. struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
  511. s64 diff;
  512. /*
  513. * Can't reclaim from ourselves or disabled runqueues.
  514. */
  515. if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF)
  516. continue;
  517. raw_spin_lock(&iter->rt_runtime_lock);
  518. if (want > 0) {
  519. diff = min_t(s64, iter->rt_runtime, want);
  520. iter->rt_runtime -= diff;
  521. want -= diff;
  522. } else {
  523. iter->rt_runtime -= want;
  524. want -= want;
  525. }
  526. raw_spin_unlock(&iter->rt_runtime_lock);
  527. if (!want)
  528. break;
  529. }
  530. raw_spin_lock(&rt_rq->rt_runtime_lock);
  531. /*
  532. * We cannot be left wanting - that would mean some runtime
  533. * leaked out of the system.
  534. */
  535. BUG_ON(want);
  536. balanced:
  537. /*
  538. * Disable all the borrow logic by pretending we have inf
  539. * runtime - in which case borrowing doesn't make sense.
  540. */
  541. rt_rq->rt_runtime = RUNTIME_INF;
  542. rt_rq->rt_throttled = 0;
  543. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  544. raw_spin_unlock(&rt_b->rt_runtime_lock);
  545. }
  546. }
  547. static void __enable_runtime(struct rq *rq)
  548. {
  549. rt_rq_iter_t iter;
  550. struct rt_rq *rt_rq;
  551. if (unlikely(!scheduler_running))
  552. return;
  553. /*
  554. * Reset each runqueue's bandwidth settings
  555. */
  556. for_each_rt_rq(rt_rq, iter, rq) {
  557. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  558. raw_spin_lock(&rt_b->rt_runtime_lock);
  559. raw_spin_lock(&rt_rq->rt_runtime_lock);
  560. rt_rq->rt_runtime = rt_b->rt_runtime;
  561. rt_rq->rt_time = 0;
  562. rt_rq->rt_throttled = 0;
  563. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  564. raw_spin_unlock(&rt_b->rt_runtime_lock);
  565. }
  566. }
  567. static int balance_runtime(struct rt_rq *rt_rq)
  568. {
  569. int more = 0;
  570. if (!sched_feat(RT_RUNTIME_SHARE))
  571. return more;
  572. if (rt_rq->rt_time > rt_rq->rt_runtime) {
  573. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  574. more = do_balance_runtime(rt_rq);
  575. raw_spin_lock(&rt_rq->rt_runtime_lock);
  576. }
  577. return more;
  578. }
  579. #else /* !CONFIG_SMP */
  580. static inline int balance_runtime(struct rt_rq *rt_rq)
  581. {
  582. return 0;
  583. }
  584. #endif /* CONFIG_SMP */
  585. static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
  586. {
  587. int i, idle = 1, throttled = 0;
  588. const struct cpumask *span;
  589. span = sched_rt_period_mask();
  590. #ifdef CONFIG_RT_GROUP_SCHED
  591. /*
  592. * FIXME: isolated CPUs should really leave the root task group,
  593. * whether they are isolcpus or were isolated via cpusets, lest
  594. * the timer run on a CPU which does not service all runqueues,
  595. * potentially leaving other CPUs indefinitely throttled. If
  596. * isolation is really required, the user will turn the throttle
  597. * off to kill the perturbations it causes anyway. Meanwhile,
  598. * this maintains functionality for boot and/or troubleshooting.
  599. */
  600. if (rt_b == &root_task_group.rt_bandwidth)
  601. span = cpu_online_mask;
  602. #endif
  603. for_each_cpu(i, span) {
  604. int enqueue = 0;
  605. struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
  606. struct rq *rq = rq_of_rt_rq(rt_rq);
  607. raw_spin_lock(&rq->lock);
  608. if (rt_rq->rt_time) {
  609. u64 runtime;
  610. raw_spin_lock(&rt_rq->rt_runtime_lock);
  611. if (rt_rq->rt_throttled)
  612. balance_runtime(rt_rq);
  613. runtime = rt_rq->rt_runtime;
  614. rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
  615. if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
  616. rt_rq->rt_throttled = 0;
  617. enqueue = 1;
  618. /*
  619. * Force a clock update if the CPU was idle,
  620. * lest wakeup -> unthrottle time accumulate.
  621. */
  622. if (rt_rq->rt_nr_running && rq->curr == rq->idle)
  623. rq->skip_clock_update = -1;
  624. }
  625. if (rt_rq->rt_time || rt_rq->rt_nr_running)
  626. idle = 0;
  627. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  628. } else if (rt_rq->rt_nr_running) {
  629. idle = 0;
  630. if (!rt_rq_throttled(rt_rq))
  631. enqueue = 1;
  632. }
  633. if (rt_rq->rt_throttled)
  634. throttled = 1;
  635. if (enqueue)
  636. sched_rt_rq_enqueue(rt_rq);
  637. raw_spin_unlock(&rq->lock);
  638. }
  639. if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF))
  640. return 1;
  641. return idle;
  642. }
  643. static inline int rt_se_prio(struct sched_rt_entity *rt_se)
  644. {
  645. #ifdef CONFIG_RT_GROUP_SCHED
  646. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  647. if (rt_rq)
  648. return rt_rq->highest_prio.curr;
  649. #endif
  650. return rt_task_of(rt_se)->prio;
  651. }
  652. static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
  653. {
  654. u64 runtime = sched_rt_runtime(rt_rq);
  655. if (rt_rq->rt_throttled)
  656. return rt_rq_throttled(rt_rq);
  657. if (runtime >= sched_rt_period(rt_rq))
  658. return 0;
  659. balance_runtime(rt_rq);
  660. runtime = sched_rt_runtime(rt_rq);
  661. if (runtime == RUNTIME_INF)
  662. return 0;
  663. if (rt_rq->rt_time > runtime) {
  664. struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
  665. /*
  666. * Don't actually throttle groups that have no runtime assigned
  667. * but accrue some time due to boosting.
  668. */
  669. if (likely(rt_b->rt_runtime)) {
  670. static bool once = false;
  671. rt_rq->rt_throttled = 1;
  672. if (!once) {
  673. once = true;
  674. printk_sched("sched: RT throttling activated\n");
  675. }
  676. } else {
  677. /*
  678. * In case we did anyway, make it go away,
  679. * replenishment is a joke, since it will replenish us
  680. * with exactly 0 ns.
  681. */
  682. rt_rq->rt_time = 0;
  683. }
  684. if (rt_rq_throttled(rt_rq)) {
  685. sched_rt_rq_dequeue(rt_rq);
  686. return 1;
  687. }
  688. }
  689. return 0;
  690. }
  691. /*
  692. * Update the current task's runtime statistics. Skip current tasks that
  693. * are not in our scheduling class.
  694. */
  695. static void update_curr_rt(struct rq *rq)
  696. {
  697. struct task_struct *curr = rq->curr;
  698. struct sched_rt_entity *rt_se = &curr->rt;
  699. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  700. u64 delta_exec;
  701. if (curr->sched_class != &rt_sched_class)
  702. return;
  703. delta_exec = rq_clock_task(rq) - curr->se.exec_start;
  704. if (unlikely((s64)delta_exec <= 0))
  705. return;
  706. schedstat_set(curr->se.statistics.exec_max,
  707. max(curr->se.statistics.exec_max, delta_exec));
  708. curr->se.sum_exec_runtime += delta_exec;
  709. account_group_exec_runtime(curr, delta_exec);
  710. curr->se.exec_start = rq_clock_task(rq);
  711. cpuacct_charge(curr, delta_exec);
  712. sched_rt_avg_update(rq, delta_exec);
  713. if (!rt_bandwidth_enabled())
  714. return;
  715. for_each_sched_rt_entity(rt_se) {
  716. rt_rq = rt_rq_of_se(rt_se);
  717. if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
  718. raw_spin_lock(&rt_rq->rt_runtime_lock);
  719. rt_rq->rt_time += delta_exec;
  720. if (sched_rt_runtime_exceeded(rt_rq))
  721. resched_task(curr);
  722. raw_spin_unlock(&rt_rq->rt_runtime_lock);
  723. }
  724. }
  725. }
  726. #if defined CONFIG_SMP
  727. static void
  728. inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
  729. {
  730. struct rq *rq = rq_of_rt_rq(rt_rq);
  731. #ifdef CONFIG_RT_GROUP_SCHED
  732. /*
  733. * Change rq's cpupri only if rt_rq is the top queue.
  734. */
  735. if (&rq->rt != rt_rq)
  736. return;
  737. #endif
  738. if (rq->online && prio < prev_prio)
  739. cpupri_set(&rq->rd->cpupri, rq->cpu, prio);
  740. }
  741. static void
  742. dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
  743. {
  744. struct rq *rq = rq_of_rt_rq(rt_rq);
  745. #ifdef CONFIG_RT_GROUP_SCHED
  746. /*
  747. * Change rq's cpupri only if rt_rq is the top queue.
  748. */
  749. if (&rq->rt != rt_rq)
  750. return;
  751. #endif
  752. if (rq->online && rt_rq->highest_prio.curr != prev_prio)
  753. cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr);
  754. }
  755. #else /* CONFIG_SMP */
  756. static inline
  757. void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  758. static inline
  759. void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  760. #endif /* CONFIG_SMP */
  761. #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
  762. static void
  763. inc_rt_prio(struct rt_rq *rt_rq, int prio)
  764. {
  765. int prev_prio = rt_rq->highest_prio.curr;
  766. if (prio < prev_prio)
  767. rt_rq->highest_prio.curr = prio;
  768. inc_rt_prio_smp(rt_rq, prio, prev_prio);
  769. }
  770. static void
  771. dec_rt_prio(struct rt_rq *rt_rq, int prio)
  772. {
  773. int prev_prio = rt_rq->highest_prio.curr;
  774. if (rt_rq->rt_nr_running) {
  775. WARN_ON(prio < prev_prio);
  776. /*
  777. * This may have been our highest task, and therefore
  778. * we may have some recomputation to do
  779. */
  780. if (prio == prev_prio) {
  781. struct rt_prio_array *array = &rt_rq->active;
  782. rt_rq->highest_prio.curr =
  783. sched_find_first_bit(array->bitmap);
  784. }
  785. } else
  786. rt_rq->highest_prio.curr = MAX_RT_PRIO;
  787. dec_rt_prio_smp(rt_rq, prio, prev_prio);
  788. }
  789. #else
  790. static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {}
  791. static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {}
  792. #endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */
  793. #ifdef CONFIG_RT_GROUP_SCHED
  794. static void
  795. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  796. {
  797. if (rt_se_boosted(rt_se))
  798. rt_rq->rt_nr_boosted++;
  799. if (rt_rq->tg)
  800. start_rt_bandwidth(&rt_rq->tg->rt_bandwidth);
  801. }
  802. static void
  803. dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  804. {
  805. if (rt_se_boosted(rt_se))
  806. rt_rq->rt_nr_boosted--;
  807. WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted);
  808. }
  809. #else /* CONFIG_RT_GROUP_SCHED */
  810. static void
  811. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  812. {
  813. start_rt_bandwidth(&def_rt_bandwidth);
  814. }
  815. static inline
  816. void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {}
  817. #endif /* CONFIG_RT_GROUP_SCHED */
  818. static inline
  819. void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  820. {
  821. int prio = rt_se_prio(rt_se);
  822. WARN_ON(!rt_prio(prio));
  823. rt_rq->rt_nr_running++;
  824. inc_rt_prio(rt_rq, prio);
  825. inc_rt_migration(rt_se, rt_rq);
  826. inc_rt_group(rt_se, rt_rq);
  827. }
  828. static inline
  829. void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  830. {
  831. WARN_ON(!rt_prio(rt_se_prio(rt_se)));
  832. WARN_ON(!rt_rq->rt_nr_running);
  833. rt_rq->rt_nr_running--;
  834. dec_rt_prio(rt_rq, rt_se_prio(rt_se));
  835. dec_rt_migration(rt_se, rt_rq);
  836. dec_rt_group(rt_se, rt_rq);
  837. }
  838. static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  839. {
  840. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  841. struct rt_prio_array *array = &rt_rq->active;
  842. struct rt_rq *group_rq = group_rt_rq(rt_se);
  843. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  844. /*
  845. * Don't enqueue the group if its throttled, or when empty.
  846. * The latter is a consequence of the former when a child group
  847. * get throttled and the current group doesn't have any other
  848. * active members.
  849. */
  850. if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running))
  851. return;
  852. if (head)
  853. list_add(&rt_se->run_list, queue);
  854. else
  855. list_add_tail(&rt_se->run_list, queue);
  856. __set_bit(rt_se_prio(rt_se), array->bitmap);
  857. inc_rt_tasks(rt_se, rt_rq);
  858. }
  859. static void __dequeue_rt_entity(struct sched_rt_entity *rt_se)
  860. {
  861. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  862. struct rt_prio_array *array = &rt_rq->active;
  863. list_del_init(&rt_se->run_list);
  864. if (list_empty(array->queue + rt_se_prio(rt_se)))
  865. __clear_bit(rt_se_prio(rt_se), array->bitmap);
  866. dec_rt_tasks(rt_se, rt_rq);
  867. }
  868. /*
  869. * Because the prio of an upper entry depends on the lower
  870. * entries, we must remove entries top - down.
  871. */
  872. static void dequeue_rt_stack(struct sched_rt_entity *rt_se)
  873. {
  874. struct sched_rt_entity *back = NULL;
  875. for_each_sched_rt_entity(rt_se) {
  876. rt_se->back = back;
  877. back = rt_se;
  878. }
  879. for (rt_se = back; rt_se; rt_se = rt_se->back) {
  880. if (on_rt_rq(rt_se))
  881. __dequeue_rt_entity(rt_se);
  882. }
  883. }
  884. static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  885. {
  886. dequeue_rt_stack(rt_se);
  887. for_each_sched_rt_entity(rt_se)
  888. __enqueue_rt_entity(rt_se, head);
  889. }
  890. static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
  891. {
  892. dequeue_rt_stack(rt_se);
  893. for_each_sched_rt_entity(rt_se) {
  894. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  895. if (rt_rq && rt_rq->rt_nr_running)
  896. __enqueue_rt_entity(rt_se, false);
  897. }
  898. }
  899. /*
  900. * Adding/removing a task to/from a priority array:
  901. */
  902. static void
  903. enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  904. {
  905. struct sched_rt_entity *rt_se = &p->rt;
  906. if (flags & ENQUEUE_WAKEUP)
  907. rt_se->timeout = 0;
  908. enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
  909. if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
  910. enqueue_pushable_task(rq, p);
  911. inc_nr_running(rq);
  912. }
  913. static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  914. {
  915. struct sched_rt_entity *rt_se = &p->rt;
  916. update_curr_rt(rq);
  917. dequeue_rt_entity(rt_se);
  918. dequeue_pushable_task(rq, p);
  919. dec_nr_running(rq);
  920. }
  921. /*
  922. * Put task to the head or the end of the run list without the overhead of
  923. * dequeue followed by enqueue.
  924. */
  925. static void
  926. requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head)
  927. {
  928. if (on_rt_rq(rt_se)) {
  929. struct rt_prio_array *array = &rt_rq->active;
  930. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  931. if (head)
  932. list_move(&rt_se->run_list, queue);
  933. else
  934. list_move_tail(&rt_se->run_list, queue);
  935. }
  936. }
  937. static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
  938. {
  939. struct sched_rt_entity *rt_se = &p->rt;
  940. struct rt_rq *rt_rq;
  941. for_each_sched_rt_entity(rt_se) {
  942. rt_rq = rt_rq_of_se(rt_se);
  943. requeue_rt_entity(rt_rq, rt_se, head);
  944. }
  945. }
  946. static void yield_task_rt(struct rq *rq)
  947. {
  948. requeue_task_rt(rq, rq->curr, 0);
  949. }
  950. #ifdef CONFIG_SMP
  951. static int find_lowest_rq(struct task_struct *task);
  952. static int
  953. select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags)
  954. {
  955. struct task_struct *curr;
  956. struct rq *rq;
  957. if (p->nr_cpus_allowed == 1)
  958. goto out;
  959. /* For anything but wake ups, just return the task_cpu */
  960. if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
  961. goto out;
  962. rq = cpu_rq(cpu);
  963. rcu_read_lock();
  964. curr = ACCESS_ONCE(rq->curr); /* unlocked access */
  965. /*
  966. * If the current task on @p's runqueue is an RT task, then
  967. * try to see if we can wake this RT task up on another
  968. * runqueue. Otherwise simply start this RT task
  969. * on its current runqueue.
  970. *
  971. * We want to avoid overloading runqueues. If the woken
  972. * task is a higher priority, then it will stay on this CPU
  973. * and the lower prio task should be moved to another CPU.
  974. * Even though this will probably make the lower prio task
  975. * lose its cache, we do not want to bounce a higher task
  976. * around just because it gave up its CPU, perhaps for a
  977. * lock?
  978. *
  979. * For equal prio tasks, we just let the scheduler sort it out.
  980. *
  981. * Otherwise, just let it ride on the affined RQ and the
  982. * post-schedule router will push the preempted task away
  983. *
  984. * This test is optimistic, if we get it wrong the load-balancer
  985. * will have to sort it out.
  986. */
  987. if (curr && unlikely(rt_task(curr)) &&
  988. (curr->nr_cpus_allowed < 2 ||
  989. curr->prio <= p->prio)) {
  990. int target = find_lowest_rq(p);
  991. if (target != -1)
  992. cpu = target;
  993. }
  994. rcu_read_unlock();
  995. out:
  996. return cpu;
  997. }
  998. static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
  999. {
  1000. if (rq->curr->nr_cpus_allowed == 1)
  1001. return;
  1002. if (p->nr_cpus_allowed != 1
  1003. && cpupri_find(&rq->rd->cpupri, p, NULL))
  1004. return;
  1005. if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
  1006. return;
  1007. /*
  1008. * There appears to be other cpus that can accept
  1009. * current and none to run 'p', so lets reschedule
  1010. * to try and push current away:
  1011. */
  1012. requeue_task_rt(rq, p, 1);
  1013. resched_task(rq->curr);
  1014. }
  1015. #endif /* CONFIG_SMP */
  1016. /*
  1017. * Preempt the current task with a newly woken task if needed:
  1018. */
  1019. static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags)
  1020. {
  1021. if (p->prio < rq->curr->prio) {
  1022. resched_task(rq->curr);
  1023. return;
  1024. }
  1025. #ifdef CONFIG_SMP
  1026. /*
  1027. * If:
  1028. *
  1029. * - the newly woken task is of equal priority to the current task
  1030. * - the newly woken task is non-migratable while current is migratable
  1031. * - current will be preempted on the next reschedule
  1032. *
  1033. * we should check to see if current can readily move to a different
  1034. * cpu. If so, we will reschedule to allow the push logic to try
  1035. * to move current somewhere else, making room for our non-migratable
  1036. * task.
  1037. */
  1038. if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr))
  1039. check_preempt_equal_prio(rq, p);
  1040. #endif
  1041. }
  1042. static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq,
  1043. struct rt_rq *rt_rq)
  1044. {
  1045. struct rt_prio_array *array = &rt_rq->active;
  1046. struct sched_rt_entity *next = NULL;
  1047. struct list_head *queue;
  1048. int idx;
  1049. idx = sched_find_first_bit(array->bitmap);
  1050. BUG_ON(idx >= MAX_RT_PRIO);
  1051. queue = array->queue + idx;
  1052. next = list_entry(queue->next, struct sched_rt_entity, run_list);
  1053. return next;
  1054. }
  1055. static struct task_struct *_pick_next_task_rt(struct rq *rq)
  1056. {
  1057. struct sched_rt_entity *rt_se;
  1058. struct task_struct *p;
  1059. struct rt_rq *rt_rq;
  1060. rt_rq = &rq->rt;
  1061. if (!rt_rq->rt_nr_running)
  1062. return NULL;
  1063. if (rt_rq_throttled(rt_rq))
  1064. return NULL;
  1065. do {
  1066. rt_se = pick_next_rt_entity(rq, rt_rq);
  1067. BUG_ON(!rt_se);
  1068. rt_rq = group_rt_rq(rt_se);
  1069. } while (rt_rq);
  1070. p = rt_task_of(rt_se);
  1071. p->se.exec_start = rq_clock_task(rq);
  1072. return p;
  1073. }
  1074. static struct task_struct *pick_next_task_rt(struct rq *rq)
  1075. {
  1076. struct task_struct *p = _pick_next_task_rt(rq);
  1077. /* The running task is never eligible for pushing */
  1078. if (p)
  1079. dequeue_pushable_task(rq, p);
  1080. #ifdef CONFIG_SMP
  1081. /*
  1082. * We detect this state here so that we can avoid taking the RQ
  1083. * lock again later if there is no need to push
  1084. */
  1085. rq->post_schedule = has_pushable_tasks(rq);
  1086. #endif
  1087. return p;
  1088. }
  1089. static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
  1090. {
  1091. update_curr_rt(rq);
  1092. /*
  1093. * The previous task needs to be made eligible for pushing
  1094. * if it is still active
  1095. */
  1096. if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
  1097. enqueue_pushable_task(rq, p);
  1098. }
  1099. #ifdef CONFIG_SMP
  1100. /* Only try algorithms three times */
  1101. #define RT_MAX_TRIES 3
  1102. static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
  1103. {
  1104. if (!task_running(rq, p) &&
  1105. cpumask_test_cpu(cpu, tsk_cpus_allowed(p)))
  1106. return 1;
  1107. return 0;
  1108. }
  1109. /*
  1110. * Return the highest pushable rq's task, which is suitable to be executed
  1111. * on the cpu, NULL otherwise
  1112. */
  1113. static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu)
  1114. {
  1115. struct plist_head *head = &rq->rt.pushable_tasks;
  1116. struct task_struct *p;
  1117. if (!has_pushable_tasks(rq))
  1118. return NULL;
  1119. plist_for_each_entry(p, head, pushable_tasks) {
  1120. if (pick_rt_task(rq, p, cpu))
  1121. return p;
  1122. }
  1123. return NULL;
  1124. }
  1125. static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask);
  1126. static int find_lowest_rq(struct task_struct *task)
  1127. {
  1128. struct sched_domain *sd;
  1129. struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask);
  1130. int this_cpu = smp_processor_id();
  1131. int cpu = task_cpu(task);
  1132. /* Make sure the mask is initialized first */
  1133. if (unlikely(!lowest_mask))
  1134. return -1;
  1135. if (task->nr_cpus_allowed == 1)
  1136. return -1; /* No other targets possible */
  1137. if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
  1138. return -1; /* No targets found */
  1139. /*
  1140. * At this point we have built a mask of cpus representing the
  1141. * lowest priority tasks in the system. Now we want to elect
  1142. * the best one based on our affinity and topology.
  1143. *
  1144. * We prioritize the last cpu that the task executed on since
  1145. * it is most likely cache-hot in that location.
  1146. */
  1147. if (cpumask_test_cpu(cpu, lowest_mask))
  1148. return cpu;
  1149. /*
  1150. * Otherwise, we consult the sched_domains span maps to figure
  1151. * out which cpu is logically closest to our hot cache data.
  1152. */
  1153. if (!cpumask_test_cpu(this_cpu, lowest_mask))
  1154. this_cpu = -1; /* Skip this_cpu opt if not among lowest */
  1155. rcu_read_lock();
  1156. for_each_domain(cpu, sd) {
  1157. if (sd->flags & SD_WAKE_AFFINE) {
  1158. int best_cpu;
  1159. /*
  1160. * "this_cpu" is cheaper to preempt than a
  1161. * remote processor.
  1162. */
  1163. if (this_cpu != -1 &&
  1164. cpumask_test_cpu(this_cpu, sched_domain_span(sd))) {
  1165. rcu_read_unlock();
  1166. return this_cpu;
  1167. }
  1168. best_cpu = cpumask_first_and(lowest_mask,
  1169. sched_domain_span(sd));
  1170. if (best_cpu < nr_cpu_ids) {
  1171. rcu_read_unlock();
  1172. return best_cpu;
  1173. }
  1174. }
  1175. }
  1176. rcu_read_unlock();
  1177. /*
  1178. * And finally, if there were no matches within the domains
  1179. * just give the caller *something* to work with from the compatible
  1180. * locations.
  1181. */
  1182. if (this_cpu != -1)
  1183. return this_cpu;
  1184. cpu = cpumask_any(lowest_mask);
  1185. if (cpu < nr_cpu_ids)
  1186. return cpu;
  1187. return -1;
  1188. }
  1189. /* Will lock the rq it finds */
  1190. static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
  1191. {
  1192. struct rq *lowest_rq = NULL;
  1193. int tries;
  1194. int cpu;
  1195. for (tries = 0; tries < RT_MAX_TRIES; tries++) {
  1196. cpu = find_lowest_rq(task);
  1197. if ((cpu == -1) || (cpu == rq->cpu))
  1198. break;
  1199. lowest_rq = cpu_rq(cpu);
  1200. /* if the prio of this runqueue changed, try again */
  1201. if (double_lock_balance(rq, lowest_rq)) {
  1202. /*
  1203. * We had to unlock the run queue. In
  1204. * the mean time, task could have
  1205. * migrated already or had its affinity changed.
  1206. * Also make sure that it wasn't scheduled on its rq.
  1207. */
  1208. if (unlikely(task_rq(task) != rq ||
  1209. !cpumask_test_cpu(lowest_rq->cpu,
  1210. tsk_cpus_allowed(task)) ||
  1211. task_running(rq, task) ||
  1212. !task->on_rq)) {
  1213. double_unlock_balance(rq, lowest_rq);
  1214. lowest_rq = NULL;
  1215. break;
  1216. }
  1217. }
  1218. /* If this rq is still suitable use it. */
  1219. if (lowest_rq->rt.highest_prio.curr > task->prio)
  1220. break;
  1221. /* try again */
  1222. double_unlock_balance(rq, lowest_rq);
  1223. lowest_rq = NULL;
  1224. }
  1225. return lowest_rq;
  1226. }
  1227. static struct task_struct *pick_next_pushable_task(struct rq *rq)
  1228. {
  1229. struct task_struct *p;
  1230. if (!has_pushable_tasks(rq))
  1231. return NULL;
  1232. p = plist_first_entry(&rq->rt.pushable_tasks,
  1233. struct task_struct, pushable_tasks);
  1234. BUG_ON(rq->cpu != task_cpu(p));
  1235. BUG_ON(task_current(rq, p));
  1236. BUG_ON(p->nr_cpus_allowed <= 1);
  1237. BUG_ON(!p->on_rq);
  1238. BUG_ON(!rt_task(p));
  1239. return p;
  1240. }
  1241. /*
  1242. * If the current CPU has more than one RT task, see if the non
  1243. * running task can migrate over to a CPU that is running a task
  1244. * of lesser priority.
  1245. */
  1246. static int push_rt_task(struct rq *rq)
  1247. {
  1248. struct task_struct *next_task;
  1249. struct rq *lowest_rq;
  1250. int ret = 0;
  1251. if (!rq->rt.overloaded)
  1252. return 0;
  1253. next_task = pick_next_pushable_task(rq);
  1254. if (!next_task)
  1255. return 0;
  1256. retry:
  1257. if (unlikely(next_task == rq->curr)) {
  1258. WARN_ON(1);
  1259. return 0;
  1260. }
  1261. /*
  1262. * It's possible that the next_task slipped in of
  1263. * higher priority than current. If that's the case
  1264. * just reschedule current.
  1265. */
  1266. if (unlikely(next_task->prio < rq->curr->prio)) {
  1267. resched_task(rq->curr);
  1268. return 0;
  1269. }
  1270. /* We might release rq lock */
  1271. get_task_struct(next_task);
  1272. /* find_lock_lowest_rq locks the rq if found */
  1273. lowest_rq = find_lock_lowest_rq(next_task, rq);
  1274. if (!lowest_rq) {
  1275. struct task_struct *task;
  1276. /*
  1277. * find_lock_lowest_rq releases rq->lock
  1278. * so it is possible that next_task has migrated.
  1279. *
  1280. * We need to make sure that the task is still on the same
  1281. * run-queue and is also still the next task eligible for
  1282. * pushing.
  1283. */
  1284. task = pick_next_pushable_task(rq);
  1285. if (task_cpu(next_task) == rq->cpu && task == next_task) {
  1286. /*
  1287. * The task hasn't migrated, and is still the next
  1288. * eligible task, but we failed to find a run-queue
  1289. * to push it to. Do not retry in this case, since
  1290. * other cpus will pull from us when ready.
  1291. */
  1292. goto out;
  1293. }
  1294. if (!task)
  1295. /* No more tasks, just exit */
  1296. goto out;
  1297. /*
  1298. * Something has shifted, try again.
  1299. */
  1300. put_task_struct(next_task);
  1301. next_task = task;
  1302. goto retry;
  1303. }
  1304. deactivate_task(rq, next_task, 0);
  1305. set_task_cpu(next_task, lowest_rq->cpu);
  1306. activate_task(lowest_rq, next_task, 0);
  1307. ret = 1;
  1308. resched_task(lowest_rq->curr);
  1309. double_unlock_balance(rq, lowest_rq);
  1310. out:
  1311. put_task_struct(next_task);
  1312. return ret;
  1313. }
  1314. static void push_rt_tasks(struct rq *rq)
  1315. {
  1316. /* push_rt_task will return true if it moved an RT */
  1317. while (push_rt_task(rq))
  1318. ;
  1319. }
  1320. static int pull_rt_task(struct rq *this_rq)
  1321. {
  1322. int this_cpu = this_rq->cpu, ret = 0, cpu;
  1323. struct task_struct *p;
  1324. struct rq *src_rq;
  1325. if (likely(!rt_overloaded(this_rq)))
  1326. return 0;
  1327. /*
  1328. * Match the barrier from rt_set_overloaded; this guarantees that if we
  1329. * see overloaded we must also see the rto_mask bit.
  1330. */
  1331. smp_rmb();
  1332. for_each_cpu(cpu, this_rq->rd->rto_mask) {
  1333. if (this_cpu == cpu)
  1334. continue;
  1335. src_rq = cpu_rq(cpu);
  1336. /*
  1337. * Don't bother taking the src_rq->lock if the next highest
  1338. * task is known to be lower-priority than our current task.
  1339. * This may look racy, but if this value is about to go
  1340. * logically higher, the src_rq will push this task away.
  1341. * And if its going logically lower, we do not care
  1342. */
  1343. if (src_rq->rt.highest_prio.next >=
  1344. this_rq->rt.highest_prio.curr)
  1345. continue;
  1346. /*
  1347. * We can potentially drop this_rq's lock in
  1348. * double_lock_balance, and another CPU could
  1349. * alter this_rq
  1350. */
  1351. double_lock_balance(this_rq, src_rq);
  1352. /*
  1353. * We can pull only a task, which is pushable
  1354. * on its rq, and no others.
  1355. */
  1356. p = pick_highest_pushable_task(src_rq, this_cpu);
  1357. /*
  1358. * Do we have an RT task that preempts
  1359. * the to-be-scheduled task?
  1360. */
  1361. if (p && (p->prio < this_rq->rt.highest_prio.curr)) {
  1362. WARN_ON(p == src_rq->curr);
  1363. WARN_ON(!p->on_rq);
  1364. /*
  1365. * There's a chance that p is higher in priority
  1366. * than what's currently running on its cpu.
  1367. * This is just that p is wakeing up and hasn't
  1368. * had a chance to schedule. We only pull
  1369. * p if it is lower in priority than the
  1370. * current task on the run queue
  1371. */
  1372. if (p->prio < src_rq->curr->prio)
  1373. goto skip;
  1374. ret = 1;
  1375. deactivate_task(src_rq, p, 0);
  1376. set_task_cpu(p, this_cpu);
  1377. activate_task(this_rq, p, 0);
  1378. /*
  1379. * We continue with the search, just in
  1380. * case there's an even higher prio task
  1381. * in another runqueue. (low likelihood
  1382. * but possible)
  1383. */
  1384. }
  1385. skip:
  1386. double_unlock_balance(this_rq, src_rq);
  1387. }
  1388. return ret;
  1389. }
  1390. static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
  1391. {
  1392. /* Try to pull RT tasks here if we lower this rq's prio */
  1393. if (rq->rt.highest_prio.curr > prev->prio)
  1394. pull_rt_task(rq);
  1395. }
  1396. static void post_schedule_rt(struct rq *rq)
  1397. {
  1398. push_rt_tasks(rq);
  1399. }
  1400. /*
  1401. * If we are not running and we are not going to reschedule soon, we should
  1402. * try to push tasks away now
  1403. */
  1404. static void task_woken_rt(struct rq *rq, struct task_struct *p)
  1405. {
  1406. if (!task_running(rq, p) &&
  1407. !test_tsk_need_resched(rq->curr) &&
  1408. has_pushable_tasks(rq) &&
  1409. p->nr_cpus_allowed > 1 &&
  1410. (dl_task(rq->curr) || rt_task(rq->curr)) &&
  1411. (rq->curr->nr_cpus_allowed < 2 ||
  1412. rq->curr->prio <= p->prio))
  1413. push_rt_tasks(rq);
  1414. }
  1415. static void set_cpus_allowed_rt(struct task_struct *p,
  1416. const struct cpumask *new_mask)
  1417. {
  1418. struct rq *rq;
  1419. int weight;
  1420. BUG_ON(!rt_task(p));
  1421. if (!p->on_rq)
  1422. return;
  1423. weight = cpumask_weight(new_mask);
  1424. /*
  1425. * Only update if the process changes its state from whether it
  1426. * can migrate or not.
  1427. */
  1428. if ((p->nr_cpus_allowed > 1) == (weight > 1))
  1429. return;
  1430. rq = task_rq(p);
  1431. /*
  1432. * The process used to be able to migrate OR it can now migrate
  1433. */
  1434. if (weight <= 1) {
  1435. if (!task_current(rq, p))
  1436. dequeue_pushable_task(rq, p);
  1437. BUG_ON(!rq->rt.rt_nr_migratory);
  1438. rq->rt.rt_nr_migratory--;
  1439. } else {
  1440. if (!task_current(rq, p))
  1441. enqueue_pushable_task(rq, p);
  1442. rq->rt.rt_nr_migratory++;
  1443. }
  1444. update_rt_migration(&rq->rt);
  1445. }
  1446. /* Assumes rq->lock is held */
  1447. static void rq_online_rt(struct rq *rq)
  1448. {
  1449. if (rq->rt.overloaded)
  1450. rt_set_overload(rq);
  1451. __enable_runtime(rq);
  1452. cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
  1453. }
  1454. /* Assumes rq->lock is held */
  1455. static void rq_offline_rt(struct rq *rq)
  1456. {
  1457. if (rq->rt.overloaded)
  1458. rt_clear_overload(rq);
  1459. __disable_runtime(rq);
  1460. cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
  1461. }
  1462. /*
  1463. * When switch from the rt queue, we bring ourselves to a position
  1464. * that we might want to pull RT tasks from other runqueues.
  1465. */
  1466. static void switched_from_rt(struct rq *rq, struct task_struct *p)
  1467. {
  1468. /*
  1469. * If there are other RT tasks then we will reschedule
  1470. * and the scheduling of the other RT tasks will handle
  1471. * the balancing. But if we are the last RT task
  1472. * we may need to handle the pulling of RT tasks
  1473. * now.
  1474. */
  1475. if (!p->on_rq || rq->rt.rt_nr_running)
  1476. return;
  1477. if (pull_rt_task(rq))
  1478. resched_task(rq->curr);
  1479. }
  1480. void init_sched_rt_class(void)
  1481. {
  1482. unsigned int i;
  1483. for_each_possible_cpu(i) {
  1484. zalloc_cpumask_var_node(&per_cpu(local_cpu_mask, i),
  1485. GFP_KERNEL, cpu_to_node(i));
  1486. }
  1487. }
  1488. #endif /* CONFIG_SMP */
  1489. /*
  1490. * When switching a task to RT, we may overload the runqueue
  1491. * with RT tasks. In this case we try to push them off to
  1492. * other runqueues.
  1493. */
  1494. static void switched_to_rt(struct rq *rq, struct task_struct *p)
  1495. {
  1496. int check_resched = 1;
  1497. /*
  1498. * If we are already running, then there's nothing
  1499. * that needs to be done. But if we are not running
  1500. * we may need to preempt the current running task.
  1501. * If that current running task is also an RT task
  1502. * then see if we can move to another run queue.
  1503. */
  1504. if (p->on_rq && rq->curr != p) {
  1505. #ifdef CONFIG_SMP
  1506. if (rq->rt.overloaded && push_rt_task(rq) &&
  1507. /* Don't resched if we changed runqueues */
  1508. rq != task_rq(p))
  1509. check_resched = 0;
  1510. #endif /* CONFIG_SMP */
  1511. if (check_resched && p->prio < rq->curr->prio)
  1512. resched_task(rq->curr);
  1513. }
  1514. }
  1515. /*
  1516. * Priority of the task has changed. This may cause
  1517. * us to initiate a push or pull.
  1518. */
  1519. static void
  1520. prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio)
  1521. {
  1522. if (!p->on_rq)
  1523. return;
  1524. if (rq->curr == p) {
  1525. #ifdef CONFIG_SMP
  1526. /*
  1527. * If our priority decreases while running, we
  1528. * may need to pull tasks to this runqueue.
  1529. */
  1530. if (oldprio < p->prio)
  1531. pull_rt_task(rq);
  1532. /*
  1533. * If there's a higher priority task waiting to run
  1534. * then reschedule. Note, the above pull_rt_task
  1535. * can release the rq lock and p could migrate.
  1536. * Only reschedule if p is still on the same runqueue.
  1537. */
  1538. if (p->prio > rq->rt.highest_prio.curr && rq->curr == p)
  1539. resched_task(p);
  1540. #else
  1541. /* For UP simply resched on drop of prio */
  1542. if (oldprio < p->prio)
  1543. resched_task(p);
  1544. #endif /* CONFIG_SMP */
  1545. } else {
  1546. /*
  1547. * This task is not running, but if it is
  1548. * greater than the current running task
  1549. * then reschedule.
  1550. */
  1551. if (p->prio < rq->curr->prio)
  1552. resched_task(rq->curr);
  1553. }
  1554. }
  1555. static void watchdog(struct rq *rq, struct task_struct *p)
  1556. {
  1557. unsigned long soft, hard;
  1558. /* max may change after cur was read, this will be fixed next tick */
  1559. soft = task_rlimit(p, RLIMIT_RTTIME);
  1560. hard = task_rlimit_max(p, RLIMIT_RTTIME);
  1561. if (soft != RLIM_INFINITY) {
  1562. unsigned long next;
  1563. if (p->rt.watchdog_stamp != jiffies) {
  1564. p->rt.timeout++;
  1565. p->rt.watchdog_stamp = jiffies;
  1566. }
  1567. next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
  1568. if (p->rt.timeout > next)
  1569. p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
  1570. }
  1571. }
  1572. static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
  1573. {
  1574. struct sched_rt_entity *rt_se = &p->rt;
  1575. update_curr_rt(rq);
  1576. watchdog(rq, p);
  1577. /*
  1578. * RR tasks need a special form of timeslice management.
  1579. * FIFO tasks have no timeslices.
  1580. */
  1581. if (p->policy != SCHED_RR)
  1582. return;
  1583. if (--p->rt.time_slice)
  1584. return;
  1585. p->rt.time_slice = sched_rr_timeslice;
  1586. /*
  1587. * Requeue to the end of queue if we (and all of our ancestors) are not
  1588. * the only element on the queue
  1589. */
  1590. for_each_sched_rt_entity(rt_se) {
  1591. if (rt_se->run_list.prev != rt_se->run_list.next) {
  1592. requeue_task_rt(rq, p, 0);
  1593. set_tsk_need_resched(p);
  1594. return;
  1595. }
  1596. }
  1597. }
  1598. static void set_curr_task_rt(struct rq *rq)
  1599. {
  1600. struct task_struct *p = rq->curr;
  1601. p->se.exec_start = rq_clock_task(rq);
  1602. /* The running task is never eligible for pushing */
  1603. dequeue_pushable_task(rq, p);
  1604. }
  1605. static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)
  1606. {
  1607. /*
  1608. * Time slice is 0 for SCHED_FIFO tasks
  1609. */
  1610. if (task->policy == SCHED_RR)
  1611. return sched_rr_timeslice;
  1612. else
  1613. return 0;
  1614. }
  1615. const struct sched_class rt_sched_class = {
  1616. .next = &fair_sched_class,
  1617. .enqueue_task = enqueue_task_rt,
  1618. .dequeue_task = dequeue_task_rt,
  1619. .yield_task = yield_task_rt,
  1620. .check_preempt_curr = check_preempt_curr_rt,
  1621. .pick_next_task = pick_next_task_rt,
  1622. .put_prev_task = put_prev_task_rt,
  1623. #ifdef CONFIG_SMP
  1624. .select_task_rq = select_task_rq_rt,
  1625. .set_cpus_allowed = set_cpus_allowed_rt,
  1626. .rq_online = rq_online_rt,
  1627. .rq_offline = rq_offline_rt,
  1628. .pre_schedule = pre_schedule_rt,
  1629. .post_schedule = post_schedule_rt,
  1630. .task_woken = task_woken_rt,
  1631. .switched_from = switched_from_rt,
  1632. #endif
  1633. .set_curr_task = set_curr_task_rt,
  1634. .task_tick = task_tick_rt,
  1635. .get_rr_interval = get_rr_interval_rt,
  1636. .prio_changed = prio_changed_rt,
  1637. .switched_to = switched_to_rt,
  1638. };
  1639. #ifdef CONFIG_SCHED_DEBUG
  1640. extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
  1641. void print_rt_stats(struct seq_file *m, int cpu)
  1642. {
  1643. rt_rq_iter_t iter;
  1644. struct rt_rq *rt_rq;
  1645. rcu_read_lock();
  1646. for_each_rt_rq(rt_rq, iter, cpu_rq(cpu))
  1647. print_rt_rq(m, cpu, rt_rq);
  1648. rcu_read_unlock();
  1649. }
  1650. #endif /* CONFIG_SCHED_DEBUG */