2 #include <linux/sched.h>
3 #include <linux/mutex.h>
4 #include <linux/spinlock.h>
5 #include <linux/stop_machine.h>
7 #include "sched_cpupri.h"
9 extern __read_mostly
int scheduler_running
;
12 * Convert user-nice values [ -20 ... 0 ... 19 ]
13 * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
16 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
17 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
18 #define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
21 * 'User priority' is the nice value converted to something we
22 * can work with better when scaling various scheduler parameters,
23 * it's a [ 0 ... 39 ] range.
25 #define USER_PRIO(p) ((p)-MAX_RT_PRIO)
26 #define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
27 #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
30 * Helpers for converting nanosecond timing to jiffy resolution
32 #define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
34 #define NICE_0_LOAD SCHED_LOAD_SCALE
35 #define NICE_0_SHIFT SCHED_LOAD_SHIFT
38 * These are the 'tuning knobs' of the scheduler:
40 * default timeslice is 100 msecs (used only for SCHED_RR tasks).
41 * Timeslices get refilled after they expire.
43 #define DEF_TIMESLICE (100 * HZ / 1000)
46 * single value that denotes runtime == period, ie unlimited time.
48 #define RUNTIME_INF ((u64)~0ULL)
50 static inline int rt_policy(int policy
)
52 if (policy
== SCHED_FIFO
|| policy
== SCHED_RR
)
57 static inline int task_has_rt_policy(struct task_struct
*p
)
59 return rt_policy(p
->policy
);
63 * This is the priority-queue data structure of the RT scheduling class:
65 struct rt_prio_array
{
66 DECLARE_BITMAP(bitmap
, MAX_RT_PRIO
+1); /* include 1 bit for delimiter */
67 struct list_head queue
[MAX_RT_PRIO
];
71 /* nests inside the rq lock: */
72 raw_spinlock_t rt_runtime_lock
;
75 struct hrtimer rt_period_timer
;
78 extern struct mutex sched_domains_mutex
;
80 #ifdef CONFIG_CGROUP_SCHED
82 #include <linux/cgroup.h>
87 static LIST_HEAD(task_groups
);
89 struct cfs_bandwidth
{
90 #ifdef CONFIG_CFS_BANDWIDTH
97 int idle
, timer_active
;
98 struct hrtimer period_timer
, slack_timer
;
99 struct list_head throttled_cfs_rq
;
102 int nr_periods
, nr_throttled
;
107 /* task group related information */
109 struct cgroup_subsys_state css
;
111 #ifdef CONFIG_FAIR_GROUP_SCHED
112 /* schedulable entities of this group on each cpu */
113 struct sched_entity
**se
;
114 /* runqueue "owned" by this group on each cpu */
115 struct cfs_rq
**cfs_rq
;
116 unsigned long shares
;
118 atomic_t load_weight
;
121 #ifdef CONFIG_RT_GROUP_SCHED
122 struct sched_rt_entity
**rt_se
;
123 struct rt_rq
**rt_rq
;
125 struct rt_bandwidth rt_bandwidth
;
129 struct list_head list
;
131 struct task_group
*parent
;
132 struct list_head siblings
;
133 struct list_head children
;
135 #ifdef CONFIG_SCHED_AUTOGROUP
136 struct autogroup
*autogroup
;
139 struct cfs_bandwidth cfs_bandwidth
;
142 #ifdef CONFIG_FAIR_GROUP_SCHED
143 #define ROOT_TASK_GROUP_LOAD NICE_0_LOAD
146 * A weight of 0 or 1 can cause arithmetics problems.
147 * A weight of a cfs_rq is the sum of weights of which entities
148 * are queued on this cfs_rq, so a weight of a entity should not be
149 * too large, so as the shares value of a task group.
150 * (The default weight is 1024 - so there's no practical
151 * limitation from this.)
153 #define MIN_SHARES (1UL << 1)
154 #define MAX_SHARES (1UL << 18)
157 /* Default task group.
158 * Every task in system belong to this group at bootup.
160 extern struct task_group root_task_group
;
162 typedef int (*tg_visitor
)(struct task_group
*, void *);
164 extern int walk_tg_tree_from(struct task_group
*from
,
165 tg_visitor down
, tg_visitor up
, void *data
);
168 * Iterate the full tree, calling @down when first entering a node and @up when
169 * leaving it for the final time.
171 * Caller must hold rcu_lock or sufficient equivalent.
173 static inline int walk_tg_tree(tg_visitor down
, tg_visitor up
, void *data
)
175 return walk_tg_tree_from(&root_task_group
, down
, up
, data
);
178 extern int tg_nop(struct task_group
*tg
, void *data
);
180 extern void free_fair_sched_group(struct task_group
*tg
);
181 extern int alloc_fair_sched_group(struct task_group
*tg
, struct task_group
*parent
);
182 extern void unregister_fair_sched_group(struct task_group
*tg
, int cpu
);
183 extern void init_tg_cfs_entry(struct task_group
*tg
, struct cfs_rq
*cfs_rq
,
184 struct sched_entity
*se
, int cpu
,
185 struct sched_entity
*parent
);
186 extern void init_cfs_bandwidth(struct cfs_bandwidth
*cfs_b
);
187 extern int sched_group_set_shares(struct task_group
*tg
, unsigned long shares
);
189 extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth
*cfs_b
);
190 extern void __start_cfs_bandwidth(struct cfs_bandwidth
*cfs_b
);
191 extern void unthrottle_cfs_rq(struct cfs_rq
*cfs_rq
);
193 extern void free_rt_sched_group(struct task_group
*tg
);
194 extern int alloc_rt_sched_group(struct task_group
*tg
, struct task_group
*parent
);
195 extern void init_tg_rt_entry(struct task_group
*tg
, struct rt_rq
*rt_rq
,
196 struct sched_rt_entity
*rt_se
, int cpu
,
197 struct sched_rt_entity
*parent
);
199 #else /* CONFIG_CGROUP_SCHED */
201 struct cfs_bandwidth
{ };
203 #endif /* CONFIG_CGROUP_SCHED */
205 /* CFS-related fields in a runqueue */
207 struct load_weight load
;
208 unsigned long nr_running
, h_nr_running
;
213 u64 min_vruntime_copy
;
216 struct rb_root tasks_timeline
;
217 struct rb_node
*rb_leftmost
;
219 struct list_head tasks
;
220 struct list_head
*balance_iterator
;
223 * 'curr' points to currently running entity on this cfs_rq.
224 * It is set to NULL otherwise (i.e when none are currently running).
226 struct sched_entity
*curr
, *next
, *last
, *skip
;
228 #ifdef CONFIG_SCHED_DEBUG
229 unsigned int nr_spread_over
;
232 #ifdef CONFIG_FAIR_GROUP_SCHED
233 struct rq
*rq
; /* cpu runqueue to which this cfs_rq is attached */
236 * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in
237 * a hierarchy). Non-leaf lrqs hold other higher schedulable entities
238 * (like users, containers etc.)
240 * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a cpu. This
241 * list is used during load balance.
244 struct list_head leaf_cfs_rq_list
;
245 struct task_group
*tg
; /* group that "owns" this runqueue */
249 * the part of load.weight contributed by tasks
251 unsigned long task_weight
;
254 * h_load = weight * f(tg)
256 * Where f(tg) is the recursive weight fraction assigned to
259 unsigned long h_load
;
262 * Maintaining per-cpu shares distribution for group scheduling
264 * load_stamp is the last time we updated the load average
265 * load_last is the last time we updated the load average and saw load
266 * load_unacc_exec_time is currently unaccounted execution time
270 u64 load_stamp
, load_last
, load_unacc_exec_time
;
272 unsigned long load_contribution
;
273 #endif /* CONFIG_SMP */
274 #ifdef CONFIG_CFS_BANDWIDTH
277 s64 runtime_remaining
;
279 u64 throttled_timestamp
;
280 int throttled
, throttle_count
;
281 struct list_head throttled_list
;
282 #endif /* CONFIG_CFS_BANDWIDTH */
283 #endif /* CONFIG_FAIR_GROUP_SCHED */
286 static inline int rt_bandwidth_enabled(void)
288 return sysctl_sched_rt_runtime
>= 0;
291 /* Real-Time classes' related field in a runqueue: */
293 struct rt_prio_array active
;
294 unsigned long rt_nr_running
;
295 #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
297 int curr
; /* highest queued rt task prio */
299 int next
; /* next highest */
304 unsigned long rt_nr_migratory
;
305 unsigned long rt_nr_total
;
307 struct plist_head pushable_tasks
;
312 /* Nests inside the rq lock: */
313 raw_spinlock_t rt_runtime_lock
;
315 #ifdef CONFIG_RT_GROUP_SCHED
316 unsigned long rt_nr_boosted
;
319 struct list_head leaf_rt_rq_list
;
320 struct task_group
*tg
;
327 * We add the notion of a root-domain which will be used to define per-domain
328 * variables. Each exclusive cpuset essentially defines an island domain by
329 * fully partitioning the member cpus from any other cpuset. Whenever a new
330 * exclusive cpuset is created, we also create and attach a new root-domain
339 cpumask_var_t online
;
342 * The "RT overload" flag: it gets set if a CPU has more than
343 * one runnable RT task.
345 cpumask_var_t rto_mask
;
346 struct cpupri cpupri
;
349 extern struct root_domain def_root_domain
;
351 #endif /* CONFIG_SMP */
354 * This is the main, per-CPU runqueue data structure.
356 * Locking rule: those places that want to lock multiple runqueues
357 * (such as the load balancing or the thread migration code), lock
358 * acquire operations must be ordered by ascending &runqueue.
365 * nr_running and cpu_load should be in the same cacheline because
366 * remote CPUs use both these fields when doing load calculation.
368 unsigned long nr_running
;
369 #define CPU_LOAD_IDX_MAX 5
370 unsigned long cpu_load
[CPU_LOAD_IDX_MAX
];
371 unsigned long last_load_update_tick
;
374 unsigned char nohz_balance_kick
;
376 int skip_clock_update
;
378 /* capture load from *all* tasks on this cpu: */
379 struct load_weight load
;
380 unsigned long nr_load_updates
;
386 #ifdef CONFIG_FAIR_GROUP_SCHED
387 /* list of leaf cfs_rq on this cpu: */
388 struct list_head leaf_cfs_rq_list
;
390 #ifdef CONFIG_RT_GROUP_SCHED
391 struct list_head leaf_rt_rq_list
;
395 * This is part of a global counter where only the total sum
396 * over all CPUs matters. A task can increase this counter on
397 * one CPU and if it got migrated afterwards it may decrease
398 * it on another CPU. Always updated under the runqueue lock:
400 unsigned long nr_uninterruptible
;
402 struct task_struct
*curr
, *idle
, *stop
;
403 unsigned long next_balance
;
404 struct mm_struct
*prev_mm
;
412 struct root_domain
*rd
;
413 struct sched_domain
*sd
;
415 unsigned long cpu_power
;
417 unsigned char idle_balance
;
418 /* For active balancing */
422 struct cpu_stop_work active_balance_work
;
423 /* cpu of this runqueue: */
433 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
436 #ifdef CONFIG_PARAVIRT
439 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
440 u64 prev_steal_time_rq
;
443 /* calc_load related fields */
444 unsigned long calc_load_update
;
445 long calc_load_active
;
447 #ifdef CONFIG_SCHED_HRTICK
449 int hrtick_csd_pending
;
450 struct call_single_data hrtick_csd
;
452 struct hrtimer hrtick_timer
;
455 #ifdef CONFIG_SCHEDSTATS
457 struct sched_info rq_sched_info
;
458 unsigned long long rq_cpu_time
;
459 /* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */
461 /* sys_sched_yield() stats */
462 unsigned int yld_count
;
464 /* schedule() stats */
465 unsigned int sched_switch
;
466 unsigned int sched_count
;
467 unsigned int sched_goidle
;
469 /* try_to_wake_up() stats */
470 unsigned int ttwu_count
;
471 unsigned int ttwu_local
;
475 struct llist_head wake_list
;
479 static inline int cpu_of(struct rq
*rq
)
488 DECLARE_PER_CPU(struct rq
, runqueues
);
490 #define rcu_dereference_check_sched_domain(p) \
491 rcu_dereference_check((p), \
492 lockdep_is_held(&sched_domains_mutex))
495 * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
496 * See detach_destroy_domains: synchronize_sched for details.
498 * The domain tree of any CPU may only be accessed from within
499 * preempt-disabled sections.
501 #define for_each_domain(cpu, __sd) \
502 for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)
504 #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
505 #define this_rq() (&__get_cpu_var(runqueues))
506 #define task_rq(p) cpu_rq(task_cpu(p))
507 #define cpu_curr(cpu) (cpu_rq(cpu)->curr)
508 #define raw_rq() (&__raw_get_cpu_var(runqueues))
510 #include "sched_stats.h"
511 #include "sched_autogroup.h"
513 #ifdef CONFIG_CGROUP_SCHED
516 * Return the group to which this tasks belongs.
518 * We use task_subsys_state_check() and extend the RCU verification with
519 * pi->lock and rq->lock because cpu_cgroup_attach() holds those locks for each
520 * task it moves into the cgroup. Therefore by holding either of those locks,
521 * we pin the task to the current cgroup.
523 static inline struct task_group
*task_group(struct task_struct
*p
)
525 struct task_group
*tg
;
526 struct cgroup_subsys_state
*css
;
528 css
= task_subsys_state_check(p
, cpu_cgroup_subsys_id
,
529 lockdep_is_held(&p
->pi_lock
) ||
530 lockdep_is_held(&task_rq(p
)->lock
));
531 tg
= container_of(css
, struct task_group
, css
);
533 return autogroup_task_group(p
, tg
);
536 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
537 static inline void set_task_rq(struct task_struct
*p
, unsigned int cpu
)
539 #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
540 struct task_group
*tg
= task_group(p
);
543 #ifdef CONFIG_FAIR_GROUP_SCHED
544 p
->se
.cfs_rq
= tg
->cfs_rq
[cpu
];
545 p
->se
.parent
= tg
->se
[cpu
];
548 #ifdef CONFIG_RT_GROUP_SCHED
549 p
->rt
.rt_rq
= tg
->rt_rq
[cpu
];
550 p
->rt
.parent
= tg
->rt_se
[cpu
];
554 #else /* CONFIG_CGROUP_SCHED */
556 static inline void set_task_rq(struct task_struct
*p
, unsigned int cpu
) { }
557 static inline struct task_group
*task_group(struct task_struct
*p
)
562 #endif /* CONFIG_CGROUP_SCHED */
564 static inline void __set_task_cpu(struct task_struct
*p
, unsigned int cpu
)
569 * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
570 * successfuly executed on another CPU. We must ensure that updates of
571 * per-task data have been completed by this moment.
574 task_thread_info(p
)->cpu
= cpu
;
579 * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
581 #ifdef CONFIG_SCHED_DEBUG
582 # define const_debug __read_mostly
584 # define const_debug const
587 extern const_debug
unsigned int sysctl_sched_features
;
589 #define SCHED_FEAT(name, enabled) \
590 __SCHED_FEAT_##name ,
593 #include "sched_features.h"
598 #define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
600 static inline u64
global_rt_period(void)
602 return (u64
)sysctl_sched_rt_period
* NSEC_PER_USEC
;
605 static inline u64
global_rt_runtime(void)
607 if (sysctl_sched_rt_runtime
< 0)
610 return (u64
)sysctl_sched_rt_runtime
* NSEC_PER_USEC
;
615 static inline int task_current(struct rq
*rq
, struct task_struct
*p
)
617 return rq
->curr
== p
;
620 static inline int task_running(struct rq
*rq
, struct task_struct
*p
)
625 return task_current(rq
, p
);
630 #ifndef prepare_arch_switch
631 # define prepare_arch_switch(next) do { } while (0)
633 #ifndef finish_arch_switch
634 # define finish_arch_switch(prev) do { } while (0)
637 #ifndef __ARCH_WANT_UNLOCKED_CTXSW
638 static inline void prepare_lock_switch(struct rq
*rq
, struct task_struct
*next
)
642 * We can optimise this out completely for !SMP, because the
643 * SMP rebalancing from interrupt is the only thing that cares
650 static inline void finish_lock_switch(struct rq
*rq
, struct task_struct
*prev
)
654 * After ->on_cpu is cleared, the task can be moved to a different CPU.
655 * We must ensure this doesn't happen until the switch is completely
661 #ifdef CONFIG_DEBUG_SPINLOCK
662 /* this is a valid case when another task releases the spinlock */
663 rq
->lock
.owner
= current
;
666 * If we are tracking spinlock dependencies then we have to
667 * fix up the runqueue lock - which gets 'carried over' from
670 spin_acquire(&rq
->lock
.dep_map
, 0, 0, _THIS_IP_
);
672 raw_spin_unlock_irq(&rq
->lock
);
675 #else /* __ARCH_WANT_UNLOCKED_CTXSW */
676 static inline void prepare_lock_switch(struct rq
*rq
, struct task_struct
*next
)
680 * We can optimise this out completely for !SMP, because the
681 * SMP rebalancing from interrupt is the only thing that cares
686 #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
687 raw_spin_unlock_irq(&rq
->lock
);
689 raw_spin_unlock(&rq
->lock
);
693 static inline void finish_lock_switch(struct rq
*rq
, struct task_struct
*prev
)
697 * After ->on_cpu is cleared, the task can be moved to a different CPU.
698 * We must ensure this doesn't happen until the switch is completely
704 #ifndef __ARCH_WANT_INTERRUPTS_ON_CTXSW
708 #endif /* __ARCH_WANT_UNLOCKED_CTXSW */
711 static inline void update_load_add(struct load_weight
*lw
, unsigned long inc
)
717 static inline void update_load_sub(struct load_weight
*lw
, unsigned long dec
)
723 static inline void update_load_set(struct load_weight
*lw
, unsigned long w
)
730 * To aid in avoiding the subversion of "niceness" due to uneven distribution
731 * of tasks with abnormal "nice" values across CPUs the contribution that
732 * each task makes to its run queue's load is weighted according to its
733 * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a
734 * scaled version of the new time slice allocation that they receive on time
738 #define WEIGHT_IDLEPRIO 3
739 #define WMULT_IDLEPRIO 1431655765
742 * Nice levels are multiplicative, with a gentle 10% change for every
743 * nice level changed. I.e. when a CPU-bound task goes from nice 0 to
744 * nice 1, it will get ~10% less CPU time than another CPU-bound task
745 * that remained on nice 0.
747 * The "10% effect" is relative and cumulative: from _any_ nice level,
748 * if you go up 1 level, it's -10% CPU usage, if you go down 1 level
749 * it's +10% CPU usage. (to achieve that we use a multiplier of 1.25.
750 * If a task goes up by ~10% and another task goes down by ~10% then
751 * the relative distance between them is ~25%.)
753 static const int prio_to_weight
[40] = {
754 /* -20 */ 88761, 71755, 56483, 46273, 36291,
755 /* -15 */ 29154, 23254, 18705, 14949, 11916,
756 /* -10 */ 9548, 7620, 6100, 4904, 3906,
757 /* -5 */ 3121, 2501, 1991, 1586, 1277,
758 /* 0 */ 1024, 820, 655, 526, 423,
759 /* 5 */ 335, 272, 215, 172, 137,
760 /* 10 */ 110, 87, 70, 56, 45,
761 /* 15 */ 36, 29, 23, 18, 15,
765 * Inverse (2^32/x) values of the prio_to_weight[] array, precalculated.
767 * In cases where the weight does not change often, we can use the
768 * precalculated inverse to speed up arithmetics by turning divisions
769 * into multiplications:
771 static const u32 prio_to_wmult
[40] = {
772 /* -20 */ 48388, 59856, 76040, 92818, 118348,
773 /* -15 */ 147320, 184698, 229616, 287308, 360437,
774 /* -10 */ 449829, 563644, 704093, 875809, 1099582,
775 /* -5 */ 1376151, 1717300, 2157191, 2708050, 3363326,
776 /* 0 */ 4194304, 5237765, 6557202, 8165337, 10153587,
777 /* 5 */ 12820798, 15790321, 19976592, 24970740, 31350126,
778 /* 10 */ 39045157, 49367440, 61356676, 76695844, 95443717,
779 /* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
782 /* Time spent by the tasks of the cpu accounting group executing in ... */
783 enum cpuacct_stat_index
{
784 CPUACCT_STAT_USER
, /* ... user mode */
785 CPUACCT_STAT_SYSTEM
, /* ... kernel mode */
791 #define sched_class_highest (&stop_sched_class)
792 #define for_each_class(class) \
793 for (class = sched_class_highest; class; class = class->next)
795 extern const struct sched_class stop_sched_class
;
796 extern const struct sched_class rt_sched_class
;
797 extern const struct sched_class fair_sched_class
;
798 extern const struct sched_class idle_sched_class
;
803 extern void trigger_load_balance(struct rq
*rq
, int cpu
);
804 extern void idle_balance(int this_cpu
, struct rq
*this_rq
);
806 #else /* CONFIG_SMP */
808 static inline void idle_balance(int cpu
, struct rq
*rq
)
814 extern void sysrq_sched_debug_show(void);
815 extern void sched_init_granularity(void);
816 extern void update_max_interval(void);
817 extern void update_group_power(struct sched_domain
*sd
, int cpu
);
818 extern int update_runtime(struct notifier_block
*nfb
, unsigned long action
, void *hcpu
);
819 extern void init_sched_rt_class(void);
820 extern void init_sched_fair_class(void);
822 extern void resched_task(struct task_struct
*p
);
823 extern void resched_cpu(int cpu
);
825 extern struct rt_bandwidth def_rt_bandwidth
;
826 extern void init_rt_bandwidth(struct rt_bandwidth
*rt_b
, u64 period
, u64 runtime
);
828 extern void update_cpu_load(struct rq
*this_rq
);
830 #ifdef CONFIG_CGROUP_CPUACCT
831 extern void cpuacct_charge(struct task_struct
*tsk
, u64 cputime
);
832 extern void cpuacct_update_stats(struct task_struct
*tsk
,
833 enum cpuacct_stat_index idx
, cputime_t val
);
835 static inline void cpuacct_charge(struct task_struct
*tsk
, u64 cputime
) {}
836 static inline void cpuacct_update_stats(struct task_struct
*tsk
,
837 enum cpuacct_stat_index idx
, cputime_t val
) {}
840 static inline void inc_nr_running(struct rq
*rq
)
845 static inline void dec_nr_running(struct rq
*rq
)
850 extern void update_rq_clock(struct rq
*rq
);
852 extern void activate_task(struct rq
*rq
, struct task_struct
*p
, int flags
);
853 extern void deactivate_task(struct rq
*rq
, struct task_struct
*p
, int flags
);
855 extern void check_preempt_curr(struct rq
*rq
, struct task_struct
*p
, int flags
);
857 extern const_debug
unsigned int sysctl_sched_time_avg
;
858 extern const_debug
unsigned int sysctl_sched_nr_migrate
;
859 extern const_debug
unsigned int sysctl_sched_migration_cost
;
861 static inline u64
sched_avg_period(void)
863 return (u64
)sysctl_sched_time_avg
* NSEC_PER_MSEC
/ 2;
866 void calc_load_account_idle(struct rq
*this_rq
);
868 #ifdef CONFIG_SCHED_HRTICK
872 * - enabled by features
873 * - hrtimer is actually high res
875 static inline int hrtick_enabled(struct rq
*rq
)
877 if (!sched_feat(HRTICK
))
879 if (!cpu_active(cpu_of(rq
)))
881 return hrtimer_is_hres_active(&rq
->hrtick_timer
);
884 void hrtick_start(struct rq
*rq
, u64 delay
);
886 #endif /* CONFIG_SCHED_HRTICK */
889 extern void sched_avg_update(struct rq
*rq
);
890 static inline void sched_rt_avg_update(struct rq
*rq
, u64 rt_delta
)
892 rq
->rt_avg
+= rt_delta
;
893 sched_avg_update(rq
);
896 static inline void sched_rt_avg_update(struct rq
*rq
, u64 rt_delta
) { }
897 static inline void sched_avg_update(struct rq
*rq
) { }
900 extern void start_bandwidth_timer(struct hrtimer
*period_timer
, ktime_t period
);
903 #ifdef CONFIG_PREEMPT
905 static inline void double_rq_lock(struct rq
*rq1
, struct rq
*rq2
);
908 * fair double_lock_balance: Safely acquires both rq->locks in a fair
909 * way at the expense of forcing extra atomic operations in all
910 * invocations. This assures that the double_lock is acquired using the
911 * same underlying policy as the spinlock_t on this architecture, which
912 * reduces latency compared to the unfair variant below. However, it
913 * also adds more overhead and therefore may reduce throughput.
915 static inline int _double_lock_balance(struct rq
*this_rq
, struct rq
*busiest
)
916 __releases(this_rq
->lock
)
917 __acquires(busiest
->lock
)
918 __acquires(this_rq
->lock
)
920 raw_spin_unlock(&this_rq
->lock
);
921 double_rq_lock(this_rq
, busiest
);
928 * Unfair double_lock_balance: Optimizes throughput at the expense of
929 * latency by eliminating extra atomic operations when the locks are
930 * already in proper order on entry. This favors lower cpu-ids and will
931 * grant the double lock to lower cpus over higher ids under contention,
932 * regardless of entry order into the function.
934 static inline int _double_lock_balance(struct rq
*this_rq
, struct rq
*busiest
)
935 __releases(this_rq
->lock
)
936 __acquires(busiest
->lock
)
937 __acquires(this_rq
->lock
)
941 if (unlikely(!raw_spin_trylock(&busiest
->lock
))) {
942 if (busiest
< this_rq
) {
943 raw_spin_unlock(&this_rq
->lock
);
944 raw_spin_lock(&busiest
->lock
);
945 raw_spin_lock_nested(&this_rq
->lock
,
946 SINGLE_DEPTH_NESTING
);
949 raw_spin_lock_nested(&busiest
->lock
,
950 SINGLE_DEPTH_NESTING
);
955 #endif /* CONFIG_PREEMPT */
958 * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
960 static inline int double_lock_balance(struct rq
*this_rq
, struct rq
*busiest
)
962 if (unlikely(!irqs_disabled())) {
963 /* printk() doesn't work good under rq->lock */
964 raw_spin_unlock(&this_rq
->lock
);
968 return _double_lock_balance(this_rq
, busiest
);
971 static inline void double_unlock_balance(struct rq
*this_rq
, struct rq
*busiest
)
972 __releases(busiest
->lock
)
974 raw_spin_unlock(&busiest
->lock
);
975 lock_set_subclass(&this_rq
->lock
.dep_map
, 0, _RET_IP_
);
979 * double_rq_lock - safely lock two runqueues
981 * Note this does not disable interrupts like task_rq_lock,
982 * you need to do so manually before calling.
984 static inline void double_rq_lock(struct rq
*rq1
, struct rq
*rq2
)
985 __acquires(rq1
->lock
)
986 __acquires(rq2
->lock
)
988 BUG_ON(!irqs_disabled());
990 raw_spin_lock(&rq1
->lock
);
991 __acquire(rq2
->lock
); /* Fake it out ;) */
994 raw_spin_lock(&rq1
->lock
);
995 raw_spin_lock_nested(&rq2
->lock
, SINGLE_DEPTH_NESTING
);
997 raw_spin_lock(&rq2
->lock
);
998 raw_spin_lock_nested(&rq1
->lock
, SINGLE_DEPTH_NESTING
);
1004 * double_rq_unlock - safely unlock two runqueues
1006 * Note this does not restore interrupts like task_rq_unlock,
1007 * you need to do so manually after calling.
1009 static inline void double_rq_unlock(struct rq
*rq1
, struct rq
*rq2
)
1010 __releases(rq1
->lock
)
1011 __releases(rq2
->lock
)
1013 raw_spin_unlock(&rq1
->lock
);
1015 raw_spin_unlock(&rq2
->lock
);
1017 __release(rq2
->lock
);
1020 #else /* CONFIG_SMP */
1023 * double_rq_lock - safely lock two runqueues
1025 * Note this does not disable interrupts like task_rq_lock,
1026 * you need to do so manually before calling.
1028 static inline void double_rq_lock(struct rq
*rq1
, struct rq
*rq2
)
1029 __acquires(rq1
->lock
)
1030 __acquires(rq2
->lock
)
1032 BUG_ON(!irqs_disabled());
1034 raw_spin_lock(&rq1
->lock
);
1035 __acquire(rq2
->lock
); /* Fake it out ;) */
1039 * double_rq_unlock - safely unlock two runqueues
1041 * Note this does not restore interrupts like task_rq_unlock,
1042 * you need to do so manually after calling.
1044 static inline void double_rq_unlock(struct rq
*rq1
, struct rq
*rq2
)
1045 __releases(rq1
->lock
)
1046 __releases(rq2
->lock
)
1049 raw_spin_unlock(&rq1
->lock
);
1050 __release(rq2
->lock
);
1055 extern struct sched_entity
*__pick_first_entity(struct cfs_rq
*cfs_rq
);
1056 extern struct sched_entity
*__pick_last_entity(struct cfs_rq
*cfs_rq
);
1057 extern void print_cfs_stats(struct seq_file
*m
, int cpu
);
1058 extern void print_rt_stats(struct seq_file
*m
, int cpu
);
1060 extern void init_cfs_rq(struct cfs_rq
*cfs_rq
);
1061 extern void init_rt_rq(struct rt_rq
*rt_rq
, struct rq
*rq
);
1062 extern void unthrottle_offline_cfs_rqs(struct rq
*rq
);
1064 extern void account_cfs_bandwidth_used(int enabled
, int was_enabled
);