rt.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  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. #ifdef CONFIG_RT_GROUP_SCHED
  726. /*
  727. * Change rq's cpupri only if rt_rq is the top queue.
  728. */
  729. if (&rq->rt != rt_rq)
  730. return;
  731. #endif
  732. if (rq->online && prio < prev_prio)
  733. cpupri_set(&rq->rd->cpupri, rq->cpu, prio);
  734. }
  735. static void
  736. dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
  737. {
  738. struct rq *rq = rq_of_rt_rq(rt_rq);
  739. #ifdef CONFIG_RT_GROUP_SCHED
  740. /*
  741. * Change rq's cpupri only if rt_rq is the top queue.
  742. */
  743. if (&rq->rt != rt_rq)
  744. return;
  745. #endif
  746. if (rq->online && rt_rq->highest_prio.curr != prev_prio)
  747. cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr);
  748. }
  749. #else /* CONFIG_SMP */
  750. static inline
  751. void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  752. static inline
  753. void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
  754. #endif /* CONFIG_SMP */
  755. #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
  756. static void
  757. inc_rt_prio(struct rt_rq *rt_rq, int prio)
  758. {
  759. int prev_prio = rt_rq->highest_prio.curr;
  760. if (prio < prev_prio)
  761. rt_rq->highest_prio.curr = prio;
  762. inc_rt_prio_smp(rt_rq, prio, prev_prio);
  763. }
  764. static void
  765. dec_rt_prio(struct rt_rq *rt_rq, int prio)
  766. {
  767. int prev_prio = rt_rq->highest_prio.curr;
  768. if (rt_rq->rt_nr_running) {
  769. WARN_ON(prio < prev_prio);
  770. /*
  771. * This may have been our highest task, and therefore
  772. * we may have some recomputation to do
  773. */
  774. if (prio == prev_prio) {
  775. struct rt_prio_array *array = &rt_rq->active;
  776. rt_rq->highest_prio.curr =
  777. sched_find_first_bit(array->bitmap);
  778. }
  779. } else
  780. rt_rq->highest_prio.curr = MAX_RT_PRIO;
  781. dec_rt_prio_smp(rt_rq, prio, prev_prio);
  782. }
  783. #else
  784. static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {}
  785. static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {}
  786. #endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */
  787. #ifdef CONFIG_RT_GROUP_SCHED
  788. static void
  789. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  790. {
  791. if (rt_se_boosted(rt_se))
  792. rt_rq->rt_nr_boosted++;
  793. if (rt_rq->tg)
  794. start_rt_bandwidth(&rt_rq->tg->rt_bandwidth);
  795. }
  796. static void
  797. dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  798. {
  799. if (rt_se_boosted(rt_se))
  800. rt_rq->rt_nr_boosted--;
  801. WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted);
  802. }
  803. #else /* CONFIG_RT_GROUP_SCHED */
  804. static void
  805. inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  806. {
  807. start_rt_bandwidth(&def_rt_bandwidth);
  808. }
  809. static inline
  810. void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {}
  811. #endif /* CONFIG_RT_GROUP_SCHED */
  812. static inline
  813. void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  814. {
  815. int prio = rt_se_prio(rt_se);
  816. WARN_ON(!rt_prio(prio));
  817. rt_rq->rt_nr_running++;
  818. inc_rt_prio(rt_rq, prio);
  819. inc_rt_migration(rt_se, rt_rq);
  820. inc_rt_group(rt_se, rt_rq);
  821. }
  822. static inline
  823. void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
  824. {
  825. WARN_ON(!rt_prio(rt_se_prio(rt_se)));
  826. WARN_ON(!rt_rq->rt_nr_running);
  827. rt_rq->rt_nr_running--;
  828. dec_rt_prio(rt_rq, rt_se_prio(rt_se));
  829. dec_rt_migration(rt_se, rt_rq);
  830. dec_rt_group(rt_se, rt_rq);
  831. }
  832. static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  833. {
  834. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  835. struct rt_prio_array *array = &rt_rq->active;
  836. struct rt_rq *group_rq = group_rt_rq(rt_se);
  837. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  838. /*
  839. * Don't enqueue the group if its throttled, or when empty.
  840. * The latter is a consequence of the former when a child group
  841. * get throttled and the current group doesn't have any other
  842. * active members.
  843. */
  844. if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running))
  845. return;
  846. if (head)
  847. list_add(&rt_se->run_list, queue);
  848. else
  849. list_add_tail(&rt_se->run_list, queue);
  850. __set_bit(rt_se_prio(rt_se), array->bitmap);
  851. inc_rt_tasks(rt_se, rt_rq);
  852. }
  853. static void __dequeue_rt_entity(struct sched_rt_entity *rt_se)
  854. {
  855. struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
  856. struct rt_prio_array *array = &rt_rq->active;
  857. list_del_init(&rt_se->run_list);
  858. if (list_empty(array->queue + rt_se_prio(rt_se)))
  859. __clear_bit(rt_se_prio(rt_se), array->bitmap);
  860. dec_rt_tasks(rt_se, rt_rq);
  861. }
  862. /*
  863. * Because the prio of an upper entry depends on the lower
  864. * entries, we must remove entries top - down.
  865. */
  866. static void dequeue_rt_stack(struct sched_rt_entity *rt_se)
  867. {
  868. struct sched_rt_entity *back = NULL;
  869. for_each_sched_rt_entity(rt_se) {
  870. rt_se->back = back;
  871. back = rt_se;
  872. }
  873. for (rt_se = back; rt_se; rt_se = rt_se->back) {
  874. if (on_rt_rq(rt_se))
  875. __dequeue_rt_entity(rt_se);
  876. }
  877. }
  878. static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
  879. {
  880. dequeue_rt_stack(rt_se);
  881. for_each_sched_rt_entity(rt_se)
  882. __enqueue_rt_entity(rt_se, head);
  883. }
  884. static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
  885. {
  886. dequeue_rt_stack(rt_se);
  887. for_each_sched_rt_entity(rt_se) {
  888. struct rt_rq *rt_rq = group_rt_rq(rt_se);
  889. if (rt_rq && rt_rq->rt_nr_running)
  890. __enqueue_rt_entity(rt_se, false);
  891. }
  892. }
  893. /*
  894. * Adding/removing a task to/from a priority array:
  895. */
  896. static void
  897. enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  898. {
  899. struct sched_rt_entity *rt_se = &p->rt;
  900. if (flags & ENQUEUE_WAKEUP)
  901. rt_se->timeout = 0;
  902. enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
  903. if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
  904. enqueue_pushable_task(rq, p);
  905. inc_nr_running(rq);
  906. }
  907. static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
  908. {
  909. struct sched_rt_entity *rt_se = &p->rt;
  910. update_curr_rt(rq);
  911. dequeue_rt_entity(rt_se);
  912. dequeue_pushable_task(rq, p);
  913. dec_nr_running(rq);
  914. }
  915. /*
  916. * Put task to the head or the end of the run list without the overhead of
  917. * dequeue followed by enqueue.
  918. */
  919. static void
  920. requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head)
  921. {
  922. if (on_rt_rq(rt_se)) {
  923. struct rt_prio_array *array = &rt_rq->active;
  924. struct list_head *queue = array->queue + rt_se_prio(rt_se);
  925. if (head)
  926. list_move(&rt_se->run_list, queue);
  927. else
  928. list_move_tail(&rt_se->run_list, queue);
  929. }
  930. }
  931. static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
  932. {
  933. struct sched_rt_entity *rt_se = &p->rt;
  934. struct rt_rq *rt_rq;
  935. for_each_sched_rt_entity(rt_se) {
  936. rt_rq = rt_rq_of_se(rt_se);
  937. requeue_rt_entity(rt_rq, rt_se, head);
  938. }
  939. }
  940. static void yield_task_rt(struct rq *rq)
  941. {
  942. requeue_task_rt(rq, rq->curr, 0);
  943. }
  944. #ifdef CONFIG_SMP
  945. static int find_lowest_rq(struct task_struct *task);
  946. static int
  947. select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags)
  948. {
  949. struct task_struct *curr;
  950. struct rq *rq;
  951. if (p->nr_cpus_allowed == 1)
  952. goto out;
  953. /* For anything but wake ups, just return the task_cpu */
  954. if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
  955. goto out;
  956. rq = cpu_rq(cpu);
  957. rcu_read_lock();
  958. curr = ACCESS_ONCE(rq->curr); /* unlocked access */
  959. /*
  960. * If the current task on @p's runqueue is an RT task, then
  961. * try to see if we can wake this RT task up on another
  962. * runqueue. Otherwise simply start this RT task
  963. * on its current runqueue.
  964. *
  965. * We want to avoid overloading runqueues. If the woken
  966. * task is a higher priority, then it will stay on this CPU
  967. * and the lower prio task should be moved to another CPU.
  968. * Even though this will probably make the lower prio task
  969. * lose its cache, we do not want to bounce a higher task
  970. * around just because it gave up its CPU, perhaps for a
  971. * lock?
  972. *
  973. * For equal prio tasks, we just let the scheduler sort it out.
  974. *
  975. * Otherwise, just let it ride on the affined RQ and the
  976. * post-schedule router will push the preempted task away
  977. *
  978. * This test is optimistic, if we get it wrong the load-balancer
  979. * will have to sort it out.
  980. */
  981. if (curr && unlikely(rt_task(curr)) &&
  982. (curr->nr_cpus_allowed < 2 ||
  983. curr->prio <= p->prio)) {
  984. int target = find_lowest_rq(p);
  985. if (target != -1)
  986. cpu = target;
  987. }
  988. rcu_read_unlock();
  989. out:
  990. return cpu;
  991. }
  992. static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
  993. {
  994. if (rq->curr->nr_cpus_allowed == 1)
  995. return;
  996. if (p->nr_cpus_allowed != 1
  997. && cpupri_find(&rq->rd->cpupri, p, NULL))
  998. return;
  999. if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
  1000. return;
  1001. /*
  1002. * There appears to be other cpus that can accept
  1003. * current and none to run 'p', so lets reschedule
  1004. * to try and push current away:
  1005. */
  1006. requeue_task_rt(rq, p, 1);
  1007. resched_task(rq->curr);
  1008. }
  1009. #endif /* CONFIG_SMP */
  1010. /*
  1011. * Preempt the current task with a newly woken task if needed:
  1012. */
  1013. static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags)
  1014. {
  1015. if (p->prio < rq->curr->prio) {
  1016. resched_task(rq->curr);
  1017. return;
  1018. }
  1019. #ifdef CONFIG_SMP
  1020. /*
  1021. * If:
  1022. *
  1023. * - the newly woken task is of equal priority to the current task
  1024. * - the newly woken task is non-migratable while current is migratable
  1025. * - current will be preempted on the next reschedule
  1026. *
  1027. * we should check to see if current can readily move to a different
  1028. * cpu. If so, we will reschedule to allow the push logic to try
  1029. * to move current somewhere else, making room for our non-migratable
  1030. * task.
  1031. */
  1032. if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr))
  1033. check_preempt_equal_prio(rq, p);
  1034. #endif
  1035. }
  1036. static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq,
  1037. struct rt_rq *rt_rq)
  1038. {
  1039. struct rt_prio_array *array = &rt_rq->active;
  1040. struct sched_rt_entity *next = NULL;
  1041. struct list_head *queue;
  1042. int idx;
  1043. idx = sched_find_first_bit(array->bitmap);
  1044. BUG_ON(idx >= MAX_RT_PRIO);
  1045. queue = array->queue + idx;
  1046. next = list_entry(queue->next, struct sched_rt_entity, run_list);
  1047. return next;
  1048. }
  1049. static struct task_struct *_pick_next_task_rt(struct rq *rq)
  1050. {
  1051. struct sched_rt_entity *rt_se;
  1052. struct task_struct *p;
  1053. struct rt_rq *rt_rq;
  1054. rt_rq = &rq->rt;
  1055. if (!rt_rq->rt_nr_running)
  1056. return NULL;
  1057. if (rt_rq_throttled(rt_rq))
  1058. return NULL;
  1059. do {
  1060. rt_se = pick_next_rt_entity(rq, rt_rq);
  1061. BUG_ON(!rt_se);
  1062. rt_rq = group_rt_rq(rt_se);
  1063. } while (rt_rq);
  1064. p = rt_task_of(rt_se);
  1065. p->se.exec_start = rq_clock_task(rq);
  1066. return p;
  1067. }
  1068. static struct task_struct *pick_next_task_rt(struct rq *rq)
  1069. {
  1070. struct task_struct *p = _pick_next_task_rt(rq);
  1071. /* The running task is never eligible for pushing */
  1072. if (p)
  1073. dequeue_pushable_task(rq, p);
  1074. #ifdef CONFIG_SMP
  1075. /*
  1076. * We detect this state here so that we can avoid taking the RQ
  1077. * lock again later if there is no need to push
  1078. */
  1079. rq->post_schedule = has_pushable_tasks(rq);
  1080. #endif
  1081. return p;
  1082. }
  1083. static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
  1084. {
  1085. update_curr_rt(rq);
  1086. /*
  1087. * The previous task needs to be made eligible for pushing
  1088. * if it is still active
  1089. */
  1090. if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
  1091. enqueue_pushable_task(rq, p);
  1092. }
  1093. #ifdef CONFIG_SMP
  1094. /* Only try algorithms three times */
  1095. #define RT_MAX_TRIES 3
  1096. static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
  1097. {
  1098. if (!task_running(rq, p) &&
  1099. cpumask_test_cpu(cpu, tsk_cpus_allowed(p)))
  1100. return 1;
  1101. return 0;
  1102. }
  1103. /*
  1104. * Return the highest pushable rq's task, which is suitable to be executed
  1105. * on the cpu, NULL otherwise
  1106. */
  1107. static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu)
  1108. {
  1109. struct plist_head *head = &rq->rt.pushable_tasks;
  1110. struct task_struct *p;
  1111. if (!has_pushable_tasks(rq))
  1112. return NULL;
  1113. plist_for_each_entry(p, head, pushable_tasks) {
  1114. if (pick_rt_task(rq, p, cpu))
  1115. return p;
  1116. }
  1117. return NULL;
  1118. }
  1119. static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask);
  1120. static int find_lowest_rq(struct task_struct *task)
  1121. {
  1122. struct sched_domain *sd;
  1123. struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask);
  1124. int this_cpu = smp_processor_id();
  1125. int cpu = task_cpu(task);
  1126. /* Make sure the mask is initialized first */
  1127. if (unlikely(!lowest_mask))
  1128. return -1;
  1129. if (task->nr_cpus_allowed == 1)
  1130. return -1; /* No other targets possible */
  1131. if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
  1132. return -1; /* No targets found */
  1133. /*
  1134. * At this point we have built a mask of cpus representing the
  1135. * lowest priority tasks in the system. Now we want to elect
  1136. * the best one based on our affinity and topology.
  1137. *
  1138. * We prioritize the last cpu that the task executed on since
  1139. * it is most likely cache-hot in that location.
  1140. */
  1141. if (cpumask_test_cpu(cpu, lowest_mask))
  1142. return cpu;
  1143. /*
  1144. * Otherwise, we consult the sched_domains span maps to figure
  1145. * out which cpu is logically closest to our hot cache data.
  1146. */
  1147. if (!cpumask_test_cpu(this_cpu, lowest_mask))
  1148. this_cpu = -1; /* Skip this_cpu opt if not among lowest */
  1149. rcu_read_lock();
  1150. for_each_domain(cpu, sd) {
  1151. if (sd->flags & SD_WAKE_AFFINE) {
  1152. int best_cpu;
  1153. /*
  1154. * "this_cpu" is cheaper to preempt than a
  1155. * remote processor.
  1156. */
  1157. if (this_cpu != -1 &&
  1158. cpumask_test_cpu(this_cpu, sched_domain_span(sd))) {
  1159. rcu_read_unlock();
  1160. return this_cpu;
  1161. }
  1162. best_cpu = cpumask_first_and(lowest_mask,
  1163. sched_domain_span(sd));
  1164. if (best_cpu < nr_cpu_ids) {
  1165. rcu_read_unlock();
  1166. return best_cpu;
  1167. }
  1168. }
  1169. }
  1170. rcu_read_unlock();
  1171. /*
  1172. * And finally, if there were no matches within the domains
  1173. * just give the caller *something* to work with from the compatible
  1174. * locations.
  1175. */
  1176. if (this_cpu != -1)
  1177. return this_cpu;
  1178. cpu = cpumask_any(lowest_mask);
  1179. if (cpu < nr_cpu_ids)
  1180. return cpu;
  1181. return -1;
  1182. }
  1183. /* Will lock the rq it finds */
  1184. static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
  1185. {
  1186. struct rq *lowest_rq = NULL;
  1187. int tries;
  1188. int cpu;
  1189. for (tries = 0; tries < RT_MAX_TRIES; tries++) {
  1190. cpu = find_lowest_rq(task);
  1191. if ((cpu == -1) || (cpu == rq->cpu))
  1192. break;
  1193. lowest_rq = cpu_rq(cpu);
  1194. /* if the prio of this runqueue changed, try again */
  1195. if (double_lock_balance(rq, lowest_rq)) {
  1196. /*
  1197. * We had to unlock the run queue. In
  1198. * the mean time, task could have
  1199. * migrated already or had its affinity changed.
  1200. * Also make sure that it wasn't scheduled on its rq.
  1201. */
  1202. if (unlikely(task_rq(task) != rq ||
  1203. !cpumask_test_cpu(lowest_rq->cpu,
  1204. tsk_cpus_allowed(task)) ||
  1205. task_running(rq, task) ||
  1206. !task->on_rq)) {
  1207. double_unlock_balance(rq, lowest_rq);
  1208. lowest_rq = NULL;
  1209. break;
  1210. }
  1211. }
  1212. /* If this rq is still suitable use it. */
  1213. if (lowest_rq->rt.highest_prio.curr > task->prio)
  1214. break;
  1215. /* try again */
  1216. double_unlock_balance(rq, lowest_rq);
  1217. lowest_rq = NULL;
  1218. }
  1219. return lowest_rq;
  1220. }
  1221. static struct task_struct *pick_next_pushable_task(struct rq *rq)
  1222. {
  1223. struct task_struct *p;
  1224. if (!has_pushable_tasks(rq))
  1225. return NULL;
  1226. p = plist_first_entry(&rq->rt.pushable_tasks,
  1227. struct task_struct, pushable_tasks);
  1228. BUG_ON(rq->cpu != task_cpu(p));
  1229. BUG_ON(task_current(rq, p));
  1230. BUG_ON(p->nr_cpus_allowed <= 1);
  1231. BUG_ON(!p->on_rq);
  1232. BUG_ON(!rt_task(p));
  1233. return p;
  1234. }
  1235. /*
  1236. * If the current CPU has more than one RT task, see if the non
  1237. * running task can migrate over to a CPU that is running a task
  1238. * of lesser priority.
  1239. */
  1240. static int push_rt_task(struct rq *rq)
  1241. {
  1242. struct task_struct *next_task;
  1243. struct rq *lowest_rq;
  1244. int ret = 0;
  1245. if (!rq->rt.overloaded)
  1246. return 0;
  1247. next_task = pick_next_pushable_task(rq);
  1248. if (!next_task)
  1249. return 0;
  1250. retry:
  1251. if (unlikely(next_task == rq->curr)) {
  1252. WARN_ON(1);
  1253. return 0;
  1254. }
  1255. /*
  1256. * It's possible that the next_task slipped in of
  1257. * higher priority than current. If that's the case
  1258. * just reschedule current.
  1259. */
  1260. if (unlikely(next_task->prio < rq->curr->prio)) {
  1261. resched_task(rq->curr);
  1262. return 0;
  1263. }
  1264. /* We might release rq lock */
  1265. get_task_struct(next_task);
  1266. /* find_lock_lowest_rq locks the rq if found */
  1267. lowest_rq = find_lock_lowest_rq(next_task, rq);
  1268. if (!lowest_rq) {
  1269. struct task_struct *task;
  1270. /*
  1271. * find_lock_lowest_rq releases rq->lock
  1272. * so it is possible that next_task has migrated.
  1273. *
  1274. * We need to make sure that the task is still on the same
  1275. * run-queue and is also still the next task eligible for
  1276. * pushing.
  1277. */
  1278. task = pick_next_pushable_task(rq);
  1279. if (task_cpu(next_task) == rq->cpu && task == next_task) {
  1280. /*
  1281. * The task hasn't migrated, and is still the next
  1282. * eligible task, but we failed to find a run-queue
  1283. * to push it to. Do not retry in this case, since
  1284. * other cpus will pull from us when ready.
  1285. */
  1286. goto out;
  1287. }
  1288. if (!task)
  1289. /* No more tasks, just exit */
  1290. goto out;
  1291. /*
  1292. * Something has shifted, try again.
  1293. */
  1294. put_task_struct(next_task);
  1295. next_task = task;
  1296. goto retry;
  1297. }
  1298. deactivate_task(rq, next_task, 0);
  1299. set_task_cpu(next_task, lowest_rq->cpu);
  1300. activate_task(lowest_rq, next_task, 0);
  1301. ret = 1;
  1302. resched_task(lowest_rq->curr);
  1303. double_unlock_balance(rq, lowest_rq);
  1304. out:
  1305. put_task_struct(next_task);
  1306. return ret;
  1307. }
  1308. static void push_rt_tasks(struct rq *rq)
  1309. {
  1310. /* push_rt_task will return true if it moved an RT */
  1311. while (push_rt_task(rq))
  1312. ;
  1313. }
  1314. static int pull_rt_task(struct rq *this_rq)
  1315. {
  1316. int this_cpu = this_rq->cpu, ret = 0, cpu;
  1317. struct task_struct *p;
  1318. struct rq *src_rq;
  1319. if (likely(!rt_overloaded(this_rq)))
  1320. return 0;
  1321. /*
  1322. * Match the barrier from rt_set_overloaded; this guarantees that if we
  1323. * see overloaded we must also see the rto_mask bit.
  1324. */
  1325. smp_rmb();
  1326. for_each_cpu(cpu, this_rq->rd->rto_mask) {
  1327. if (this_cpu == cpu)
  1328. continue;
  1329. src_rq = cpu_rq(cpu);
  1330. /*
  1331. * Don't bother taking the src_rq->lock if the next highest
  1332. * task is known to be lower-priority than our current task.
  1333. * This may look racy, but if this value is about to go
  1334. * logically higher, the src_rq will push this task away.
  1335. * And if its going logically lower, we do not care
  1336. */
  1337. if (src_rq->rt.highest_prio.next >=
  1338. this_rq->rt.highest_prio.curr)
  1339. continue;
  1340. /*
  1341. * We can potentially drop this_rq's lock in
  1342. * double_lock_balance, and another CPU could
  1343. * alter this_rq
  1344. */
  1345. double_lock_balance(this_rq, src_rq);
  1346. /*
  1347. * We can pull only a task, which is pushable
  1348. * on its rq, and no others.
  1349. */
  1350. p = pick_highest_pushable_task(src_rq, this_cpu);
  1351. /*
  1352. * Do we have an RT task that preempts
  1353. * the to-be-scheduled task?
  1354. */
  1355. if (p && (p->prio < this_rq->rt.highest_prio.curr)) {
  1356. WARN_ON(p == src_rq->curr);
  1357. WARN_ON(!p->on_rq);
  1358. /*
  1359. * There's a chance that p is higher in priority
  1360. * than what's currently running on its cpu.
  1361. * This is just that p is wakeing up and hasn't
  1362. * had a chance to schedule. We only pull
  1363. * p if it is lower in priority than the
  1364. * current task on the run queue
  1365. */
  1366. if (p->prio < src_rq->curr->prio)
  1367. goto skip;
  1368. ret = 1;
  1369. deactivate_task(src_rq, p, 0);
  1370. set_task_cpu(p, this_cpu);
  1371. activate_task(this_rq, p, 0);
  1372. /*
  1373. * We continue with the search, just in
  1374. * case there's an even higher prio task
  1375. * in another runqueue. (low likelihood
  1376. * but possible)
  1377. */
  1378. }
  1379. skip:
  1380. double_unlock_balance(this_rq, src_rq);
  1381. }
  1382. return ret;
  1383. }
  1384. static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
  1385. {
  1386. /* Try to pull RT tasks here if we lower this rq's prio */
  1387. if (rq->rt.highest_prio.curr > prev->prio)
  1388. pull_rt_task(rq);
  1389. }
  1390. static void post_schedule_rt(struct rq *rq)
  1391. {
  1392. push_rt_tasks(rq);
  1393. }
  1394. /*
  1395. * If we are not running and we are not going to reschedule soon, we should
  1396. * try to push tasks away now
  1397. */
  1398. static void task_woken_rt(struct rq *rq, struct task_struct *p)
  1399. {
  1400. if (!task_running(rq, p) &&
  1401. !test_tsk_need_resched(rq->curr) &&
  1402. has_pushable_tasks(rq) &&
  1403. p->nr_cpus_allowed > 1 &&
  1404. (dl_task(rq->curr) || rt_task(rq->curr)) &&
  1405. (rq->curr->nr_cpus_allowed < 2 ||
  1406. rq->curr->prio <= p->prio))
  1407. push_rt_tasks(rq);
  1408. }
  1409. static void set_cpus_allowed_rt(struct task_struct *p,
  1410. const struct cpumask *new_mask)
  1411. {
  1412. struct rq *rq;
  1413. int weight;
  1414. BUG_ON(!rt_task(p));
  1415. if (!p->on_rq)
  1416. return;
  1417. weight = cpumask_weight(new_mask);
  1418. /*
  1419. * Only update if the process changes its state from whether it
  1420. * can migrate or not.
  1421. */
  1422. if ((p->nr_cpus_allowed > 1) == (weight > 1))
  1423. return;
  1424. rq = task_rq(p);
  1425. /*
  1426. * The process used to be able to migrate OR it can now migrate
  1427. */
  1428. if (weight <= 1) {
  1429. if (!task_current(rq, p))
  1430. dequeue_pushable_task(rq, p);
  1431. BUG_ON(!rq->rt.rt_nr_migratory);
  1432. rq->rt.rt_nr_migratory--;
  1433. } else {
  1434. if (!task_current(rq, p))
  1435. enqueue_pushable_task(rq, p);
  1436. rq->rt.rt_nr_migratory++;
  1437. }
  1438. update_rt_migration(&rq->rt);
  1439. }
  1440. /* Assumes rq->lock is held */
  1441. static void rq_online_rt(struct rq *rq)
  1442. {
  1443. if (rq->rt.overloaded)
  1444. rt_set_overload(rq);
  1445. __enable_runtime(rq);
  1446. cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
  1447. }
  1448. /* Assumes rq->lock is held */
  1449. static void rq_offline_rt(struct rq *rq)
  1450. {
  1451. if (rq->rt.overloaded)
  1452. rt_clear_overload(rq);
  1453. __disable_runtime(rq);
  1454. cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
  1455. }
  1456. /*
  1457. * When switch from the rt queue, we bring ourselves to a position
  1458. * that we might want to pull RT tasks from other runqueues.
  1459. */
  1460. static void switched_from_rt(struct rq *rq, struct task_struct *p)
  1461. {
  1462. /*
  1463. * If there are other RT tasks then we will reschedule
  1464. * and the scheduling of the other RT tasks will handle
  1465. * the balancing. But if we are the last RT task
  1466. * we may need to handle the pulling of RT tasks
  1467. * now.
  1468. */
  1469. if (!p->on_rq || rq->rt.rt_nr_running)
  1470. return;
  1471. if (pull_rt_task(rq))
  1472. resched_task(rq->curr);
  1473. }
  1474. void init_sched_rt_class(void)
  1475. {
  1476. unsigned int i;
  1477. for_each_possible_cpu(i) {
  1478. zalloc_cpumask_var_node(&per_cpu(local_cpu_mask, i),
  1479. GFP_KERNEL, cpu_to_node(i));
  1480. }
  1481. }
  1482. #endif /* CONFIG_SMP */
  1483. /*
  1484. * When switching a task to RT, we may overload the runqueue
  1485. * with RT tasks. In this case we try to push them off to
  1486. * other runqueues.
  1487. */
  1488. static void switched_to_rt(struct rq *rq, struct task_struct *p)
  1489. {
  1490. int check_resched = 1;
  1491. /*
  1492. * If we are already running, then there's nothing
  1493. * that needs to be done. But if we are not running
  1494. * we may need to preempt the current running task.
  1495. * If that current running task is also an RT task
  1496. * then see if we can move to another run queue.
  1497. */
  1498. if (p->on_rq && rq->curr != p) {
  1499. #ifdef CONFIG_SMP
  1500. if (rq->rt.overloaded && push_rt_task(rq) &&
  1501. /* Don't resched if we changed runqueues */
  1502. rq != task_rq(p))
  1503. check_resched = 0;
  1504. #endif /* CONFIG_SMP */
  1505. if (check_resched && p->prio < rq->curr->prio)
  1506. resched_task(rq->curr);
  1507. }
  1508. }
  1509. /*
  1510. * Priority of the task has changed. This may cause
  1511. * us to initiate a push or pull.
  1512. */
  1513. static void
  1514. prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio)
  1515. {
  1516. if (!p->on_rq)
  1517. return;
  1518. if (rq->curr == p) {
  1519. #ifdef CONFIG_SMP
  1520. /*
  1521. * If our priority decreases while running, we
  1522. * may need to pull tasks to this runqueue.
  1523. */
  1524. if (oldprio < p->prio)
  1525. pull_rt_task(rq);
  1526. /*
  1527. * If there's a higher priority task waiting to run
  1528. * then reschedule. Note, the above pull_rt_task
  1529. * can release the rq lock and p could migrate.
  1530. * Only reschedule if p is still on the same runqueue.
  1531. */
  1532. if (p->prio > rq->rt.highest_prio.curr && rq->curr == p)
  1533. resched_task(p);
  1534. #else
  1535. /* For UP simply resched on drop of prio */
  1536. if (oldprio < p->prio)
  1537. resched_task(p);
  1538. #endif /* CONFIG_SMP */
  1539. } else {
  1540. /*
  1541. * This task is not running, but if it is
  1542. * greater than the current running task
  1543. * then reschedule.
  1544. */
  1545. if (p->prio < rq->curr->prio)
  1546. resched_task(rq->curr);
  1547. }
  1548. }
  1549. static void watchdog(struct rq *rq, struct task_struct *p)
  1550. {
  1551. unsigned long soft, hard;
  1552. /* max may change after cur was read, this will be fixed next tick */
  1553. soft = task_rlimit(p, RLIMIT_RTTIME);
  1554. hard = task_rlimit_max(p, RLIMIT_RTTIME);
  1555. if (soft != RLIM_INFINITY) {
  1556. unsigned long next;
  1557. if (p->rt.watchdog_stamp != jiffies) {
  1558. p->rt.timeout++;
  1559. p->rt.watchdog_stamp = jiffies;
  1560. }
  1561. next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
  1562. if (p->rt.timeout > next)
  1563. p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
  1564. }
  1565. }
  1566. static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
  1567. {
  1568. struct sched_rt_entity *rt_se = &p->rt;
  1569. update_curr_rt(rq);
  1570. watchdog(rq, p);
  1571. /*
  1572. * RR tasks need a special form of timeslice management.
  1573. * FIFO tasks have no timeslices.
  1574. */
  1575. if (p->policy != SCHED_RR)
  1576. return;
  1577. if (--p->rt.time_slice)
  1578. return;
  1579. p->rt.time_slice = sched_rr_timeslice;
  1580. /*
  1581. * Requeue to the end of queue if we (and all of our ancestors) are not
  1582. * the only element on the queue
  1583. */
  1584. for_each_sched_rt_entity(rt_se) {
  1585. if (rt_se->run_list.prev != rt_se->run_list.next) {
  1586. requeue_task_rt(rq, p, 0);
  1587. set_tsk_need_resched(p);
  1588. return;
  1589. }
  1590. }
  1591. }
  1592. static void set_curr_task_rt(struct rq *rq)
  1593. {
  1594. struct task_struct *p = rq->curr;
  1595. p->se.exec_start = rq_clock_task(rq);
  1596. /* The running task is never eligible for pushing */
  1597. dequeue_pushable_task(rq, p);
  1598. }
  1599. static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)
  1600. {
  1601. /*
  1602. * Time slice is 0 for SCHED_FIFO tasks
  1603. */
  1604. if (task->policy == SCHED_RR)
  1605. return sched_rr_timeslice;
  1606. else
  1607. return 0;
  1608. }
  1609. const struct sched_class rt_sched_class = {
  1610. .next = &fair_sched_class,
  1611. .enqueue_task = enqueue_task_rt,
  1612. .dequeue_task = dequeue_task_rt,
  1613. .yield_task = yield_task_rt,
  1614. .check_preempt_curr = check_preempt_curr_rt,
  1615. .pick_next_task = pick_next_task_rt,
  1616. .put_prev_task = put_prev_task_rt,
  1617. #ifdef CONFIG_SMP
  1618. .select_task_rq = select_task_rq_rt,
  1619. .set_cpus_allowed = set_cpus_allowed_rt,
  1620. .rq_online = rq_online_rt,
  1621. .rq_offline = rq_offline_rt,
  1622. .pre_schedule = pre_schedule_rt,
  1623. .post_schedule = post_schedule_rt,
  1624. .task_woken = task_woken_rt,
  1625. .switched_from = switched_from_rt,
  1626. #endif
  1627. .set_curr_task = set_curr_task_rt,
  1628. .task_tick = task_tick_rt,
  1629. .get_rr_interval = get_rr_interval_rt,
  1630. .prio_changed = prio_changed_rt,
  1631. .switched_to = switched_to_rt,
  1632. };
  1633. #ifdef CONFIG_SCHED_DEBUG
  1634. extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
  1635. void print_rt_stats(struct seq_file *m, int cpu)
  1636. {
  1637. rt_rq_iter_t iter;
  1638. struct rt_rq *rt_rq;
  1639. rcu_read_lock();
  1640. for_each_rt_rq(rt_rq, iter, cpu_rq(cpu))
  1641. print_rt_rq(m, cpu, rt_rq);
  1642. rcu_read_unlock();
  1643. }
  1644. #endif /* CONFIG_SCHED_DEBUG */