2 #include <linux/sched.h>
3 #include <linux/sched/sysctl.h>
4 #include <linux/sched/rt.h>
5 #include <linux/sched/deadline.h>
6 #include <linux/binfmts.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 cpu_load_update_active(struct rq *this_rq);
36 static inline void cpu_load_update_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. 64bit). The costs for increasing resolution when 32bit are
53 * pretty high and the returns do not justify the increased costs.
55 * Really only required when CONFIG_FAIR_GROUP_SCHED is also set, but to
56 * increase coverage and consistency always enable it on 64bit platforms.
59 # define SCHED_LOAD_RESOLUTION 10
60 # define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)
61 # define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)
63 # define SCHED_LOAD_RESOLUTION 0
64 # define scale_load(w) (w)
65 # define scale_load_down(w) (w)
68 #define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)
69 #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
71 #define NICE_0_LOAD SCHED_LOAD_SCALE
72 #define NICE_0_SHIFT SCHED_LOAD_SHIFT
75 * Single value that decides SCHED_DEADLINE internal math precision.
76 * 10 -> just above 1us
77 * 9 -> just above 0.5us
82 * These are the 'tuning knobs' of the scheduler:
86 * single value that denotes runtime == period, ie unlimited time.
88 #define RUNTIME_INF ((u64)~0ULL)
90 static inline int idle_policy(int policy)
92 return policy == SCHED_IDLE;
94 static inline int fair_policy(int policy)
96 return policy == SCHED_NORMAL || policy == SCHED_BATCH;
99 static inline int rt_policy(int policy)
101 return policy == SCHED_FIFO || policy == SCHED_RR;
104 static inline int dl_policy(int policy)
106 return policy == SCHED_DEADLINE;
108 static inline bool valid_policy(int policy)
110 return idle_policy(policy) || fair_policy(policy) ||
111 rt_policy(policy) || dl_policy(policy);
114 static inline int task_has_rt_policy(struct task_struct *p)
116 return rt_policy(p->policy);
119 static inline int task_has_dl_policy(struct task_struct *p)
121 return dl_policy(p->policy);
125 * Tells if entity @a should preempt entity @b.
128 dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b)
130 return dl_time_before(a->deadline, b->deadline);
134 * This is the priority-queue data structure of the RT scheduling class:
136 struct rt_prio_array {
137 DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */
138 struct list_head queue[MAX_RT_PRIO];
141 struct rt_bandwidth {
142 /* nests inside the rq lock: */
143 raw_spinlock_t rt_runtime_lock;
146 struct hrtimer rt_period_timer;
147 unsigned int rt_period_active;
150 void __dl_clear_params(struct task_struct *p);
153 * To keep the bandwidth of -deadline tasks and groups under control
154 * we need some place where:
155 * - store the maximum -deadline bandwidth of the system (the group);
156 * - cache the fraction of that bandwidth that is currently allocated.
158 * This is all done in the data structure below. It is similar to the
159 * one used for RT-throttling (rt_bandwidth), with the main difference
160 * that, since here we are only interested in admission control, we
161 * do not decrease any runtime while the group "executes", neither we
162 * need a timer to replenish it.
164 * With respect to SMP, the bandwidth is given on a per-CPU basis,
166 * - dl_bw (< 100%) is the bandwidth of the system (group) on each CPU;
167 * - dl_total_bw array contains, in the i-eth element, the currently
168 * allocated bandwidth on the i-eth CPU.
169 * Moreover, groups consume bandwidth on each CPU, while tasks only
170 * consume bandwidth on the CPU they're running on.
171 * Finally, dl_total_bw_cpu is used to cache the index of dl_total_bw
172 * that will be shown the next time the proc or cgroup controls will
173 * be red. It on its turn can be changed by writing on its own
176 struct dl_bandwidth {
177 raw_spinlock_t dl_runtime_lock;
182 static inline int dl_bandwidth_enabled(void)
184 return sysctl_sched_rt_runtime >= 0;
187 extern struct dl_bw *dl_bw_of(int i);
195 void __dl_clear(struct dl_bw *dl_b, u64 tsk_bw)
197 dl_b->total_bw -= tsk_bw;
201 void __dl_add(struct dl_bw *dl_b, u64 tsk_bw)
203 dl_b->total_bw += tsk_bw;
207 bool __dl_overflow(struct dl_bw *dl_b, int cpus, u64 old_bw, u64 new_bw)
209 return dl_b->bw != -1 &&
210 dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw;
213 extern struct mutex sched_domains_mutex;
215 #ifdef CONFIG_CGROUP_SCHED
217 #include <linux/cgroup.h>
222 extern struct list_head task_groups;
224 struct cfs_bandwidth {
225 #ifdef CONFIG_CFS_BANDWIDTH
229 s64 hierarchical_quota;
232 int idle, period_active;
233 struct hrtimer period_timer, slack_timer;
234 struct list_head throttled_cfs_rq;
237 int nr_periods, nr_throttled;
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;
255 * load_avg can be heavily contended at clock tick time, so put
256 * it in its own cacheline separated from the fields above which
257 * will also be accessed at each tick.
259 atomic_long_t load_avg ____cacheline_aligned;
263 #ifdef CONFIG_RT_GROUP_SCHED
264 struct sched_rt_entity **rt_se;
265 struct rt_rq **rt_rq;
267 struct rt_bandwidth rt_bandwidth;
271 struct list_head list;
273 struct task_group *parent;
274 struct list_head siblings;
275 struct list_head children;
277 #ifdef CONFIG_SCHED_AUTOGROUP
278 struct autogroup *autogroup;
281 struct cfs_bandwidth cfs_bandwidth;
284 #ifdef CONFIG_FAIR_GROUP_SCHED
285 #define ROOT_TASK_GROUP_LOAD NICE_0_LOAD
288 * A weight of 0 or 1 can cause arithmetics problems.
289 * A weight of a cfs_rq is the sum of weights of which entities
290 * are queued on this cfs_rq, so a weight of a entity should not be
291 * too large, so as the shares value of a task group.
292 * (The default weight is 1024 - so there's no practical
293 * limitation from this.)
295 #define MIN_SHARES (1UL << 1)
296 #define MAX_SHARES (1UL << 18)
299 typedef int (*tg_visitor)(struct task_group *, void *);
301 extern int walk_tg_tree_from(struct task_group *from,
302 tg_visitor down, tg_visitor up, void *data);
305 * Iterate the full tree, calling @down when first entering a node and @up when
306 * leaving it for the final time.
308 * Caller must hold rcu_lock or sufficient equivalent.
310 static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
312 return walk_tg_tree_from(&root_task_group, down, up, data);
315 extern int tg_nop(struct task_group *tg, void *data);
317 extern void free_fair_sched_group(struct task_group *tg);
318 extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent);
319 extern void unregister_fair_sched_group(struct task_group *tg);
320 extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
321 struct sched_entity *se, int cpu,
322 struct sched_entity *parent);
323 extern void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
325 extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b);
326 extern void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
327 extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq);
329 extern void free_rt_sched_group(struct task_group *tg);
330 extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent);
331 extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
332 struct sched_rt_entity *rt_se, int cpu,
333 struct sched_rt_entity *parent);
335 extern struct task_group *sched_create_group(struct task_group *parent);
336 extern void sched_online_group(struct task_group *tg,
337 struct task_group *parent);
338 extern void sched_destroy_group(struct task_group *tg);
339 extern void sched_offline_group(struct task_group *tg);
341 extern void sched_move_task(struct task_struct *tsk);
343 #ifdef CONFIG_FAIR_GROUP_SCHED
344 extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
347 extern void set_task_rq_fair(struct sched_entity *se,
348 struct cfs_rq *prev, struct cfs_rq *next);
349 #else /* !CONFIG_SMP */
350 static inline void set_task_rq_fair(struct sched_entity *se,
351 struct cfs_rq *prev, struct cfs_rq *next) { }
352 #endif /* CONFIG_SMP */
353 #endif /* CONFIG_FAIR_GROUP_SCHED */
355 #else /* CONFIG_CGROUP_SCHED */
357 struct cfs_bandwidth { };
359 #endif /* CONFIG_CGROUP_SCHED */
361 /* CFS-related fields in a runqueue */
363 struct load_weight load;
364 unsigned int nr_running, h_nr_running;
369 u64 min_vruntime_copy;
372 struct rb_root tasks_timeline;
373 struct rb_node *rb_leftmost;
376 * 'curr' points to currently running entity on this cfs_rq.
377 * It is set to NULL otherwise (i.e when none are currently running).
379 struct sched_entity *curr, *next, *last, *skip;
381 #ifdef CONFIG_SCHED_DEBUG
382 unsigned int nr_spread_over;
389 struct sched_avg avg;
390 u64 runnable_load_sum;
391 unsigned long runnable_load_avg;
392 #ifdef CONFIG_FAIR_GROUP_SCHED
393 unsigned long tg_load_avg_contrib;
395 atomic_long_t removed_load_avg, removed_util_avg;
397 u64 load_last_update_time_copy;
400 #ifdef CONFIG_FAIR_GROUP_SCHED
402 * h_load = weight * f(tg)
404 * Where f(tg) is the recursive weight fraction assigned to
407 unsigned long h_load;
408 u64 last_h_load_update;
409 struct sched_entity *h_load_next;
410 #endif /* CONFIG_FAIR_GROUP_SCHED */
411 #endif /* CONFIG_SMP */
413 #ifdef CONFIG_FAIR_GROUP_SCHED
414 struct rq *rq; /* cpu runqueue to which this cfs_rq is attached */
417 * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in
418 * a hierarchy). Non-leaf lrqs hold other higher schedulable entities
419 * (like users, containers etc.)
421 * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a cpu. This
422 * list is used during load balance.
425 struct list_head leaf_cfs_rq_list;
426 struct task_group *tg; /* group that "owns" this runqueue */
428 #ifdef CONFIG_CFS_BANDWIDTH
431 s64 runtime_remaining;
433 u64 throttled_clock, throttled_clock_task;
434 u64 throttled_clock_task_time;
435 int throttled, throttle_count;
436 struct list_head throttled_list;
437 #endif /* CONFIG_CFS_BANDWIDTH */
438 #endif /* CONFIG_FAIR_GROUP_SCHED */
441 static inline int rt_bandwidth_enabled(void)
443 return sysctl_sched_rt_runtime >= 0;
446 /* RT IPI pull logic requires IRQ_WORK */
447 #ifdef CONFIG_IRQ_WORK
448 # define HAVE_RT_PUSH_IPI
451 /* Real-Time classes' related field in a runqueue: */
453 struct rt_prio_array active;
454 unsigned int rt_nr_running;
455 unsigned int rr_nr_running;
456 #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
458 int curr; /* highest queued rt task prio */
460 int next; /* next highest */
465 unsigned long rt_nr_migratory;
466 unsigned long rt_nr_total;
468 struct plist_head pushable_tasks;
469 #ifdef HAVE_RT_PUSH_IPI
472 struct irq_work push_work;
473 raw_spinlock_t push_lock;
475 #endif /* CONFIG_SMP */
481 /* Nests inside the rq lock: */
482 raw_spinlock_t rt_runtime_lock;
484 #ifdef CONFIG_RT_GROUP_SCHED
485 unsigned long rt_nr_boosted;
488 struct task_group *tg;
492 /* Deadline class' related fields in a runqueue */
494 /* runqueue is an rbtree, ordered by deadline */
495 struct rb_root rb_root;
496 struct rb_node *rb_leftmost;
498 unsigned long dl_nr_running;
502 * Deadline values of the currently executing and the
503 * earliest ready task on this rq. Caching these facilitates
504 * the decision wether or not a ready but not running task
505 * should migrate somewhere else.
512 unsigned long dl_nr_migratory;
516 * Tasks on this rq that can be pushed away. They are kept in
517 * an rb-tree, ordered by tasks' deadlines, with caching
518 * of the leftmost (earliest deadline) element.
520 struct rb_root pushable_dl_tasks_root;
521 struct rb_node *pushable_dl_tasks_leftmost;
530 * We add the notion of a root-domain which will be used to define per-domain
531 * variables. Each exclusive cpuset essentially defines an island domain by
532 * fully partitioning the member cpus from any other cpuset. Whenever a new
533 * exclusive cpuset is created, we also create and attach a new root-domain
542 cpumask_var_t online;
544 /* Indicate more than one runnable task for any CPU */
548 * The bit corresponding to a CPU gets set here if such CPU has more
549 * than one runnable -deadline task (as it is below for RT tasks).
551 cpumask_var_t dlo_mask;
557 * The "RT overload" flag: it gets set if a CPU has more than
558 * one runnable RT task.
560 cpumask_var_t rto_mask;
561 struct cpupri cpupri;
564 extern struct root_domain def_root_domain;
566 #endif /* CONFIG_SMP */
569 * This is the main, per-CPU runqueue data structure.
571 * Locking rule: those places that want to lock multiple runqueues
572 * (such as the load balancing or the thread migration code), lock
573 * acquire operations must be ordered by ascending &runqueue.
580 * nr_running and cpu_load should be in the same cacheline because
581 * remote CPUs use both these fields when doing load calculation.
583 unsigned int nr_running;
584 #ifdef CONFIG_NUMA_BALANCING
585 unsigned int nr_numa_running;
586 unsigned int nr_preferred_running;
588 #define CPU_LOAD_IDX_MAX 5
589 unsigned long cpu_load[CPU_LOAD_IDX_MAX];
590 #ifdef CONFIG_NO_HZ_COMMON
592 unsigned long last_load_update_tick;
593 #endif /* CONFIG_SMP */
595 unsigned long nohz_flags;
596 #endif /* CONFIG_NO_HZ_COMMON */
597 #ifdef CONFIG_NO_HZ_FULL
598 unsigned long last_sched_tick;
600 /* capture load from *all* tasks on this cpu: */
601 struct load_weight load;
602 unsigned long nr_load_updates;
609 #ifdef CONFIG_FAIR_GROUP_SCHED
610 /* list of leaf cfs_rq on this cpu: */
611 struct list_head leaf_cfs_rq_list;
612 #endif /* CONFIG_FAIR_GROUP_SCHED */
615 * This is part of a global counter where only the total sum
616 * over all CPUs matters. A task can increase this counter on
617 * one CPU and if it got migrated afterwards it may decrease
618 * it on another CPU. Always updated under the runqueue lock:
620 unsigned long nr_uninterruptible;
622 struct task_struct *curr, *idle, *stop;
623 unsigned long next_balance;
624 struct mm_struct *prev_mm;
626 unsigned int clock_skip_update;
633 struct root_domain *rd;
634 struct sched_domain *sd;
636 unsigned long cpu_capacity;
637 unsigned long cpu_capacity_orig;
639 struct callback_head *balance_callback;
641 unsigned char idle_balance;
642 /* For active balancing */
645 struct cpu_stop_work active_balance_work;
646 /* cpu of this runqueue: */
650 struct list_head cfs_tasks;
657 /* This is used to determine avg_idle's max value */
658 u64 max_idle_balance_cost;
661 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
664 #ifdef CONFIG_PARAVIRT
667 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
668 u64 prev_steal_time_rq;
671 /* calc_load related fields */
672 unsigned long calc_load_update;
673 long calc_load_active;
675 #ifdef CONFIG_SCHED_HRTICK
677 int hrtick_csd_pending;
678 struct call_single_data hrtick_csd;
680 struct hrtimer hrtick_timer;
683 #ifdef CONFIG_SCHEDSTATS
685 struct sched_info rq_sched_info;
686 unsigned long long rq_cpu_time;
687 /* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */
689 /* sys_sched_yield() stats */
690 unsigned int yld_count;
692 /* schedule() stats */
693 unsigned int sched_count;
694 unsigned int sched_goidle;
696 /* try_to_wake_up() stats */
697 unsigned int ttwu_count;
698 unsigned int ttwu_local;
702 struct llist_head wake_list;
705 #ifdef CONFIG_CPU_IDLE
706 /* Must be inspected within a rcu lock section */
707 struct cpuidle_state *idle_state;
711 static inline int cpu_of(struct rq *rq)
720 DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
722 #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
723 #define this_rq() this_cpu_ptr(&runqueues)
724 #define task_rq(p) cpu_rq(task_cpu(p))
725 #define cpu_curr(cpu) (cpu_rq(cpu)->curr)
726 #define raw_rq() raw_cpu_ptr(&runqueues)
728 static inline u64 __rq_clock_broken(struct rq *rq)
730 return READ_ONCE(rq->clock);
733 static inline u64 rq_clock(struct rq *rq)
735 lockdep_assert_held(&rq->lock);
739 static inline u64 rq_clock_task(struct rq *rq)
741 lockdep_assert_held(&rq->lock);
742 return rq->clock_task;
745 #define RQCF_REQ_SKIP 0x01
746 #define RQCF_ACT_SKIP 0x02
748 static inline void rq_clock_skip_update(struct rq *rq, bool skip)
750 lockdep_assert_held(&rq->lock);
752 rq->clock_skip_update |= RQCF_REQ_SKIP;
754 rq->clock_skip_update &= ~RQCF_REQ_SKIP;
758 enum numa_topology_type {
763 extern enum numa_topology_type sched_numa_topology_type;
764 extern int sched_max_numa_distance;
765 extern bool find_numa_distance(int distance);
768 #ifdef CONFIG_NUMA_BALANCING
769 /* The regions in numa_faults array from task_struct */
770 enum numa_faults_stats {
776 extern void sched_setnuma(struct task_struct *p, int node);
777 extern int migrate_task_to(struct task_struct *p, int cpu);
778 extern int migrate_swap(struct task_struct *, struct task_struct *);
779 #endif /* CONFIG_NUMA_BALANCING */
784 queue_balance_callback(struct rq *rq,
785 struct callback_head *head,
786 void (*func)(struct rq *rq))
788 lockdep_assert_held(&rq->lock);
790 if (unlikely(head->next))
793 head->func = (void (*)(struct callback_head *))func;
794 head->next = rq->balance_callback;
795 rq->balance_callback = head;
798 extern void sched_ttwu_pending(void);
800 #define rcu_dereference_check_sched_domain(p) \
801 rcu_dereference_check((p), \
802 lockdep_is_held(&sched_domains_mutex))
805 * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
806 * See detach_destroy_domains: synchronize_sched for details.
808 * The domain tree of any CPU may only be accessed from within
809 * preempt-disabled sections.
811 #define for_each_domain(cpu, __sd) \
812 for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \
813 __sd; __sd = __sd->parent)
815 #define for_each_lower_domain(sd) for (; sd; sd = sd->child)
818 * highest_flag_domain - Return highest sched_domain containing flag.
819 * @cpu: The cpu whose highest level of sched domain is to
821 * @flag: The flag to check for the highest sched_domain
824 * Returns the highest sched_domain of a cpu which contains the given flag.
826 static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
828 struct sched_domain *sd, *hsd = NULL;
830 for_each_domain(cpu, sd) {
831 if (!(sd->flags & flag))
839 static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
841 struct sched_domain *sd;
843 for_each_domain(cpu, sd) {
844 if (sd->flags & flag)
851 DECLARE_PER_CPU(struct sched_domain *, sd_llc);
852 DECLARE_PER_CPU(int, sd_llc_size);
853 DECLARE_PER_CPU(int, sd_llc_id);
854 DECLARE_PER_CPU(struct sched_domain *, sd_numa);
855 DECLARE_PER_CPU(struct sched_domain *, sd_busy);
856 DECLARE_PER_CPU(struct sched_domain *, sd_asym);
858 struct sched_group_capacity {
861 * CPU capacity of this group, SCHED_LOAD_SCALE being max capacity
864 unsigned int capacity;
865 unsigned long next_update;
866 int imbalance; /* XXX unrelated to capacity but shared group state */
868 * Number of busy cpus in this group.
870 atomic_t nr_busy_cpus;
872 unsigned long cpumask[0]; /* iteration mask */
876 struct sched_group *next; /* Must be a circular list */
879 unsigned int group_weight;
880 struct sched_group_capacity *sgc;
883 * The CPUs this group covers.
885 * NOTE: this field is variable length. (Allocated dynamically
886 * by attaching extra space to the end of the structure,
887 * depending on how many CPUs the kernel has booted up with)
889 unsigned long cpumask[0];
892 static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
894 return to_cpumask(sg->cpumask);
898 * cpumask masking which cpus in the group are allowed to iterate up the domain
901 static inline struct cpumask *sched_group_mask(struct sched_group *sg)
903 return to_cpumask(sg->sgc->cpumask);
907 * group_first_cpu - Returns the first cpu in the cpumask of a sched_group.
908 * @group: The group whose first cpu is to be returned.
910 static inline unsigned int group_first_cpu(struct sched_group *group)
912 return cpumask_first(sched_group_cpus(group));
915 extern int group_balance_cpu(struct sched_group *sg);
917 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
918 void register_sched_domain_sysctl(void);
919 void unregister_sched_domain_sysctl(void);
921 static inline void register_sched_domain_sysctl(void)
924 static inline void unregister_sched_domain_sysctl(void)
931 static inline void sched_ttwu_pending(void) { }
933 #endif /* CONFIG_SMP */
936 #include "auto_group.h"
938 #ifdef CONFIG_CGROUP_SCHED
941 * Return the group to which this tasks belongs.
943 * We cannot use task_css() and friends because the cgroup subsystem
944 * changes that value before the cgroup_subsys::attach() method is called,
945 * therefore we cannot pin it and might observe the wrong value.
947 * The same is true for autogroup's p->signal->autogroup->tg, the autogroup
948 * core changes this before calling sched_move_task().
950 * Instead we use a 'copy' which is updated from sched_move_task() while
951 * holding both task_struct::pi_lock and rq::lock.
953 static inline struct task_group *task_group(struct task_struct *p)
955 return p->sched_task_group;
958 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
959 static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
961 #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
962 struct task_group *tg = task_group(p);
965 #ifdef CONFIG_FAIR_GROUP_SCHED
966 set_task_rq_fair(&p->se, p->se.cfs_rq, tg->cfs_rq[cpu]);
967 p->se.cfs_rq = tg->cfs_rq[cpu];
968 p->se.parent = tg->se[cpu];
971 #ifdef CONFIG_RT_GROUP_SCHED
972 p->rt.rt_rq = tg->rt_rq[cpu];
973 p->rt.parent = tg->rt_se[cpu];
977 #else /* CONFIG_CGROUP_SCHED */
979 static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
980 static inline struct task_group *task_group(struct task_struct *p)
985 #endif /* CONFIG_CGROUP_SCHED */
987 static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
992 * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
993 * successfuly executed on another CPU. We must ensure that updates of
994 * per-task data have been completed by this moment.
997 task_thread_info(p)->cpu = cpu;
1003 * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
1005 #ifdef CONFIG_SCHED_DEBUG
1006 # include <linux/static_key.h>
1007 # define const_debug __read_mostly
1009 # define const_debug const
1012 extern const_debug unsigned int sysctl_sched_features;
1014 #define SCHED_FEAT(name, enabled) \
1015 __SCHED_FEAT_##name ,
1018 #include "features.h"
1024 #if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
1025 #define SCHED_FEAT(name, enabled) \
1026 static __always_inline bool static_branch_##name(struct static_key *key) \
1028 return static_key_##enabled(key); \
1031 #include "features.h"
1035 extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
1036 #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
1037 #else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */
1038 #define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
1039 #endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */
1041 extern struct static_key_false sched_numa_balancing;
1042 extern struct static_key_false sched_schedstats;
1044 static inline u64 global_rt_period(void)
1046 return (u64)sysctl_sched_rt_period * NSEC_PER_USEC;
1049 static inline u64 global_rt_runtime(void)
1051 if (sysctl_sched_rt_runtime < 0)
1054 return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
1057 static inline int task_current(struct rq *rq, struct task_struct *p)
1059 return rq->curr == p;
1062 static inline int task_running(struct rq *rq, struct task_struct *p)
1067 return task_current(rq, p);
1071 static inline int task_on_rq_queued(struct task_struct *p)
1073 return p->on_rq == TASK_ON_RQ_QUEUED;
1076 static inline int task_on_rq_migrating(struct task_struct *p)
1078 return p->on_rq == TASK_ON_RQ_MIGRATING;
1081 #ifndef prepare_arch_switch
1082 # define prepare_arch_switch(next) do { } while (0)
1084 #ifndef finish_arch_post_lock_switch
1085 # define finish_arch_post_lock_switch() do { } while (0)
1088 static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
1092 * We can optimise this out completely for !SMP, because the
1093 * SMP rebalancing from interrupt is the only thing that cares
1100 static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
1104 * After ->on_cpu is cleared, the task can be moved to a different CPU.
1105 * We must ensure this doesn't happen until the switch is completely
1108 * In particular, the load of prev->state in finish_task_switch() must
1109 * happen before this.
1111 * Pairs with the smp_cond_acquire() in try_to_wake_up().
1113 smp_store_release(&prev->on_cpu, 0);
1115 #ifdef CONFIG_DEBUG_SPINLOCK
1116 /* this is a valid case when another task releases the spinlock */
1117 rq->lock.owner = current;
1120 * If we are tracking spinlock dependencies then we have to
1121 * fix up the runqueue lock - which gets 'carried over' from
1122 * prev into current:
1124 spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_);
1126 raw_spin_unlock_irq(&rq->lock);
1132 #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
1133 #define WF_FORK 0x02 /* child wakeup after fork */
1134 #define WF_MIGRATED 0x4 /* internal use, task got migrated */
1137 * To aid in avoiding the subversion of "niceness" due to uneven distribution
1138 * of tasks with abnormal "nice" values across CPUs the contribution that
1139 * each task makes to its run queue's load is weighted according to its
1140 * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a
1141 * scaled version of the new time slice allocation that they receive on time
1145 #define WEIGHT_IDLEPRIO 3
1146 #define WMULT_IDLEPRIO 1431655765
1148 extern const int sched_prio_to_weight[40];
1149 extern const u32 sched_prio_to_wmult[40];
1152 * {de,en}queue flags:
1154 * DEQUEUE_SLEEP - task is no longer runnable
1155 * ENQUEUE_WAKEUP - task just became runnable
1157 * SAVE/RESTORE - an otherwise spurious dequeue/enqueue, done to ensure tasks
1158 * are in a known state which allows modification. Such pairs
1159 * should preserve as much state as possible.
1161 * MOVE - paired with SAVE/RESTORE, explicitly does not preserve the location
1164 * ENQUEUE_HEAD - place at front of runqueue (tail if not specified)
1165 * ENQUEUE_REPLENISH - CBS (replenish runtime and postpone deadline)
1166 * ENQUEUE_WAKING - sched_class::task_waking was called
1170 #define DEQUEUE_SLEEP 0x01
1171 #define DEQUEUE_SAVE 0x02 /* matches ENQUEUE_RESTORE */
1172 #define DEQUEUE_MOVE 0x04 /* matches ENQUEUE_MOVE */
1174 #define ENQUEUE_WAKEUP 0x01
1175 #define ENQUEUE_RESTORE 0x02
1176 #define ENQUEUE_MOVE 0x04
1178 #define ENQUEUE_HEAD 0x08
1179 #define ENQUEUE_REPLENISH 0x10
1181 #define ENQUEUE_WAKING 0x20
1183 #define ENQUEUE_WAKING 0x00
1186 #define RETRY_TASK ((void *)-1UL)
1188 struct sched_class {
1189 const struct sched_class *next;
1191 void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1192 void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
1193 void (*yield_task) (struct rq *rq);
1194 bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
1196 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
1199 * It is the responsibility of the pick_next_task() method that will
1200 * return the next task to call put_prev_task() on the @prev task or
1201 * something equivalent.
1203 * May return RETRY_TASK when it finds a higher prio class has runnable
1206 struct task_struct * (*pick_next_task) (struct rq *rq,
1207 struct task_struct *prev,
1208 struct pin_cookie cookie);
1209 void (*put_prev_task) (struct rq *rq, struct task_struct *p);
1212 int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
1213 void (*migrate_task_rq)(struct task_struct *p);
1215 void (*task_waking) (struct task_struct *task);
1216 void (*task_woken) (struct rq *this_rq, struct task_struct *task);
1218 void (*set_cpus_allowed)(struct task_struct *p,
1219 const struct cpumask *newmask);
1221 void (*rq_online)(struct rq *rq);
1222 void (*rq_offline)(struct rq *rq);
1225 void (*set_curr_task) (struct rq *rq);
1226 void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
1227 void (*task_fork) (struct task_struct *p);
1228 void (*task_dead) (struct task_struct *p);
1231 * The switched_from() call is allowed to drop rq->lock, therefore we
1232 * cannot assume the switched_from/switched_to pair is serliazed by
1233 * rq->lock. They are however serialized by p->pi_lock.
1235 void (*switched_from) (struct rq *this_rq, struct task_struct *task);
1236 void (*switched_to) (struct rq *this_rq, struct task_struct *task);
1237 void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1240 unsigned int (*get_rr_interval) (struct rq *rq,
1241 struct task_struct *task);
1243 void (*update_curr) (struct rq *rq);
1245 #ifdef CONFIG_FAIR_GROUP_SCHED
1246 void (*task_move_group) (struct task_struct *p);
1250 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
1252 prev->sched_class->put_prev_task(rq, prev);
1255 #define sched_class_highest (&stop_sched_class)
1256 #define for_each_class(class) \
1257 for (class = sched_class_highest; class; class = class->next)
1259 extern const struct sched_class stop_sched_class;
1260 extern const struct sched_class dl_sched_class;
1261 extern const struct sched_class rt_sched_class;
1262 extern const struct sched_class fair_sched_class;
1263 extern const struct sched_class idle_sched_class;
1268 extern void update_group_capacity(struct sched_domain *sd, int cpu);
1270 extern void trigger_load_balance(struct rq *rq);
1272 extern void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask);
1276 #ifdef CONFIG_CPU_IDLE
1277 static inline void idle_set_state(struct rq *rq,
1278 struct cpuidle_state *idle_state)
1280 rq->idle_state = idle_state;
1283 static inline struct cpuidle_state *idle_get_state(struct rq *rq)
1285 WARN_ON(!rcu_read_lock_held());
1286 return rq->idle_state;
1289 static inline void idle_set_state(struct rq *rq,
1290 struct cpuidle_state *idle_state)
1294 static inline struct cpuidle_state *idle_get_state(struct rq *rq)
1300 extern void sysrq_sched_debug_show(void);
1301 extern void sched_init_granularity(void);
1302 extern void update_max_interval(void);
1304 extern void init_sched_dl_class(void);
1305 extern void init_sched_rt_class(void);
1306 extern void init_sched_fair_class(void);
1308 extern void resched_curr(struct rq *rq);
1309 extern void resched_cpu(int cpu);
1311 extern struct rt_bandwidth def_rt_bandwidth;
1312 extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
1314 extern struct dl_bandwidth def_dl_bandwidth;
1315 extern void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime);
1316 extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
1318 unsigned long to_ratio(u64 period, u64 runtime);
1320 extern void init_entity_runnable_average(struct sched_entity *se);
1321 extern void post_init_entity_util_avg(struct sched_entity *se);
1323 #ifdef CONFIG_NO_HZ_FULL
1324 extern bool sched_can_stop_tick(struct rq *rq);
1327 * Tick may be needed by tasks in the runqueue depending on their policy and
1328 * requirements. If tick is needed, lets send the target an IPI to kick it out of
1329 * nohz mode if necessary.
1331 static inline void sched_update_tick_dependency(struct rq *rq)
1335 if (!tick_nohz_full_enabled())
1340 if (!tick_nohz_full_cpu(cpu))
1343 if (sched_can_stop_tick(rq))
1344 tick_nohz_dep_clear_cpu(cpu, TICK_DEP_BIT_SCHED);
1346 tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
1349 static inline void sched_update_tick_dependency(struct rq *rq) { }
1352 static inline void add_nr_running(struct rq *rq, unsigned count)
1354 unsigned prev_nr = rq->nr_running;
1356 rq->nr_running = prev_nr + count;
1358 if (prev_nr < 2 && rq->nr_running >= 2) {
1360 if (!rq->rd->overload)
1361 rq->rd->overload = true;
1365 sched_update_tick_dependency(rq);
1368 static inline void sub_nr_running(struct rq *rq, unsigned count)
1370 rq->nr_running -= count;
1371 /* Check if we still need preemption */
1372 sched_update_tick_dependency(rq);
1375 static inline void rq_last_tick_reset(struct rq *rq)
1377 #ifdef CONFIG_NO_HZ_FULL
1378 rq->last_sched_tick = jiffies;
1382 extern void update_rq_clock(struct rq *rq);
1384 extern void activate_task(struct rq *rq, struct task_struct *p, int flags);
1385 extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);
1387 extern void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags);
1389 extern const_debug unsigned int sysctl_sched_time_avg;
1390 extern const_debug unsigned int sysctl_sched_nr_migrate;
1391 extern const_debug unsigned int sysctl_sched_migration_cost;
1393 static inline u64 sched_avg_period(void)
1395 return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2;
1398 #ifdef CONFIG_SCHED_HRTICK
1402 * - enabled by features
1403 * - hrtimer is actually high res
1405 static inline int hrtick_enabled(struct rq *rq)
1407 if (!sched_feat(HRTICK))
1409 if (!cpu_active(cpu_of(rq)))
1411 return hrtimer_is_hres_active(&rq->hrtick_timer);
1414 void hrtick_start(struct rq *rq, u64 delay);
1418 static inline int hrtick_enabled(struct rq *rq)
1423 #endif /* CONFIG_SCHED_HRTICK */
1426 extern void sched_avg_update(struct rq *rq);
1428 #ifndef arch_scale_freq_capacity
1429 static __always_inline
1430 unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu)
1432 return SCHED_CAPACITY_SCALE;
1436 #ifndef arch_scale_cpu_capacity
1437 static __always_inline
1438 unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu)
1440 if (sd && (sd->flags & SD_SHARE_CPUCAPACITY) && (sd->span_weight > 1))
1441 return sd->smt_gain / sd->span_weight;
1443 return SCHED_CAPACITY_SCALE;
1447 static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
1449 rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq));
1450 sched_avg_update(rq);
1453 static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { }
1454 static inline void sched_avg_update(struct rq *rq) { }
1458 unsigned long flags;
1459 struct pin_cookie cookie;
1462 struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf)
1463 __acquires(rq->lock);
1464 struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf)
1465 __acquires(p->pi_lock)
1466 __acquires(rq->lock);
1468 static inline void __task_rq_unlock(struct rq *rq, struct rq_flags *rf)
1469 __releases(rq->lock)
1471 lockdep_unpin_lock(&rq->lock, rf->cookie);
1472 raw_spin_unlock(&rq->lock);
1476 task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf)
1477 __releases(rq->lock)
1478 __releases(p->pi_lock)
1480 lockdep_unpin_lock(&rq->lock, rf->cookie);
1481 raw_spin_unlock(&rq->lock);
1482 raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags);
1486 #ifdef CONFIG_PREEMPT
1488 static inline void double_rq_lock(struct rq *rq1, struct rq *rq2);
1491 * fair double_lock_balance: Safely acquires both rq->locks in a fair
1492 * way at the expense of forcing extra atomic operations in all
1493 * invocations. This assures that the double_lock is acquired using the
1494 * same underlying policy as the spinlock_t on this architecture, which
1495 * reduces latency compared to the unfair variant below. However, it
1496 * also adds more overhead and therefore may reduce throughput.
1498 static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
1499 __releases(this_rq->lock)
1500 __acquires(busiest->lock)
1501 __acquires(this_rq->lock)
1503 raw_spin_unlock(&this_rq->lock);
1504 double_rq_lock(this_rq, busiest);
1511 * Unfair double_lock_balance: Optimizes throughput at the expense of
1512 * latency by eliminating extra atomic operations when the locks are
1513 * already in proper order on entry. This favors lower cpu-ids and will
1514 * grant the double lock to lower cpus over higher ids under contention,
1515 * regardless of entry order into the function.
1517 static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
1518 __releases(this_rq->lock)
1519 __acquires(busiest->lock)
1520 __acquires(this_rq->lock)
1524 if (unlikely(!raw_spin_trylock(&busiest->lock))) {
1525 if (busiest < this_rq) {
1526 raw_spin_unlock(&this_rq->lock);
1527 raw_spin_lock(&busiest->lock);
1528 raw_spin_lock_nested(&this_rq->lock,
1529 SINGLE_DEPTH_NESTING);
1532 raw_spin_lock_nested(&busiest->lock,
1533 SINGLE_DEPTH_NESTING);
1538 #endif /* CONFIG_PREEMPT */
1541 * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
1543 static inline int double_lock_balance(struct rq *this_rq, struct rq *busiest)
1545 if (unlikely(!irqs_disabled())) {
1546 /* printk() doesn't work good under rq->lock */
1547 raw_spin_unlock(&this_rq->lock);
1551 return _double_lock_balance(this_rq, busiest);
1554 static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
1555 __releases(busiest->lock)
1557 raw_spin_unlock(&busiest->lock);
1558 lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_);
1561 static inline void double_lock(spinlock_t *l1, spinlock_t *l2)
1567 spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1570 static inline void double_lock_irq(spinlock_t *l1, spinlock_t *l2)
1576 spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1579 static inline void double_raw_lock(raw_spinlock_t *l1, raw_spinlock_t *l2)
1585 raw_spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
1589 * double_rq_lock - safely lock two runqueues
1591 * Note this does not disable interrupts like task_rq_lock,
1592 * you need to do so manually before calling.
1594 static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
1595 __acquires(rq1->lock)
1596 __acquires(rq2->lock)
1598 BUG_ON(!irqs_disabled());
1600 raw_spin_lock(&rq1->lock);
1601 __acquire(rq2->lock); /* Fake it out ;) */
1604 raw_spin_lock(&rq1->lock);
1605 raw_spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING);
1607 raw_spin_lock(&rq2->lock);
1608 raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
1614 * double_rq_unlock - safely unlock two runqueues
1616 * Note this does not restore interrupts like task_rq_unlock,
1617 * you need to do so manually after calling.
1619 static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
1620 __releases(rq1->lock)
1621 __releases(rq2->lock)
1623 raw_spin_unlock(&rq1->lock);
1625 raw_spin_unlock(&rq2->lock);
1627 __release(rq2->lock);
1630 #else /* CONFIG_SMP */
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 ;) */
1649 * double_rq_unlock - safely unlock two runqueues
1651 * Note this does not restore interrupts like task_rq_unlock,
1652 * you need to do so manually after calling.
1654 static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
1655 __releases(rq1->lock)
1656 __releases(rq2->lock)
1659 raw_spin_unlock(&rq1->lock);
1660 __release(rq2->lock);
1665 extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq);
1666 extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq);
1668 #ifdef CONFIG_SCHED_DEBUG
1669 extern void print_cfs_stats(struct seq_file *m, int cpu);
1670 extern void print_rt_stats(struct seq_file *m, int cpu);
1671 extern void print_dl_stats(struct seq_file *m, int cpu);
1673 print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
1675 #ifdef CONFIG_NUMA_BALANCING
1677 show_numa_stats(struct task_struct *p, struct seq_file *m);
1679 print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
1680 unsigned long tpf, unsigned long gsf, unsigned long gpf);
1681 #endif /* CONFIG_NUMA_BALANCING */
1682 #endif /* CONFIG_SCHED_DEBUG */
1684 extern void init_cfs_rq(struct cfs_rq *cfs_rq);
1685 extern void init_rt_rq(struct rt_rq *rt_rq);
1686 extern void init_dl_rq(struct dl_rq *dl_rq);
1688 extern void cfs_bandwidth_usage_inc(void);
1689 extern void cfs_bandwidth_usage_dec(void);
1691 #ifdef CONFIG_NO_HZ_COMMON
1692 enum rq_nohz_flag_bits {
1697 #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags)
1700 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
1702 DECLARE_PER_CPU(u64, cpu_hardirq_time);
1703 DECLARE_PER_CPU(u64, cpu_softirq_time);
1705 #ifndef CONFIG_64BIT
1706 DECLARE_PER_CPU(seqcount_t, irq_time_seq);
1708 static inline void irq_time_write_begin(void)
1710 __this_cpu_inc(irq_time_seq.sequence);
1714 static inline void irq_time_write_end(void)
1717 __this_cpu_inc(irq_time_seq.sequence);
1720 static inline u64 irq_time_read(int cpu)
1726 seq = read_seqcount_begin(&per_cpu(irq_time_seq, cpu));
1727 irq_time = per_cpu(cpu_softirq_time, cpu) +
1728 per_cpu(cpu_hardirq_time, cpu);
1729 } while (read_seqcount_retry(&per_cpu(irq_time_seq, cpu), seq));
1733 #else /* CONFIG_64BIT */
1734 static inline void irq_time_write_begin(void)
1738 static inline void irq_time_write_end(void)
1742 static inline u64 irq_time_read(int cpu)
1744 return per_cpu(cpu_softirq_time, cpu) + per_cpu(cpu_hardirq_time, cpu);
1746 #endif /* CONFIG_64BIT */
1747 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
1749 #ifdef CONFIG_CPU_FREQ
1750 DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
1753 * cpufreq_update_util - Take a note about CPU utilization changes.
1754 * @time: Current time.
1755 * @util: Current utilization.
1756 * @max: Utilization ceiling.
1758 * This function is called by the scheduler on every invocation of
1759 * update_load_avg() on the CPU whose utilization is being updated.
1761 * It can only be called from RCU-sched read-side critical sections.
1763 static inline void cpufreq_update_util(u64 time, unsigned long util, unsigned long max)
1765 struct update_util_data *data;
1767 data = rcu_dereference_sched(*this_cpu_ptr(&cpufreq_update_util_data));
1769 data->func(data, time, util, max);
1773 * cpufreq_trigger_update - Trigger CPU performance state evaluation if needed.
1774 * @time: Current time.
1776 * The way cpufreq is currently arranged requires it to evaluate the CPU
1777 * performance state (frequency/voltage) on a regular basis to prevent it from
1778 * being stuck in a completely inadequate performance level for too long.
1779 * That is not guaranteed to happen if the updates are only triggered from CFS,
1780 * though, because they may not be coming in if RT or deadline tasks are active
1781 * all the time (or there are RT and DL tasks only).
1783 * As a workaround for that issue, this function is called by the RT and DL
1784 * sched classes to trigger extra cpufreq updates to prevent it from stalling,
1785 * but that really is a band-aid. Going forward it should be replaced with
1786 * solutions targeted more specifically at RT and DL tasks.
1788 static inline void cpufreq_trigger_update(u64 time)
1790 cpufreq_update_util(time, ULONG_MAX, 0);
1793 static inline void cpufreq_update_util(u64 time, unsigned long util, unsigned long max) {}
1794 static inline void cpufreq_trigger_update(u64 time) {}
1795 #endif /* CONFIG_CPU_FREQ */
1797 static inline void account_reset_rq(struct rq *rq)
1799 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
1800 rq->prev_irq_time = 0;
1802 #ifdef CONFIG_PARAVIRT
1803 rq->prev_steal_time = 0;
1805 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
1806 rq->prev_steal_time_rq = 0;