sched_fair.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * Completely Fair Scheduling (CFS) Class (SCHED_NORMAL/SCHED_BATCH)
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  5. *
  6. * Interactivity improvements by Mike Galbraith
  7. * (C) 2007 Mike Galbraith <efault@gmx.de>
  8. *
  9. * Various enhancements by Dmitry Adamushko.
  10. * (C) 2007 Dmitry Adamushko <dmitry.adamushko@gmail.com>
  11. *
  12. * Group scheduling enhancements by Srivatsa Vaddagiri
  13. * Copyright IBM Corporation, 2007
  14. * Author: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
  15. *
  16. * Scaled math optimizations by Thomas Gleixner
  17. * Copyright (C) 2007, Thomas Gleixner <tglx@linutronix.de>
  18. *
  19. * Adaptive scheduling granularity, math enhancements by Peter Zijlstra
  20. * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
  21. */
  22. #include <linux/latencytop.h>
  23. /*
  24. * Targeted preemption latency for CPU-bound tasks:
  25. * (default: 20ms * (1 + ilog(ncpus)), units: nanoseconds)
  26. *
  27. * NOTE: this latency value is not the same as the concept of
  28. * 'timeslice length' - timeslices in CFS are of variable length
  29. * and have no persistent notion like in traditional, time-slice
  30. * based scheduling concepts.
  31. *
  32. * (to see the precise effective timeslice length of your workload,
  33. * run vmstat and monitor the context-switches (cs) field)
  34. */
  35. unsigned int sysctl_sched_latency = 20000000ULL;
  36. /*
  37. * Minimal preemption granularity for CPU-bound tasks:
  38. * (default: 4 msec * (1 + ilog(ncpus)), units: nanoseconds)
  39. */
  40. unsigned int sysctl_sched_min_granularity = 4000000ULL;
  41. /*
  42. * is kept at sysctl_sched_latency / sysctl_sched_min_granularity
  43. */
  44. static unsigned int sched_nr_latency = 5;
  45. /*
  46. * After fork, child runs first. (default) If set to 0 then
  47. * parent will (try to) run first.
  48. */
  49. const_debug unsigned int sysctl_sched_child_runs_first = 1;
  50. /*
  51. * sys_sched_yield() compat mode
  52. *
  53. * This option switches the agressive yield implementation of the
  54. * old scheduler back on.
  55. */
  56. unsigned int __read_mostly sysctl_sched_compat_yield;
  57. /*
  58. * SCHED_BATCH wake-up granularity.
  59. * (default: 10 msec * (1 + ilog(ncpus)), units: nanoseconds)
  60. *
  61. * This option delays the preemption effects of decoupled workloads
  62. * and reduces their over-scheduling. Synchronous workloads will still
  63. * have immediate wakeup/sleep latencies.
  64. */
  65. unsigned int sysctl_sched_batch_wakeup_granularity = 10000000UL;
  66. /*
  67. * SCHED_OTHER wake-up granularity.
  68. * (default: 10 msec * (1 + ilog(ncpus)), units: nanoseconds)
  69. *
  70. * This option delays the preemption effects of decoupled workloads
  71. * and reduces their over-scheduling. Synchronous workloads will still
  72. * have immediate wakeup/sleep latencies.
  73. */
  74. unsigned int sysctl_sched_wakeup_granularity = 10000000UL;
  75. const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
  76. /**************************************************************
  77. * CFS operations on generic schedulable entities:
  78. */
  79. #ifdef CONFIG_FAIR_GROUP_SCHED
  80. /* cpu runqueue to which this cfs_rq is attached */
  81. static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
  82. {
  83. return cfs_rq->rq;
  84. }
  85. /* An entity is a task if it doesn't "own" a runqueue */
  86. #define entity_is_task(se) (!se->my_q)
  87. #else /* CONFIG_FAIR_GROUP_SCHED */
  88. static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
  89. {
  90. return container_of(cfs_rq, struct rq, cfs);
  91. }
  92. #define entity_is_task(se) 1
  93. #endif /* CONFIG_FAIR_GROUP_SCHED */
  94. static inline struct task_struct *task_of(struct sched_entity *se)
  95. {
  96. return container_of(se, struct task_struct, se);
  97. }
  98. /**************************************************************
  99. * Scheduling class tree data structure manipulation methods:
  100. */
  101. static inline u64 max_vruntime(u64 min_vruntime, u64 vruntime)
  102. {
  103. s64 delta = (s64)(vruntime - min_vruntime);
  104. if (delta > 0)
  105. min_vruntime = vruntime;
  106. return min_vruntime;
  107. }
  108. static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
  109. {
  110. s64 delta = (s64)(vruntime - min_vruntime);
  111. if (delta < 0)
  112. min_vruntime = vruntime;
  113. return min_vruntime;
  114. }
  115. static inline s64 entity_key(struct cfs_rq *cfs_rq, struct sched_entity *se)
  116. {
  117. return se->vruntime - cfs_rq->min_vruntime;
  118. }
  119. /*
  120. * Enqueue an entity into the rb-tree:
  121. */
  122. static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
  123. {
  124. struct rb_node **link = &cfs_rq->tasks_timeline.rb_node;
  125. struct rb_node *parent = NULL;
  126. struct sched_entity *entry;
  127. s64 key = entity_key(cfs_rq, se);
  128. int leftmost = 1;
  129. /*
  130. * Find the right place in the rbtree:
  131. */
  132. while (*link) {
  133. parent = *link;
  134. entry = rb_entry(parent, struct sched_entity, run_node);
  135. /*
  136. * We dont care about collisions. Nodes with
  137. * the same key stay together.
  138. */
  139. if (key < entity_key(cfs_rq, entry)) {
  140. link = &parent->rb_left;
  141. } else {
  142. link = &parent->rb_right;
  143. leftmost = 0;
  144. }
  145. }
  146. /*
  147. * Maintain a cache of leftmost tree entries (it is frequently
  148. * used):
  149. */
  150. if (leftmost)
  151. cfs_rq->rb_leftmost = &se->run_node;
  152. rb_link_node(&se->run_node, parent, link);
  153. rb_insert_color(&se->run_node, &cfs_rq->tasks_timeline);
  154. }
  155. static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
  156. {
  157. if (cfs_rq->rb_leftmost == &se->run_node)
  158. cfs_rq->rb_leftmost = rb_next(&se->run_node);
  159. rb_erase(&se->run_node, &cfs_rq->tasks_timeline);
  160. }
  161. static inline struct rb_node *first_fair(struct cfs_rq *cfs_rq)
  162. {
  163. return cfs_rq->rb_leftmost;
  164. }
  165. static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq)
  166. {
  167. return rb_entry(first_fair(cfs_rq), struct sched_entity, run_node);
  168. }
  169. static inline struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
  170. {
  171. struct rb_node *last = rb_last(&cfs_rq->tasks_timeline);
  172. if (!last)
  173. return NULL;
  174. return rb_entry(last, struct sched_entity, run_node);
  175. }
  176. /**************************************************************
  177. * Scheduling class statistics methods:
  178. */
  179. #ifdef CONFIG_SCHED_DEBUG
  180. int sched_nr_latency_handler(struct ctl_table *table, int write,
  181. struct file *filp, void __user *buffer, size_t *lenp,
  182. loff_t *ppos)
  183. {
  184. int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
  185. if (ret || !write)
  186. return ret;
  187. sched_nr_latency = DIV_ROUND_UP(sysctl_sched_latency,
  188. sysctl_sched_min_granularity);
  189. return 0;
  190. }
  191. #endif
  192. /*
  193. * The idea is to set a period in which each task runs once.
  194. *
  195. * When there are too many tasks (sysctl_sched_nr_latency) we have to stretch
  196. * this period because otherwise the slices get too small.
  197. *
  198. * p = (nr <= nl) ? l : l*nr/nl
  199. */
  200. static u64 __sched_period(unsigned long nr_running)
  201. {
  202. u64 period = sysctl_sched_latency;
  203. unsigned long nr_latency = sched_nr_latency;
  204. if (unlikely(nr_running > nr_latency)) {
  205. period = sysctl_sched_min_granularity;
  206. period *= nr_running;
  207. }
  208. return period;
  209. }
  210. /*
  211. * We calculate the wall-time slice from the period by taking a part
  212. * proportional to the weight.
  213. *
  214. * s = p*w/rw
  215. */
  216. static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
  217. {
  218. u64 slice = __sched_period(cfs_rq->nr_running);
  219. slice *= se->load.weight;
  220. do_div(slice, cfs_rq->load.weight);
  221. return slice;
  222. }
  223. /*
  224. * We calculate the vruntime slice.
  225. *
  226. * vs = s/w = p/rw
  227. */
  228. static u64 __sched_vslice(unsigned long rq_weight, unsigned long nr_running)
  229. {
  230. u64 vslice = __sched_period(nr_running);
  231. vslice *= NICE_0_LOAD;
  232. do_div(vslice, rq_weight);
  233. return vslice;
  234. }
  235. static u64 sched_vslice(struct cfs_rq *cfs_rq)
  236. {
  237. return __sched_vslice(cfs_rq->load.weight, cfs_rq->nr_running);
  238. }
  239. static u64 sched_vslice_add(struct cfs_rq *cfs_rq, struct sched_entity *se)
  240. {
  241. return __sched_vslice(cfs_rq->load.weight + se->load.weight,
  242. cfs_rq->nr_running + 1);
  243. }
  244. /*
  245. * Update the current task's runtime statistics. Skip current tasks that
  246. * are not in our scheduling class.
  247. */
  248. static inline void
  249. __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr,
  250. unsigned long delta_exec)
  251. {
  252. unsigned long delta_exec_weighted;
  253. u64 vruntime;
  254. schedstat_set(curr->exec_max, max((u64)delta_exec, curr->exec_max));
  255. curr->sum_exec_runtime += delta_exec;
  256. schedstat_add(cfs_rq, exec_clock, delta_exec);
  257. delta_exec_weighted = delta_exec;
  258. if (unlikely(curr->load.weight != NICE_0_LOAD)) {
  259. delta_exec_weighted = calc_delta_fair(delta_exec_weighted,
  260. &curr->load);
  261. }
  262. curr->vruntime += delta_exec_weighted;
  263. /*
  264. * maintain cfs_rq->min_vruntime to be a monotonic increasing
  265. * value tracking the leftmost vruntime in the tree.
  266. */
  267. if (first_fair(cfs_rq)) {
  268. vruntime = min_vruntime(curr->vruntime,
  269. __pick_next_entity(cfs_rq)->vruntime);
  270. } else
  271. vruntime = curr->vruntime;
  272. cfs_rq->min_vruntime =
  273. max_vruntime(cfs_rq->min_vruntime, vruntime);
  274. }
  275. static void update_curr(struct cfs_rq *cfs_rq)
  276. {
  277. struct sched_entity *curr = cfs_rq->curr;
  278. u64 now = rq_of(cfs_rq)->clock;
  279. unsigned long delta_exec;
  280. if (unlikely(!curr))
  281. return;
  282. /*
  283. * Get the amount of time the current task was running
  284. * since the last time we changed load (this cannot
  285. * overflow on 32 bits):
  286. */
  287. delta_exec = (unsigned long)(now - curr->exec_start);
  288. __update_curr(cfs_rq, curr, delta_exec);
  289. curr->exec_start = now;
  290. if (entity_is_task(curr)) {
  291. struct task_struct *curtask = task_of(curr);
  292. cpuacct_charge(curtask, delta_exec);
  293. }
  294. }
  295. static inline void
  296. update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
  297. {
  298. schedstat_set(se->wait_start, rq_of(cfs_rq)->clock);
  299. }
  300. /*
  301. * Task is being enqueued - update stats:
  302. */
  303. static void update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
  304. {
  305. /*
  306. * Are we enqueueing a waiting task? (for current tasks
  307. * a dequeue/enqueue event is a NOP)
  308. */
  309. if (se != cfs_rq->curr)
  310. update_stats_wait_start(cfs_rq, se);
  311. }
  312. static void
  313. update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
  314. {
  315. schedstat_set(se->wait_max, max(se->wait_max,
  316. rq_of(cfs_rq)->clock - se->wait_start));
  317. schedstat_set(se->wait_count, se->wait_count + 1);
  318. schedstat_set(se->wait_sum, se->wait_sum +
  319. rq_of(cfs_rq)->clock - se->wait_start);
  320. schedstat_set(se->wait_start, 0);
  321. }
  322. static inline void
  323. update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
  324. {
  325. /*
  326. * Mark the end of the wait period if dequeueing a
  327. * waiting task:
  328. */
  329. if (se != cfs_rq->curr)
  330. update_stats_wait_end(cfs_rq, se);
  331. }
  332. /*
  333. * We are picking a new current task - update its stats:
  334. */
  335. static inline void
  336. update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
  337. {
  338. /*
  339. * We are starting a new run period:
  340. */
  341. se->exec_start = rq_of(cfs_rq)->clock;
  342. }
  343. /**************************************************
  344. * Scheduling class queueing methods:
  345. */
  346. static void
  347. account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
  348. {
  349. update_load_add(&cfs_rq->load, se->load.weight);
  350. cfs_rq->nr_running++;
  351. se->on_rq = 1;
  352. }
  353. static void
  354. account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
  355. {
  356. update_load_sub(&cfs_rq->load, se->load.weight);
  357. cfs_rq->nr_running--;
  358. se->on_rq = 0;
  359. }
  360. static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
  361. {
  362. #ifdef CONFIG_SCHEDSTATS
  363. if (se->sleep_start) {
  364. u64 delta = rq_of(cfs_rq)->clock - se->sleep_start;
  365. struct task_struct *tsk = task_of(se);
  366. if ((s64)delta < 0)
  367. delta = 0;
  368. if (unlikely(delta > se->sleep_max))
  369. se->sleep_max = delta;
  370. se->sleep_start = 0;
  371. se->sum_sleep_runtime += delta;
  372. account_scheduler_latency(tsk, delta >> 10, 1);
  373. }
  374. if (se->block_start) {
  375. u64 delta = rq_of(cfs_rq)->clock - se->block_start;
  376. struct task_struct *tsk = task_of(se);
  377. if ((s64)delta < 0)
  378. delta = 0;
  379. if (unlikely(delta > se->block_max))
  380. se->block_max = delta;
  381. se->block_start = 0;
  382. se->sum_sleep_runtime += delta;
  383. /*
  384. * Blocking time is in units of nanosecs, so shift by 20 to
  385. * get a milliseconds-range estimation of the amount of
  386. * time that the task spent sleeping:
  387. */
  388. if (unlikely(prof_on == SLEEP_PROFILING)) {
  389. profile_hits(SLEEP_PROFILING, (void *)get_wchan(tsk),
  390. delta >> 20);
  391. }
  392. account_scheduler_latency(tsk, delta >> 10, 0);
  393. }
  394. #endif
  395. }
  396. static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se)
  397. {
  398. #ifdef CONFIG_SCHED_DEBUG
  399. s64 d = se->vruntime - cfs_rq->min_vruntime;
  400. if (d < 0)
  401. d = -d;
  402. if (d > 3*sysctl_sched_latency)
  403. schedstat_inc(cfs_rq, nr_spread_over);
  404. #endif
  405. }
  406. static void
  407. place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
  408. {
  409. u64 vruntime;
  410. vruntime = cfs_rq->min_vruntime;
  411. if (sched_feat(TREE_AVG)) {
  412. struct sched_entity *last = __pick_last_entity(cfs_rq);
  413. if (last) {
  414. vruntime += last->vruntime;
  415. vruntime >>= 1;
  416. }
  417. } else if (sched_feat(APPROX_AVG) && cfs_rq->nr_running)
  418. vruntime += sched_vslice(cfs_rq)/2;
  419. /*
  420. * The 'current' period is already promised to the current tasks,
  421. * however the extra weight of the new task will slow them down a
  422. * little, place the new task so that it fits in the slot that
  423. * stays open at the end.
  424. */
  425. if (initial && sched_feat(START_DEBIT))
  426. vruntime += sched_vslice_add(cfs_rq, se);
  427. if (!initial) {
  428. /* sleeps upto a single latency don't count. */
  429. if (sched_feat(NEW_FAIR_SLEEPERS))
  430. vruntime -= sysctl_sched_latency;
  431. /* ensure we never gain time by being placed backwards. */
  432. vruntime = max_vruntime(se->vruntime, vruntime);
  433. }
  434. se->vruntime = vruntime;
  435. }
  436. static void
  437. enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
  438. {
  439. /*
  440. * Update run-time statistics of the 'current'.
  441. */
  442. update_curr(cfs_rq);
  443. if (wakeup) {
  444. place_entity(cfs_rq, se, 0);
  445. enqueue_sleeper(cfs_rq, se);
  446. }
  447. update_stats_enqueue(cfs_rq, se);
  448. check_spread(cfs_rq, se);
  449. if (se != cfs_rq->curr)
  450. __enqueue_entity(cfs_rq, se);
  451. account_entity_enqueue(cfs_rq, se);
  452. }
  453. static void
  454. dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
  455. {
  456. /*
  457. * Update run-time statistics of the 'current'.
  458. */
  459. update_curr(cfs_rq);
  460. update_stats_dequeue(cfs_rq, se);
  461. if (sleep) {
  462. #ifdef CONFIG_SCHEDSTATS
  463. if (entity_is_task(se)) {
  464. struct task_struct *tsk = task_of(se);
  465. if (tsk->state & TASK_INTERRUPTIBLE)
  466. se->sleep_start = rq_of(cfs_rq)->clock;
  467. if (tsk->state & TASK_UNINTERRUPTIBLE)
  468. se->block_start = rq_of(cfs_rq)->clock;
  469. }
  470. #endif
  471. }
  472. if (se != cfs_rq->curr)
  473. __dequeue_entity(cfs_rq, se);
  474. account_entity_dequeue(cfs_rq, se);
  475. }
  476. /*
  477. * Preempt the current task with a newly woken task if needed:
  478. */
  479. static void
  480. check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
  481. {
  482. unsigned long ideal_runtime, delta_exec;
  483. ideal_runtime = sched_slice(cfs_rq, curr);
  484. delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
  485. if (delta_exec > ideal_runtime)
  486. resched_task(rq_of(cfs_rq)->curr);
  487. }
  488. static void
  489. set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
  490. {
  491. /* 'current' is not kept within the tree. */
  492. if (se->on_rq) {
  493. /*
  494. * Any task has to be enqueued before it get to execute on
  495. * a CPU. So account for the time it spent waiting on the
  496. * runqueue.
  497. */
  498. update_stats_wait_end(cfs_rq, se);
  499. __dequeue_entity(cfs_rq, se);
  500. }
  501. update_stats_curr_start(cfs_rq, se);
  502. cfs_rq->curr = se;
  503. #ifdef CONFIG_SCHEDSTATS
  504. /*
  505. * Track our maximum slice length, if the CPU's load is at
  506. * least twice that of our own weight (i.e. dont track it
  507. * when there are only lesser-weight tasks around):
  508. */
  509. if (rq_of(cfs_rq)->load.weight >= 2*se->load.weight) {
  510. se->slice_max = max(se->slice_max,
  511. se->sum_exec_runtime - se->prev_sum_exec_runtime);
  512. }
  513. #endif
  514. se->prev_sum_exec_runtime = se->sum_exec_runtime;
  515. }
  516. static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq)
  517. {
  518. struct sched_entity *se = NULL;
  519. if (first_fair(cfs_rq)) {
  520. se = __pick_next_entity(cfs_rq);
  521. set_next_entity(cfs_rq, se);
  522. }
  523. return se;
  524. }
  525. static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
  526. {
  527. /*
  528. * If still on the runqueue then deactivate_task()
  529. * was not called and update_curr() has to be done:
  530. */
  531. if (prev->on_rq)
  532. update_curr(cfs_rq);
  533. check_spread(cfs_rq, prev);
  534. if (prev->on_rq) {
  535. update_stats_wait_start(cfs_rq, prev);
  536. /* Put 'current' back into the tree. */
  537. __enqueue_entity(cfs_rq, prev);
  538. }
  539. cfs_rq->curr = NULL;
  540. }
  541. static void
  542. entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
  543. {
  544. /*
  545. * Update run-time statistics of the 'current'.
  546. */
  547. update_curr(cfs_rq);
  548. #ifdef CONFIG_SCHED_HRTICK
  549. /*
  550. * queued ticks are scheduled to match the slice, so don't bother
  551. * validating it and just reschedule.
  552. */
  553. if (queued)
  554. return resched_task(rq_of(cfs_rq)->curr);
  555. /*
  556. * don't let the period tick interfere with the hrtick preemption
  557. */
  558. if (!sched_feat(DOUBLE_TICK) &&
  559. hrtimer_active(&rq_of(cfs_rq)->hrtick_timer))
  560. return;
  561. #endif
  562. if (cfs_rq->nr_running > 1 || !sched_feat(WAKEUP_PREEMPT))
  563. check_preempt_tick(cfs_rq, curr);
  564. }
  565. /**************************************************
  566. * CFS operations on tasks:
  567. */
  568. #ifdef CONFIG_FAIR_GROUP_SCHED
  569. /* Walk up scheduling entities hierarchy */
  570. #define for_each_sched_entity(se) \
  571. for (; se; se = se->parent)
  572. static inline struct cfs_rq *task_cfs_rq(struct task_struct *p)
  573. {
  574. return p->se.cfs_rq;
  575. }
  576. /* runqueue on which this entity is (to be) queued */
  577. static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se)
  578. {
  579. return se->cfs_rq;
  580. }
  581. /* runqueue "owned" by this group */
  582. static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
  583. {
  584. return grp->my_q;
  585. }
  586. /* Given a group's cfs_rq on one cpu, return its corresponding cfs_rq on
  587. * another cpu ('this_cpu')
  588. */
  589. static inline struct cfs_rq *cpu_cfs_rq(struct cfs_rq *cfs_rq, int this_cpu)
  590. {
  591. return cfs_rq->tg->cfs_rq[this_cpu];
  592. }
  593. /* Iterate thr' all leaf cfs_rq's on a runqueue */
  594. #define for_each_leaf_cfs_rq(rq, cfs_rq) \
  595. list_for_each_entry_rcu(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list)
  596. /* Do the two (enqueued) entities belong to the same group ? */
  597. static inline int
  598. is_same_group(struct sched_entity *se, struct sched_entity *pse)
  599. {
  600. if (se->cfs_rq == pse->cfs_rq)
  601. return 1;
  602. return 0;
  603. }
  604. static inline struct sched_entity *parent_entity(struct sched_entity *se)
  605. {
  606. return se->parent;
  607. }
  608. #else /* CONFIG_FAIR_GROUP_SCHED */
  609. #define for_each_sched_entity(se) \
  610. for (; se; se = NULL)
  611. static inline struct cfs_rq *task_cfs_rq(struct task_struct *p)
  612. {
  613. return &task_rq(p)->cfs;
  614. }
  615. static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se)
  616. {
  617. struct task_struct *p = task_of(se);
  618. struct rq *rq = task_rq(p);
  619. return &rq->cfs;
  620. }
  621. /* runqueue "owned" by this group */
  622. static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
  623. {
  624. return NULL;
  625. }
  626. static inline struct cfs_rq *cpu_cfs_rq(struct cfs_rq *cfs_rq, int this_cpu)
  627. {
  628. return &cpu_rq(this_cpu)->cfs;
  629. }
  630. #define for_each_leaf_cfs_rq(rq, cfs_rq) \
  631. for (cfs_rq = &rq->cfs; cfs_rq; cfs_rq = NULL)
  632. static inline int
  633. is_same_group(struct sched_entity *se, struct sched_entity *pse)
  634. {
  635. return 1;
  636. }
  637. static inline struct sched_entity *parent_entity(struct sched_entity *se)
  638. {
  639. return NULL;
  640. }
  641. #endif /* CONFIG_FAIR_GROUP_SCHED */
  642. #ifdef CONFIG_SCHED_HRTICK
  643. static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
  644. {
  645. int requeue = rq->curr == p;
  646. struct sched_entity *se = &p->se;
  647. struct cfs_rq *cfs_rq = cfs_rq_of(se);
  648. WARN_ON(task_rq(p) != rq);
  649. if (hrtick_enabled(rq) && cfs_rq->nr_running > 1) {
  650. u64 slice = sched_slice(cfs_rq, se);
  651. u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime;
  652. s64 delta = slice - ran;
  653. if (delta < 0) {
  654. if (rq->curr == p)
  655. resched_task(p);
  656. return;
  657. }
  658. /*
  659. * Don't schedule slices shorter than 10000ns, that just
  660. * doesn't make sense. Rely on vruntime for fairness.
  661. */
  662. if (!requeue)
  663. delta = max(10000LL, delta);
  664. hrtick_start(rq, delta, requeue);
  665. }
  666. }
  667. #else
  668. static inline void
  669. hrtick_start_fair(struct rq *rq, struct task_struct *p)
  670. {
  671. }
  672. #endif
  673. /*
  674. * The enqueue_task method is called before nr_running is
  675. * increased. Here we update the fair scheduling stats and
  676. * then put the task into the rbtree:
  677. */
  678. static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
  679. {
  680. struct cfs_rq *cfs_rq;
  681. struct sched_entity *se = &p->se;
  682. for_each_sched_entity(se) {
  683. if (se->on_rq)
  684. break;
  685. cfs_rq = cfs_rq_of(se);
  686. enqueue_entity(cfs_rq, se, wakeup);
  687. wakeup = 1;
  688. }
  689. hrtick_start_fair(rq, rq->curr);
  690. }
  691. /*
  692. * The dequeue_task method is called before nr_running is
  693. * decreased. We remove the task from the rbtree and
  694. * update the fair scheduling stats:
  695. */
  696. static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int sleep)
  697. {
  698. struct cfs_rq *cfs_rq;
  699. struct sched_entity *se = &p->se;
  700. for_each_sched_entity(se) {
  701. cfs_rq = cfs_rq_of(se);
  702. dequeue_entity(cfs_rq, se, sleep);
  703. /* Don't dequeue parent if it has other entities besides us */
  704. if (cfs_rq->load.weight)
  705. break;
  706. sleep = 1;
  707. }
  708. hrtick_start_fair(rq, rq->curr);
  709. }
  710. /*
  711. * sched_yield() support is very simple - we dequeue and enqueue.
  712. *
  713. * If compat_yield is turned on then we requeue to the end of the tree.
  714. */
  715. static void yield_task_fair(struct rq *rq)
  716. {
  717. struct task_struct *curr = rq->curr;
  718. struct cfs_rq *cfs_rq = task_cfs_rq(curr);
  719. struct sched_entity *rightmost, *se = &curr->se;
  720. /*
  721. * Are we the only task in the tree?
  722. */
  723. if (unlikely(cfs_rq->nr_running == 1))
  724. return;
  725. if (likely(!sysctl_sched_compat_yield) && curr->policy != SCHED_BATCH) {
  726. __update_rq_clock(rq);
  727. /*
  728. * Update run-time statistics of the 'current'.
  729. */
  730. update_curr(cfs_rq);
  731. return;
  732. }
  733. /*
  734. * Find the rightmost entry in the rbtree:
  735. */
  736. rightmost = __pick_last_entity(cfs_rq);
  737. /*
  738. * Already in the rightmost position?
  739. */
  740. if (unlikely(rightmost->vruntime < se->vruntime))
  741. return;
  742. /*
  743. * Minimally necessary key value to be last in the tree:
  744. * Upon rescheduling, sched_class::put_prev_task() will place
  745. * 'current' within the tree based on its new key value.
  746. */
  747. se->vruntime = rightmost->vruntime + 1;
  748. }
  749. /*
  750. * wake_idle() will wake a task on an idle cpu if task->cpu is
  751. * not idle and an idle cpu is available. The span of cpus to
  752. * search starts with cpus closest then further out as needed,
  753. * so we always favor a closer, idle cpu.
  754. *
  755. * Returns the CPU we should wake onto.
  756. */
  757. #if defined(ARCH_HAS_SCHED_WAKE_IDLE)
  758. static int wake_idle(int cpu, struct task_struct *p)
  759. {
  760. cpumask_t tmp;
  761. struct sched_domain *sd;
  762. int i;
  763. /*
  764. * If it is idle, then it is the best cpu to run this task.
  765. *
  766. * This cpu is also the best, if it has more than one task already.
  767. * Siblings must be also busy(in most cases) as they didn't already
  768. * pickup the extra load from this cpu and hence we need not check
  769. * sibling runqueue info. This will avoid the checks and cache miss
  770. * penalities associated with that.
  771. */
  772. if (idle_cpu(cpu) || cpu_rq(cpu)->nr_running > 1)
  773. return cpu;
  774. for_each_domain(cpu, sd) {
  775. if (sd->flags & SD_WAKE_IDLE) {
  776. cpus_and(tmp, sd->span, p->cpus_allowed);
  777. for_each_cpu_mask(i, tmp) {
  778. if (idle_cpu(i)) {
  779. if (i != task_cpu(p)) {
  780. schedstat_inc(p,
  781. se.nr_wakeups_idle);
  782. }
  783. return i;
  784. }
  785. }
  786. } else {
  787. break;
  788. }
  789. }
  790. return cpu;
  791. }
  792. #else
  793. static inline int wake_idle(int cpu, struct task_struct *p)
  794. {
  795. return cpu;
  796. }
  797. #endif
  798. #ifdef CONFIG_SMP
  799. static int select_task_rq_fair(struct task_struct *p, int sync)
  800. {
  801. int cpu, this_cpu;
  802. struct rq *rq;
  803. struct sched_domain *sd, *this_sd = NULL;
  804. int new_cpu;
  805. cpu = task_cpu(p);
  806. rq = task_rq(p);
  807. this_cpu = smp_processor_id();
  808. new_cpu = cpu;
  809. if (cpu == this_cpu)
  810. goto out_set_cpu;
  811. for_each_domain(this_cpu, sd) {
  812. if (cpu_isset(cpu, sd->span)) {
  813. this_sd = sd;
  814. break;
  815. }
  816. }
  817. if (unlikely(!cpu_isset(this_cpu, p->cpus_allowed)))
  818. goto out_set_cpu;
  819. /*
  820. * Check for affine wakeup and passive balancing possibilities.
  821. */
  822. if (this_sd) {
  823. int idx = this_sd->wake_idx;
  824. unsigned int imbalance;
  825. unsigned long load, this_load;
  826. imbalance = 100 + (this_sd->imbalance_pct - 100) / 2;
  827. load = source_load(cpu, idx);
  828. this_load = target_load(this_cpu, idx);
  829. new_cpu = this_cpu; /* Wake to this CPU if we can */
  830. if (this_sd->flags & SD_WAKE_AFFINE) {
  831. unsigned long tl = this_load;
  832. unsigned long tl_per_task;
  833. /*
  834. * Attract cache-cold tasks on sync wakeups:
  835. */
  836. if (sync && !task_hot(p, rq->clock, this_sd))
  837. goto out_set_cpu;
  838. schedstat_inc(p, se.nr_wakeups_affine_attempts);
  839. tl_per_task = cpu_avg_load_per_task(this_cpu);
  840. /*
  841. * If sync wakeup then subtract the (maximum possible)
  842. * effect of the currently running task from the load
  843. * of the current CPU:
  844. */
  845. if (sync)
  846. tl -= current->se.load.weight;
  847. if ((tl <= load &&
  848. tl + target_load(cpu, idx) <= tl_per_task) ||
  849. 100*(tl + p->se.load.weight) <= imbalance*load) {
  850. /*
  851. * This domain has SD_WAKE_AFFINE and
  852. * p is cache cold in this domain, and
  853. * there is no bad imbalance.
  854. */
  855. schedstat_inc(this_sd, ttwu_move_affine);
  856. schedstat_inc(p, se.nr_wakeups_affine);
  857. goto out_set_cpu;
  858. }
  859. }
  860. /*
  861. * Start passive balancing when half the imbalance_pct
  862. * limit is reached.
  863. */
  864. if (this_sd->flags & SD_WAKE_BALANCE) {
  865. if (imbalance*this_load <= 100*load) {
  866. schedstat_inc(this_sd, ttwu_move_balance);
  867. schedstat_inc(p, se.nr_wakeups_passive);
  868. goto out_set_cpu;
  869. }
  870. }
  871. }
  872. new_cpu = cpu; /* Could not wake to this_cpu. Wake to cpu instead */
  873. out_set_cpu:
  874. return wake_idle(new_cpu, p);
  875. }
  876. #endif /* CONFIG_SMP */
  877. /*
  878. * Preempt the current task with a newly woken task if needed:
  879. */
  880. static void check_preempt_wakeup(struct rq *rq, struct task_struct *p)
  881. {
  882. struct task_struct *curr = rq->curr;
  883. struct cfs_rq *cfs_rq = task_cfs_rq(curr);
  884. struct sched_entity *se = &curr->se, *pse = &p->se;
  885. unsigned long gran;
  886. if (unlikely(rt_prio(p->prio))) {
  887. update_rq_clock(rq);
  888. update_curr(cfs_rq);
  889. resched_task(curr);
  890. return;
  891. }
  892. /*
  893. * Batch tasks do not preempt (their preemption is driven by
  894. * the tick):
  895. */
  896. if (unlikely(p->policy == SCHED_BATCH))
  897. return;
  898. if (!sched_feat(WAKEUP_PREEMPT))
  899. return;
  900. while (!is_same_group(se, pse)) {
  901. se = parent_entity(se);
  902. pse = parent_entity(pse);
  903. }
  904. gran = sysctl_sched_wakeup_granularity;
  905. /*
  906. * More easily preempt - nice tasks, while not making
  907. * it harder for + nice tasks.
  908. */
  909. if (unlikely(se->load.weight > NICE_0_LOAD))
  910. gran = calc_delta_fair(gran, &se->load);
  911. if (pse->vruntime + gran < se->vruntime)
  912. resched_task(curr);
  913. }
  914. static struct task_struct *pick_next_task_fair(struct rq *rq)
  915. {
  916. struct task_struct *p;
  917. struct cfs_rq *cfs_rq = &rq->cfs;
  918. struct sched_entity *se;
  919. if (unlikely(!cfs_rq->nr_running))
  920. return NULL;
  921. do {
  922. se = pick_next_entity(cfs_rq);
  923. cfs_rq = group_cfs_rq(se);
  924. } while (cfs_rq);
  925. p = task_of(se);
  926. hrtick_start_fair(rq, p);
  927. return p;
  928. }
  929. /*
  930. * Account for a descheduled task:
  931. */
  932. static void put_prev_task_fair(struct rq *rq, struct task_struct *prev)
  933. {
  934. struct sched_entity *se = &prev->se;
  935. struct cfs_rq *cfs_rq;
  936. for_each_sched_entity(se) {
  937. cfs_rq = cfs_rq_of(se);
  938. put_prev_entity(cfs_rq, se);
  939. }
  940. }
  941. #ifdef CONFIG_SMP
  942. /**************************************************
  943. * Fair scheduling class load-balancing methods:
  944. */
  945. /*
  946. * Load-balancing iterator. Note: while the runqueue stays locked
  947. * during the whole iteration, the current task might be
  948. * dequeued so the iterator has to be dequeue-safe. Here we
  949. * achieve that by always pre-iterating before returning
  950. * the current task:
  951. */
  952. static struct task_struct *
  953. __load_balance_iterator(struct cfs_rq *cfs_rq, struct rb_node *curr)
  954. {
  955. struct task_struct *p;
  956. if (!curr)
  957. return NULL;
  958. p = rb_entry(curr, struct task_struct, se.run_node);
  959. cfs_rq->rb_load_balance_curr = rb_next(curr);
  960. return p;
  961. }
  962. static struct task_struct *load_balance_start_fair(void *arg)
  963. {
  964. struct cfs_rq *cfs_rq = arg;
  965. return __load_balance_iterator(cfs_rq, first_fair(cfs_rq));
  966. }
  967. static struct task_struct *load_balance_next_fair(void *arg)
  968. {
  969. struct cfs_rq *cfs_rq = arg;
  970. return __load_balance_iterator(cfs_rq, cfs_rq->rb_load_balance_curr);
  971. }
  972. #ifdef CONFIG_FAIR_GROUP_SCHED
  973. static int cfs_rq_best_prio(struct cfs_rq *cfs_rq)
  974. {
  975. struct sched_entity *curr;
  976. struct task_struct *p;
  977. if (!cfs_rq->nr_running || !first_fair(cfs_rq))
  978. return MAX_PRIO;
  979. curr = cfs_rq->curr;
  980. if (!curr)
  981. curr = __pick_next_entity(cfs_rq);
  982. p = task_of(curr);
  983. return p->prio;
  984. }
  985. #endif
  986. static unsigned long
  987. load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
  988. unsigned long max_load_move,
  989. struct sched_domain *sd, enum cpu_idle_type idle,
  990. int *all_pinned, int *this_best_prio)
  991. {
  992. struct cfs_rq *busy_cfs_rq;
  993. long rem_load_move = max_load_move;
  994. struct rq_iterator cfs_rq_iterator;
  995. cfs_rq_iterator.start = load_balance_start_fair;
  996. cfs_rq_iterator.next = load_balance_next_fair;
  997. for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
  998. #ifdef CONFIG_FAIR_GROUP_SCHED
  999. struct cfs_rq *this_cfs_rq;
  1000. long imbalance;
  1001. unsigned long maxload;
  1002. this_cfs_rq = cpu_cfs_rq(busy_cfs_rq, this_cpu);
  1003. imbalance = busy_cfs_rq->load.weight - this_cfs_rq->load.weight;
  1004. /* Don't pull if this_cfs_rq has more load than busy_cfs_rq */
  1005. if (imbalance <= 0)
  1006. continue;
  1007. /* Don't pull more than imbalance/2 */
  1008. imbalance /= 2;
  1009. maxload = min(rem_load_move, imbalance);
  1010. *this_best_prio = cfs_rq_best_prio(this_cfs_rq);
  1011. #else
  1012. # define maxload rem_load_move
  1013. #endif
  1014. /*
  1015. * pass busy_cfs_rq argument into
  1016. * load_balance_[start|next]_fair iterators
  1017. */
  1018. cfs_rq_iterator.arg = busy_cfs_rq;
  1019. rem_load_move -= balance_tasks(this_rq, this_cpu, busiest,
  1020. maxload, sd, idle, all_pinned,
  1021. this_best_prio,
  1022. &cfs_rq_iterator);
  1023. if (rem_load_move <= 0)
  1024. break;
  1025. }
  1026. return max_load_move - rem_load_move;
  1027. }
  1028. static int
  1029. move_one_task_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
  1030. struct sched_domain *sd, enum cpu_idle_type idle)
  1031. {
  1032. struct cfs_rq *busy_cfs_rq;
  1033. struct rq_iterator cfs_rq_iterator;
  1034. cfs_rq_iterator.start = load_balance_start_fair;
  1035. cfs_rq_iterator.next = load_balance_next_fair;
  1036. for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
  1037. /*
  1038. * pass busy_cfs_rq argument into
  1039. * load_balance_[start|next]_fair iterators
  1040. */
  1041. cfs_rq_iterator.arg = busy_cfs_rq;
  1042. if (iter_move_one_task(this_rq, this_cpu, busiest, sd, idle,
  1043. &cfs_rq_iterator))
  1044. return 1;
  1045. }
  1046. return 0;
  1047. }
  1048. #endif
  1049. /*
  1050. * scheduler tick hitting a task of our scheduling class:
  1051. */
  1052. static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
  1053. {
  1054. struct cfs_rq *cfs_rq;
  1055. struct sched_entity *se = &curr->se;
  1056. for_each_sched_entity(se) {
  1057. cfs_rq = cfs_rq_of(se);
  1058. entity_tick(cfs_rq, se, queued);
  1059. }
  1060. }
  1061. #define swap(a, b) do { typeof(a) tmp = (a); (a) = (b); (b) = tmp; } while (0)
  1062. /*
  1063. * Share the fairness runtime between parent and child, thus the
  1064. * total amount of pressure for CPU stays equal - new tasks
  1065. * get a chance to run but frequent forkers are not allowed to
  1066. * monopolize the CPU. Note: the parent runqueue is locked,
  1067. * the child is not running yet.
  1068. */
  1069. static void task_new_fair(struct rq *rq, struct task_struct *p)
  1070. {
  1071. struct cfs_rq *cfs_rq = task_cfs_rq(p);
  1072. struct sched_entity *se = &p->se, *curr = cfs_rq->curr;
  1073. int this_cpu = smp_processor_id();
  1074. sched_info_queued(p);
  1075. update_curr(cfs_rq);
  1076. place_entity(cfs_rq, se, 1);
  1077. /* 'curr' will be NULL if the child belongs to a different group */
  1078. if (sysctl_sched_child_runs_first && this_cpu == task_cpu(p) &&
  1079. curr && curr->vruntime < se->vruntime) {
  1080. /*
  1081. * Upon rescheduling, sched_class::put_prev_task() will place
  1082. * 'current' within the tree based on its new key value.
  1083. */
  1084. swap(curr->vruntime, se->vruntime);
  1085. }
  1086. enqueue_task_fair(rq, p, 0);
  1087. resched_task(rq->curr);
  1088. }
  1089. /*
  1090. * Priority of the task has changed. Check to see if we preempt
  1091. * the current task.
  1092. */
  1093. static void prio_changed_fair(struct rq *rq, struct task_struct *p,
  1094. int oldprio, int running)
  1095. {
  1096. /*
  1097. * Reschedule if we are currently running on this runqueue and
  1098. * our priority decreased, or if we are not currently running on
  1099. * this runqueue and our priority is higher than the current's
  1100. */
  1101. if (running) {
  1102. if (p->prio > oldprio)
  1103. resched_task(rq->curr);
  1104. } else
  1105. check_preempt_curr(rq, p);
  1106. }
  1107. /*
  1108. * We switched to the sched_fair class.
  1109. */
  1110. static void switched_to_fair(struct rq *rq, struct task_struct *p,
  1111. int running)
  1112. {
  1113. /*
  1114. * We were most likely switched from sched_rt, so
  1115. * kick off the schedule if running, otherwise just see
  1116. * if we can still preempt the current task.
  1117. */
  1118. if (running)
  1119. resched_task(rq->curr);
  1120. else
  1121. check_preempt_curr(rq, p);
  1122. }
  1123. /* Account for a task changing its policy or group.
  1124. *
  1125. * This routine is mostly called to set cfs_rq->curr field when a task
  1126. * migrates between groups/classes.
  1127. */
  1128. static void set_curr_task_fair(struct rq *rq)
  1129. {
  1130. struct sched_entity *se = &rq->curr->se;
  1131. for_each_sched_entity(se)
  1132. set_next_entity(cfs_rq_of(se), se);
  1133. }
  1134. /*
  1135. * All the scheduling class methods:
  1136. */
  1137. static const struct sched_class fair_sched_class = {
  1138. .next = &idle_sched_class,
  1139. .enqueue_task = enqueue_task_fair,
  1140. .dequeue_task = dequeue_task_fair,
  1141. .yield_task = yield_task_fair,
  1142. #ifdef CONFIG_SMP
  1143. .select_task_rq = select_task_rq_fair,
  1144. #endif /* CONFIG_SMP */
  1145. .check_preempt_curr = check_preempt_wakeup,
  1146. .pick_next_task = pick_next_task_fair,
  1147. .put_prev_task = put_prev_task_fair,
  1148. #ifdef CONFIG_SMP
  1149. .load_balance = load_balance_fair,
  1150. .move_one_task = move_one_task_fair,
  1151. #endif
  1152. .set_curr_task = set_curr_task_fair,
  1153. .task_tick = task_tick_fair,
  1154. .task_new = task_new_fair,
  1155. .prio_changed = prio_changed_fair,
  1156. .switched_to = switched_to_fair,
  1157. };
  1158. #ifdef CONFIG_SCHED_DEBUG
  1159. static void print_cfs_stats(struct seq_file *m, int cpu)
  1160. {
  1161. struct cfs_rq *cfs_rq;
  1162. #ifdef CONFIG_FAIR_GROUP_SCHED
  1163. print_cfs_rq(m, cpu, &cpu_rq(cpu)->cfs);
  1164. #endif
  1165. rcu_read_lock();
  1166. for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq)
  1167. print_cfs_rq(m, cpu, cfs_rq);
  1168. rcu_read_unlock();
  1169. }
  1170. #endif