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