2 #include <linux/sched.h>
3 #include <linux/sched/sysctl.h>
4 #include <linux/sched/rt.h>
5 #include <linux/sched/smt.h>
6 #include <linux/sched/deadline.h>
7 #include <linux/mutex.h>
8 #include <linux/spinlock.h>
9 #include <linux/stop_machine.h>
10 #include <linux/irq_work.h>
11 #include <linux/tick.h>
12 #include <linux/slab.h>
15 #include "cpudeadline.h"
21 /* task_struct::on_rq states: */
22 #define TASK_ON_RQ_QUEUED 1
23 #define TASK_ON_RQ_MIGRATING 2
25 extern __read_mostly int scheduler_running;
27 extern unsigned long calc_load_update;
28 extern atomic_long_t calc_load_tasks;
30 extern void calc_global_load_tick(struct rq *this_rq);
31 extern long calc_load_fold_active(struct rq *this_rq);
34 extern void update_cpu_load_active(struct rq *this_rq);
36 static inline void update_cpu_load_active(struct rq *this_rq) { }
40 * Helpers for converting nanosecond timing to jiffy resolution
42 #define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
45 * Increase resolution of nice-level calculations for 64-bit architectures.
46 * The extra resolution improves shares distribution and load balancing of
47 * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
48 * hierarchies, especially on larger systems. This is not a user-visible change
49 * and does not change the user-interface for setting shares/weights.
51 * We increase resolution only if we have enough bits to allow this increased
52 * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution
53 * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the
56 #if 0 /* BITS_PER_LONG > 32 -- currently broken: it increases power usage under light load */
57 # define SCHED_LOAD_RESOLUTION 10
58 # define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)
59 # define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)
61 # define SCHED_LOAD_RESOLUTION 0
62 # define scale_load(w) (w)
63 # define scale_load_down(w) (w)
66 #define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)
67 #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
69 #define NICE_0_LOAD SCHED_LOAD_SCALE
70 #define NICE_0_SHIFT SCHED_LOAD_SHIFT
73 * Single value that decides SCHED_DEADLINE internal math precision.
74 * 10 -> just above 1us
75 * 9 -> just above 0.5us
80 * These are the 'tuning knobs' of the scheduler:
84 * single value that denotes runtime == period, ie unlimited time.
86 #define RUNTIME_INF ((u64)~0ULL)
88 static inline int idle_policy(int policy)
90 return policy == SCHED_IDLE;
92 static inline int fair_policy(int policy)
94 return policy == SCHED_NORMAL || policy == SCHED_BATCH;
97 static inline int rt_policy(int policy)
99 return policy == SCHED_FIFO || policy == SCHED_RR;
102 static inline int dl_policy(int policy)
104 return policy == SCHED_DEADLINE;
106 static inline bool valid_policy(int policy)
108 return idle_policy(policy) || fair_policy(policy) ||
109 rt_policy(policy) || dl_policy(policy);
112 static inline int task_has_rt_policy(struct task_struct *p)
114 return rt_policy(p->policy);
117 static inline int task_has_dl_policy(struct task_struct *p)
119 return dl_policy(p->policy);
123 * Tells if entity @a should preempt entity @b.
126 dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b)
128 return dl_time_before(a->deadline, b->deadline);
132 * This is the priority-queue data structure of the RT scheduling class:
134 struct rt_prio_array {
135 DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */
136 struct list_head queue[MAX_RT_PRIO];
139 struct rt_bandwidth {
140 /* nests inside the rq lock: */
141 raw_spinlock_t rt_runtime_lock;
144 struct hrtimer rt_period_timer;
145 unsigned int rt_period_active;
148 void __dl_clear_params(struct task_struct *p);
151 * To keep the bandwidth of -deadline tasks and groups under control
152 * we need some place where:
153 * - store the maximum -deadline bandwidth of the system (the group);
154 * - cache the fraction of that bandwidth that is currently allocated.
156 * This is all done in the data structure below. It is similar to the
157 * one used for RT-throttling (rt_bandwidth), with the main difference
158 * that, since here we are only interested in admission control, we
159 * do not decrease any runtime while the group "executes", neither we
160 * need a timer to replenish it.
162 * With respect to SMP, the bandwidth is given on a per-CPU basis,
164 * - dl_bw (< 100%) is the bandwidth of the system (group) on each CPU;
165 * - dl_total_bw array contains, in the i-eth element, the currently
166 * allocated bandwidth on the i-eth CPU.
167 * Moreover, groups consume bandwidth on each CPU, while tasks only
168 * consume bandwidth on the CPU they're running on.
169 * Finally, dl_total_bw_cpu is used to cache the index of dl_total_bw
170 * that will be shown the next time the proc or cgroup controls will
171 * be red. It on its turn can be changed by writing on its own
174 struct dl_bandwidth {
175 raw_spinlock_t dl_runtime_lock;
180 static inline int dl_bandwidth_enabled(void)
182 return sysctl_sched_rt_runtime >= 0;
185 extern struct dl_bw *dl_bw_of(int i);
193 void __dl_clear(struct dl_bw *dl_b, u64 tsk_bw)
195 dl_b->total_bw -= tsk_bw;
199 void __dl_add(struct dl_bw *dl_b, u64 tsk_bw)
201 dl_b->total_bw += tsk_bw;
205 bool __dl_overflow(struct dl_bw *dl_b, int cpus, u64 old_bw, u64 new_bw)
207 return dl_b->bw != -1 &&
208 dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw;
211 extern struct mutex sched_domains_mutex;
213 #ifdef CONFIG_CGROUP_SCHED
215 #include <linux/cgroup.h>
220 extern struct list_head task_groups;
222 struct cfs_bandwidth {
223 #ifdef CONFIG_CFS_BANDWIDTH
227 s64 hierarchical_quota;
230 int idle, period_active;
231 struct hrtimer period_timer, slack_timer;
232 struct list_head throttled_cfs_rq;
235 int nr_periods, nr_throttled;
238 bool distribute_running;
242 /* task group related information */
244 struct cgroup_subsys_state css;
246 #ifdef CONFIG_FAIR_GROUP_SCHED
247 /* schedulable entities of this group on each cpu */
248 struct sched_entity **se;
249 /* runqueue "owned" by this group on each cpu */
250 struct cfs_rq **cfs_rq;
251 unsigned long shares;
254 atomic_long_t load_avg;
258 #ifdef CONFIG_RT_GROUP_SCHED
259 struct sched_rt_entity **rt_se;
260 struct rt_rq **rt_rq;
262 struct rt_bandwidth rt_bandwidth;
266 struct list_head list;
268 struct task_group *parent;
269 struct list_head siblings;
270 struct list_head children;
272 #ifdef CONFIG_SCHED_AUTOGROUP
273 struct autogroup *autogroup;
276 struct cfs_bandwidth cfs_bandwidth;
279 #ifdef CONFIG_FAIR_GROUP_SCHED
280 #define ROOT_TASK_GROUP_LOAD NICE_0_LOAD
283 * A weight of 0 or 1 can cause arithmetics problems.
284 * A weight of a cfs_rq is the sum of weights of which entities
285 * are queued on this cfs_rq, so a weight of a entity should not be
286 * too large, so as the shares value of a task group.
287 * (The default weight is 1024 - so there's no practical
288 * limitation from this.)
290 #define MIN_SHARES (1UL << 1)
291 #define MAX_SHARES (1UL << 18)
294 typedef int (*tg_visitor)(struct task_group *, void *);
296 extern int walk_tg_tree_from(struct task_group *from,
297 tg_visitor down, tg_visitor up, void *data);
300 * Iterate the full tree, calling @down when first entering a node and @up when
301 * leaving it for the final time.
303 * Caller must hold rcu_lock or sufficient equivalent.
305 static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
307 return walk_tg_tree_from(&root_task_group, down, up, data);
310 extern int tg_nop(struct task_group *tg, void *data);
312 extern void free_fair_sched_group(struct task_group *tg);
313 extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent);
314 extern void unregister_fair_sched_group(struct task_group *tg);
315 extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
316 struct sched_entity *se, int cpu,
317 struct sched_entity *parent);
318 extern void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
319 extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
321 extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b);
322 extern void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
323 extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq);
325 extern void free_rt_sched_group(struct task_group *tg);
326 extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent);
327 extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
328 struct sched_rt_entity *rt_se, int cpu,
329 struct sched_rt_entity *parent);
331 extern struct task_group *sched_create_group(struct task_group *parent);
332 extern void sched_online_group(struct task_group *tg,
333 struct task_group *parent);
334 extern void sched_destroy_group(struct task_group *tg);
335 extern void sched_offline_group(struct task_group *tg);
337 extern void sched_move_task(struct task_struct *tsk);
339 #ifdef CONFIG_FAIR_GROUP_SCHED
340 extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
343 #else /* CONFIG_CGROUP_SCHED */
345 struct cfs_bandwidth { };
347 #endif /* CONFIG_CGROUP_SCHED */
349 /* CFS-related fields in a runqueue */
351 struct load_weight load;
352 unsigned int nr_running, h_nr_running;
357 u64 min_vruntime_copy;
360 struct rb_root tasks_timeline;
361 struct rb_node *rb_leftmost;
364 * 'curr' points to currently running entity on this cfs_rq.
365 * It is set to NULL otherwise (i.e when none are currently running).
367 struct sched_entity *curr, *next, *last, *skip;
369 #ifdef CONFIG_SCHED_DEBUG
370 unsigned int nr_spread_over;
377 struct sched_avg avg;
378 u64 runnable_load_sum;
379 unsigned long runnable_load_avg;
380 #ifdef CONFIG_FAIR_GROUP_SCHED
381 unsigned long tg_load_avg_contrib;
383 atomic_long_t removed_load_avg, removed_util_avg;
385 u64 load_last_update_time_copy;
388 #ifdef CONFIG_FAIR_GROUP_SCHED
390 * h_load = weight * f(tg)
392 * Where f(tg) is the recursive weight fraction assigned to
395 unsigned long h_load;
396 u64 last_h_load_update;
397 struct sched_entity *h_load_next;
398 #endif /* CONFIG_FAIR_GROUP_SCHED */
399 #endif /* CONFIG_SMP */
401 #ifdef CONFIG_FAIR_GROUP_SCHED
402 struct rq *rq; /* cpu runqueue to which this cfs_rq is attached */
405 * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in
406 * a hierarchy). Non-leaf lrqs hold other higher schedulable entities
407 * (like users, containers etc.)
409 * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a cpu. This
410 * list is used during load balance.
413 struct list_head leaf_cfs_rq_list;
414 struct task_group *tg; /* group that "owns" this runqueue */
416 #ifdef CONFIG_CFS_BANDWIDTH
419 s64 runtime_remaining;
421 u64 throttled_clock, throttled_clock_task;
422 u64 throttled_clock_task_time;
423 int throttled, throttle_count, throttle_uptodate;
424 struct list_head throttled_list;
425 #endif /* CONFIG_CFS_BANDWIDTH */
426 #endif /* CONFIG_FAIR_GROUP_SCHED */
429 static inline int rt_bandwidth_enabled(void)
431 return sysctl_sched_rt_runtime >= 0;
434 /* RT IPI pull logic requires IRQ_WORK */
435 #if defined(CONFIG_IRQ_WORK) && defined(CONFIG_SMP)
436 # define HAVE_RT_PUSH_IPI
439 /* Real-Time classes' related field in a runqueue: */
441 struct rt_prio_array active;
442 unsigned int rt_nr_running;
443 #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
445 int curr; /* highest queued rt task prio */
447 int next; /* next highest */
452 unsigned long rt_nr_migratory;
453 unsigned long rt_nr_total;
455 struct plist_head pushable_tasks;
456 #endif /* CONFIG_SMP */
462 /* Nests inside the rq lock: */
463 raw_spinlock_t rt_runtime_lock;
465 #ifdef CONFIG_RT_GROUP_SCHED
466 unsigned long rt_nr_boosted;
469 struct task_group *tg;
473 /* Deadline class' related fields in a runqueue */
475 /* runqueue is an rbtree, ordered by deadline */
476 struct rb_root rb_root;
477 struct rb_node *rb_leftmost;
479 unsigned long dl_nr_running;
483 * Deadline values of the currently executing and the
484 * earliest ready task on this rq. Caching these facilitates
485 * the decision wether or not a ready but not running task
486 * should migrate somewhere else.
493 unsigned long dl_nr_migratory;
497 * Tasks on this rq that can be pushed away. They are kept in
498 * an rb-tree, ordered by tasks' deadlines, with caching
499 * of the leftmost (earliest deadline) element.
501 struct rb_root pushable_dl_tasks_root;
502 struct rb_node *pushable_dl_tasks_leftmost;
511 * We add the notion of a root-domain which will be used to define per-domain
512 * variables. Each exclusive cpuset essentially defines an island domain by
513 * fully partitioning the member cpus from any other cpuset. Whenever a new
514 * exclusive cpuset is created, we also create and attach a new root-domain
523 cpumask_var_t online;
525 /* Indicate more than one runnable task for any CPU */
529 * The bit corresponding to a CPU gets set here if such CPU has more
530 * than one runnable -deadline task (as it is below for RT tasks).
532 cpumask_var_t dlo_mask;
537 #ifdef HAVE_RT_PUSH_IPI
539 * For IPI pull requests, loop across the rto_mask.
541 struct irq_work rto_push_work;
542 raw_spinlock_t rto_lock;
543 /* These are only updated and read within rto_lock */
546 /* These atomics are updated outside of a lock */
547 atomic_t rto_loop_next;
548 atomic_t rto_loop_start;
551 * The "RT overload" flag: it gets set if a CPU has more than
552 * one runnable RT task.
554 cpumask_var_t rto_mask;
555 struct cpupri cpupri;
558 extern struct root_domain def_root_domain;
559 extern void sched_get_rd(struct root_domain *rd);
560 extern void sched_put_rd(struct root_domain *rd);
562 #ifdef HAVE_RT_PUSH_IPI
563 extern void rto_push_irq_work_func(struct irq_work *work);
565 #endif /* CONFIG_SMP */
568 * This is the main, per-CPU runqueue data structure.
570 * Locking rule: those places that want to lock multiple runqueues
571 * (such as the load balancing or the thread migration code), lock
572 * acquire operations must be ordered by ascending &runqueue.
579 * nr_running and cpu_load should be in the same cacheline because
580 * remote CPUs use both these fields when doing load calculation.
582 unsigned int nr_running;
583 #ifdef CONFIG_NUMA_BALANCING
584 unsigned int nr_numa_running;
585 unsigned int nr_preferred_running;
587 #define CPU_LOAD_IDX_MAX 5
588 unsigned long cpu_load[CPU_LOAD_IDX_MAX];
589 unsigned long last_load_update_tick;
590 #ifdef CONFIG_NO_HZ_COMMON
592 unsigned long nohz_flags;
594 #ifdef CONFIG_NO_HZ_FULL
595 unsigned long last_sched_tick;
597 /* capture load from *all* tasks on this cpu: */
598 struct load_weight load;
599 unsigned long nr_load_updates;
606 #ifdef CONFIG_FAIR_GROUP_SCHED
607 /* list of leaf cfs_rq on this cpu: */
608 struct list_head leaf_cfs_rq_list;
609 #endif /* CONFIG_FAIR_GROUP_SCHED */
612 * This is part of a global counter where only the total sum
613 * over all CPUs matters. A task can increase this counter on
614 * one CPU and if it got migrated afterwards it may decrease
615 * it on another CPU. Always updated under the runqueue lock:
617 unsigned long nr_uninterruptible;
619 struct task_struct *curr, *idle, *stop;
620 unsigned long next_balance;
621 struct mm_struct *prev_mm;
623 unsigned int clock_skip_update;
630 struct root_domain *rd;
631 struct sched_domain *sd;
633 unsigned long cpu_capacity;
634 unsigned long cpu_capacity_orig;
636 struct callback_head *balance_callback;
638 unsigned char idle_balance;
639 /* For active balancing */
642 struct cpu_stop_work active_balance_work;
643 /* cpu of this runqueue: */
647 struct list_head cfs_tasks;
654 /* This is used to determine avg_idle's max value */
655 u64 max_idle_balance_cost;
658 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
661 #ifdef CONFIG_PARAVIRT
664 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
665 u64 prev_steal_time_rq;
668 /* calc_load related fields */
669 unsigned long calc_load_update;
670 long calc_load_active;
672 #ifdef CONFIG_SCHED_HRTICK
674 int hrtick_csd_pending;
675 struct call_single_data hrtick_csd;
677 struct hrtimer hrtick_timer;
680 #ifdef CONFIG_SCHEDSTATS
682 struct sched_info rq_sched_info;
683 unsigned long long rq_cpu_time;
684 /* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */
686 /* sys_sched_yield() stats */
687 unsigned int yld_count;
689 /* schedule() stats */
690 unsigned int sched_count;
691 unsigned int sched_goidle;
693 /* try_to_wake_up() stats */
694 unsigned int ttwu_count;
695 unsigned int ttwu_local;
699 struct llist_head wake_list;
702 #ifdef CONFIG_CPU_IDLE
703 /* Must be inspected within a rcu lock section */
704 struct cpuidle_state *idle_state;
708 static inline int cpu_of(struct rq *rq)
717 DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
719 #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
720 #define this_rq() this_cpu_ptr(&runqueues)
721 #define task_rq(p) cpu_rq(task_cpu(p))
722 #define cpu_curr(cpu) (cpu_rq(cpu)->curr)
723 #define raw_rq() raw_cpu_ptr(&runqueues)
725 static inline u64 __rq_clock_broken(struct rq *rq)
727 return READ_ONCE(rq->clock);
730 static inline u64 rq_clock(struct rq *rq)
732 lockdep_assert_held(&rq->lock);
736 static inline u64 rq_clock_task(struct rq *rq)
738 lockdep_assert_held(&rq->lock);
739 return rq->clock_task;
742 #define RQCF_REQ_SKIP 0x01
743 #define RQCF_ACT_SKIP 0x02
745 static inline void rq_clock_skip_update(struct rq *rq, bool skip)
747 lockdep_assert_held(&rq->lock);
749 rq->clock_skip_update |= RQCF_REQ_SKIP;
751 rq->clock_skip_update &= ~RQCF_REQ_SKIP;
755 enum numa_topology_type {
760 extern enum numa_topology_type sched_numa_topology_type;
761 extern int sched_max_numa_distance;
762 extern bool find_numa_distance(int distance);
765 #ifdef CONFIG_NUMA_BALANCING
766 /* The regions in numa_faults array from task_struct */
767 enum numa_faults_stats {
773 extern void sched_setnuma(struct task_struct *p, int node);
774 extern int migrate_task_to(struct task_struct *p, int cpu);
775 extern int migrate_swap(struct task_struct *, struct task_struct *);
776 #endif /* CONFIG_NUMA_BALANCING */
781 queue_balance_callback(struct rq *rq,
782 struct callback_head *head,
783 void (*func)(struct rq *rq))
785 lockdep_assert_held(&rq->lock);
787 if (unlikely(head->next))
790 head->func = (void (*)(struct callback_head *))func;
791 head->next = rq->balance_callback;
792 rq->balance_callback = head;
795 extern void sched_ttwu_pending(void);
797 #define rcu_dereference_check_sched_domain(p) \
798 rcu_dereference_check((p), \
799 lockdep_is_held(&sched_domains_mutex))
802 * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
803 * See detach_destroy_domains: synchronize_sched for details.
805 * The domain tree of any CPU may only be accessed from within
806 * preempt-disabled sections.
808 #define for_each_domain(cpu, __sd) \
809 for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \
810 __sd; __sd = __sd->parent)
812 #define for_each_lower_domain(sd) for (; sd; sd = sd->child)
815 * highest_flag_domain - Return highest sched_domain containing flag.
816 * @cpu: The cpu whose highest level of sched domain is to
818 * @flag: The flag to check for the highest sched_domain
821 * Returns the highest sched_domain of a cpu which contains the given flag.
823 static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
825 struct sched_domain *sd, *hsd = NULL;
827 for_each_domain(cpu, sd) {
828 if (!(sd->flags & flag))
836 static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
838 struct sched_domain *sd;
840 for_each_domain(cpu, sd) {
841 if (sd->flags & flag)
848 DECLARE_PER_CPU(struct sched_domain *, sd_llc);
849 DECLARE_PER_CPU(int, sd_llc_size);
850 DECLARE_PER_CPU(int, sd_llc_id);
851 DECLARE_PER_CPU(struct sched_domain *, sd_numa);
852 DECLARE_PER_CPU(struct sched_domain *, sd_busy);
853 DECLARE_PER_CPU(struct sched_domain *, sd_asym);
855 struct sched_group_capacity {
858 * CPU capacity of this group, SCHED_LOAD_SCALE being max capacity
861 unsigned int capacity;
862 unsigned long next_update;
863 int imbalance; /* XXX unrelated to capacity but shared group state */
865 * Number of busy cpus in this group.
867 atomic_t nr_busy_cpus;
869 unsigned long cpumask[0]; /* iteration mask */
873 struct sched_group *next; /* Must be a circular list */
876 unsigned int group_weight;
877 struct sched_group_capacity *sgc;
880 * The CPUs this group covers.
882 * NOTE: this field is variable length. (Allocated dynamically
883 * by attaching extra space to the end of the structure,
884 * depending on how many CPUs the kernel has booted up with)
886 unsigned long cpumask[0];
889 static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
891 return to_cpumask(sg->cpumask);
895 * cpumask masking which cpus in the group are allowed to iterate up the domain
898 static inline struct cpumask *sched_group_mask(struct sched_group *sg)
900 return to_cpumask(sg->sgc->cpumask);
904 * group_first_cpu - Returns the first cpu in the cpumask of a sched_group.
905 * @group: The group whose first cpu is to be returned.
907 static inline unsigned int group_first_cpu(struct sched_group *group)
909 return cpumask_first(sched_group_cpus(group));
912 extern int group_balance_cpu(struct sched_group *sg);
916 static inline void sched_ttwu_pending(void) { }
918 #endif /* CONFIG_SMP */
921 #include "auto_group.h"
923 #ifdef CONFIG_CGROUP_SCHED
926 * Return the group to which this tasks belongs.
928 * We cannot use task_css() and friends because the cgroup subsystem
929 * changes that value before the cgroup_subsys::attach() method is called,
930 * therefore we cannot pin it and might observe the wrong value.
932 * The same is true for autogroup's p->signal->autogroup->tg, the autogroup
933 * core changes this before calling sched_move_task().
935 * Instead we use a 'copy' which is updated from sched_move_task() while
936 * holding both task_struct::pi_lock and rq::lock.
938 static inline struct task_group *task_group(struct task_struct *p)
940 return p->sched_task_group;
943 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
944 static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
946 #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
947 struct task_group *tg = task_group(p);
950 #ifdef CONFIG_FAIR_GROUP_SCHED
951 p->se.cfs_rq = tg->cfs_rq[cpu];
952 p->se.parent = tg->se[cpu];
955 #ifdef CONFIG_RT_GROUP_SCHED
956 p->rt.rt_rq = tg->rt_rq[cpu];
957 p->rt.parent = tg->rt_se[cpu];
961 #else /* CONFIG_CGROUP_SCHED */
963 static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
964 static inline struct task_group *task_group(struct task_struct *p)
969 #endif /* CONFIG_CGROUP_SCHED */
971 static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
976 * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
977 * successfuly executed on another CPU. We must ensure that updates of
978 * per-task data have been completed by this moment.
981 #ifdef CONFIG_THREAD_INFO_IN_TASK
984 task_thread_info(p)->cpu = cpu;
991 * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
993 #ifdef CONFIG_SCHED_DEBUG
994 # include <linux/static_key.h>
995 # define const_debug __read_mostly
997 # define const_debug const
1000 extern const_debug unsigned int sysctl_sched_features;
1002 #define SCHED_FEAT(name, enabled) \
1003 __SCHED_FEAT_##name ,
1006 #include "features.h"
1012 #if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
1013 #define SCHED_FEAT(name, enabled) \
1014 static __always_inline bool static_branch_##name(struct static_key *key) \
1016 return static_key_##enabled(key); \
1019 #include "features.h"
1023 extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
1024 #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
1025 #else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */
1026 #define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
1027 #endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */
1029 extern struct static_key_false sched_numa_balancing;
1031 static inline u64 global_rt_period(void)
1033 return (u64)sysctl_sched_rt_period * NSEC_PER_USEC;
1036 static inline u64 global_rt_runtime(void)
1038 if (sysctl_sched_rt_runtime < 0)
1041 return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
1044 static inline int task_current(struct rq *rq, struct task_struct *p)
1046 return rq->curr == p;
1049 static inline int task_running(struct rq *rq, struct task_struct *p)
1054 return task_current(rq, p);
1058 static inline int task_on_rq_queued(struct task_struct *p)
1060 return p->on_rq == TASK_ON_RQ_QUEUED;
1063 static inline int task_on_rq_migrating(struct task_struct *p)
1065 return p->on_rq == TASK_ON_RQ_MIGRATING;
1068 #ifndef prepare_arch_switch
1069 # define prepare_arch_switch(next) do { } while (0)
1071 #ifndef finish_arch_post_lock_switch
1072 # define finish_arch_post_lock_switch() do { } while (0)
1075 static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
1079 * We can optimise this out completely for !SMP, because the
1080 * SMP rebalancing from interrupt is the only thing that cares
1087 static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
1091 * After ->on_cpu is cleared, the task can be moved to a different CPU.
1092 * We must ensure this doesn't happen until the switch is completely
1095 * In particular, the load of prev->state in finish_task_switch() must
1096 * happen before this.
1098 * Pairs with the control dependency and rmb in try_to_wake_up().
1100 smp_store_release(&prev->on_cpu, 0);
1102 #ifdef CONFIG_DEBUG_SPINLOCK
1103 /* this is a valid case when another task releases the spinlock */
1104 rq->lock.owner = current;
1107 * If we are tracking spinlock dependencies then we have to
1108 * fix up the runqueue lock - which gets 'carried over' from
1109 * prev into current:
1111 spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_);
1113 raw_spin_unlock_irq(&rq->lock);
1119 #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
1120 #define WF_FORK 0x02 /* child wakeup after fork */
1121 #define WF_MIGRATED 0x4 /* internal use, task got migrated */
1124 * To aid in avoiding the subversion of "niceness" due to uneven distribution
1125 * of tasks with abnormal "nice" values across CPUs the contribution that
1126 * each task makes to its run queue's load is weighted according to its
1127 * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a
1128 * scaled version of the new time slice allocation that they receive on time
1132 #define WEIGHT_IDLEPRIO 3
1133 #define WMULT_IDLEPRIO 1431655765
1136 * Nice levels are multiplicative, with a gentle 10% change for every
1137 * nice level changed. I.e. when a CPU-bound task goes from nice 0 to
1138 * nice 1, it will get ~10% less CPU time than another CPU-bound task
1139 * that remained on nice 0.
1141 * The "10% effect" is relative and cumulative: from _any_ nice level,
1142 * if you go up 1 level, it's -10% CPU usage, if you go down 1 level
1143 * it's +10% CPU usage. (to achieve that we use a multiplier of 1.25.
1144 * If a task goes up by ~10% and another task goes down by ~10% then
1145 * the relative distance between them is ~25%.)
1147 static const int prio_to_weight[40] = {
1148 /* -20 */ 88761, 71755, 56483, 46273, 36291,
1149 /* -15 */ 29154, 23254, 18705, 14949, 11916,
1150 /* -10 */ 9548, 7620, 6100, 4904, 3906,
1151 /* -5 */ 3121, 2501, 1991, 1586, 1277,
1152 /* 0 */ 1024, 820, 655, 526, 423,
1153 /* 5 */ 335, 272, 215, 172, 137,
1154 /* 10 */ 110, 87, 70, 56, 45,
1155 /* 15 */ 36, 29, 23, 18, 15,
1159 * Inverse (2^32/x) values of the prio_to_weight[] array, precalculated.
1161 * In cases where the weight does not change often, we can use the
1162 * precalculated inverse to speed up arithmetics by turning divisions
1163 * into multiplications:
1165 static const u32 prio_to_wmult[40] = {
1166 /* -20 */ 48388, 59856, 76040, 92818, 118348,
1167 /* -15 */ 147320, 184698, 229616, 287308, 360437,
1168 /* -10 */ 449829, 563644, 704093, 875809, 1099582,
1169 /* -5 */ 1376151, 1717300, 2157191, 2708050, 3363326,
1170 /* 0 */ 4194304, 5237765, 6557202, 8165337, 10153587,
1171 /* 5 */ 12820798, 15790321, 19976592, 24970740, 31350126,
1172 /* 10 */ 39045157, 49367440, 61356676, 76695844, 95443717,
1173 /* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
1176 #define ENQUEUE_WAKEUP 0x01
1177 #define ENQUEUE_HEAD 0x02
1179 #define ENQUEUE_WAKING 0x04 /* sched_class::task_waking was called */
1181 #define ENQUEUE_WAKING 0x00
1183 #define ENQUEUE_REPLENISH 0x08
1184 #define ENQUEUE_RESTORE 0x10
1186 #define DEQUEUE_SLEEP 0x01
1187 #define DEQUEUE_SAVE 0x02
1189 #define RETRY_TASK ((void *)-1UL)
1191 struct sched_class {
1192 const struct sched_class *next;
1194 void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1195 void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
1196 void (*yield_task) (struct rq *rq);
1197 bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
1199 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
1202 * It is the responsibility of the pick_next_task() method that will
1203 * return the next task to call put_prev_task() on the @prev task or
1204 * something equivalent.
1206 * May return RETRY_TASK when it finds a higher prio class has runnable
1209 struct task_struct * (*pick_next_task) (struct rq *rq,
1210 struct task_struct *prev);
1211 void (*put_prev_task) (struct rq *rq, struct task_struct *p);
1214 int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
1215 void (*migrate_task_rq)(struct task_struct *p);
1217 void (*task_waking) (struct task_struct *task);
1218 void (*task_woken) (struct rq *this_rq, struct task_struct *task);
1220 void (*set_cpus_allowed)(struct task_struct *p,
1221 const struct cpumask *newmask);
1223 void (*rq_online)(struct rq *rq);
1224 void (*rq_offline)(struct rq *rq);
1227 void (*set_curr_task) (struct rq *rq);
1228 void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
1229 void (*task_fork) (struct task_struct *p);
1230 void (*task_dead) (struct task_struct *p);
1233 * The switched_from() call is allowed to drop rq->lock, therefore we
1234 * cannot assume the switched_from/switched_to pair is serliazed by
1235 * rq->lock. They are however serialized by p->pi_lock.
1237 void (*switched_from) (struct rq *this_rq, struct task_struct *task);
1238 void (*switched_to) (struct rq *this_rq, struct task_struct *task);
1239 void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1242 unsigned int (*get_rr_interval) (struct rq *rq,
1243 struct task_struct *task);
1245 void (*update_curr) (struct rq *rq);
1247 #ifdef CONFIG_FAIR_GROUP_SCHED
1248 void (*task_move_group) (struct task_struct *p);
1252 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
1254 prev->sched_class->put_prev_task(rq, prev);
1257 #define sched_class_highest (&stop_sched_class)
1258 #define for_each_class(class) \
1259 for (class = sched_class_highest; class; class = class->next)
1261 extern const struct sched_class stop_sched_class;
1262 extern const struct sched_class dl_sched_class;
1263 extern const struct sched_class rt_sched_class;
1264 extern const struct sched_class fair_sched_class;
1265 extern const struct sched_class idle_sched_class;
1270 extern void update_group_capacity(struct sched_domain *sd, int cpu);
1272 extern void trigger_load_balance(struct rq *rq);
1274 extern void idle_enter_fair(struct rq *this_rq);
1275 extern void idle_exit_fair(struct rq *this_rq);
1277 extern void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask);
1281 static inline void idle_enter_fair(struct rq *rq) { }
1282 static inline void idle_exit_fair(struct rq *rq) { }
1286 #ifdef CONFIG_CPU_IDLE
1287 static inline void idle_set_state(struct rq *rq,
1288 struct cpuidle_state *idle_state)
1290 rq->idle_state = idle_state;
1293 static inline struct cpuidle_state *idle_get_state(struct rq *rq)
1295 WARN_ON(!rcu_read_lock_held());
1296 return rq->idle_state;
1299 static inline void idle_set_state(struct rq *rq,
1300 struct cpuidle_state *idle_state)
1304 static inline struct cpuidle_state *idle_get_state(struct rq *rq)
1310 extern void sysrq_sched_debug_show(void);
1311 extern void sched_init_granularity(void);
1312 extern void update_max_interval(void);
1314 extern void init_sched_dl_class(void);
1315 extern void init_sched_rt_class(void);
1316 extern void init_sched_fair_class(void);
1318 extern void resched_curr(struct rq *rq);
1319 extern void resched_cpu(int cpu);
1321 extern struct rt_bandwidth def_rt_bandwidth;
1322 extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
1324 extern struct dl_bandwidth def_dl_bandwidth;
1325 extern void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime);
1326 extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
1328 unsigned long to_ratio(u64 period, u64 runtime);
1330 extern void init_entity_runnable_average(struct sched_entity *se);
1332 static inline void add_nr_running(struct rq *rq, unsigned count)
1334 unsigned prev_nr = rq->nr_running;
1336 rq->nr_running = prev_nr + count;
1338 if (prev_nr < 2 && rq->nr_running >= 2) {
1340 if (!rq->rd->overload)
1341 rq->rd->overload = true;
1344 #ifdef CONFIG_NO_HZ_FULL
1345 if (tick_nohz_full_cpu(rq->cpu)) {
1347 * Tick is needed if more than one task runs on a CPU.
1348 * Send the target an IPI to kick it out of nohz mode.
1350 * We assume that IPI implies full memory barrier and the
1351 * new value of rq->nr_running is visible on reception
1354 tick_nohz_full_kick_cpu(rq->cpu);
1360 static inline void sub_nr_running(struct rq *rq, unsigned count)
1362 rq->nr_running -= count;
1365 static inline void rq_last_tick_reset(struct rq *rq)
1367 #ifdef CONFIG_NO_HZ_FULL
1368 rq->last_sched_tick = jiffies;
1372 extern void update_rq_clock(struct rq *rq);
1374 extern void activate_task(struct rq *rq, struct task_struct *p, int flags);
1375 extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);
1377 extern void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags);
1379 extern const_debug unsigned int sysctl_sched_time_avg;
1380 extern const_debug unsigned int sysctl_sched_nr_migrate;
1381 extern const_debug unsigned int sysctl_sched_migration_cost;
1383 static inline u64 sched_avg_period(void)
1385 return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2;
1388 #ifdef CONFIG_SCHED_HRTICK
1392 * - enabled by features
1393 * - hrtimer is actually high res
1395 static inline int hrtick_enabled(struct rq *rq)
1397 if (!sched_feat(HRTICK))
1399 if (!cpu_active(cpu_of(rq)))
1401 return hrtimer_is_hres_active(&rq->hrtick_timer);
1404 void hrtick_start(struct rq *rq, u64 delay);
1408 static inline int hrtick_enabled(struct rq *rq)
1413 #endif /* CONFIG_SCHED_HRTICK */
1416 extern void sched_avg_update(struct rq *rq);
1418 #ifndef arch_scale_freq_capacity
1419 static __always_inline
1420 unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu)
1422 return SCHED_CAPACITY_SCALE;
1426 #ifndef arch_scale_cpu_capacity
1427 static __always_inline
1428 unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu)
1430 if (sd && (sd->flags & SD_SHARE_CPUCAPACITY) && (sd->span_weight > 1))
1431 return sd->smt_gain / sd->span_weight;
1433 return SCHED_CAPACITY_SCALE;
1437 static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
1439 rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq));
1440 sched_avg_update(rq);
1443 static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { }
1444 static inline void sched_avg_update(struct rq *rq) { }
1448 * __task_rq_lock - lock the rq @p resides on.
1450 static inline struct rq *__task_rq_lock(struct task_struct *p)
1451 __acquires(rq->lock)
1455 lockdep_assert_held(&p->pi_lock);
1459 raw_spin_lock(&rq->lock);
1460 if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) {
1461 lockdep_pin_lock(&rq->lock);
1464 raw_spin_unlock(&rq->lock);
1466 while (unlikely(task_on_rq_migrating(p)))
1472 * task_rq_lock - lock p->pi_lock and lock the rq @p resides on.
1474 static inline struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags)
1475 __acquires(p->pi_lock)
1476 __acquires(rq->lock)
1481 raw_spin_lock_irqsave(&p->pi_lock, *flags);
1483 raw_spin_lock(&rq->lock);
1485 * move_queued_task() task_rq_lock()
1487 * ACQUIRE (rq->lock)
1488 * [S] ->on_rq = MIGRATING [L] rq = task_rq()
1489 * WMB (__set_task_cpu()) ACQUIRE (rq->lock);
1490 * [S] ->cpu = new_cpu [L] task_rq()
1492 * RELEASE (rq->lock)
1494 * If we observe the old cpu in task_rq_lock, the acquire of
1495 * the old rq->lock will fully serialize against the stores.
1497 * If we observe the new cpu in task_rq_lock, the acquire will
1498 * pair with the WMB to ensure we must then also see migrating.
1500 if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) {
1501 lockdep_pin_lock(&rq->lock);
1504 raw_spin_unlock(&rq->lock);
1505 raw_spin_unlock_irqrestore(&p->pi_lock, *flags);
1507 while (unlikely(task_on_rq_migrating(p)))
1512 static inline void __task_rq_unlock(struct rq *rq)
1513 __releases(rq->lock)
1515 lockdep_unpin_lock(&rq->lock);
1516 raw_spin_unlock(&rq->lock);
1520 task_rq_unlock(struct rq *rq, struct task_struct *p, unsigned long *flags)
1521 __releases(rq->lock)
1522 __releases(p->pi_lock)
1524 lockdep_unpin_lock(&rq->lock);
1525 raw_spin_unlock(&rq->lock);
1526 raw_spin_unlock_irqrestore(&p->pi_lock, *flags);
1530 #ifdef CONFIG_PREEMPT
1532 static inline void double_rq_lock(struct rq *rq1, struct rq *rq2);
1535 * fair double_lock_balance: Safely acquires both rq->locks in a fair
1536 * way at the expense of forcing extra atomic operations in all
1537 * invocations. This assures that the double_lock is acquired using the
1538 * same underlying policy as the spinlock_t on this architecture, which
1539 * reduces latency compared to the unfair variant below. However, it
1540 * also adds more overhead and therefore may reduce throughput.
1542 static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
1543 __releases(this_rq->lock)
1544 __acquires(busiest->lock)
1545 __acquires(this_rq->lock)
1547 raw_spin_unlock(&this_rq->lock);
1548 double_rq_lock(this_rq, busiest);
1555 * Unfair double_lock_balance: Optimizes throughput at the expense of
1556 * latency by eliminating extra atomic operations when the locks are
1557 * already in proper order on entry. This favors lower cpu-ids and will
1558 * grant the double lock to lower cpus over higher ids under contention,
1559 * regardless of entry order into the function.
1561 static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
1562 __releases(this_rq->lock)
1563 __acquires(busiest->lock)
1564 __acquires(this_rq->lock)
1568 if (unlikely(!raw_spin_trylock(&busiest->lock))) {
1569 if (busiest < this_rq) {
1570 raw_spin_unlock(&this_rq->lock);
1571 raw_spin_lock(&busiest->lock);
1572 raw_spin_lock_nested(&this_rq->lock,
1573 SINGLE_DEPTH_NESTING);
1576 raw_spin_lock_nested(&busiest->lock,
1577 SINGLE_DEPTH_NESTING);
1582 #endif /* CONFIG_PREEMPT */
1585 * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
1587 static inline int double_lock_balance(struct rq *this_rq, struct rq *busiest)
1589 if (unlikely(!irqs_disabled())) {
1590 /* printk() doesn't work good under rq->lock */
1591 raw_spin_unlock(&this_rq->lock);
1595 return _double_lock_balance(this_rq, busiest);
1598 static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
1599 __releases(busiest->lock)
1601 raw_spin_unlock(&busiest->lock);
1602 lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_);
1605 static inline void double_lock(spinlock_t *l1, spinlock_t *l2)
1611 spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1614 static inline void double_lock_irq(spinlock_t *l1, spinlock_t *l2)
1620 spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1623 static inline void double_raw_lock(raw_spinlock_t *l1, raw_spinlock_t *l2)
1629 raw_spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1633 * double_rq_lock - safely lock two runqueues
1635 * Note this does not disable interrupts like task_rq_lock,
1636 * you need to do so manually before calling.
1638 static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
1639 __acquires(rq1->lock)
1640 __acquires(rq2->lock)
1642 BUG_ON(!irqs_disabled());
1644 raw_spin_lock(&rq1->lock);
1645 __acquire(rq2->lock); /* Fake it out ;) */
1648 raw_spin_lock(&rq1->lock);
1649 raw_spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING);
1651 raw_spin_lock(&rq2->lock);
1652 raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
1658 * double_rq_unlock - safely unlock two runqueues
1660 * Note this does not restore interrupts like task_rq_unlock,
1661 * you need to do so manually after calling.
1663 static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
1664 __releases(rq1->lock)
1665 __releases(rq2->lock)
1667 raw_spin_unlock(&rq1->lock);
1669 raw_spin_unlock(&rq2->lock);
1671 __release(rq2->lock);
1674 #else /* CONFIG_SMP */
1677 * double_rq_lock - safely lock two runqueues
1679 * Note this does not disable interrupts like task_rq_lock,
1680 * you need to do so manually before calling.
1682 static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
1683 __acquires(rq1->lock)
1684 __acquires(rq2->lock)
1686 BUG_ON(!irqs_disabled());
1688 raw_spin_lock(&rq1->lock);
1689 __acquire(rq2->lock); /* Fake it out ;) */
1693 * double_rq_unlock - safely unlock two runqueues
1695 * Note this does not restore interrupts like task_rq_unlock,
1696 * you need to do so manually after calling.
1698 static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
1699 __releases(rq1->lock)
1700 __releases(rq2->lock)
1703 raw_spin_unlock(&rq1->lock);
1704 __release(rq2->lock);
1709 extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq);
1710 extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq);
1712 #ifdef CONFIG_SCHED_DEBUG
1713 extern void print_cfs_stats(struct seq_file *m, int cpu);
1714 extern void print_rt_stats(struct seq_file *m, int cpu);
1715 extern void print_dl_stats(struct seq_file *m, int cpu);
1717 print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
1719 #ifdef CONFIG_NUMA_BALANCING
1721 show_numa_stats(struct task_struct *p, struct seq_file *m);
1723 print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
1724 unsigned long tpf, unsigned long gsf, unsigned long gpf);
1725 #endif /* CONFIG_NUMA_BALANCING */
1726 #endif /* CONFIG_SCHED_DEBUG */
1728 extern void init_cfs_rq(struct cfs_rq *cfs_rq);
1729 extern void init_rt_rq(struct rt_rq *rt_rq);
1730 extern void init_dl_rq(struct dl_rq *dl_rq);
1732 extern void cfs_bandwidth_usage_inc(void);
1733 extern void cfs_bandwidth_usage_dec(void);
1735 #ifdef CONFIG_NO_HZ_COMMON
1736 enum rq_nohz_flag_bits {
1741 #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)
1744 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
1746 DECLARE_PER_CPU(u64, cpu_hardirq_time);
1747 DECLARE_PER_CPU(u64, cpu_softirq_time);
1749 #ifndef CONFIG_64BIT
1750 DECLARE_PER_CPU(seqcount_t, irq_time_seq);
1752 static inline void irq_time_write_begin(void)
1754 __this_cpu_inc(irq_time_seq.sequence);
1758 static inline void irq_time_write_end(void)
1761 __this_cpu_inc(irq_time_seq.sequence);
1764 static inline u64 irq_time_read(int cpu)
1770 seq = read_seqcount_begin(&per_cpu(irq_time_seq, cpu));
1771 irq_time = per_cpu(cpu_softirq_time, cpu) +
1772 per_cpu(cpu_hardirq_time, cpu);
1773 } while (read_seqcount_retry(&per_cpu(irq_time_seq, cpu), seq));
1777 #else /* CONFIG_64BIT */
1778 static inline void irq_time_write_begin(void)
1782 static inline void irq_time_write_end(void)
1786 static inline u64 irq_time_read(int cpu)
1788 return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu);
1790 #endif /* CONFIG_64BIT */
1791 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */