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