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