sched.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  1. #include <linux/sched.h>
  2. #include <linux/sched/sysctl.h>
  3. #include <linux/sched/rt.h>
  4. #include <linux/mutex.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/stop_machine.h>
  7. #include <linux/tick.h>
  8. #include "cpupri.h"
  9. #include "cpuacct.h"
  10. struct rq;
  11. extern __read_mostly int scheduler_running;
  12. extern unsigned long calc_load_update;
  13. extern atomic_long_t calc_load_tasks;
  14. extern long calc_load_fold_active(struct rq *this_rq);
  15. extern void update_cpu_load_active(struct rq *this_rq);
  16. /*
  17. * Convert user-nice values [ -20 ... 0 ... 19 ]
  18. * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
  19. * and back.
  20. */
  21. #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
  22. #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
  23. #define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
  24. /*
  25. * 'User priority' is the nice value converted to something we
  26. * can work with better when scaling various scheduler parameters,
  27. * it's a [ 0 ... 39 ] range.
  28. */
  29. #define USER_PRIO(p) ((p)-MAX_RT_PRIO)
  30. #define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
  31. #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
  32. /*
  33. * Helpers for converting nanosecond timing to jiffy resolution
  34. */
  35. #define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
  36. /*
  37. * Increase resolution of nice-level calculations for 64-bit architectures.
  38. * The extra resolution improves shares distribution and load balancing of
  39. * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
  40. * hierarchies, especially on larger systems. This is not a user-visible change
  41. * and does not change the user-interface for setting shares/weights.
  42. *
  43. * We increase resolution only if we have enough bits to allow this increased
  44. * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution
  45. * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the
  46. * increased costs.
  47. */
  48. #if 0 /* BITS_PER_LONG > 32 -- currently broken: it increases power usage under light load */
  49. # define SCHED_LOAD_RESOLUTION 10
  50. # define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)
  51. # define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)
  52. #else
  53. # define SCHED_LOAD_RESOLUTION 0
  54. # define scale_load(w) (w)
  55. # define scale_load_down(w) (w)
  56. #endif
  57. #define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)
  58. #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
  59. #define NICE_0_LOAD SCHED_LOAD_SCALE
  60. #define NICE_0_SHIFT SCHED_LOAD_SHIFT
  61. /*
  62. * These are the 'tuning knobs' of the scheduler:
  63. */
  64. /*
  65. * single value that denotes runtime == period, ie unlimited time.
  66. */
  67. #define RUNTIME_INF ((u64)~0ULL)
  68. static inline int rt_policy(int policy)
  69. {
  70. if (policy == SCHED_FIFO || policy == SCHED_RR)
  71. return 1;
  72. return 0;
  73. }
  74. static inline int task_has_rt_policy(struct task_struct *p)
  75. {
  76. return rt_policy(p->policy);
  77. }
  78. /*
  79. * This is the priority-queue data structure of the RT scheduling class:
  80. */
  81. struct rt_prio_array {
  82. DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */
  83. struct list_head queue[MAX_RT_PRIO];
  84. };
  85. struct rt_bandwidth {
  86. /* nests inside the rq lock: */
  87. raw_spinlock_t rt_runtime_lock;
  88. ktime_t rt_period;
  89. u64 rt_runtime;
  90. struct hrtimer rt_period_timer;
  91. };
  92. extern struct mutex sched_domains_mutex;
  93. #ifdef CONFIG_CGROUP_SCHED
  94. #include <linux/cgroup.h>
  95. struct cfs_rq;
  96. struct rt_rq;
  97. extern struct list_head task_groups;
  98. struct cfs_bandwidth {
  99. #ifdef CONFIG_CFS_BANDWIDTH
  100. raw_spinlock_t lock;
  101. ktime_t period;
  102. u64 quota, runtime;
  103. s64 hierarchal_quota;
  104. u64 runtime_expires;
  105. int idle, timer_active;
  106. struct hrtimer period_timer, slack_timer;
  107. struct list_head throttled_cfs_rq;
  108. /* statistics */
  109. int nr_periods, nr_throttled;
  110. u64 throttled_time;
  111. #endif
  112. };
  113. /* task group related information */
  114. struct task_group {
  115. struct cgroup_subsys_state css;
  116. #ifdef CONFIG_FAIR_GROUP_SCHED
  117. /* schedulable entities of this group on each cpu */
  118. struct sched_entity **se;
  119. /* runqueue "owned" by this group on each cpu */
  120. struct cfs_rq **cfs_rq;
  121. unsigned long shares;
  122. #ifdef CONFIG_SMP
  123. atomic_long_t load_avg;
  124. atomic_t runnable_avg;
  125. #endif
  126. #endif
  127. #ifdef CONFIG_RT_GROUP_SCHED
  128. struct sched_rt_entity **rt_se;
  129. struct rt_rq **rt_rq;
  130. struct rt_bandwidth rt_bandwidth;
  131. #endif
  132. struct rcu_head rcu;
  133. struct list_head list;
  134. struct task_group *parent;
  135. struct list_head siblings;
  136. struct list_head children;
  137. #ifdef CONFIG_SCHED_AUTOGROUP
  138. struct autogroup *autogroup;
  139. #endif
  140. struct cfs_bandwidth cfs_bandwidth;
  141. };
  142. #ifdef CONFIG_FAIR_GROUP_SCHED
  143. #define ROOT_TASK_GROUP_LOAD NICE_0_LOAD
  144. /*
  145. * A weight of 0 or 1 can cause arithmetics problems.
  146. * A weight of a cfs_rq is the sum of weights of which entities
  147. * are queued on this cfs_rq, so a weight of a entity should not be
  148. * too large, so as the shares value of a task group.
  149. * (The default weight is 1024 - so there's no practical
  150. * limitation from this.)
  151. */
  152. #define MIN_SHARES (1UL << 1)
  153. #define MAX_SHARES (1UL << 18)
  154. #endif
  155. typedef int (*tg_visitor)(struct task_group *, void *);
  156. extern int walk_tg_tree_from(struct task_group *from,
  157. tg_visitor down, tg_visitor up, void *data);
  158. /*
  159. * Iterate the full tree, calling @down when first entering a node and @up when
  160. * leaving it for the final time.
  161. *
  162. * Caller must hold rcu_lock or sufficient equivalent.
  163. */
  164. static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
  165. {
  166. return walk_tg_tree_from(&root_task_group, down, up, data);
  167. }
  168. extern int tg_nop(struct task_group *tg, void *data);
  169. extern void free_fair_sched_group(struct task_group *tg);
  170. extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent);
  171. extern void unregister_fair_sched_group(struct task_group *tg, int cpu);
  172. extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
  173. struct sched_entity *se, int cpu,
  174. struct sched_entity *parent);
  175. extern void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
  176. extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
  177. extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b);
  178. extern void __start_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
  179. extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq);
  180. extern void free_rt_sched_group(struct task_group *tg);
  181. extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent);
  182. extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
  183. struct sched_rt_entity *rt_se, int cpu,
  184. struct sched_rt_entity *parent);
  185. extern struct task_group *sched_create_group(struct task_group *parent);
  186. extern void sched_online_group(struct task_group *tg,
  187. struct task_group *parent);
  188. extern void sched_destroy_group(struct task_group *tg);
  189. extern void sched_offline_group(struct task_group *tg);
  190. extern void sched_move_task(struct task_struct *tsk);
  191. #ifdef CONFIG_FAIR_GROUP_SCHED
  192. extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
  193. #endif
  194. #else /* CONFIG_CGROUP_SCHED */
  195. struct cfs_bandwidth { };
  196. #endif /* CONFIG_CGROUP_SCHED */
  197. /* CFS-related fields in a runqueue */
  198. struct cfs_rq {
  199. struct load_weight load;
  200. unsigned int nr_running, h_nr_running;
  201. u64 exec_clock;
  202. u64 min_vruntime;
  203. #ifndef CONFIG_64BIT
  204. u64 min_vruntime_copy;
  205. #endif
  206. struct rb_root tasks_timeline;
  207. struct rb_node *rb_leftmost;
  208. /*
  209. * 'curr' points to currently running entity on this cfs_rq.
  210. * It is set to NULL otherwise (i.e when none are currently running).
  211. */
  212. struct sched_entity *curr, *next, *last, *skip;
  213. #ifdef CONFIG_SCHED_DEBUG
  214. unsigned int nr_spread_over;
  215. #endif
  216. #ifdef CONFIG_SMP
  217. /*
  218. * CFS Load tracking
  219. * Under CFS, load is tracked on a per-entity basis and aggregated up.
  220. * This allows for the description of both thread and group usage (in
  221. * the FAIR_GROUP_SCHED case).
  222. */
  223. unsigned long runnable_load_avg, blocked_load_avg;
  224. atomic64_t decay_counter;
  225. u64 last_decay;
  226. atomic_long_t removed_load;
  227. #ifdef CONFIG_FAIR_GROUP_SCHED
  228. /* Required to track per-cpu representation of a task_group */
  229. u32 tg_runnable_contrib;
  230. unsigned long tg_load_contrib;
  231. /*
  232. * h_load = weight * f(tg)
  233. *
  234. * Where f(tg) is the recursive weight fraction assigned to
  235. * this group.
  236. */
  237. unsigned long h_load;
  238. u64 last_h_load_update;
  239. struct sched_entity *h_load_next;
  240. #endif /* CONFIG_FAIR_GROUP_SCHED */
  241. #endif /* CONFIG_SMP */
  242. #ifdef CONFIG_FAIR_GROUP_SCHED
  243. struct rq *rq; /* cpu runqueue to which this cfs_rq is attached */
  244. /*
  245. * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in
  246. * a hierarchy). Non-leaf lrqs hold other higher schedulable entities
  247. * (like users, containers etc.)
  248. *
  249. * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a cpu. This
  250. * list is used during load balance.
  251. */
  252. int on_list;
  253. struct list_head leaf_cfs_rq_list;
  254. struct task_group *tg; /* group that "owns" this runqueue */
  255. #ifdef CONFIG_CFS_BANDWIDTH
  256. int runtime_enabled;
  257. u64 runtime_expires;
  258. s64 runtime_remaining;
  259. u64 throttled_clock, throttled_clock_task;
  260. u64 throttled_clock_task_time;
  261. int throttled, throttle_count;
  262. struct list_head throttled_list;
  263. #endif /* CONFIG_CFS_BANDWIDTH */
  264. #endif /* CONFIG_FAIR_GROUP_SCHED */
  265. };
  266. static inline int rt_bandwidth_enabled(void)
  267. {
  268. return sysctl_sched_rt_runtime >= 0;
  269. }
  270. /* Real-Time classes' related field in a runqueue: */
  271. struct rt_rq {
  272. struct rt_prio_array active;
  273. unsigned int rt_nr_running;
  274. #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
  275. struct {
  276. int curr; /* highest queued rt task prio */
  277. #ifdef CONFIG_SMP
  278. int next; /* next highest */
  279. #endif
  280. } highest_prio;
  281. #endif
  282. #ifdef CONFIG_SMP
  283. unsigned long rt_nr_migratory;
  284. unsigned long rt_nr_total;
  285. int overloaded;
  286. struct plist_head pushable_tasks;
  287. #endif
  288. int rt_throttled;
  289. u64 rt_time;
  290. u64 rt_runtime;
  291. /* Nests inside the rq lock: */
  292. raw_spinlock_t rt_runtime_lock;
  293. #ifdef CONFIG_RT_GROUP_SCHED
  294. unsigned long rt_nr_boosted;
  295. struct rq *rq;
  296. struct task_group *tg;
  297. #endif
  298. };
  299. #ifdef CONFIG_SMP
  300. /*
  301. * We add the notion of a root-domain which will be used to define per-domain
  302. * variables. Each exclusive cpuset essentially defines an island domain by
  303. * fully partitioning the member cpus from any other cpuset. Whenever a new
  304. * exclusive cpuset is created, we also create and attach a new root-domain
  305. * object.
  306. *
  307. */
  308. struct root_domain {
  309. atomic_t refcount;
  310. atomic_t rto_count;
  311. struct rcu_head rcu;
  312. cpumask_var_t span;
  313. cpumask_var_t online;
  314. /*
  315. * The "RT overload" flag: it gets set if a CPU has more than
  316. * one runnable RT task.
  317. */
  318. cpumask_var_t rto_mask;
  319. struct cpupri cpupri;
  320. };
  321. extern struct root_domain def_root_domain;
  322. #endif /* CONFIG_SMP */
  323. /*
  324. * This is the main, per-CPU runqueue data structure.
  325. *
  326. * Locking rule: those places that want to lock multiple runqueues
  327. * (such as the load balancing or the thread migration code), lock
  328. * acquire operations must be ordered by ascending &runqueue.
  329. */
  330. struct rq {
  331. /* runqueue lock: */
  332. raw_spinlock_t lock;
  333. /*
  334. * nr_running and cpu_load should be in the same cacheline because
  335. * remote CPUs use both these fields when doing load calculation.
  336. */
  337. unsigned int nr_running;
  338. #define CPU_LOAD_IDX_MAX 5
  339. unsigned long cpu_load[CPU_LOAD_IDX_MAX];
  340. unsigned long last_load_update_tick;
  341. #ifdef CONFIG_NO_HZ_COMMON
  342. u64 nohz_stamp;
  343. unsigned long nohz_flags;
  344. #endif
  345. #ifdef CONFIG_NO_HZ_FULL
  346. unsigned long last_sched_tick;
  347. #endif
  348. int skip_clock_update;
  349. /* capture load from *all* tasks on this cpu: */
  350. struct load_weight load;
  351. unsigned long nr_load_updates;
  352. u64 nr_switches;
  353. struct cfs_rq cfs;
  354. struct rt_rq rt;
  355. #ifdef CONFIG_FAIR_GROUP_SCHED
  356. /* list of leaf cfs_rq on this cpu: */
  357. struct list_head leaf_cfs_rq_list;
  358. #endif /* CONFIG_FAIR_GROUP_SCHED */
  359. #ifdef CONFIG_RT_GROUP_SCHED
  360. struct list_head leaf_rt_rq_list;
  361. #endif
  362. /*
  363. * This is part of a global counter where only the total sum
  364. * over all CPUs matters. A task can increase this counter on
  365. * one CPU and if it got migrated afterwards it may decrease
  366. * it on another CPU. Always updated under the runqueue lock:
  367. */
  368. unsigned long nr_uninterruptible;
  369. struct task_struct *curr, *idle, *stop;
  370. unsigned long next_balance;
  371. struct mm_struct *prev_mm;
  372. u64 clock;
  373. u64 clock_task;
  374. atomic_t nr_iowait;
  375. #ifdef CONFIG_SMP
  376. struct root_domain *rd;
  377. struct sched_domain *sd;
  378. unsigned long cpu_power;
  379. unsigned char idle_balance;
  380. /* For active balancing */
  381. int post_schedule;
  382. int active_balance;
  383. int push_cpu;
  384. struct cpu_stop_work active_balance_work;
  385. /* cpu of this runqueue: */
  386. int cpu;
  387. int online;
  388. struct list_head cfs_tasks;
  389. u64 rt_avg;
  390. u64 age_stamp;
  391. u64 idle_stamp;
  392. u64 avg_idle;
  393. /* This is used to determine avg_idle's max value */
  394. u64 max_idle_balance_cost;
  395. #endif
  396. #ifdef CONFIG_IRQ_TIME_ACCOUNTING
  397. u64 prev_irq_time;
  398. #endif
  399. #ifdef CONFIG_PARAVIRT
  400. u64 prev_steal_time;
  401. #endif
  402. #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
  403. u64 prev_steal_time_rq;
  404. #endif
  405. /* calc_load related fields */
  406. unsigned long calc_load_update;
  407. long calc_load_active;
  408. #ifdef CONFIG_SCHED_HRTICK
  409. #ifdef CONFIG_SMP
  410. int hrtick_csd_pending;
  411. struct call_single_data hrtick_csd;
  412. #endif
  413. struct hrtimer hrtick_timer;
  414. #endif
  415. #ifdef CONFIG_SCHEDSTATS
  416. /* latency stats */
  417. struct sched_info rq_sched_info;
  418. unsigned long long rq_cpu_time;
  419. /* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */
  420. /* sys_sched_yield() stats */
  421. unsigned int yld_count;
  422. /* schedule() stats */
  423. unsigned int sched_count;
  424. unsigned int sched_goidle;
  425. /* try_to_wake_up() stats */
  426. unsigned int ttwu_count;
  427. unsigned int ttwu_local;
  428. #endif
  429. #ifdef CONFIG_SMP
  430. struct llist_head wake_list;
  431. #endif
  432. struct sched_avg avg;
  433. };
  434. static inline int cpu_of(struct rq *rq)
  435. {
  436. #ifdef CONFIG_SMP
  437. return rq->cpu;
  438. #else
  439. return 0;
  440. #endif
  441. }
  442. DECLARE_PER_CPU(struct rq, runqueues);
  443. #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
  444. #define this_rq() (&__get_cpu_var(runqueues))
  445. #define task_rq(p) cpu_rq(task_cpu(p))
  446. #define cpu_curr(cpu) (cpu_rq(cpu)->curr)
  447. #define raw_rq() (&__raw_get_cpu_var(runqueues))
  448. static inline u64 rq_clock(struct rq *rq)
  449. {
  450. return rq->clock;
  451. }
  452. static inline u64 rq_clock_task(struct rq *rq)
  453. {
  454. return rq->clock_task;
  455. }
  456. #ifdef CONFIG_SMP
  457. #define rcu_dereference_check_sched_domain(p) \
  458. rcu_dereference_check((p), \
  459. lockdep_is_held(&sched_domains_mutex))
  460. /*
  461. * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
  462. * See detach_destroy_domains: synchronize_sched for details.
  463. *
  464. * The domain tree of any CPU may only be accessed from within
  465. * preempt-disabled sections.
  466. */
  467. #define for_each_domain(cpu, __sd) \
  468. for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \
  469. __sd; __sd = __sd->parent)
  470. #define for_each_lower_domain(sd) for (; sd; sd = sd->child)
  471. /**
  472. * highest_flag_domain - Return highest sched_domain containing flag.
  473. * @cpu: The cpu whose highest level of sched domain is to
  474. * be returned.
  475. * @flag: The flag to check for the highest sched_domain
  476. * for the given cpu.
  477. *
  478. * Returns the highest sched_domain of a cpu which contains the given flag.
  479. */
  480. static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
  481. {
  482. struct sched_domain *sd, *hsd = NULL;
  483. for_each_domain(cpu, sd) {
  484. if (!(sd->flags & flag))
  485. break;
  486. hsd = sd;
  487. }
  488. return hsd;
  489. }
  490. DECLARE_PER_CPU(struct sched_domain *, sd_llc);
  491. DECLARE_PER_CPU(int, sd_llc_size);
  492. DECLARE_PER_CPU(int, sd_llc_id);
  493. struct sched_group_power {
  494. atomic_t ref;
  495. /*
  496. * CPU power of this group, SCHED_LOAD_SCALE being max power for a
  497. * single CPU.
  498. */
  499. unsigned int power, power_orig;
  500. unsigned long next_update;
  501. int imbalance; /* XXX unrelated to power but shared group state */
  502. /*
  503. * Number of busy cpus in this group.
  504. */
  505. atomic_t nr_busy_cpus;
  506. unsigned long cpumask[0]; /* iteration mask */
  507. };
  508. struct sched_group {
  509. struct sched_group *next; /* Must be a circular list */
  510. atomic_t ref;
  511. unsigned int group_weight;
  512. struct sched_group_power *sgp;
  513. /*
  514. * The CPUs this group covers.
  515. *
  516. * NOTE: this field is variable length. (Allocated dynamically
  517. * by attaching extra space to the end of the structure,
  518. * depending on how many CPUs the kernel has booted up with)
  519. */
  520. unsigned long cpumask[0];
  521. };
  522. static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
  523. {
  524. return to_cpumask(sg->cpumask);
  525. }
  526. /*
  527. * cpumask masking which cpus in the group are allowed to iterate up the domain
  528. * tree.
  529. */
  530. static inline struct cpumask *sched_group_mask(struct sched_group *sg)
  531. {
  532. return to_cpumask(sg->sgp->cpumask);
  533. }
  534. /**
  535. * group_first_cpu - Returns the first cpu in the cpumask of a sched_group.
  536. * @group: The group whose first cpu is to be returned.
  537. */
  538. static inline unsigned int group_first_cpu(struct sched_group *group)
  539. {
  540. return cpumask_first(sched_group_cpus(group));
  541. }
  542. extern int group_balance_cpu(struct sched_group *sg);
  543. #endif /* CONFIG_SMP */
  544. #include "stats.h"
  545. #include "auto_group.h"
  546. #ifdef CONFIG_CGROUP_SCHED
  547. /*
  548. * Return the group to which this tasks belongs.
  549. *
  550. * We cannot use task_css() and friends because the cgroup subsystem
  551. * changes that value before the cgroup_subsys::attach() method is called,
  552. * therefore we cannot pin it and might observe the wrong value.
  553. *
  554. * The same is true for autogroup's p->signal->autogroup->tg, the autogroup
  555. * core changes this before calling sched_move_task().
  556. *
  557. * Instead we use a 'copy' which is updated from sched_move_task() while
  558. * holding both task_struct::pi_lock and rq::lock.
  559. */
  560. static inline struct task_group *task_group(struct task_struct *p)
  561. {
  562. return p->sched_task_group;
  563. }
  564. /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
  565. static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
  566. {
  567. #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
  568. struct task_group *tg = task_group(p);
  569. #endif
  570. #ifdef CONFIG_FAIR_GROUP_SCHED
  571. p->se.cfs_rq = tg->cfs_rq[cpu];
  572. p->se.parent = tg->se[cpu];
  573. #endif
  574. #ifdef CONFIG_RT_GROUP_SCHED
  575. p->rt.rt_rq = tg->rt_rq[cpu];
  576. p->rt.parent = tg->rt_se[cpu];
  577. #endif
  578. }
  579. #else /* CONFIG_CGROUP_SCHED */
  580. static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
  581. static inline struct task_group *task_group(struct task_struct *p)
  582. {
  583. return NULL;
  584. }
  585. #endif /* CONFIG_CGROUP_SCHED */
  586. static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
  587. {
  588. set_task_rq(p, cpu);
  589. #ifdef CONFIG_SMP
  590. /*
  591. * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
  592. * successfuly executed on another CPU. We must ensure that updates of
  593. * per-task data have been completed by this moment.
  594. */
  595. smp_wmb();
  596. task_thread_info(p)->cpu = cpu;
  597. #endif
  598. }
  599. /*
  600. * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
  601. */
  602. #ifdef CONFIG_SCHED_DEBUG
  603. # include <linux/static_key.h>
  604. # define const_debug __read_mostly
  605. #else
  606. # define const_debug const
  607. #endif
  608. extern const_debug unsigned int sysctl_sched_features;
  609. #define SCHED_FEAT(name, enabled) \
  610. __SCHED_FEAT_##name ,
  611. enum {
  612. #include "features.h"
  613. __SCHED_FEAT_NR,
  614. };
  615. #undef SCHED_FEAT
  616. #if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
  617. static __always_inline bool static_branch__true(struct static_key *key)
  618. {
  619. return static_key_true(key); /* Not out of line branch. */
  620. }
  621. static __always_inline bool static_branch__false(struct static_key *key)
  622. {
  623. return static_key_false(key); /* Out of line branch. */
  624. }
  625. #define SCHED_FEAT(name, enabled) \
  626. static __always_inline bool static_branch_##name(struct static_key *key) \
  627. { \
  628. return static_branch__##enabled(key); \
  629. }
  630. #include "features.h"
  631. #undef SCHED_FEAT
  632. extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
  633. #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
  634. #else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */
  635. #define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
  636. #endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */
  637. #ifdef CONFIG_NUMA_BALANCING
  638. #define sched_feat_numa(x) sched_feat(x)
  639. #ifdef CONFIG_SCHED_DEBUG
  640. #define numabalancing_enabled sched_feat_numa(NUMA)
  641. #else
  642. extern bool numabalancing_enabled;
  643. #endif /* CONFIG_SCHED_DEBUG */
  644. #else
  645. #define sched_feat_numa(x) (0)
  646. #define numabalancing_enabled (0)
  647. #endif /* CONFIG_NUMA_BALANCING */
  648. static inline u64 global_rt_period(void)
  649. {
  650. return (u64)sysctl_sched_rt_period * NSEC_PER_USEC;
  651. }
  652. static inline u64 global_rt_runtime(void)
  653. {
  654. if (sysctl_sched_rt_runtime < 0)
  655. return RUNTIME_INF;
  656. return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
  657. }
  658. static inline int task_current(struct rq *rq, struct task_struct *p)
  659. {
  660. return rq->curr == p;
  661. }
  662. static inline int task_running(struct rq *rq, struct task_struct *p)
  663. {
  664. #ifdef CONFIG_SMP
  665. return p->on_cpu;
  666. #else
  667. return task_current(rq, p);
  668. #endif
  669. }
  670. #ifndef prepare_arch_switch
  671. # define prepare_arch_switch(next) do { } while (0)
  672. #endif
  673. #ifndef finish_arch_switch
  674. # define finish_arch_switch(prev) do { } while (0)
  675. #endif
  676. #ifndef finish_arch_post_lock_switch
  677. # define finish_arch_post_lock_switch() do { } while (0)
  678. #endif
  679. #ifndef __ARCH_WANT_UNLOCKED_CTXSW
  680. static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
  681. {
  682. #ifdef CONFIG_SMP
  683. /*
  684. * We can optimise this out completely for !SMP, because the
  685. * SMP rebalancing from interrupt is the only thing that cares
  686. * here.
  687. */
  688. next->on_cpu = 1;
  689. #endif
  690. }
  691. static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
  692. {
  693. #ifdef CONFIG_SMP
  694. /*
  695. * After ->on_cpu is cleared, the task can be moved to a different CPU.
  696. * We must ensure this doesn't happen until the switch is completely
  697. * finished.
  698. */
  699. smp_wmb();
  700. prev->on_cpu = 0;
  701. #endif
  702. #ifdef CONFIG_DEBUG_SPINLOCK
  703. /* this is a valid case when another task releases the spinlock */
  704. rq->lock.owner = current;
  705. #endif
  706. /*
  707. * If we are tracking spinlock dependencies then we have to
  708. * fix up the runqueue lock - which gets 'carried over' from
  709. * prev into current:
  710. */
  711. spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_);
  712. raw_spin_unlock_irq(&rq->lock);
  713. }
  714. #else /* __ARCH_WANT_UNLOCKED_CTXSW */
  715. static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
  716. {
  717. #ifdef CONFIG_SMP
  718. /*
  719. * We can optimise this out completely for !SMP, because the
  720. * SMP rebalancing from interrupt is the only thing that cares
  721. * here.
  722. */
  723. next->on_cpu = 1;
  724. #endif
  725. raw_spin_unlock(&rq->lock);
  726. }
  727. static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
  728. {
  729. #ifdef CONFIG_SMP
  730. /*
  731. * After ->on_cpu is cleared, the task can be moved to a different CPU.
  732. * We must ensure this doesn't happen until the switch is completely
  733. * finished.
  734. */
  735. smp_wmb();
  736. prev->on_cpu = 0;
  737. #endif
  738. local_irq_enable();
  739. }
  740. #endif /* __ARCH_WANT_UNLOCKED_CTXSW */
  741. /*
  742. * wake flags
  743. */
  744. #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
  745. #define WF_FORK 0x02 /* child wakeup after fork */
  746. #define WF_MIGRATED 0x4 /* internal use, task got migrated */
  747. /*
  748. * To aid in avoiding the subversion of "niceness" due to uneven distribution
  749. * of tasks with abnormal "nice" values across CPUs the contribution that
  750. * each task makes to its run queue's load is weighted according to its
  751. * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a
  752. * scaled version of the new time slice allocation that they receive on time
  753. * slice expiry etc.
  754. */
  755. #define WEIGHT_IDLEPRIO 3
  756. #define WMULT_IDLEPRIO 1431655765
  757. /*
  758. * Nice levels are multiplicative, with a gentle 10% change for every
  759. * nice level changed. I.e. when a CPU-bound task goes from nice 0 to
  760. * nice 1, it will get ~10% less CPU time than another CPU-bound task
  761. * that remained on nice 0.
  762. *
  763. * The "10% effect" is relative and cumulative: from _any_ nice level,
  764. * if you go up 1 level, it's -10% CPU usage, if you go down 1 level
  765. * it's +10% CPU usage. (to achieve that we use a multiplier of 1.25.
  766. * If a task goes up by ~10% and another task goes down by ~10% then
  767. * the relative distance between them is ~25%.)
  768. */
  769. static const int prio_to_weight[40] = {
  770. /* -20 */ 88761, 71755, 56483, 46273, 36291,
  771. /* -15 */ 29154, 23254, 18705, 14949, 11916,
  772. /* -10 */ 9548, 7620, 6100, 4904, 3906,
  773. /* -5 */ 3121, 2501, 1991, 1586, 1277,
  774. /* 0 */ 1024, 820, 655, 526, 423,
  775. /* 5 */ 335, 272, 215, 172, 137,
  776. /* 10 */ 110, 87, 70, 56, 45,
  777. /* 15 */ 36, 29, 23, 18, 15,
  778. };
  779. /*
  780. * Inverse (2^32/x) values of the prio_to_weight[] array, precalculated.
  781. *
  782. * In cases where the weight does not change often, we can use the
  783. * precalculated inverse to speed up arithmetics by turning divisions
  784. * into multiplications:
  785. */
  786. static const u32 prio_to_wmult[40] = {
  787. /* -20 */ 48388, 59856, 76040, 92818, 118348,
  788. /* -15 */ 147320, 184698, 229616, 287308, 360437,
  789. /* -10 */ 449829, 563644, 704093, 875809, 1099582,
  790. /* -5 */ 1376151, 1717300, 2157191, 2708050, 3363326,
  791. /* 0 */ 4194304, 5237765, 6557202, 8165337, 10153587,
  792. /* 5 */ 12820798, 15790321, 19976592, 24970740, 31350126,
  793. /* 10 */ 39045157, 49367440, 61356676, 76695844, 95443717,
  794. /* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
  795. };
  796. #define ENQUEUE_WAKEUP 1
  797. #define ENQUEUE_HEAD 2
  798. #ifdef CONFIG_SMP
  799. #define ENQUEUE_WAKING 4 /* sched_class::task_waking was called */
  800. #else
  801. #define ENQUEUE_WAKING 0
  802. #endif
  803. #define DEQUEUE_SLEEP 1
  804. struct sched_class {
  805. const struct sched_class *next;
  806. void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
  807. void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
  808. void (*yield_task) (struct rq *rq);
  809. bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
  810. void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
  811. struct task_struct * (*pick_next_task) (struct rq *rq);
  812. void (*put_prev_task) (struct rq *rq, struct task_struct *p);
  813. #ifdef CONFIG_SMP
  814. int (*select_task_rq)(struct task_struct *p, int sd_flag, int flags);
  815. void (*migrate_task_rq)(struct task_struct *p, int next_cpu);
  816. void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
  817. void (*post_schedule) (struct rq *this_rq);
  818. void (*task_waking) (struct task_struct *task);
  819. void (*task_woken) (struct rq *this_rq, struct task_struct *task);
  820. void (*set_cpus_allowed)(struct task_struct *p,
  821. const struct cpumask *newmask);
  822. void (*rq_online)(struct rq *rq);
  823. void (*rq_offline)(struct rq *rq);
  824. #endif
  825. void (*set_curr_task) (struct rq *rq);
  826. void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
  827. void (*task_fork) (struct task_struct *p);
  828. void (*switched_from) (struct rq *this_rq, struct task_struct *task);
  829. void (*switched_to) (struct rq *this_rq, struct task_struct *task);
  830. void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
  831. int oldprio);
  832. unsigned int (*get_rr_interval) (struct rq *rq,
  833. struct task_struct *task);
  834. #ifdef CONFIG_FAIR_GROUP_SCHED
  835. void (*task_move_group) (struct task_struct *p, int on_rq);
  836. #endif
  837. };
  838. #define sched_class_highest (&stop_sched_class)
  839. #define for_each_class(class) \
  840. for (class = sched_class_highest; class; class = class->next)
  841. extern const struct sched_class stop_sched_class;
  842. extern const struct sched_class rt_sched_class;
  843. extern const struct sched_class fair_sched_class;
  844. extern const struct sched_class idle_sched_class;
  845. #ifdef CONFIG_SMP
  846. extern void update_group_power(struct sched_domain *sd, int cpu);
  847. extern void trigger_load_balance(struct rq *rq, int cpu);
  848. extern void idle_balance(int this_cpu, struct rq *this_rq);
  849. extern void idle_enter_fair(struct rq *this_rq);
  850. extern void idle_exit_fair(struct rq *this_rq);
  851. #else /* CONFIG_SMP */
  852. static inline void idle_balance(int cpu, struct rq *rq)
  853. {
  854. }
  855. #endif
  856. extern void sysrq_sched_debug_show(void);
  857. extern void sched_init_granularity(void);
  858. extern void update_max_interval(void);
  859. extern void init_sched_rt_class(void);
  860. extern void init_sched_fair_class(void);
  861. extern void resched_task(struct task_struct *p);
  862. extern void resched_cpu(int cpu);
  863. extern struct rt_bandwidth def_rt_bandwidth;
  864. extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
  865. extern void update_idle_cpu_load(struct rq *this_rq);
  866. extern void init_task_runnable_average(struct task_struct *p);
  867. #ifdef CONFIG_PARAVIRT
  868. static inline u64 steal_ticks(u64 steal)
  869. {
  870. if (unlikely(steal > NSEC_PER_SEC))
  871. return div_u64(steal, TICK_NSEC);
  872. return __iter_div_u64_rem(steal, TICK_NSEC, &steal);
  873. }
  874. #endif
  875. static inline void inc_nr_running(struct rq *rq)
  876. {
  877. rq->nr_running++;
  878. #ifdef CONFIG_NO_HZ_FULL
  879. if (rq->nr_running == 2) {
  880. if (tick_nohz_full_cpu(rq->cpu)) {
  881. /* Order rq->nr_running write against the IPI */
  882. smp_wmb();
  883. smp_send_reschedule(rq->cpu);
  884. }
  885. }
  886. #endif
  887. }
  888. static inline void dec_nr_running(struct rq *rq)
  889. {
  890. rq->nr_running--;
  891. }
  892. static inline void rq_last_tick_reset(struct rq *rq)
  893. {
  894. #ifdef CONFIG_NO_HZ_FULL
  895. rq->last_sched_tick = jiffies;
  896. #endif
  897. }
  898. extern void update_rq_clock(struct rq *rq);
  899. extern void activate_task(struct rq *rq, struct task_struct *p, int flags);
  900. extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);
  901. extern void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags);
  902. extern const_debug unsigned int sysctl_sched_time_avg;
  903. extern const_debug unsigned int sysctl_sched_nr_migrate;
  904. extern const_debug unsigned int sysctl_sched_migration_cost;
  905. static inline u64 sched_avg_period(void)
  906. {
  907. return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2;
  908. }
  909. #ifdef CONFIG_SCHED_HRTICK
  910. /*
  911. * Use hrtick when:
  912. * - enabled by features
  913. * - hrtimer is actually high res
  914. */
  915. static inline int hrtick_enabled(struct rq *rq)
  916. {
  917. if (!sched_feat(HRTICK))
  918. return 0;
  919. if (!cpu_active(cpu_of(rq)))
  920. return 0;
  921. return hrtimer_is_hres_active(&rq->hrtick_timer);
  922. }
  923. void hrtick_start(struct rq *rq, u64 delay);
  924. #else
  925. static inline int hrtick_enabled(struct rq *rq)
  926. {
  927. return 0;
  928. }
  929. #endif /* CONFIG_SCHED_HRTICK */
  930. #ifdef CONFIG_SMP
  931. extern void sched_avg_update(struct rq *rq);
  932. static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
  933. {
  934. rq->rt_avg += rt_delta;
  935. sched_avg_update(rq);
  936. }
  937. #else
  938. static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { }
  939. static inline void sched_avg_update(struct rq *rq) { }
  940. #endif
  941. extern void start_bandwidth_timer(struct hrtimer *period_timer, ktime_t period);
  942. #ifdef CONFIG_SMP
  943. #ifdef CONFIG_PREEMPT
  944. static inline void double_rq_lock(struct rq *rq1, struct rq *rq2);
  945. /*
  946. * fair double_lock_balance: Safely acquires both rq->locks in a fair
  947. * way at the expense of forcing extra atomic operations in all
  948. * invocations. This assures that the double_lock is acquired using the
  949. * same underlying policy as the spinlock_t on this architecture, which
  950. * reduces latency compared to the unfair variant below. However, it
  951. * also adds more overhead and therefore may reduce throughput.
  952. */
  953. static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
  954. __releases(this_rq->lock)
  955. __acquires(busiest->lock)
  956. __acquires(this_rq->lock)
  957. {
  958. raw_spin_unlock(&this_rq->lock);
  959. double_rq_lock(this_rq, busiest);
  960. return 1;
  961. }
  962. #else
  963. /*
  964. * Unfair double_lock_balance: Optimizes throughput at the expense of
  965. * latency by eliminating extra atomic operations when the locks are
  966. * already in proper order on entry. This favors lower cpu-ids and will
  967. * grant the double lock to lower cpus over higher ids under contention,
  968. * regardless of entry order into the function.
  969. */
  970. static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
  971. __releases(this_rq->lock)
  972. __acquires(busiest->lock)
  973. __acquires(this_rq->lock)
  974. {
  975. int ret = 0;
  976. if (unlikely(!raw_spin_trylock(&busiest->lock))) {
  977. if (busiest < this_rq) {
  978. raw_spin_unlock(&this_rq->lock);
  979. raw_spin_lock(&busiest->lock);
  980. raw_spin_lock_nested(&this_rq->lock,
  981. SINGLE_DEPTH_NESTING);
  982. ret = 1;
  983. } else
  984. raw_spin_lock_nested(&busiest->lock,
  985. SINGLE_DEPTH_NESTING);
  986. }
  987. return ret;
  988. }
  989. #endif /* CONFIG_PREEMPT */
  990. /*
  991. * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
  992. */
  993. static inline int double_lock_balance(struct rq *this_rq, struct rq *busiest)
  994. {
  995. if (unlikely(!irqs_disabled())) {
  996. /* printk() doesn't work good under rq->lock */
  997. raw_spin_unlock(&this_rq->lock);
  998. BUG_ON(1);
  999. }
  1000. return _double_lock_balance(this_rq, busiest);
  1001. }
  1002. static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
  1003. __releases(busiest->lock)
  1004. {
  1005. raw_spin_unlock(&busiest->lock);
  1006. lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_);
  1007. }
  1008. /*
  1009. * double_rq_lock - safely lock two runqueues
  1010. *
  1011. * Note this does not disable interrupts like task_rq_lock,
  1012. * you need to do so manually before calling.
  1013. */
  1014. static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
  1015. __acquires(rq1->lock)
  1016. __acquires(rq2->lock)
  1017. {
  1018. BUG_ON(!irqs_disabled());
  1019. if (rq1 == rq2) {
  1020. raw_spin_lock(&rq1->lock);
  1021. __acquire(rq2->lock); /* Fake it out ;) */
  1022. } else {
  1023. if (rq1 < rq2) {
  1024. raw_spin_lock(&rq1->lock);
  1025. raw_spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING);
  1026. } else {
  1027. raw_spin_lock(&rq2->lock);
  1028. raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
  1029. }
  1030. }
  1031. }
  1032. /*
  1033. * double_rq_unlock - safely unlock two runqueues
  1034. *
  1035. * Note this does not restore interrupts like task_rq_unlock,
  1036. * you need to do so manually after calling.
  1037. */
  1038. static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
  1039. __releases(rq1->lock)
  1040. __releases(rq2->lock)
  1041. {
  1042. raw_spin_unlock(&rq1->lock);
  1043. if (rq1 != rq2)
  1044. raw_spin_unlock(&rq2->lock);
  1045. else
  1046. __release(rq2->lock);
  1047. }
  1048. #else /* CONFIG_SMP */
  1049. /*
  1050. * double_rq_lock - safely lock two runqueues
  1051. *
  1052. * Note this does not disable interrupts like task_rq_lock,
  1053. * you need to do so manually before calling.
  1054. */
  1055. static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
  1056. __acquires(rq1->lock)
  1057. __acquires(rq2->lock)
  1058. {
  1059. BUG_ON(!irqs_disabled());
  1060. BUG_ON(rq1 != rq2);
  1061. raw_spin_lock(&rq1->lock);
  1062. __acquire(rq2->lock); /* Fake it out ;) */
  1063. }
  1064. /*
  1065. * double_rq_unlock - safely unlock two runqueues
  1066. *
  1067. * Note this does not restore interrupts like task_rq_unlock,
  1068. * you need to do so manually after calling.
  1069. */
  1070. static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
  1071. __releases(rq1->lock)
  1072. __releases(rq2->lock)
  1073. {
  1074. BUG_ON(rq1 != rq2);
  1075. raw_spin_unlock(&rq1->lock);
  1076. __release(rq2->lock);
  1077. }
  1078. #endif
  1079. extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq);
  1080. extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq);
  1081. extern void print_cfs_stats(struct seq_file *m, int cpu);
  1082. extern void print_rt_stats(struct seq_file *m, int cpu);
  1083. extern void init_cfs_rq(struct cfs_rq *cfs_rq);
  1084. extern void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq);
  1085. extern void account_cfs_bandwidth_used(int enabled, int was_enabled);
  1086. #ifdef CONFIG_NO_HZ_COMMON
  1087. enum rq_nohz_flag_bits {
  1088. NOHZ_TICK_STOPPED,
  1089. NOHZ_BALANCE_KICK,
  1090. };
  1091. #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)
  1092. #endif
  1093. #ifdef CONFIG_IRQ_TIME_ACCOUNTING
  1094. DECLARE_PER_CPU(u64, cpu_hardirq_time);
  1095. DECLARE_PER_CPU(u64, cpu_softirq_time);
  1096. #ifndef CONFIG_64BIT
  1097. DECLARE_PER_CPU(seqcount_t, irq_time_seq);
  1098. static inline void irq_time_write_begin(void)
  1099. {
  1100. __this_cpu_inc(irq_time_seq.sequence);
  1101. smp_wmb();
  1102. }
  1103. static inline void irq_time_write_end(void)
  1104. {
  1105. smp_wmb();
  1106. __this_cpu_inc(irq_time_seq.sequence);
  1107. }
  1108. static inline u64 irq_time_read(int cpu)
  1109. {
  1110. u64 irq_time;
  1111. unsigned seq;
  1112. do {
  1113. seq = read_seqcount_begin(&per_cpu(irq_time_seq, cpu));
  1114. irq_time = per_cpu(cpu_softirq_time, cpu) +
  1115. per_cpu(cpu_hardirq_time, cpu);
  1116. } while (read_seqcount_retry(&per_cpu(irq_time_seq, cpu), seq));
  1117. return irq_time;
  1118. }
  1119. #else /* CONFIG_64BIT */
  1120. static inline void irq_time_write_begin(void)
  1121. {
  1122. }
  1123. static inline void irq_time_write_end(void)
  1124. {
  1125. }
  1126. static inline u64 irq_time_read(int cpu)
  1127. {
  1128. return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu);
  1129. }
  1130. #endif /* CONFIG_64BIT */
  1131. #endif /* CONFIG_IRQ_TIME_ACCOUNTING */