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