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> |
Ben Hutchings | c803409 | 2019-05-10 00:46:25 +0100 | [diff] [blame] | 5 | #include <linux/sched/smt.h> |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 6 | #include <linux/u64_stats_sync.h> |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 7 | #include <linux/sched/deadline.h> |
Frederic Weisbecker | 034cd8a | 2017-01-31 04:09:32 +0100 | [diff] [blame] | 8 | #include <linux/kernel_stat.h> |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 9 | #include <linux/binfmts.h> |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 10 | #include <linux/mutex.h> |
Johannes Weiner | 3df0e59 | 2018-10-26 15:06:27 -0700 | [diff] [blame] | 11 | #include <linux/psi.h> |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/stop_machine.h> |
Steven Rostedt | b6366f0 | 2015-03-18 14:49:46 -0400 | [diff] [blame] | 14 | #include <linux/irq_work.h> |
Frederic Weisbecker | 9f3660c | 2013-04-20 14:35:09 +0200 | [diff] [blame] | 15 | #include <linux/tick.h> |
Mel Gorman | f809ca9 | 2013-10-07 11:28:57 +0100 | [diff] [blame] | 16 | #include <linux/slab.h> |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 17 | #include <linux/sched_energy.h> |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 18 | |
Peter Zijlstra | 391e43d | 2011-11-15 17:14:39 +0100 | [diff] [blame] | 19 | #include "cpupri.h" |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 20 | #include "cpudeadline.h" |
Li Zefan | 60fed78 | 2013-03-29 14:36:43 +0800 | [diff] [blame] | 21 | #include "cpuacct.h" |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 22 | |
Peter Zijlstra | 9148a3a | 2016-09-20 22:34:51 +0200 | [diff] [blame] | 23 | #ifdef CONFIG_SCHED_DEBUG |
| 24 | #define SCHED_WARN_ON(x) WARN_ONCE(x, #x) |
| 25 | #else |
| 26 | #define SCHED_WARN_ON(x) ((void)(x)) |
| 27 | #endif |
| 28 | |
Paul Gortmaker | 45ceebf | 2013-04-19 15:10:49 -0400 | [diff] [blame] | 29 | struct rq; |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 30 | struct cpuidle_state; |
Paul Gortmaker | 45ceebf | 2013-04-19 15:10:49 -0400 | [diff] [blame] | 31 | |
Syed Rameez Mustafa | e14a233 | 2017-05-19 14:42:35 -0700 | [diff] [blame] | 32 | extern __read_mostly bool sched_predl; |
Pavankumar Kondeti | 0d91fac | 2017-10-11 14:50:28 +0530 | [diff] [blame] | 33 | extern unsigned int sched_smp_overlap_capacity; |
Syed Rameez Mustafa | e14a233 | 2017-05-19 14:42:35 -0700 | [diff] [blame] | 34 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 35 | #ifdef CONFIG_SCHED_WALT |
| 36 | extern unsigned int sched_ravg_window; |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 37 | extern unsigned int walt_cpu_util_freq_divisor; |
Channagoud Kadabi | 8810e5f | 2017-02-17 16:01:05 -0800 | [diff] [blame] | 38 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 39 | struct walt_sched_stats { |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 40 | int nr_big_tasks; |
| 41 | u64 cumulative_runnable_avg; |
| 42 | u64 pred_demands_sum; |
| 43 | }; |
| 44 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 45 | struct cpu_cycle { |
| 46 | u64 cycles; |
| 47 | u64 time; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct group_cpu_time { |
| 51 | u64 curr_runnable_sum; |
| 52 | u64 prev_runnable_sum; |
| 53 | u64 nt_curr_runnable_sum; |
| 54 | u64 nt_prev_runnable_sum; |
| 55 | }; |
| 56 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 57 | struct load_subtractions { |
| 58 | u64 window_start; |
| 59 | u64 subs; |
| 60 | u64 new_subs; |
| 61 | }; |
| 62 | |
| 63 | #define NUM_TRACKED_WINDOWS 2 |
| 64 | #define NUM_LOAD_INDICES 1000 |
| 65 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 66 | struct sched_cluster { |
| 67 | raw_spinlock_t load_lock; |
| 68 | struct list_head list; |
| 69 | struct cpumask cpus; |
| 70 | int id; |
| 71 | int max_power_cost; |
| 72 | int min_power_cost; |
| 73 | int max_possible_capacity; |
| 74 | int capacity; |
| 75 | int efficiency; /* Differentiate cpus with different IPC capability */ |
| 76 | int load_scale_factor; |
| 77 | unsigned int exec_scale_factor; |
| 78 | /* |
| 79 | * max_freq = user maximum |
| 80 | * max_mitigated_freq = thermal defined maximum |
| 81 | * max_possible_freq = maximum supported by hardware |
| 82 | */ |
| 83 | unsigned int cur_freq, max_freq, max_mitigated_freq, min_freq; |
| 84 | unsigned int max_possible_freq; |
| 85 | bool freq_init_done; |
| 86 | int dstate, dstate_wakeup_latency, dstate_wakeup_energy; |
| 87 | unsigned int static_cluster_pwr_cost; |
| 88 | int notifier_sent; |
| 89 | bool wake_up_idle; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 90 | u64 aggr_grp_load; |
Satya Durga Srinivasu Prabhala | c18b403 | 2018-04-17 11:21:23 -0700 | [diff] [blame] | 91 | u64 coloc_boost_load; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
Vikram Mulukutla | 4b54aae | 2017-03-20 13:41:37 -0700 | [diff] [blame] | 94 | extern unsigned int sched_disable_window_stats; |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 95 | |
| 96 | extern struct timer_list sched_grp_timer; |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 97 | #endif /* CONFIG_SCHED_WALT */ |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 98 | |
| 99 | |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 100 | /* task_struct::on_rq states: */ |
| 101 | #define TASK_ON_RQ_QUEUED 1 |
Kirill Tkhai | cca26e8 | 2014-08-20 13:47:42 +0400 | [diff] [blame] | 102 | #define TASK_ON_RQ_MIGRATING 2 |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 103 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 104 | extern __read_mostly int scheduler_running; |
| 105 | |
Paul Gortmaker | 45ceebf | 2013-04-19 15:10:49 -0400 | [diff] [blame] | 106 | extern unsigned long calc_load_update; |
| 107 | extern atomic_long_t calc_load_tasks; |
| 108 | |
Peter Zijlstra | 3289bdb | 2015-04-14 13:19:42 +0200 | [diff] [blame] | 109 | extern void calc_global_load_tick(struct rq *this_rq); |
Thomas Gleixner | d60585c | 2016-07-12 18:33:56 +0200 | [diff] [blame] | 110 | extern long calc_load_fold_active(struct rq *this_rq, long adjust); |
Peter Zijlstra | 3289bdb | 2015-04-14 13:19:42 +0200 | [diff] [blame] | 111 | |
| 112 | #ifdef CONFIG_SMP |
Frederic Weisbecker | cee1afc | 2016-04-13 15:56:50 +0200 | [diff] [blame] | 113 | extern void cpu_load_update_active(struct rq *this_rq); |
Peter Zijlstra | 3289bdb | 2015-04-14 13:19:42 +0200 | [diff] [blame] | 114 | #else |
Frederic Weisbecker | cee1afc | 2016-04-13 15:56:50 +0200 | [diff] [blame] | 115 | static inline void cpu_load_update_active(struct rq *this_rq) { } |
Peter Zijlstra | 3289bdb | 2015-04-14 13:19:42 +0200 | [diff] [blame] | 116 | #endif |
Paul Gortmaker | 45ceebf | 2013-04-19 15:10:49 -0400 | [diff] [blame] | 117 | |
Greg Kroah-Hartman | a0a93e3 | 2017-07-19 09:58:49 +0200 | [diff] [blame] | 118 | #ifdef CONFIG_SCHED_SMT |
| 119 | extern void update_idle_core(struct rq *rq); |
| 120 | #else |
| 121 | static inline void update_idle_core(struct rq *rq) { } |
| 122 | #endif |
| 123 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 124 | /* |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 125 | * Helpers for converting nanosecond timing to jiffy resolution |
| 126 | */ |
| 127 | #define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ)) |
| 128 | |
Li Zefan | cc1f4b1 | 2013-03-05 16:06:09 +0800 | [diff] [blame] | 129 | /* |
| 130 | * Increase resolution of nice-level calculations for 64-bit architectures. |
| 131 | * The extra resolution improves shares distribution and load balancing of |
| 132 | * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup |
| 133 | * hierarchies, especially on larger systems. This is not a user-visible change |
| 134 | * and does not change the user-interface for setting shares/weights. |
| 135 | * |
| 136 | * We increase resolution only if we have enough bits to allow this increased |
Peter Zijlstra | 2159197 | 2016-04-28 12:49:38 +0200 | [diff] [blame] | 137 | * resolution (i.e. 64bit). The costs for increasing resolution when 32bit are |
| 138 | * pretty high and the returns do not justify the increased costs. |
| 139 | * |
| 140 | * Really only required when CONFIG_FAIR_GROUP_SCHED is also set, but to |
| 141 | * increase coverage and consistency always enable it on 64bit platforms. |
Li Zefan | cc1f4b1 | 2013-03-05 16:06:09 +0800 | [diff] [blame] | 142 | */ |
Peter Zijlstra | 2159197 | 2016-04-28 12:49:38 +0200 | [diff] [blame] | 143 | #ifdef CONFIG_64BIT |
Yuyang Du | 172895e | 2016-04-05 12:12:27 +0800 | [diff] [blame] | 144 | # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT + SCHED_FIXEDPOINT_SHIFT) |
Yuyang Du | 6ecdd74 | 2016-04-05 12:12:26 +0800 | [diff] [blame] | 145 | # define scale_load(w) ((w) << SCHED_FIXEDPOINT_SHIFT) |
| 146 | # define scale_load_down(w) ((w) >> SCHED_FIXEDPOINT_SHIFT) |
Li Zefan | cc1f4b1 | 2013-03-05 16:06:09 +0800 | [diff] [blame] | 147 | #else |
Yuyang Du | 172895e | 2016-04-05 12:12:27 +0800 | [diff] [blame] | 148 | # define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT) |
Li Zefan | cc1f4b1 | 2013-03-05 16:06:09 +0800 | [diff] [blame] | 149 | # define scale_load(w) (w) |
| 150 | # define scale_load_down(w) (w) |
| 151 | #endif |
| 152 | |
Yuyang Du | 6ecdd74 | 2016-04-05 12:12:26 +0800 | [diff] [blame] | 153 | /* |
Yuyang Du | 172895e | 2016-04-05 12:12:27 +0800 | [diff] [blame] | 154 | * Task weight (visible to users) and its load (invisible to users) have |
| 155 | * independent resolution, but they should be well calibrated. We use |
| 156 | * scale_load() and scale_load_down(w) to convert between them. The |
| 157 | * following must be true: |
| 158 | * |
| 159 | * scale_load(sched_prio_to_weight[USER_PRIO(NICE_TO_PRIO(0))]) == NICE_0_LOAD |
| 160 | * |
Yuyang Du | 6ecdd74 | 2016-04-05 12:12:26 +0800 | [diff] [blame] | 161 | */ |
Yuyang Du | 172895e | 2016-04-05 12:12:27 +0800 | [diff] [blame] | 162 | #define NICE_0_LOAD (1L << NICE_0_LOAD_SHIFT) |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 163 | |
| 164 | /* |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 165 | * Single value that decides SCHED_DEADLINE internal math precision. |
| 166 | * 10 -> just above 1us |
| 167 | * 9 -> just above 0.5us |
| 168 | */ |
| 169 | #define DL_SCALE (10) |
| 170 | |
| 171 | /* |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 172 | * These are the 'tuning knobs' of the scheduler: |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 173 | */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * single value that denotes runtime == period, ie unlimited time. |
| 177 | */ |
| 178 | #define RUNTIME_INF ((u64)~0ULL) |
| 179 | |
Henrik Austad | 20f9cd2 | 2015-09-09 17:00:41 +0200 | [diff] [blame] | 180 | static inline int idle_policy(int policy) |
| 181 | { |
| 182 | return policy == SCHED_IDLE; |
| 183 | } |
Dario Faggioli | d50dde5 | 2013-11-07 14:43:36 +0100 | [diff] [blame] | 184 | static inline int fair_policy(int policy) |
| 185 | { |
| 186 | return policy == SCHED_NORMAL || policy == SCHED_BATCH; |
| 187 | } |
| 188 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 189 | static inline int rt_policy(int policy) |
| 190 | { |
Dario Faggioli | d50dde5 | 2013-11-07 14:43:36 +0100 | [diff] [blame] | 191 | return policy == SCHED_FIFO || policy == SCHED_RR; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 194 | static inline int dl_policy(int policy) |
| 195 | { |
| 196 | return policy == SCHED_DEADLINE; |
| 197 | } |
Henrik Austad | 20f9cd2 | 2015-09-09 17:00:41 +0200 | [diff] [blame] | 198 | static inline bool valid_policy(int policy) |
| 199 | { |
| 200 | return idle_policy(policy) || fair_policy(policy) || |
| 201 | rt_policy(policy) || dl_policy(policy); |
| 202 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 203 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 204 | static inline int task_has_rt_policy(struct task_struct *p) |
| 205 | { |
| 206 | return rt_policy(p->policy); |
| 207 | } |
| 208 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 209 | static inline int task_has_dl_policy(struct task_struct *p) |
| 210 | { |
| 211 | return dl_policy(p->policy); |
| 212 | } |
| 213 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 214 | /* |
| 215 | * Tells if entity @a should preempt entity @b. |
| 216 | */ |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 217 | static inline bool |
| 218 | dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b) |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 219 | { |
| 220 | return dl_time_before(a->deadline, b->deadline); |
| 221 | } |
| 222 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 223 | /* |
| 224 | * This is the priority-queue data structure of the RT scheduling class: |
| 225 | */ |
| 226 | struct rt_prio_array { |
| 227 | DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */ |
| 228 | struct list_head queue[MAX_RT_PRIO]; |
| 229 | }; |
| 230 | |
| 231 | struct rt_bandwidth { |
| 232 | /* nests inside the rq lock: */ |
| 233 | raw_spinlock_t rt_runtime_lock; |
| 234 | ktime_t rt_period; |
| 235 | u64 rt_runtime; |
| 236 | struct hrtimer rt_period_timer; |
Peter Zijlstra | 4cfafd3 | 2015-05-14 12:23:11 +0200 | [diff] [blame] | 237 | unsigned int rt_period_active; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 238 | }; |
Juri Lelli | a5e7be3 | 2014-09-19 10:22:39 +0100 | [diff] [blame] | 239 | |
| 240 | void __dl_clear_params(struct task_struct *p); |
| 241 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 242 | /* |
| 243 | * To keep the bandwidth of -deadline tasks and groups under control |
| 244 | * we need some place where: |
| 245 | * - store the maximum -deadline bandwidth of the system (the group); |
| 246 | * - cache the fraction of that bandwidth that is currently allocated. |
| 247 | * |
| 248 | * This is all done in the data structure below. It is similar to the |
| 249 | * one used for RT-throttling (rt_bandwidth), with the main difference |
| 250 | * that, since here we are only interested in admission control, we |
| 251 | * do not decrease any runtime while the group "executes", neither we |
| 252 | * need a timer to replenish it. |
| 253 | * |
| 254 | * With respect to SMP, the bandwidth is given on a per-CPU basis, |
| 255 | * meaning that: |
| 256 | * - dl_bw (< 100%) is the bandwidth of the system (group) on each CPU; |
| 257 | * - dl_total_bw array contains, in the i-eth element, the currently |
| 258 | * allocated bandwidth on the i-eth CPU. |
| 259 | * Moreover, groups consume bandwidth on each CPU, while tasks only |
| 260 | * consume bandwidth on the CPU they're running on. |
| 261 | * Finally, dl_total_bw_cpu is used to cache the index of dl_total_bw |
| 262 | * that will be shown the next time the proc or cgroup controls will |
| 263 | * be red. It on its turn can be changed by writing on its own |
| 264 | * control. |
| 265 | */ |
| 266 | struct dl_bandwidth { |
| 267 | raw_spinlock_t dl_runtime_lock; |
| 268 | u64 dl_runtime; |
| 269 | u64 dl_period; |
| 270 | }; |
| 271 | |
| 272 | static inline int dl_bandwidth_enabled(void) |
| 273 | { |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 274 | return sysctl_sched_rt_runtime >= 0; |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | extern struct dl_bw *dl_bw_of(int i); |
| 278 | |
| 279 | struct dl_bw { |
| 280 | raw_spinlock_t lock; |
| 281 | u64 bw, total_bw; |
| 282 | }; |
| 283 | |
Juri Lelli | 7f51412 | 2014-09-19 10:22:40 +0100 | [diff] [blame] | 284 | static inline |
| 285 | void __dl_clear(struct dl_bw *dl_b, u64 tsk_bw) |
| 286 | { |
| 287 | dl_b->total_bw -= tsk_bw; |
| 288 | } |
| 289 | |
| 290 | static inline |
| 291 | void __dl_add(struct dl_bw *dl_b, u64 tsk_bw) |
| 292 | { |
| 293 | dl_b->total_bw += tsk_bw; |
| 294 | } |
| 295 | |
| 296 | static inline |
| 297 | bool __dl_overflow(struct dl_bw *dl_b, int cpus, u64 old_bw, u64 new_bw) |
| 298 | { |
| 299 | return dl_b->bw != -1 && |
| 300 | dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw; |
| 301 | } |
| 302 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 303 | extern struct mutex sched_domains_mutex; |
| 304 | |
| 305 | #ifdef CONFIG_CGROUP_SCHED |
| 306 | |
| 307 | #include <linux/cgroup.h> |
Johannes Weiner | 3df0e59 | 2018-10-26 15:06:27 -0700 | [diff] [blame] | 308 | #include <linux/psi.h> |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 309 | |
| 310 | struct cfs_rq; |
| 311 | struct rt_rq; |
| 312 | |
Mike Galbraith | 35cf4e5 | 2012-08-07 05:00:13 +0200 | [diff] [blame] | 313 | extern struct list_head task_groups; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 314 | |
| 315 | struct cfs_bandwidth { |
| 316 | #ifdef CONFIG_CFS_BANDWIDTH |
| 317 | raw_spinlock_t lock; |
| 318 | ktime_t period; |
| 319 | u64 quota, runtime; |
Zhihui Zhang | 9c58c79 | 2014-09-20 21:24:36 -0400 | [diff] [blame] | 320 | s64 hierarchical_quota; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 321 | u64 runtime_expires; |
| 322 | |
Peter Zijlstra | 4cfafd3 | 2015-05-14 12:23:11 +0200 | [diff] [blame] | 323 | int idle, period_active; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 324 | struct hrtimer period_timer, slack_timer; |
| 325 | struct list_head throttled_cfs_rq; |
| 326 | |
| 327 | /* statistics */ |
| 328 | int nr_periods, nr_throttled; |
| 329 | u64 throttled_time; |
Phil Auld | bc1fccc | 2018-10-08 10:36:40 -0400 | [diff] [blame] | 330 | |
| 331 | bool distribute_running; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 332 | #endif |
| 333 | }; |
| 334 | |
| 335 | /* task group related information */ |
| 336 | struct task_group { |
| 337 | struct cgroup_subsys_state css; |
| 338 | |
| 339 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 340 | /* schedulable entities of this group on each cpu */ |
| 341 | struct sched_entity **se; |
| 342 | /* runqueue "owned" by this group on each cpu */ |
| 343 | struct cfs_rq **cfs_rq; |
| 344 | unsigned long shares; |
| 345 | |
Alex Shi | fa6bdde | 2013-06-20 10:18:46 +0800 | [diff] [blame] | 346 | #ifdef CONFIG_SMP |
Waiman Long | b036762 | 2015-12-02 13:41:49 -0500 | [diff] [blame] | 347 | /* |
| 348 | * load_avg can be heavily contended at clock tick time, so put |
| 349 | * it in its own cacheline separated from the fields above which |
| 350 | * will also be accessed at each tick. |
| 351 | */ |
| 352 | atomic_long_t load_avg ____cacheline_aligned; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 353 | #endif |
Alex Shi | fa6bdde | 2013-06-20 10:18:46 +0800 | [diff] [blame] | 354 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 355 | |
| 356 | #ifdef CONFIG_RT_GROUP_SCHED |
| 357 | struct sched_rt_entity **rt_se; |
| 358 | struct rt_rq **rt_rq; |
| 359 | |
| 360 | struct rt_bandwidth rt_bandwidth; |
| 361 | #endif |
| 362 | |
| 363 | struct rcu_head rcu; |
| 364 | struct list_head list; |
| 365 | |
| 366 | struct task_group *parent; |
| 367 | struct list_head siblings; |
| 368 | struct list_head children; |
| 369 | |
| 370 | #ifdef CONFIG_SCHED_AUTOGROUP |
| 371 | struct autogroup *autogroup; |
| 372 | #endif |
| 373 | |
| 374 | struct cfs_bandwidth cfs_bandwidth; |
| 375 | }; |
| 376 | |
| 377 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 378 | #define ROOT_TASK_GROUP_LOAD NICE_0_LOAD |
| 379 | |
| 380 | /* |
| 381 | * A weight of 0 or 1 can cause arithmetics problems. |
| 382 | * A weight of a cfs_rq is the sum of weights of which entities |
| 383 | * are queued on this cfs_rq, so a weight of a entity should not be |
| 384 | * too large, so as the shares value of a task group. |
| 385 | * (The default weight is 1024 - so there's no practical |
| 386 | * limitation from this.) |
| 387 | */ |
| 388 | #define MIN_SHARES (1UL << 1) |
| 389 | #define MAX_SHARES (1UL << 18) |
| 390 | #endif |
| 391 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 392 | typedef int (*tg_visitor)(struct task_group *, void *); |
| 393 | |
| 394 | extern int walk_tg_tree_from(struct task_group *from, |
| 395 | tg_visitor down, tg_visitor up, void *data); |
| 396 | |
| 397 | /* |
| 398 | * Iterate the full tree, calling @down when first entering a node and @up when |
| 399 | * leaving it for the final time. |
| 400 | * |
| 401 | * Caller must hold rcu_lock or sufficient equivalent. |
| 402 | */ |
| 403 | static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data) |
| 404 | { |
| 405 | return walk_tg_tree_from(&root_task_group, down, up, data); |
| 406 | } |
| 407 | |
| 408 | extern int tg_nop(struct task_group *tg, void *data); |
| 409 | |
| 410 | extern void free_fair_sched_group(struct task_group *tg); |
| 411 | extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent); |
Peter Zijlstra | 8663e24 | 2016-06-22 14:58:02 +0200 | [diff] [blame] | 412 | extern void online_fair_sched_group(struct task_group *tg); |
Peter Zijlstra | 6fe1f34 | 2016-01-21 22:24:16 +0100 | [diff] [blame] | 413 | extern void unregister_fair_sched_group(struct task_group *tg); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 414 | extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq, |
| 415 | struct sched_entity *se, int cpu, |
| 416 | struct sched_entity *parent); |
| 417 | extern void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 418 | |
| 419 | extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b); |
Peter Zijlstra | 77a4d1a | 2015-04-15 11:41:57 +0200 | [diff] [blame] | 420 | extern void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 421 | extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq); |
| 422 | |
| 423 | extern void free_rt_sched_group(struct task_group *tg); |
| 424 | extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent); |
| 425 | extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq, |
| 426 | struct sched_rt_entity *rt_se, int cpu, |
| 427 | struct sched_rt_entity *parent); |
| 428 | |
Li Zefan | 25cc7da | 2013-03-05 16:07:33 +0800 | [diff] [blame] | 429 | extern struct task_group *sched_create_group(struct task_group *parent); |
| 430 | extern void sched_online_group(struct task_group *tg, |
| 431 | struct task_group *parent); |
| 432 | extern void sched_destroy_group(struct task_group *tg); |
| 433 | extern void sched_offline_group(struct task_group *tg); |
| 434 | |
| 435 | extern void sched_move_task(struct task_struct *tsk); |
| 436 | |
| 437 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 438 | extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); |
Byungchul Park | ad936d8 | 2015-10-24 01:16:19 +0900 | [diff] [blame] | 439 | |
| 440 | #ifdef CONFIG_SMP |
| 441 | extern void set_task_rq_fair(struct sched_entity *se, |
| 442 | struct cfs_rq *prev, struct cfs_rq *next); |
| 443 | #else /* !CONFIG_SMP */ |
| 444 | static inline void set_task_rq_fair(struct sched_entity *se, |
| 445 | struct cfs_rq *prev, struct cfs_rq *next) { } |
| 446 | #endif /* CONFIG_SMP */ |
| 447 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
Li Zefan | 25cc7da | 2013-03-05 16:07:33 +0800 | [diff] [blame] | 448 | |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 449 | extern struct task_group *css_tg(struct cgroup_subsys_state *css); |
| 450 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 451 | #else /* CONFIG_CGROUP_SCHED */ |
| 452 | |
| 453 | struct cfs_bandwidth { }; |
| 454 | |
| 455 | #endif /* CONFIG_CGROUP_SCHED */ |
| 456 | |
| 457 | /* CFS-related fields in a runqueue */ |
| 458 | struct cfs_rq { |
| 459 | struct load_weight load; |
Peter Zijlstra | c82513e | 2012-04-26 13:12:27 +0200 | [diff] [blame] | 460 | unsigned int nr_running, h_nr_running; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 461 | |
| 462 | u64 exec_clock; |
| 463 | u64 min_vruntime; |
| 464 | #ifndef CONFIG_64BIT |
| 465 | u64 min_vruntime_copy; |
| 466 | #endif |
| 467 | |
| 468 | struct rb_root tasks_timeline; |
| 469 | struct rb_node *rb_leftmost; |
| 470 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 471 | /* |
| 472 | * 'curr' points to currently running entity on this cfs_rq. |
| 473 | * It is set to NULL otherwise (i.e when none are currently running). |
| 474 | */ |
| 475 | struct sched_entity *curr, *next, *last, *skip; |
| 476 | |
| 477 | #ifdef CONFIG_SCHED_DEBUG |
| 478 | unsigned int nr_spread_over; |
| 479 | #endif |
| 480 | |
Paul Turner | 2dac754 | 2012-10-04 13:18:30 +0200 | [diff] [blame] | 481 | #ifdef CONFIG_SMP |
| 482 | /* |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 483 | * CFS load tracking |
Paul Turner | 2dac754 | 2012-10-04 13:18:30 +0200 | [diff] [blame] | 484 | */ |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 485 | struct sched_avg avg; |
Yuyang Du | 1396223 | 2015-07-15 08:04:41 +0800 | [diff] [blame] | 486 | u64 runnable_load_sum; |
| 487 | unsigned long runnable_load_avg; |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 488 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 489 | unsigned long tg_load_avg_contrib; |
Vincent Guittot | 96956e2 | 2016-11-08 10:53:44 +0100 | [diff] [blame] | 490 | unsigned long propagate_avg; |
Yuyang Du | 9d89c25 | 2015-07-15 08:04:37 +0800 | [diff] [blame] | 491 | #endif |
| 492 | atomic_long_t removed_load_avg, removed_util_avg; |
| 493 | #ifndef CONFIG_64BIT |
| 494 | u64 load_last_update_time_copy; |
| 495 | #endif |
Alex Shi | 141965c | 2013-06-26 13:05:39 +0800 | [diff] [blame] | 496 | |
Paul Turner | c566e8e | 2012-10-04 13:18:30 +0200 | [diff] [blame] | 497 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Paul Turner | 8295836 | 2012-10-04 13:18:31 +0200 | [diff] [blame] | 498 | /* |
| 499 | * h_load = weight * f(tg) |
| 500 | * |
| 501 | * Where f(tg) is the recursive weight fraction assigned to |
| 502 | * this group. |
| 503 | */ |
| 504 | unsigned long h_load; |
Vladimir Davydov | 6852079 | 2013-07-15 17:49:19 +0400 | [diff] [blame] | 505 | u64 last_h_load_update; |
| 506 | struct sched_entity *h_load_next; |
| 507 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
Paul Turner | 8295836 | 2012-10-04 13:18:31 +0200 | [diff] [blame] | 508 | #endif /* CONFIG_SMP */ |
| 509 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 510 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 511 | struct rq *rq; /* cpu runqueue to which this cfs_rq is attached */ |
| 512 | |
| 513 | /* |
| 514 | * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in |
| 515 | * a hierarchy). Non-leaf lrqs hold other higher schedulable entities |
| 516 | * (like users, containers etc.) |
| 517 | * |
| 518 | * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a cpu. This |
| 519 | * list is used during load balance. |
| 520 | */ |
| 521 | int on_list; |
| 522 | struct list_head leaf_cfs_rq_list; |
| 523 | struct task_group *tg; /* group that "owns" this runqueue */ |
| 524 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 525 | #ifdef CONFIG_CFS_BANDWIDTH |
Pavankumar Kondeti | 39c695e | 2017-07-20 16:05:51 +0530 | [diff] [blame] | 526 | |
| 527 | #ifdef CONFIG_SCHED_WALT |
| 528 | struct walt_sched_stats walt_stats; |
| 529 | #endif |
| 530 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 531 | int runtime_enabled; |
| 532 | u64 runtime_expires; |
| 533 | s64 runtime_remaining; |
| 534 | |
Paul Turner | f1b1728 | 2012-10-04 13:18:31 +0200 | [diff] [blame] | 535 | u64 throttled_clock, throttled_clock_task; |
| 536 | u64 throttled_clock_task_time; |
Peter Zijlstra | 55e16d3 | 2016-06-22 15:14:26 +0200 | [diff] [blame] | 537 | int throttled, throttle_count; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 538 | struct list_head throttled_list; |
| 539 | #endif /* CONFIG_CFS_BANDWIDTH */ |
| 540 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
| 541 | }; |
| 542 | |
| 543 | static inline int rt_bandwidth_enabled(void) |
| 544 | { |
| 545 | return sysctl_sched_rt_runtime >= 0; |
| 546 | } |
| 547 | |
Steven Rostedt | b6366f0 | 2015-03-18 14:49:46 -0400 | [diff] [blame] | 548 | /* RT IPI pull logic requires IRQ_WORK */ |
Steven Rostedt (Red Hat) | 1c37ff7 | 2017-10-06 14:05:04 -0400 | [diff] [blame] | 549 | #if defined(CONFIG_IRQ_WORK) && defined(CONFIG_SMP) |
Steven Rostedt | b6366f0 | 2015-03-18 14:49:46 -0400 | [diff] [blame] | 550 | # define HAVE_RT_PUSH_IPI |
| 551 | #endif |
| 552 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 553 | /* Real-Time classes' related field in a runqueue: */ |
| 554 | struct rt_rq { |
| 555 | struct rt_prio_array active; |
Peter Zijlstra | c82513e | 2012-04-26 13:12:27 +0200 | [diff] [blame] | 556 | unsigned int rt_nr_running; |
Frederic Weisbecker | 01d36d0 | 2015-11-04 18:17:10 +0100 | [diff] [blame] | 557 | unsigned int rr_nr_running; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 558 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED |
| 559 | struct { |
| 560 | int curr; /* highest queued rt task prio */ |
| 561 | #ifdef CONFIG_SMP |
| 562 | int next; /* next highest */ |
| 563 | #endif |
| 564 | } highest_prio; |
| 565 | #endif |
| 566 | #ifdef CONFIG_SMP |
| 567 | unsigned long rt_nr_migratory; |
| 568 | unsigned long rt_nr_total; |
| 569 | int overloaded; |
| 570 | struct plist_head pushable_tasks; |
Steven Rostedt | b6366f0 | 2015-03-18 14:49:46 -0400 | [diff] [blame] | 571 | #endif /* CONFIG_SMP */ |
Kirill Tkhai | f4ebcbc | 2014-03-15 02:15:00 +0400 | [diff] [blame] | 572 | int rt_queued; |
| 573 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 574 | int rt_throttled; |
| 575 | u64 rt_time; |
| 576 | u64 rt_runtime; |
| 577 | /* Nests inside the rq lock: */ |
| 578 | raw_spinlock_t rt_runtime_lock; |
| 579 | |
| 580 | #ifdef CONFIG_RT_GROUP_SCHED |
| 581 | unsigned long rt_nr_boosted; |
| 582 | |
| 583 | struct rq *rq; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 584 | struct task_group *tg; |
| 585 | #endif |
| 586 | }; |
| 587 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 588 | /* Deadline class' related fields in a runqueue */ |
| 589 | struct dl_rq { |
| 590 | /* runqueue is an rbtree, ordered by deadline */ |
| 591 | struct rb_root rb_root; |
| 592 | struct rb_node *rb_leftmost; |
| 593 | |
| 594 | unsigned long dl_nr_running; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 595 | |
| 596 | #ifdef CONFIG_SMP |
| 597 | /* |
| 598 | * Deadline values of the currently executing and the |
| 599 | * earliest ready task on this rq. Caching these facilitates |
| 600 | * the decision wether or not a ready but not running task |
| 601 | * should migrate somewhere else. |
| 602 | */ |
| 603 | struct { |
| 604 | u64 curr; |
| 605 | u64 next; |
| 606 | } earliest_dl; |
| 607 | |
| 608 | unsigned long dl_nr_migratory; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 609 | int overloaded; |
| 610 | |
| 611 | /* |
| 612 | * Tasks on this rq that can be pushed away. They are kept in |
| 613 | * an rb-tree, ordered by tasks' deadlines, with caching |
| 614 | * of the leftmost (earliest deadline) element. |
| 615 | */ |
| 616 | struct rb_root pushable_dl_tasks_root; |
| 617 | struct rb_node *pushable_dl_tasks_leftmost; |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 618 | #else |
| 619 | struct dl_bw dl_bw; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 620 | #endif |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 621 | }; |
| 622 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 623 | #ifdef CONFIG_SMP |
| 624 | |
Dietmar Eggemann | bbb138b | 2015-09-26 18:19:54 +0100 | [diff] [blame] | 625 | struct max_cpu_capacity { |
| 626 | raw_spinlock_t lock; |
| 627 | unsigned long val; |
| 628 | int cpu; |
| 629 | }; |
| 630 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 631 | /* |
| 632 | * We add the notion of a root-domain which will be used to define per-domain |
| 633 | * variables. Each exclusive cpuset essentially defines an island domain by |
| 634 | * fully partitioning the member cpus from any other cpuset. Whenever a new |
| 635 | * exclusive cpuset is created, we also create and attach a new root-domain |
| 636 | * object. |
| 637 | * |
| 638 | */ |
| 639 | struct root_domain { |
| 640 | atomic_t refcount; |
| 641 | atomic_t rto_count; |
| 642 | struct rcu_head rcu; |
| 643 | cpumask_var_t span; |
| 644 | cpumask_var_t online; |
| 645 | |
Tim Chen | 4486edd | 2014-06-23 12:16:49 -0700 | [diff] [blame] | 646 | /* Indicate more than one runnable task for any CPU */ |
| 647 | bool overload; |
| 648 | |
Morten Rasmussen | a562dfc | 2015-05-09 16:49:57 +0100 | [diff] [blame] | 649 | /* Indicate one or more cpus over-utilized (tipping point) */ |
| 650 | bool overutilized; |
| 651 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 652 | /* |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 653 | * The bit corresponding to a CPU gets set here if such CPU has more |
| 654 | * than one runnable -deadline task (as it is below for RT tasks). |
| 655 | */ |
| 656 | cpumask_var_t dlo_mask; |
| 657 | atomic_t dlo_count; |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 658 | struct dl_bw dl_bw; |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 659 | struct cpudl cpudl; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 660 | |
Steven Rostedt (Red Hat) | 1c37ff7 | 2017-10-06 14:05:04 -0400 | [diff] [blame] | 661 | #ifdef HAVE_RT_PUSH_IPI |
| 662 | /* |
| 663 | * For IPI pull requests, loop across the rto_mask. |
| 664 | */ |
| 665 | struct irq_work rto_push_work; |
| 666 | raw_spinlock_t rto_lock; |
| 667 | /* These are only updated and read within rto_lock */ |
| 668 | int rto_loop; |
| 669 | int rto_cpu; |
| 670 | /* These atomics are updated outside of a lock */ |
| 671 | atomic_t rto_loop_next; |
| 672 | atomic_t rto_loop_start; |
| 673 | #endif |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 674 | /* |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 675 | * The "RT overload" flag: it gets set if a CPU has more than |
| 676 | * one runnable RT task. |
| 677 | */ |
| 678 | cpumask_var_t rto_mask; |
| 679 | struct cpupri cpupri; |
Dietmar Eggemann | cd92bfd | 2016-08-01 19:53:35 +0100 | [diff] [blame] | 680 | |
Dietmar Eggemann | bbb138b | 2015-09-26 18:19:54 +0100 | [diff] [blame] | 681 | /* Maximum cpu capacity in the system. */ |
| 682 | struct max_cpu_capacity max_cpu_capacity; |
Dietmar Eggemann | 14774e7 | 2017-01-08 16:16:59 +0000 | [diff] [blame] | 683 | |
| 684 | /* First cpu with maximum and minimum original capacity */ |
| 685 | int max_cap_orig_cpu, min_cap_orig_cpu; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | extern struct root_domain def_root_domain; |
Steven Rostedt (VMware) | a384e54 | 2018-01-23 20:45:38 -0500 | [diff] [blame] | 689 | extern void sched_get_rd(struct root_domain *rd); |
| 690 | extern void sched_put_rd(struct root_domain *rd); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 691 | |
Steven Rostedt (Red Hat) | 1c37ff7 | 2017-10-06 14:05:04 -0400 | [diff] [blame] | 692 | #ifdef HAVE_RT_PUSH_IPI |
| 693 | extern void rto_push_irq_work_func(struct irq_work *work); |
| 694 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 695 | #endif /* CONFIG_SMP */ |
| 696 | |
| 697 | /* |
| 698 | * This is the main, per-CPU runqueue data structure. |
| 699 | * |
| 700 | * Locking rule: those places that want to lock multiple runqueues |
| 701 | * (such as the load balancing or the thread migration code), lock |
| 702 | * acquire operations must be ordered by ascending &runqueue. |
| 703 | */ |
| 704 | struct rq { |
| 705 | /* runqueue lock: */ |
| 706 | raw_spinlock_t lock; |
| 707 | |
| 708 | /* |
| 709 | * nr_running and cpu_load should be in the same cacheline because |
| 710 | * remote CPUs use both these fields when doing load calculation. |
| 711 | */ |
Peter Zijlstra | c82513e | 2012-04-26 13:12:27 +0200 | [diff] [blame] | 712 | unsigned int nr_running; |
Peter Zijlstra | 0ec8aa0 | 2013-10-07 11:29:33 +0100 | [diff] [blame] | 713 | #ifdef CONFIG_NUMA_BALANCING |
| 714 | unsigned int nr_numa_running; |
| 715 | unsigned int nr_preferred_running; |
| 716 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 717 | #define CPU_LOAD_IDX_MAX 5 |
| 718 | unsigned long cpu_load[CPU_LOAD_IDX_MAX]; |
Morten Rasmussen | 4c6a824 | 2016-02-25 12:47:54 +0000 | [diff] [blame] | 719 | unsigned int misfit_task; |
Frederic Weisbecker | 3451d02 | 2011-08-10 23:21:01 +0200 | [diff] [blame] | 720 | #ifdef CONFIG_NO_HZ_COMMON |
Frederic Weisbecker | 9fd81dd | 2016-04-19 17:36:51 +0200 | [diff] [blame] | 721 | #ifdef CONFIG_SMP |
| 722 | unsigned long last_load_update_tick; |
| 723 | #endif /* CONFIG_SMP */ |
Suresh Siddha | 1c792db | 2011-12-01 17:07:32 -0800 | [diff] [blame] | 724 | unsigned long nohz_flags; |
Frederic Weisbecker | 9fd81dd | 2016-04-19 17:36:51 +0200 | [diff] [blame] | 725 | #endif /* CONFIG_NO_HZ_COMMON */ |
Frederic Weisbecker | 265f22a | 2013-05-03 03:39:05 +0200 | [diff] [blame] | 726 | #ifdef CONFIG_NO_HZ_FULL |
| 727 | unsigned long last_sched_tick; |
| 728 | #endif |
Joseph Lo | 7750186 | 2013-04-22 14:39:18 +0800 | [diff] [blame] | 729 | |
| 730 | #ifdef CONFIG_CPU_QUIET |
| 731 | /* time-based average load */ |
| 732 | u64 nr_last_stamp; |
| 733 | u64 nr_running_integral; |
| 734 | seqcount_t ave_seqcnt; |
| 735 | #endif |
| 736 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 737 | /* capture load from *all* tasks on this cpu: */ |
| 738 | struct load_weight load; |
| 739 | unsigned long nr_load_updates; |
| 740 | u64 nr_switches; |
| 741 | |
| 742 | struct cfs_rq cfs; |
| 743 | struct rt_rq rt; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 744 | struct dl_rq dl; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 745 | |
| 746 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 747 | /* list of leaf cfs_rq on this cpu: */ |
| 748 | struct list_head leaf_cfs_rq_list; |
Vincent Guittot | 96956e2 | 2016-11-08 10:53:44 +0100 | [diff] [blame] | 749 | struct list_head *tmp_alone_branch; |
Peter Zijlstra | a35b646 | 2012-08-08 21:46:40 +0200 | [diff] [blame] | 750 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
| 751 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 752 | /* |
| 753 | * This is part of a global counter where only the total sum |
| 754 | * over all CPUs matters. A task can increase this counter on |
| 755 | * one CPU and if it got migrated afterwards it may decrease |
| 756 | * it on another CPU. Always updated under the runqueue lock: |
| 757 | */ |
| 758 | unsigned long nr_uninterruptible; |
| 759 | |
| 760 | struct task_struct *curr, *idle, *stop; |
| 761 | unsigned long next_balance; |
| 762 | struct mm_struct *prev_mm; |
| 763 | |
Peter Zijlstra | 9edfbfe | 2015-01-05 11:18:11 +0100 | [diff] [blame] | 764 | unsigned int clock_skip_update; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 765 | u64 clock; |
| 766 | u64 clock_task; |
| 767 | |
| 768 | atomic_t nr_iowait; |
| 769 | |
| 770 | #ifdef CONFIG_SMP |
| 771 | struct root_domain *rd; |
| 772 | struct sched_domain *sd; |
| 773 | |
Nicolas Pitre | ced549f | 2014-05-26 18:19:38 -0400 | [diff] [blame] | 774 | unsigned long cpu_capacity; |
Vincent Guittot | ca6d75e | 2015-02-27 16:54:09 +0100 | [diff] [blame] | 775 | unsigned long cpu_capacity_orig; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 776 | |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 777 | struct callback_head *balance_callback; |
| 778 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 779 | unsigned char idle_balance; |
| 780 | /* For active balancing */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 781 | int active_balance; |
| 782 | int push_cpu; |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 783 | struct task_struct *push_task; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 784 | struct cpu_stop_work active_balance_work; |
| 785 | /* cpu of this runqueue: */ |
| 786 | int cpu; |
| 787 | int online; |
| 788 | |
Peter Zijlstra | 367456c | 2012-02-20 21:49:09 +0100 | [diff] [blame] | 789 | struct list_head cfs_tasks; |
| 790 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 791 | u64 rt_avg; |
| 792 | u64 age_stamp; |
| 793 | u64 idle_stamp; |
| 794 | u64 avg_idle; |
Jason Low | 9bd721c | 2013-09-13 11:26:52 -0700 | [diff] [blame] | 795 | |
| 796 | /* This is used to determine avg_idle's max value */ |
| 797 | u64 max_idle_balance_cost; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 798 | #endif |
| 799 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 800 | #ifdef CONFIG_SCHED_WALT |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 801 | struct sched_cluster *cluster; |
| 802 | struct cpumask freq_domain_cpumask; |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 803 | struct walt_sched_stats walt_stats; |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 804 | |
| 805 | int cstate, wakeup_latency, wakeup_energy; |
| 806 | u64 window_start; |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 807 | s64 cum_window_start; |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 808 | unsigned long walt_flags; |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 809 | |
| 810 | u64 cur_irqload; |
| 811 | u64 avg_irqload; |
| 812 | u64 irqload_ts; |
| 813 | unsigned int static_cpu_pwr_cost; |
| 814 | struct task_struct *ed_task; |
| 815 | struct cpu_cycle cc; |
| 816 | u64 old_busy_time, old_busy_time_group; |
| 817 | u64 old_estimated_time; |
| 818 | u64 curr_runnable_sum; |
| 819 | u64 prev_runnable_sum; |
| 820 | u64 nt_curr_runnable_sum; |
| 821 | u64 nt_prev_runnable_sum; |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 822 | u64 cum_window_demand; |
Pavankumar Kondeti | 6deb2c4 | 2017-01-09 13:56:33 +0530 | [diff] [blame] | 823 | struct group_cpu_time grp_time; |
Syed Rameez Mustafa | 59b5fb7 | 2016-05-31 16:40:45 -0700 | [diff] [blame] | 824 | struct load_subtractions load_subs[NUM_TRACKED_WINDOWS]; |
Syed Rameez Mustafa | 7ac74fc | 2016-06-07 15:18:37 -0700 | [diff] [blame] | 825 | DECLARE_BITMAP_ARRAY(top_tasks_bitmap, |
| 826 | NUM_TRACKED_WINDOWS, NUM_LOAD_INDICES); |
Syed Rameez Mustafa | 59b5fb7 | 2016-05-31 16:40:45 -0700 | [diff] [blame] | 827 | u8 *top_tasks[NUM_TRACKED_WINDOWS]; |
| 828 | u8 curr_table; |
| 829 | int prev_top; |
| 830 | int curr_top; |
Pavankumar Kondeti | 4d5dd1c | 2018-03-19 10:47:09 +0530 | [diff] [blame] | 831 | bool notif_pending; |
Vikram Mulukutla | 77ecebb | 2017-05-30 14:38:55 -0700 | [diff] [blame] | 832 | u64 last_cc_update; |
| 833 | u64 cycles; |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 834 | #endif |
| 835 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 836 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
| 837 | u64 prev_irq_time; |
| 838 | #endif |
| 839 | #ifdef CONFIG_PARAVIRT |
| 840 | u64 prev_steal_time; |
| 841 | #endif |
| 842 | #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING |
| 843 | u64 prev_steal_time_rq; |
| 844 | #endif |
| 845 | |
| 846 | /* calc_load related fields */ |
| 847 | unsigned long calc_load_update; |
| 848 | long calc_load_active; |
| 849 | |
| 850 | #ifdef CONFIG_SCHED_HRTICK |
| 851 | #ifdef CONFIG_SMP |
| 852 | int hrtick_csd_pending; |
| 853 | struct call_single_data hrtick_csd; |
| 854 | #endif |
| 855 | struct hrtimer hrtick_timer; |
| 856 | #endif |
| 857 | |
| 858 | #ifdef CONFIG_SCHEDSTATS |
| 859 | /* latency stats */ |
| 860 | struct sched_info rq_sched_info; |
| 861 | unsigned long long rq_cpu_time; |
| 862 | /* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */ |
| 863 | |
| 864 | /* sys_sched_yield() stats */ |
| 865 | unsigned int yld_count; |
| 866 | |
| 867 | /* schedule() stats */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 868 | unsigned int sched_count; |
| 869 | unsigned int sched_goidle; |
| 870 | |
| 871 | /* try_to_wake_up() stats */ |
| 872 | unsigned int ttwu_count; |
| 873 | unsigned int ttwu_local; |
Chris Redpath | 385dcec | 2017-06-03 15:03:03 +0100 | [diff] [blame] | 874 | #ifdef CONFIG_SMP |
Dietmar Eggemann | af88a16 | 2017-03-22 18:23:13 +0000 | [diff] [blame] | 875 | struct eas_stats eas_stats; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 876 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 877 | #endif |
| 878 | |
| 879 | #ifdef CONFIG_SMP |
| 880 | struct llist_head wake_list; |
| 881 | #endif |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 882 | |
| 883 | #ifdef CONFIG_CPU_IDLE |
| 884 | /* Must be inspected within a rcu lock section */ |
| 885 | struct cpuidle_state *idle_state; |
Morten Rasmussen | 0691064 | 2015-01-27 13:48:07 +0000 | [diff] [blame] | 886 | int idle_state_idx; |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 887 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 888 | }; |
| 889 | |
| 890 | static inline int cpu_of(struct rq *rq) |
| 891 | { |
| 892 | #ifdef CONFIG_SMP |
| 893 | return rq->cpu; |
| 894 | #else |
| 895 | return 0; |
| 896 | #endif |
| 897 | } |
| 898 | |
Pranith Kumar | 8b06c55 | 2014-08-13 13:28:12 -0400 | [diff] [blame] | 899 | DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 900 | |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 901 | #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu))) |
Christoph Lameter | 4a32fea | 2014-08-17 12:30:27 -0500 | [diff] [blame] | 902 | #define this_rq() this_cpu_ptr(&runqueues) |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 903 | #define task_rq(p) cpu_rq(task_cpu(p)) |
| 904 | #define cpu_curr(cpu) (cpu_rq(cpu)->curr) |
Christoph Lameter | 4a32fea | 2014-08-17 12:30:27 -0500 | [diff] [blame] | 905 | #define raw_rq() raw_cpu_ptr(&runqueues) |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 906 | |
Johannes Weiner | 089605b | 2018-10-26 15:06:19 -0700 | [diff] [blame] | 907 | extern void update_rq_clock(struct rq *rq); |
| 908 | |
Peter Zijlstra | cebde6d | 2015-01-05 11:18:10 +0100 | [diff] [blame] | 909 | static inline u64 __rq_clock_broken(struct rq *rq) |
| 910 | { |
Jason Low | 316c1608d | 2015-04-28 13:00:20 -0700 | [diff] [blame] | 911 | return READ_ONCE(rq->clock); |
Peter Zijlstra | cebde6d | 2015-01-05 11:18:10 +0100 | [diff] [blame] | 912 | } |
| 913 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 914 | static inline u64 rq_clock(struct rq *rq) |
| 915 | { |
Peter Zijlstra | cebde6d | 2015-01-05 11:18:10 +0100 | [diff] [blame] | 916 | lockdep_assert_held(&rq->lock); |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 917 | return rq->clock; |
| 918 | } |
| 919 | |
| 920 | static inline u64 rq_clock_task(struct rq *rq) |
| 921 | { |
Peter Zijlstra | cebde6d | 2015-01-05 11:18:10 +0100 | [diff] [blame] | 922 | lockdep_assert_held(&rq->lock); |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 923 | return rq->clock_task; |
| 924 | } |
| 925 | |
Peter Zijlstra | 9edfbfe | 2015-01-05 11:18:11 +0100 | [diff] [blame] | 926 | #define RQCF_REQ_SKIP 0x01 |
| 927 | #define RQCF_ACT_SKIP 0x02 |
| 928 | |
| 929 | static inline void rq_clock_skip_update(struct rq *rq, bool skip) |
| 930 | { |
| 931 | lockdep_assert_held(&rq->lock); |
| 932 | if (skip) |
| 933 | rq->clock_skip_update |= RQCF_REQ_SKIP; |
| 934 | else |
| 935 | rq->clock_skip_update &= ~RQCF_REQ_SKIP; |
| 936 | } |
| 937 | |
Matt Fleming | 5a91d73 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 938 | struct rq_flags { |
| 939 | unsigned long flags; |
| 940 | struct pin_cookie cookie; |
| 941 | }; |
| 942 | |
| 943 | static inline void rq_pin_lock(struct rq *rq, struct rq_flags *rf) |
| 944 | { |
| 945 | rf->cookie = lockdep_pin_lock(&rq->lock); |
| 946 | } |
| 947 | |
| 948 | static inline void rq_unpin_lock(struct rq *rq, struct rq_flags *rf) |
| 949 | { |
| 950 | lockdep_unpin_lock(&rq->lock, rf->cookie); |
| 951 | } |
| 952 | |
| 953 | static inline void rq_repin_lock(struct rq *rq, struct rq_flags *rf) |
| 954 | { |
| 955 | lockdep_repin_lock(&rq->lock, rf->cookie); |
| 956 | } |
| 957 | |
Johannes Weiner | 089605b | 2018-10-26 15:06:19 -0700 | [diff] [blame] | 958 | struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf) |
| 959 | __acquires(rq->lock); |
| 960 | |
| 961 | struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf) |
| 962 | __acquires(p->pi_lock) |
| 963 | __acquires(rq->lock); |
| 964 | |
| 965 | static inline void __task_rq_unlock(struct rq *rq, struct rq_flags *rf) |
| 966 | __releases(rq->lock) |
| 967 | { |
| 968 | rq_unpin_lock(rq, rf); |
| 969 | raw_spin_unlock(&rq->lock); |
| 970 | } |
| 971 | |
| 972 | static inline void |
| 973 | task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf) |
| 974 | __releases(rq->lock) |
| 975 | __releases(p->pi_lock) |
| 976 | { |
| 977 | rq_unpin_lock(rq, rf); |
| 978 | raw_spin_unlock(&rq->lock); |
| 979 | raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags); |
| 980 | } |
| 981 | |
| 982 | static inline void |
| 983 | rq_lock_irqsave(struct rq *rq, struct rq_flags *rf) |
| 984 | __acquires(rq->lock) |
| 985 | { |
| 986 | raw_spin_lock_irqsave(&rq->lock, rf->flags); |
| 987 | rq_pin_lock(rq, rf); |
| 988 | } |
| 989 | |
| 990 | static inline void |
| 991 | rq_lock_irq(struct rq *rq, struct rq_flags *rf) |
| 992 | __acquires(rq->lock) |
| 993 | { |
| 994 | raw_spin_lock_irq(&rq->lock); |
| 995 | rq_pin_lock(rq, rf); |
| 996 | } |
| 997 | |
| 998 | static inline void |
| 999 | rq_lock(struct rq *rq, struct rq_flags *rf) |
| 1000 | __acquires(rq->lock) |
| 1001 | { |
| 1002 | raw_spin_lock(&rq->lock); |
| 1003 | rq_pin_lock(rq, rf); |
| 1004 | } |
| 1005 | |
| 1006 | static inline void |
| 1007 | rq_relock(struct rq *rq, struct rq_flags *rf) |
| 1008 | __acquires(rq->lock) |
| 1009 | { |
| 1010 | raw_spin_lock(&rq->lock); |
| 1011 | rq_repin_lock(rq, rf); |
| 1012 | } |
| 1013 | |
| 1014 | static inline void |
| 1015 | rq_unlock_irqrestore(struct rq *rq, struct rq_flags *rf) |
| 1016 | __releases(rq->lock) |
| 1017 | { |
| 1018 | rq_unpin_lock(rq, rf); |
| 1019 | raw_spin_unlock_irqrestore(&rq->lock, rf->flags); |
| 1020 | } |
| 1021 | |
| 1022 | static inline void |
| 1023 | rq_unlock_irq(struct rq *rq, struct rq_flags *rf) |
| 1024 | __releases(rq->lock) |
| 1025 | { |
| 1026 | rq_unpin_lock(rq, rf); |
| 1027 | raw_spin_unlock_irq(&rq->lock); |
| 1028 | } |
| 1029 | |
| 1030 | static inline void |
| 1031 | rq_unlock(struct rq *rq, struct rq_flags *rf) |
| 1032 | __releases(rq->lock) |
| 1033 | { |
| 1034 | rq_unpin_lock(rq, rf); |
| 1035 | raw_spin_unlock(&rq->lock); |
| 1036 | } |
| 1037 | |
Johannes Weiner | 6a99eb1 | 2018-10-26 15:06:23 -0700 | [diff] [blame] | 1038 | static inline struct rq * |
| 1039 | this_rq_lock_irq(struct rq_flags *rf) |
| 1040 | __acquires(rq->lock) |
| 1041 | { |
| 1042 | struct rq *rq; |
| 1043 | |
| 1044 | local_irq_disable(); |
| 1045 | rq = this_rq(); |
| 1046 | rq_lock(rq, rf); |
| 1047 | return rq; |
| 1048 | } |
| 1049 | |
Rik van Riel | 9942f79 | 2014-10-17 03:29:49 -0400 | [diff] [blame] | 1050 | #ifdef CONFIG_NUMA |
Rik van Riel | e3fe70b | 2014-10-17 03:29:50 -0400 | [diff] [blame] | 1051 | enum numa_topology_type { |
| 1052 | NUMA_DIRECT, |
| 1053 | NUMA_GLUELESS_MESH, |
| 1054 | NUMA_BACKPLANE, |
| 1055 | }; |
| 1056 | extern enum numa_topology_type sched_numa_topology_type; |
Rik van Riel | 9942f79 | 2014-10-17 03:29:49 -0400 | [diff] [blame] | 1057 | extern int sched_max_numa_distance; |
| 1058 | extern bool find_numa_distance(int distance); |
| 1059 | #endif |
| 1060 | |
Mel Gorman | f809ca9 | 2013-10-07 11:28:57 +0100 | [diff] [blame] | 1061 | #ifdef CONFIG_NUMA_BALANCING |
Iulia Manda | 44dba3d | 2014-10-31 02:13:31 +0200 | [diff] [blame] | 1062 | /* The regions in numa_faults array from task_struct */ |
| 1063 | enum numa_faults_stats { |
| 1064 | NUMA_MEM = 0, |
| 1065 | NUMA_CPU, |
| 1066 | NUMA_MEMBUF, |
| 1067 | NUMA_CPUBUF |
| 1068 | }; |
Peter Zijlstra | 0ec8aa0 | 2013-10-07 11:29:33 +0100 | [diff] [blame] | 1069 | extern void sched_setnuma(struct task_struct *p, int node); |
Mel Gorman | e6628d5 | 2013-10-07 11:29:02 +0100 | [diff] [blame] | 1070 | extern int migrate_task_to(struct task_struct *p, int cpu); |
Mel Gorman | f809ca9 | 2013-10-07 11:28:57 +0100 | [diff] [blame] | 1071 | #endif /* CONFIG_NUMA_BALANCING */ |
Pavankumar Kondeti | 4e13d11 | 2018-01-25 01:12:08 +0530 | [diff] [blame] | 1072 | extern int migrate_swap(struct task_struct *cur, struct task_struct *p); |
Mel Gorman | f809ca9 | 2013-10-07 11:28:57 +0100 | [diff] [blame] | 1073 | |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1074 | #ifdef CONFIG_SMP |
| 1075 | |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 1076 | static inline void |
| 1077 | queue_balance_callback(struct rq *rq, |
| 1078 | struct callback_head *head, |
| 1079 | void (*func)(struct rq *rq)) |
| 1080 | { |
| 1081 | lockdep_assert_held(&rq->lock); |
| 1082 | |
| 1083 | if (unlikely(head->next)) |
| 1084 | return; |
| 1085 | |
| 1086 | head->func = (void (*)(struct callback_head *))func; |
| 1087 | head->next = rq->balance_callback; |
| 1088 | rq->balance_callback = head; |
| 1089 | } |
| 1090 | |
Peter Zijlstra | e3baac4 | 2014-06-04 10:31:18 -0700 | [diff] [blame] | 1091 | extern void sched_ttwu_pending(void); |
| 1092 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1093 | #define rcu_dereference_check_sched_domain(p) \ |
| 1094 | rcu_dereference_check((p), \ |
| 1095 | lockdep_is_held(&sched_domains_mutex)) |
| 1096 | |
| 1097 | /* |
| 1098 | * The domain tree (rq->sd) is protected by RCU's quiescent state transition. |
| 1099 | * See detach_destroy_domains: synchronize_sched for details. |
| 1100 | * |
| 1101 | * The domain tree of any CPU may only be accessed from within |
| 1102 | * preempt-disabled sections. |
| 1103 | */ |
| 1104 | #define for_each_domain(cpu, __sd) \ |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1105 | for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \ |
| 1106 | __sd; __sd = __sd->parent) |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1107 | |
Suresh Siddha | 77e8136 | 2011-11-17 11:08:23 -0800 | [diff] [blame] | 1108 | #define for_each_lower_domain(sd) for (; sd; sd = sd->child) |
| 1109 | |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1110 | /** |
| 1111 | * highest_flag_domain - Return highest sched_domain containing flag. |
| 1112 | * @cpu: The cpu whose highest level of sched domain is to |
| 1113 | * be returned. |
| 1114 | * @flag: The flag to check for the highest sched_domain |
| 1115 | * for the given cpu. |
| 1116 | * |
| 1117 | * Returns the highest sched_domain of a cpu which contains the given flag. |
| 1118 | */ |
| 1119 | static inline struct sched_domain *highest_flag_domain(int cpu, int flag) |
| 1120 | { |
| 1121 | struct sched_domain *sd, *hsd = NULL; |
| 1122 | |
| 1123 | for_each_domain(cpu, sd) { |
| 1124 | if (!(sd->flags & flag)) |
| 1125 | break; |
| 1126 | hsd = sd; |
| 1127 | } |
| 1128 | |
| 1129 | return hsd; |
| 1130 | } |
| 1131 | |
Mel Gorman | fb13c7e | 2013-10-07 11:29:17 +0100 | [diff] [blame] | 1132 | static inline struct sched_domain *lowest_flag_domain(int cpu, int flag) |
| 1133 | { |
| 1134 | struct sched_domain *sd; |
| 1135 | |
| 1136 | for_each_domain(cpu, sd) { |
| 1137 | if (sd->flags & flag) |
| 1138 | break; |
| 1139 | } |
| 1140 | |
| 1141 | return sd; |
| 1142 | } |
| 1143 | |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1144 | DECLARE_PER_CPU(struct sched_domain *, sd_llc); |
Peter Zijlstra | 7d9ffa8 | 2013-07-04 12:56:46 +0800 | [diff] [blame] | 1145 | DECLARE_PER_CPU(int, sd_llc_size); |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1146 | DECLARE_PER_CPU(int, sd_llc_id); |
Peter Zijlstra | 0e369d7 | 2016-05-09 10:38:01 +0200 | [diff] [blame] | 1147 | DECLARE_PER_CPU(struct sched_domain_shared *, sd_llc_shared); |
Mel Gorman | fb13c7e | 2013-10-07 11:29:17 +0100 | [diff] [blame] | 1148 | DECLARE_PER_CPU(struct sched_domain *, sd_numa); |
Preeti U Murthy | 37dc6b5 | 2013-10-30 08:42:52 +0530 | [diff] [blame] | 1149 | DECLARE_PER_CPU(struct sched_domain *, sd_asym); |
Morten Rasmussen | 30786a0 | 2015-01-02 17:08:52 +0000 | [diff] [blame] | 1150 | DECLARE_PER_CPU(struct sched_domain *, sd_ea); |
Morten Rasmussen | 61bf625 | 2014-12-18 14:47:18 +0000 | [diff] [blame] | 1151 | DECLARE_PER_CPU(struct sched_domain *, sd_scs); |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1152 | |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1153 | struct sched_group_capacity { |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1154 | atomic_t ref; |
| 1155 | /* |
Yuyang Du | 172895e | 2016-04-05 12:12:27 +0800 | [diff] [blame] | 1156 | * CPU capacity of this group, SCHED_CAPACITY_SCALE being max capacity |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1157 | * for a single CPU. |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1158 | */ |
Morten Rasmussen | 5cdeb5f | 2016-02-25 12:43:49 +0000 | [diff] [blame] | 1159 | unsigned long capacity; |
| 1160 | unsigned long max_capacity; /* Max per-cpu capacity in group */ |
Morten Rasmussen | 3d8cb90 | 2016-10-14 14:41:09 +0100 | [diff] [blame] | 1161 | unsigned long min_capacity; /* Min per-CPU capacity in group */ |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1162 | unsigned long next_update; |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1163 | int imbalance; /* XXX unrelated to capacity but shared group state */ |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1164 | |
| 1165 | unsigned long cpumask[0]; /* iteration mask */ |
| 1166 | }; |
| 1167 | |
| 1168 | struct sched_group { |
| 1169 | struct sched_group *next; /* Must be a circular list */ |
| 1170 | atomic_t ref; |
| 1171 | |
| 1172 | unsigned int group_weight; |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1173 | struct sched_group_capacity *sgc; |
Greg Hackmann | 2a3c6e6 | 2017-03-07 10:37:56 -0800 | [diff] [blame] | 1174 | const struct sched_group_energy *sge; |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1175 | |
| 1176 | /* |
| 1177 | * The CPUs this group covers. |
| 1178 | * |
| 1179 | * NOTE: this field is variable length. (Allocated dynamically |
| 1180 | * by attaching extra space to the end of the structure, |
| 1181 | * depending on how many CPUs the kernel has booted up with) |
| 1182 | */ |
| 1183 | unsigned long cpumask[0]; |
| 1184 | }; |
| 1185 | |
| 1186 | static inline struct cpumask *sched_group_cpus(struct sched_group *sg) |
| 1187 | { |
| 1188 | return to_cpumask(sg->cpumask); |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | * cpumask masking which cpus in the group are allowed to iterate up the domain |
| 1193 | * tree. |
| 1194 | */ |
| 1195 | static inline struct cpumask *sched_group_mask(struct sched_group *sg) |
| 1196 | { |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1197 | return to_cpumask(sg->sgc->cpumask); |
Li Zefan | 5e6521e | 2013-03-05 16:06:23 +0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * group_first_cpu - Returns the first cpu in the cpumask of a sched_group. |
| 1202 | * @group: The group whose first cpu is to be returned. |
| 1203 | */ |
| 1204 | static inline unsigned int group_first_cpu(struct sched_group *group) |
| 1205 | { |
| 1206 | return cpumask_first(sched_group_cpus(group)); |
| 1207 | } |
| 1208 | |
Peter Zijlstra | c117487 | 2012-05-31 14:47:33 +0200 | [diff] [blame] | 1209 | extern int group_balance_cpu(struct sched_group *sg); |
| 1210 | |
Steven Rostedt (Red Hat) | 3866e84 | 2016-02-22 16:26:51 -0500 | [diff] [blame] | 1211 | #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL) |
| 1212 | void register_sched_domain_sysctl(void); |
| 1213 | void unregister_sched_domain_sysctl(void); |
| 1214 | #else |
| 1215 | static inline void register_sched_domain_sysctl(void) |
| 1216 | { |
| 1217 | } |
| 1218 | static inline void unregister_sched_domain_sysctl(void) |
| 1219 | { |
| 1220 | } |
| 1221 | #endif |
| 1222 | |
Peter Zijlstra | e3baac4 | 2014-06-04 10:31:18 -0700 | [diff] [blame] | 1223 | #else |
| 1224 | |
| 1225 | static inline void sched_ttwu_pending(void) { } |
| 1226 | |
Peter Zijlstra | 518cd62 | 2011-12-07 15:07:31 +0100 | [diff] [blame] | 1227 | #endif /* CONFIG_SMP */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1228 | |
Peter Zijlstra | 391e43d | 2011-11-15 17:14:39 +0100 | [diff] [blame] | 1229 | #include "stats.h" |
| 1230 | #include "auto_group.h" |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1231 | |
Pavankumar Kondeti | cbf7ea0 | 2017-01-11 15:11:23 +0530 | [diff] [blame] | 1232 | enum sched_boost_policy { |
| 1233 | SCHED_BOOST_NONE, |
| 1234 | SCHED_BOOST_ON_BIG, |
| 1235 | SCHED_BOOST_ON_ALL, |
| 1236 | }; |
| 1237 | |
Pavankumar Kondeti | 39f8279 | 2018-04-03 14:45:06 +0530 | [diff] [blame] | 1238 | #define NO_BOOST 0 |
| 1239 | #define FULL_THROTTLE_BOOST 1 |
| 1240 | #define CONSERVATIVE_BOOST 2 |
| 1241 | #define RESTRAINED_BOOST 3 |
| 1242 | |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 1243 | /* |
| 1244 | * Returns the rq capacity of any rq in a group. This does not play |
| 1245 | * well with groups where rq capacity can change independently. |
| 1246 | */ |
| 1247 | #define group_rq_capacity(group) cpu_capacity(group_first_cpu(group)) |
| 1248 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1249 | #ifdef CONFIG_CGROUP_SCHED |
| 1250 | |
| 1251 | /* |
| 1252 | * Return the group to which this tasks belongs. |
| 1253 | * |
Tejun Heo | 8af01f5 | 2013-08-08 20:11:22 -0400 | [diff] [blame] | 1254 | * We cannot use task_css() and friends because the cgroup subsystem |
| 1255 | * changes that value before the cgroup_subsys::attach() method is called, |
| 1256 | * therefore we cannot pin it and might observe the wrong value. |
Peter Zijlstra | 8323f26 | 2012-06-22 13:36:05 +0200 | [diff] [blame] | 1257 | * |
| 1258 | * The same is true for autogroup's p->signal->autogroup->tg, the autogroup |
| 1259 | * core changes this before calling sched_move_task(). |
| 1260 | * |
| 1261 | * Instead we use a 'copy' which is updated from sched_move_task() while |
| 1262 | * holding both task_struct::pi_lock and rq::lock. |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1263 | */ |
| 1264 | static inline struct task_group *task_group(struct task_struct *p) |
| 1265 | { |
Peter Zijlstra | 8323f26 | 2012-06-22 13:36:05 +0200 | [diff] [blame] | 1266 | return p->sched_task_group; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */ |
| 1270 | static inline void set_task_rq(struct task_struct *p, unsigned int cpu) |
| 1271 | { |
| 1272 | #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED) |
| 1273 | struct task_group *tg = task_group(p); |
| 1274 | #endif |
| 1275 | |
| 1276 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Byungchul Park | ad936d8 | 2015-10-24 01:16:19 +0900 | [diff] [blame] | 1277 | set_task_rq_fair(&p->se, p->se.cfs_rq, tg->cfs_rq[cpu]); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1278 | p->se.cfs_rq = tg->cfs_rq[cpu]; |
| 1279 | p->se.parent = tg->se[cpu]; |
| 1280 | #endif |
| 1281 | |
| 1282 | #ifdef CONFIG_RT_GROUP_SCHED |
| 1283 | p->rt.rt_rq = tg->rt_rq[cpu]; |
| 1284 | p->rt.parent = tg->rt_se[cpu]; |
| 1285 | #endif |
| 1286 | } |
| 1287 | |
| 1288 | #else /* CONFIG_CGROUP_SCHED */ |
| 1289 | |
| 1290 | static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { } |
| 1291 | static inline struct task_group *task_group(struct task_struct *p) |
| 1292 | { |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | |
| 1296 | #endif /* CONFIG_CGROUP_SCHED */ |
| 1297 | |
| 1298 | static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) |
| 1299 | { |
| 1300 | set_task_rq(p, cpu); |
| 1301 | #ifdef CONFIG_SMP |
| 1302 | /* |
| 1303 | * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be |
| 1304 | * successfuly executed on another CPU. We must ensure that updates of |
| 1305 | * per-task data have been completed by this moment. |
| 1306 | */ |
| 1307 | smp_wmb(); |
Andy Lutomirski | c65eacb | 2016-09-13 14:29:24 -0700 | [diff] [blame] | 1308 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
| 1309 | p->cpu = cpu; |
| 1310 | #else |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1311 | task_thread_info(p)->cpu = cpu; |
Andy Lutomirski | c65eacb | 2016-09-13 14:29:24 -0700 | [diff] [blame] | 1312 | #endif |
Peter Zijlstra | ac66f54 | 2013-10-07 11:29:16 +0100 | [diff] [blame] | 1313 | p->wake_cpu = cpu; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1314 | #endif |
| 1315 | } |
| 1316 | |
| 1317 | /* |
| 1318 | * Tunables that become constants when CONFIG_SCHED_DEBUG is off: |
| 1319 | */ |
| 1320 | #ifdef CONFIG_SCHED_DEBUG |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 1321 | # include <linux/static_key.h> |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1322 | # define const_debug __read_mostly |
| 1323 | #else |
| 1324 | # define const_debug const |
| 1325 | #endif |
| 1326 | |
| 1327 | extern const_debug unsigned int sysctl_sched_features; |
| 1328 | |
| 1329 | #define SCHED_FEAT(name, enabled) \ |
| 1330 | __SCHED_FEAT_##name , |
| 1331 | |
| 1332 | enum { |
Peter Zijlstra | 391e43d | 2011-11-15 17:14:39 +0100 | [diff] [blame] | 1333 | #include "features.h" |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1334 | __SCHED_FEAT_NR, |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1335 | }; |
| 1336 | |
| 1337 | #undef SCHED_FEAT |
| 1338 | |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1339 | #if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL) |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1340 | #define SCHED_FEAT(name, enabled) \ |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 1341 | static __always_inline bool static_branch_##name(struct static_key *key) \ |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1342 | { \ |
Jason Baron | 6e76ea8 | 2014-07-02 15:52:41 +0000 | [diff] [blame] | 1343 | return static_key_##enabled(key); \ |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | #include "features.h" |
| 1347 | |
| 1348 | #undef SCHED_FEAT |
| 1349 | |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 1350 | extern struct static_key sched_feat_keys[__SCHED_FEAT_NR]; |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1351 | #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x])) |
| 1352 | #else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */ |
Peter Zijlstra | e3a0242 | 2018-08-29 11:45:21 +0200 | [diff] [blame] | 1353 | #define sched_feat(x) !!(sysctl_sched_features & (1UL << __SCHED_FEAT_##x)) |
Peter Zijlstra | f8b6d1c | 2011-07-06 14:20:14 +0200 | [diff] [blame] | 1354 | #endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1355 | |
Srikar Dronamraju | 2a59572 | 2015-08-11 21:54:21 +0530 | [diff] [blame] | 1356 | extern struct static_key_false sched_numa_balancing; |
Mel Gorman | cb25176 | 2016-02-05 09:08:36 +0000 | [diff] [blame] | 1357 | extern struct static_key_false sched_schedstats; |
Peter Zijlstra | cbee9f8 | 2012-10-25 14:16:43 +0200 | [diff] [blame] | 1358 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1359 | static inline u64 global_rt_period(void) |
| 1360 | { |
| 1361 | return (u64)sysctl_sched_rt_period * NSEC_PER_USEC; |
| 1362 | } |
| 1363 | |
| 1364 | static inline u64 global_rt_runtime(void) |
| 1365 | { |
| 1366 | if (sysctl_sched_rt_runtime < 0) |
| 1367 | return RUNTIME_INF; |
| 1368 | |
| 1369 | return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; |
| 1370 | } |
| 1371 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1372 | static inline int task_current(struct rq *rq, struct task_struct *p) |
| 1373 | { |
| 1374 | return rq->curr == p; |
| 1375 | } |
| 1376 | |
| 1377 | static inline int task_running(struct rq *rq, struct task_struct *p) |
| 1378 | { |
| 1379 | #ifdef CONFIG_SMP |
| 1380 | return p->on_cpu; |
| 1381 | #else |
| 1382 | return task_current(rq, p); |
| 1383 | #endif |
| 1384 | } |
| 1385 | |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1386 | static inline int task_on_rq_queued(struct task_struct *p) |
| 1387 | { |
| 1388 | return p->on_rq == TASK_ON_RQ_QUEUED; |
| 1389 | } |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1390 | |
Kirill Tkhai | cca26e8 | 2014-08-20 13:47:42 +0400 | [diff] [blame] | 1391 | static inline int task_on_rq_migrating(struct task_struct *p) |
| 1392 | { |
| 1393 | return p->on_rq == TASK_ON_RQ_MIGRATING; |
| 1394 | } |
| 1395 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1396 | #ifndef prepare_arch_switch |
| 1397 | # define prepare_arch_switch(next) do { } while (0) |
| 1398 | #endif |
Catalin Marinas | 01f23e1 | 2011-11-27 21:43:10 +0000 | [diff] [blame] | 1399 | #ifndef finish_arch_post_lock_switch |
| 1400 | # define finish_arch_post_lock_switch() do { } while (0) |
| 1401 | #endif |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1402 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1403 | static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next) |
| 1404 | { |
| 1405 | #ifdef CONFIG_SMP |
| 1406 | /* |
| 1407 | * We can optimise this out completely for !SMP, because the |
| 1408 | * SMP rebalancing from interrupt is the only thing that cares |
| 1409 | * here. |
| 1410 | */ |
| 1411 | next->on_cpu = 1; |
| 1412 | #endif |
| 1413 | } |
| 1414 | |
| 1415 | static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev) |
| 1416 | { |
| 1417 | #ifdef CONFIG_SMP |
| 1418 | /* |
| 1419 | * After ->on_cpu is cleared, the task can be moved to a different CPU. |
| 1420 | * We must ensure this doesn't happen until the switch is completely |
| 1421 | * finished. |
Peter Zijlstra | 95913d9 | 2015-09-29 14:45:09 +0200 | [diff] [blame] | 1422 | * |
Peter Zijlstra | b75a225 | 2015-10-06 14:36:17 +0200 | [diff] [blame] | 1423 | * In particular, the load of prev->state in finish_task_switch() must |
| 1424 | * happen before this. |
| 1425 | * |
Peter Zijlstra | 1f03e8d | 2016-04-04 10:57:12 +0200 | [diff] [blame] | 1426 | * Pairs with the smp_cond_load_acquire() in try_to_wake_up(). |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1427 | */ |
Peter Zijlstra | 95913d9 | 2015-09-29 14:45:09 +0200 | [diff] [blame] | 1428 | smp_store_release(&prev->on_cpu, 0); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1429 | #endif |
| 1430 | #ifdef CONFIG_DEBUG_SPINLOCK |
| 1431 | /* this is a valid case when another task releases the spinlock */ |
| 1432 | rq->lock.owner = current; |
| 1433 | #endif |
| 1434 | /* |
| 1435 | * If we are tracking spinlock dependencies then we have to |
| 1436 | * fix up the runqueue lock - which gets 'carried over' from |
| 1437 | * prev into current: |
| 1438 | */ |
| 1439 | spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_); |
| 1440 | |
| 1441 | raw_spin_unlock_irq(&rq->lock); |
| 1442 | } |
| 1443 | |
Li Zefan | b13095f | 2013-03-05 16:06:38 +0800 | [diff] [blame] | 1444 | /* |
| 1445 | * wake flags |
| 1446 | */ |
| 1447 | #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */ |
| 1448 | #define WF_FORK 0x02 /* child wakeup after fork */ |
| 1449 | #define WF_MIGRATED 0x4 /* internal use, task got migrated */ |
| 1450 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1451 | /* |
| 1452 | * To aid in avoiding the subversion of "niceness" due to uneven distribution |
| 1453 | * of tasks with abnormal "nice" values across CPUs the contribution that |
| 1454 | * each task makes to its run queue's load is weighted according to its |
| 1455 | * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a |
| 1456 | * scaled version of the new time slice allocation that they receive on time |
| 1457 | * slice expiry etc. |
| 1458 | */ |
| 1459 | |
| 1460 | #define WEIGHT_IDLEPRIO 3 |
| 1461 | #define WMULT_IDLEPRIO 1431655765 |
| 1462 | |
Andi Kleen | ed82b8a | 2015-11-29 20:59:43 -0800 | [diff] [blame] | 1463 | extern const int sched_prio_to_weight[40]; |
| 1464 | extern const u32 sched_prio_to_wmult[40]; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1465 | |
Peter Zijlstra | ff77e46 | 2016-01-18 15:27:07 +0100 | [diff] [blame] | 1466 | /* |
| 1467 | * {de,en}queue flags: |
| 1468 | * |
| 1469 | * DEQUEUE_SLEEP - task is no longer runnable |
| 1470 | * ENQUEUE_WAKEUP - task just became runnable |
| 1471 | * |
| 1472 | * SAVE/RESTORE - an otherwise spurious dequeue/enqueue, done to ensure tasks |
| 1473 | * are in a known state which allows modification. Such pairs |
| 1474 | * should preserve as much state as possible. |
| 1475 | * |
| 1476 | * MOVE - paired with SAVE/RESTORE, explicitly does not preserve the location |
| 1477 | * in the runqueue. |
| 1478 | * |
| 1479 | * ENQUEUE_HEAD - place at front of runqueue (tail if not specified) |
| 1480 | * ENQUEUE_REPLENISH - CBS (replenish runtime and postpone deadline) |
Peter Zijlstra | 59efa0b | 2016-05-10 18:24:37 +0200 | [diff] [blame] | 1481 | * ENQUEUE_MIGRATED - the task was migrated during wakeup |
Peter Zijlstra | ff77e46 | 2016-01-18 15:27:07 +0100 | [diff] [blame] | 1482 | * |
| 1483 | */ |
| 1484 | |
| 1485 | #define DEQUEUE_SLEEP 0x01 |
| 1486 | #define DEQUEUE_SAVE 0x02 /* matches ENQUEUE_RESTORE */ |
| 1487 | #define DEQUEUE_MOVE 0x04 /* matches ENQUEUE_MOVE */ |
| 1488 | |
Peter Zijlstra | 1de6444 | 2015-09-30 17:44:13 +0200 | [diff] [blame] | 1489 | #define ENQUEUE_WAKEUP 0x01 |
Peter Zijlstra | ff77e46 | 2016-01-18 15:27:07 +0100 | [diff] [blame] | 1490 | #define ENQUEUE_RESTORE 0x02 |
| 1491 | #define ENQUEUE_MOVE 0x04 |
| 1492 | |
| 1493 | #define ENQUEUE_HEAD 0x08 |
| 1494 | #define ENQUEUE_REPLENISH 0x10 |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1495 | #ifdef CONFIG_SMP |
Peter Zijlstra | 59efa0b | 2016-05-10 18:24:37 +0200 | [diff] [blame] | 1496 | #define ENQUEUE_MIGRATED 0x20 |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1497 | #else |
Peter Zijlstra | 59efa0b | 2016-05-10 18:24:37 +0200 | [diff] [blame] | 1498 | #define ENQUEUE_MIGRATED 0x00 |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1499 | #endif |
Juri Lelli | 43aac89 | 2015-06-26 12:14:23 +0100 | [diff] [blame] | 1500 | #define ENQUEUE_WAKEUP_NEW 0x40 |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1501 | |
Peter Zijlstra | 37e117c | 2014-02-14 12:25:08 +0100 | [diff] [blame] | 1502 | #define RETRY_TASK ((void *)-1UL) |
| 1503 | |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1504 | struct sched_class { |
| 1505 | const struct sched_class *next; |
| 1506 | |
| 1507 | void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags); |
| 1508 | void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags); |
| 1509 | void (*yield_task) (struct rq *rq); |
| 1510 | bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt); |
| 1511 | |
| 1512 | void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); |
| 1513 | |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1514 | /* |
| 1515 | * It is the responsibility of the pick_next_task() method that will |
| 1516 | * return the next task to call put_prev_task() on the @prev task or |
| 1517 | * something equivalent. |
Peter Zijlstra | 37e117c | 2014-02-14 12:25:08 +0100 | [diff] [blame] | 1518 | * |
| 1519 | * May return RETRY_TASK when it finds a higher prio class has runnable |
| 1520 | * tasks. |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1521 | */ |
| 1522 | struct task_struct * (*pick_next_task) (struct rq *rq, |
Peter Zijlstra | e7904a2 | 2015-08-01 19:25:08 +0200 | [diff] [blame] | 1523 | struct task_struct *prev, |
Matt Fleming | 5a91d73 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 1524 | struct rq_flags *rf); |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1525 | void (*put_prev_task) (struct rq *rq, struct task_struct *p); |
| 1526 | |
| 1527 | #ifdef CONFIG_SMP |
Peter Zijlstra | ac66f54 | 2013-10-07 11:29:16 +0100 | [diff] [blame] | 1528 | int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags); |
xiaofeng.yan | 5a4fd03 | 2015-09-23 14:55:59 +0800 | [diff] [blame] | 1529 | void (*migrate_task_rq)(struct task_struct *p); |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1530 | |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1531 | void (*task_woken) (struct rq *this_rq, struct task_struct *task); |
| 1532 | |
| 1533 | void (*set_cpus_allowed)(struct task_struct *p, |
| 1534 | const struct cpumask *newmask); |
| 1535 | |
| 1536 | void (*rq_online)(struct rq *rq); |
| 1537 | void (*rq_offline)(struct rq *rq); |
| 1538 | #endif |
| 1539 | |
| 1540 | void (*set_curr_task) (struct rq *rq); |
| 1541 | void (*task_tick) (struct rq *rq, struct task_struct *p, int queued); |
| 1542 | void (*task_fork) (struct task_struct *p); |
Dario Faggioli | e6c390f | 2013-11-07 14:43:35 +0100 | [diff] [blame] | 1543 | void (*task_dead) (struct task_struct *p); |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1544 | |
Kirill Tkhai | 67dfa1b | 2014-10-27 17:40:52 +0300 | [diff] [blame] | 1545 | /* |
| 1546 | * The switched_from() call is allowed to drop rq->lock, therefore we |
| 1547 | * cannot assume the switched_from/switched_to pair is serliazed by |
| 1548 | * rq->lock. They are however serialized by p->pi_lock. |
| 1549 | */ |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1550 | void (*switched_from) (struct rq *this_rq, struct task_struct *task); |
| 1551 | void (*switched_to) (struct rq *this_rq, struct task_struct *task); |
| 1552 | void (*prio_changed) (struct rq *this_rq, struct task_struct *task, |
| 1553 | int oldprio); |
| 1554 | |
| 1555 | unsigned int (*get_rr_interval) (struct rq *rq, |
| 1556 | struct task_struct *task); |
| 1557 | |
Stanislaw Gruszka | 6e99891 | 2014-11-12 16:58:44 +0100 | [diff] [blame] | 1558 | void (*update_curr) (struct rq *rq); |
| 1559 | |
Vincent Guittot | ea86cb4 | 2016-06-17 13:38:55 +0200 | [diff] [blame] | 1560 | #define TASK_SET_GROUP 0 |
| 1561 | #define TASK_MOVE_GROUP 1 |
| 1562 | |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1563 | #ifdef CONFIG_FAIR_GROUP_SCHED |
Vincent Guittot | ea86cb4 | 2016-06-17 13:38:55 +0200 | [diff] [blame] | 1564 | void (*task_change_group) (struct task_struct *p, int type); |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1565 | #endif |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 1566 | #ifdef CONFIG_SCHED_WALT |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 1567 | void (*fixup_walt_sched_stats)(struct rq *rq, struct task_struct *p, |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 1568 | u32 new_task_load, u32 new_pred_demand); |
Pavankumar Kondeti | 1c847af | 2019-09-04 10:08:32 +0530 | [diff] [blame] | 1569 | void (*fixup_cumulative_runnable_avg)(struct rq *rq, |
| 1570 | struct task_struct *task, |
| 1571 | u64 new_task_load); |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 1572 | #endif |
Li Zefan | c82ba9f | 2013-03-05 16:06:55 +0800 | [diff] [blame] | 1573 | }; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1574 | |
Peter Zijlstra | 3f1d2a3 | 2014-02-12 10:49:30 +0100 | [diff] [blame] | 1575 | static inline void put_prev_task(struct rq *rq, struct task_struct *prev) |
| 1576 | { |
| 1577 | prev->sched_class->put_prev_task(rq, prev); |
| 1578 | } |
| 1579 | |
Peter Zijlstra | b2bf6c3 | 2016-09-20 22:00:38 +0200 | [diff] [blame] | 1580 | static inline void set_curr_task(struct rq *rq, struct task_struct *curr) |
| 1581 | { |
| 1582 | curr->sched_class->set_curr_task(rq); |
| 1583 | } |
| 1584 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1585 | #define sched_class_highest (&stop_sched_class) |
| 1586 | #define for_each_class(class) \ |
| 1587 | for (class = sched_class_highest; class; class = class->next) |
| 1588 | |
| 1589 | extern const struct sched_class stop_sched_class; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1590 | extern const struct sched_class dl_sched_class; |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1591 | extern const struct sched_class rt_sched_class; |
| 1592 | extern const struct sched_class fair_sched_class; |
| 1593 | extern const struct sched_class idle_sched_class; |
| 1594 | |
| 1595 | |
| 1596 | #ifdef CONFIG_SMP |
| 1597 | |
Patrick Bellasi | 2178e84 | 2016-07-22 11:35:59 +0100 | [diff] [blame] | 1598 | extern void init_max_cpu_capacity(struct max_cpu_capacity *mcc); |
Nicolas Pitre | 63b2ca3 | 2014-05-26 18:19:37 -0400 | [diff] [blame] | 1599 | extern void update_group_capacity(struct sched_domain *sd, int cpu); |
Li Zefan | b719203 | 2013-03-07 10:00:26 +0800 | [diff] [blame] | 1600 | |
Daniel Lezcano | 7caff66 | 2014-01-06 12:34:38 +0100 | [diff] [blame] | 1601 | extern void trigger_load_balance(struct rq *rq); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1602 | |
Peter Zijlstra | c5b2803 | 2015-05-15 17:43:35 +0200 | [diff] [blame] | 1603 | extern void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask); |
| 1604 | |
Pavankumar Kondeti | 25ba1fa | 2018-01-31 16:36:39 +0530 | [diff] [blame] | 1605 | bool __cpu_overutilized(int cpu, int delta); |
Joonwoo Park | dc3420d | 2017-01-31 11:14:43 -0800 | [diff] [blame] | 1606 | bool cpu_overutilized(int cpu); |
| 1607 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1608 | #endif |
| 1609 | |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 1610 | #ifdef CONFIG_CPU_IDLE |
| 1611 | static inline void idle_set_state(struct rq *rq, |
| 1612 | struct cpuidle_state *idle_state) |
| 1613 | { |
| 1614 | rq->idle_state = idle_state; |
| 1615 | } |
| 1616 | |
| 1617 | static inline struct cpuidle_state *idle_get_state(struct rq *rq) |
| 1618 | { |
Peter Zijlstra | 9148a3a | 2016-09-20 22:34:51 +0200 | [diff] [blame] | 1619 | SCHED_WARN_ON(!rcu_read_lock_held()); |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 1620 | return rq->idle_state; |
| 1621 | } |
Morten Rasmussen | 0691064 | 2015-01-27 13:48:07 +0000 | [diff] [blame] | 1622 | |
| 1623 | static inline void idle_set_state_idx(struct rq *rq, int idle_state_idx) |
| 1624 | { |
| 1625 | rq->idle_state_idx = idle_state_idx; |
| 1626 | } |
| 1627 | |
| 1628 | static inline int idle_get_state_idx(struct rq *rq) |
| 1629 | { |
| 1630 | WARN_ON(!rcu_read_lock_held()); |
Pavankumar Kondeti | c3dae85 | 2017-06-19 15:30:11 +0530 | [diff] [blame] | 1631 | |
| 1632 | if (rq->nr_running || cpu_of(rq) == raw_smp_processor_id()) |
| 1633 | return -1; |
| 1634 | |
Morten Rasmussen | 0691064 | 2015-01-27 13:48:07 +0000 | [diff] [blame] | 1635 | return rq->idle_state_idx; |
| 1636 | } |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 1637 | #else |
| 1638 | static inline void idle_set_state(struct rq *rq, |
| 1639 | struct cpuidle_state *idle_state) |
| 1640 | { |
| 1641 | } |
| 1642 | |
| 1643 | static inline struct cpuidle_state *idle_get_state(struct rq *rq) |
| 1644 | { |
| 1645 | return NULL; |
| 1646 | } |
Morten Rasmussen | 0691064 | 2015-01-27 13:48:07 +0000 | [diff] [blame] | 1647 | |
| 1648 | static inline void idle_set_state_idx(struct rq *rq, int idle_state_idx) |
| 1649 | { |
| 1650 | } |
| 1651 | |
| 1652 | static inline int idle_get_state_idx(struct rq *rq) |
| 1653 | { |
| 1654 | return -1; |
| 1655 | } |
Daniel Lezcano | 442bf3a | 2014-09-04 11:32:09 -0400 | [diff] [blame] | 1656 | #endif |
| 1657 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1658 | extern void sysrq_sched_debug_show(void); |
| 1659 | extern void sched_init_granularity(void); |
| 1660 | extern void update_max_interval(void); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1661 | |
| 1662 | extern void init_sched_dl_class(void); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1663 | extern void init_sched_rt_class(void); |
| 1664 | extern void init_sched_fair_class(void); |
| 1665 | |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 1666 | extern void resched_curr(struct rq *rq); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1667 | extern void resched_cpu(int cpu); |
| 1668 | |
| 1669 | extern struct rt_bandwidth def_rt_bandwidth; |
| 1670 | extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime); |
| 1671 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 1672 | extern struct dl_bandwidth def_dl_bandwidth; |
| 1673 | extern void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1674 | extern void init_dl_task_timer(struct sched_dl_entity *dl_se); |
| 1675 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 1676 | unsigned long to_ratio(u64 period, u64 runtime); |
| 1677 | |
Yuyang Du | 540247f | 2015-07-15 08:04:39 +0800 | [diff] [blame] | 1678 | extern void init_entity_runnable_average(struct sched_entity *se); |
Yuyang Du | 2b8c41d | 2016-03-30 04:30:56 +0800 | [diff] [blame] | 1679 | extern void post_init_entity_util_avg(struct sched_entity *se); |
Alex Shi | a75cdaa | 2013-06-20 10:18:47 +0800 | [diff] [blame] | 1680 | |
Frederic Weisbecker | 76d92ac | 2015-07-17 22:25:49 +0200 | [diff] [blame] | 1681 | #ifdef CONFIG_NO_HZ_FULL |
| 1682 | extern bool sched_can_stop_tick(struct rq *rq); |
| 1683 | |
| 1684 | /* |
| 1685 | * Tick may be needed by tasks in the runqueue depending on their policy and |
| 1686 | * requirements. If tick is needed, lets send the target an IPI to kick it out of |
| 1687 | * nohz mode if necessary. |
| 1688 | */ |
| 1689 | static inline void sched_update_tick_dependency(struct rq *rq) |
| 1690 | { |
| 1691 | int cpu; |
| 1692 | |
| 1693 | if (!tick_nohz_full_enabled()) |
| 1694 | return; |
| 1695 | |
| 1696 | cpu = cpu_of(rq); |
| 1697 | |
| 1698 | if (!tick_nohz_full_cpu(cpu)) |
| 1699 | return; |
| 1700 | |
| 1701 | if (sched_can_stop_tick(rq)) |
| 1702 | tick_nohz_dep_clear_cpu(cpu, TICK_DEP_BIT_SCHED); |
| 1703 | else |
| 1704 | tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED); |
| 1705 | } |
| 1706 | #else |
| 1707 | static inline void sched_update_tick_dependency(struct rq *rq) { } |
| 1708 | #endif |
| 1709 | |
Joseph Lo | 7750186 | 2013-04-22 14:39:18 +0800 | [diff] [blame] | 1710 | static inline void __add_nr_running(struct rq *rq, unsigned count) |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1711 | { |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1712 | unsigned prev_nr = rq->nr_running; |
| 1713 | |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 1714 | sched_update_nr_prod(cpu_of(rq), count, true); |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1715 | rq->nr_running = prev_nr + count; |
Frederic Weisbecker | 9f3660c | 2013-04-20 14:35:09 +0200 | [diff] [blame] | 1716 | |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1717 | if (prev_nr < 2 && rq->nr_running >= 2) { |
Tim Chen | 4486edd | 2014-06-23 12:16:49 -0700 | [diff] [blame] | 1718 | #ifdef CONFIG_SMP |
| 1719 | if (!rq->rd->overload) |
| 1720 | rq->rd->overload = true; |
| 1721 | #endif |
Tim Chen | 4486edd | 2014-06-23 12:16:49 -0700 | [diff] [blame] | 1722 | } |
Frederic Weisbecker | 76d92ac | 2015-07-17 22:25:49 +0200 | [diff] [blame] | 1723 | |
| 1724 | sched_update_tick_dependency(rq); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
Joseph Lo | 7750186 | 2013-04-22 14:39:18 +0800 | [diff] [blame] | 1727 | static inline void __sub_nr_running(struct rq *rq, unsigned count) |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1728 | { |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 1729 | sched_update_nr_prod(cpu_of(rq), count, false); |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1730 | rq->nr_running -= count; |
Frederic Weisbecker | 76d92ac | 2015-07-17 22:25:49 +0200 | [diff] [blame] | 1731 | /* Check if we still need preemption */ |
| 1732 | sched_update_tick_dependency(rq); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1733 | } |
| 1734 | |
Joseph Lo | 7750186 | 2013-04-22 14:39:18 +0800 | [diff] [blame] | 1735 | #ifdef CONFIG_CPU_QUIET |
| 1736 | #define NR_AVE_SCALE(x) ((x) << FSHIFT) |
| 1737 | static inline u64 do_nr_running_integral(struct rq *rq) |
| 1738 | { |
| 1739 | s64 nr, deltax; |
| 1740 | u64 nr_running_integral = rq->nr_running_integral; |
| 1741 | |
| 1742 | deltax = rq->clock_task - rq->nr_last_stamp; |
| 1743 | nr = NR_AVE_SCALE(rq->nr_running); |
| 1744 | |
| 1745 | nr_running_integral += nr * deltax; |
| 1746 | |
| 1747 | return nr_running_integral; |
| 1748 | } |
| 1749 | |
| 1750 | static inline void add_nr_running(struct rq *rq, unsigned count) |
| 1751 | { |
| 1752 | write_seqcount_begin(&rq->ave_seqcnt); |
| 1753 | rq->nr_running_integral = do_nr_running_integral(rq); |
| 1754 | rq->nr_last_stamp = rq->clock_task; |
| 1755 | __add_nr_running(rq, count); |
| 1756 | write_seqcount_end(&rq->ave_seqcnt); |
| 1757 | } |
| 1758 | |
| 1759 | static inline void sub_nr_running(struct rq *rq, unsigned count) |
| 1760 | { |
| 1761 | write_seqcount_begin(&rq->ave_seqcnt); |
| 1762 | rq->nr_running_integral = do_nr_running_integral(rq); |
| 1763 | rq->nr_last_stamp = rq->clock_task; |
| 1764 | __sub_nr_running(rq, count); |
| 1765 | write_seqcount_end(&rq->ave_seqcnt); |
| 1766 | } |
| 1767 | #else |
| 1768 | #define add_nr_running __add_nr_running |
| 1769 | #define sub_nr_running __sub_nr_running |
| 1770 | #endif |
| 1771 | |
Frederic Weisbecker | 265f22a | 2013-05-03 03:39:05 +0200 | [diff] [blame] | 1772 | static inline void rq_last_tick_reset(struct rq *rq) |
| 1773 | { |
| 1774 | #ifdef CONFIG_NO_HZ_FULL |
| 1775 | rq->last_sched_tick = jiffies; |
| 1776 | #endif |
| 1777 | } |
| 1778 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1779 | extern void activate_task(struct rq *rq, struct task_struct *p, int flags); |
| 1780 | extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags); |
| 1781 | |
| 1782 | extern void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags); |
| 1783 | |
| 1784 | extern const_debug unsigned int sysctl_sched_time_avg; |
| 1785 | extern const_debug unsigned int sysctl_sched_nr_migrate; |
| 1786 | extern const_debug unsigned int sysctl_sched_migration_cost; |
| 1787 | |
| 1788 | static inline u64 sched_avg_period(void) |
| 1789 | { |
| 1790 | return (u64)sysctl_sched_time_avg * NSEC_PER_MSEC / 2; |
| 1791 | } |
| 1792 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1793 | #ifdef CONFIG_SCHED_HRTICK |
| 1794 | |
| 1795 | /* |
| 1796 | * Use hrtick when: |
| 1797 | * - enabled by features |
| 1798 | * - hrtimer is actually high res |
| 1799 | */ |
| 1800 | static inline int hrtick_enabled(struct rq *rq) |
| 1801 | { |
| 1802 | if (!sched_feat(HRTICK)) |
| 1803 | return 0; |
| 1804 | if (!cpu_active(cpu_of(rq))) |
| 1805 | return 0; |
| 1806 | return hrtimer_is_hres_active(&rq->hrtick_timer); |
| 1807 | } |
| 1808 | |
| 1809 | void hrtick_start(struct rq *rq, u64 delay); |
| 1810 | |
Mike Galbraith | b39e66e | 2011-11-22 15:20:07 +0100 | [diff] [blame] | 1811 | #else |
| 1812 | |
| 1813 | static inline int hrtick_enabled(struct rq *rq) |
| 1814 | { |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1818 | #endif /* CONFIG_SCHED_HRTICK */ |
| 1819 | |
| 1820 | #ifdef CONFIG_SMP |
| 1821 | extern void sched_avg_update(struct rq *rq); |
Peter Zijlstra | dfbca41 | 2015-03-23 14:19:05 +0100 | [diff] [blame] | 1822 | |
| 1823 | #ifndef arch_scale_freq_capacity |
| 1824 | static __always_inline |
| 1825 | unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu) |
| 1826 | { |
| 1827 | return SCHED_CAPACITY_SCALE; |
| 1828 | } |
| 1829 | #endif |
Vincent Guittot | b5b4860 | 2015-02-27 16:54:08 +0100 | [diff] [blame] | 1830 | |
Dietmar Eggemann | 29db1b4 | 2017-07-13 09:48:42 +0100 | [diff] [blame] | 1831 | #ifndef arch_scale_max_freq_capacity |
| 1832 | static __always_inline |
| 1833 | unsigned long arch_scale_max_freq_capacity(struct sched_domain *sd, int cpu) |
| 1834 | { |
| 1835 | return SCHED_CAPACITY_SCALE; |
| 1836 | } |
| 1837 | #endif |
| 1838 | |
Ionela Voinescu | ba7a2aa | 2017-08-30 16:43:11 +0100 | [diff] [blame] | 1839 | #ifndef arch_scale_min_freq_capacity |
| 1840 | static __always_inline |
| 1841 | unsigned long arch_scale_min_freq_capacity(struct sched_domain *sd, int cpu) |
| 1842 | { |
| 1843 | /* |
| 1844 | * Multiplied with any capacity value, this scale factor will return |
| 1845 | * 0, which represents an un-capped state |
| 1846 | */ |
| 1847 | return 0; |
| 1848 | } |
| 1849 | #endif |
| 1850 | |
Morten Rasmussen | 8cd5601 | 2015-08-14 17:23:10 +0100 | [diff] [blame] | 1851 | #ifndef arch_scale_cpu_capacity |
| 1852 | static __always_inline |
| 1853 | unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu) |
| 1854 | { |
Dietmar Eggemann | e3279a2 | 2015-08-15 00:04:41 +0100 | [diff] [blame] | 1855 | if (sd && (sd->flags & SD_SHARE_CPUCAPACITY) && (sd->span_weight > 1)) |
Morten Rasmussen | 8cd5601 | 2015-08-14 17:23:10 +0100 | [diff] [blame] | 1856 | return sd->smt_gain / sd->span_weight; |
| 1857 | |
| 1858 | return SCHED_CAPACITY_SCALE; |
| 1859 | } |
| 1860 | #endif |
| 1861 | |
Joonwoo Park | 28c5121 | 2017-06-09 14:06:54 -0700 | [diff] [blame] | 1862 | #ifndef arch_update_cpu_capacity |
| 1863 | static __always_inline |
| 1864 | void arch_update_cpu_capacity(int cpu) |
| 1865 | { |
| 1866 | } |
| 1867 | #endif |
| 1868 | |
Steve Muckle | 608d494 | 2015-06-25 14:12:33 +0100 | [diff] [blame] | 1869 | #ifdef CONFIG_SMP |
| 1870 | static inline unsigned long capacity_of(int cpu) |
| 1871 | { |
| 1872 | return cpu_rq(cpu)->cpu_capacity; |
| 1873 | } |
| 1874 | |
| 1875 | static inline unsigned long capacity_orig_of(int cpu) |
| 1876 | { |
| 1877 | return cpu_rq(cpu)->cpu_capacity_orig; |
| 1878 | } |
| 1879 | |
Srivatsa Vaddagiri | 26c2154 | 2016-05-31 09:08:38 -0700 | [diff] [blame] | 1880 | extern unsigned int walt_disabled; |
| 1881 | |
Pavankumar Kondeti | 3066bc4 | 2017-08-01 15:45:31 +0530 | [diff] [blame] | 1882 | static inline unsigned long task_util(struct task_struct *p) |
| 1883 | { |
| 1884 | #ifdef CONFIG_SCHED_WALT |
| 1885 | if (!walt_disabled && sysctl_sched_use_walt_task_util) |
| 1886 | return p->ravg.demand / |
| 1887 | (sched_ravg_window >> SCHED_CAPACITY_SHIFT); |
| 1888 | #endif |
| 1889 | return p->se.avg.util_avg; |
| 1890 | } |
| 1891 | |
Steve Muckle | 608d494 | 2015-06-25 14:12:33 +0100 | [diff] [blame] | 1892 | /* |
| 1893 | * cpu_util returns the amount of capacity of a CPU that is used by CFS |
| 1894 | * tasks. The unit of the return value must be the one of capacity so we can |
| 1895 | * compare the utilization with the capacity of the CPU that is available for |
| 1896 | * CFS task (ie cpu_capacity). |
| 1897 | * |
| 1898 | * cfs_rq.avg.util_avg is the sum of running time of runnable tasks plus the |
| 1899 | * recent utilization of currently non-runnable tasks on a CPU. It represents |
| 1900 | * the amount of utilization of a CPU in the range [0..capacity_orig] where |
| 1901 | * capacity_orig is the cpu_capacity available at the highest frequency |
| 1902 | * (arch_scale_freq_capacity()). |
| 1903 | * The utilization of a CPU converges towards a sum equal to or less than the |
| 1904 | * current capacity (capacity_curr <= capacity_orig) of the CPU because it is |
| 1905 | * the running time on this CPU scaled by capacity_curr. |
| 1906 | * |
| 1907 | * Nevertheless, cfs_rq.avg.util_avg can be higher than capacity_curr or even |
| 1908 | * higher than capacity_orig because of unfortunate rounding in |
| 1909 | * cfs.avg.util_avg or just after migrating tasks and new task wakeups until |
| 1910 | * the average stabilizes with the new running time. We need to check that the |
| 1911 | * utilization stays within the range of [0..capacity_orig] and cap it if |
| 1912 | * necessary. Without utilization capping, a group could be seen as overloaded |
| 1913 | * (CPU0 utilization at 121% + CPU1 utilization at 80%) whereas CPU1 has 20% of |
| 1914 | * available capacity. We allow utilization to overshoot capacity_curr (but not |
| 1915 | * capacity_orig) as it useful for predicting the capacity required after task |
| 1916 | * migrations (scheduler-driven DVFS). |
| 1917 | */ |
| 1918 | static inline unsigned long __cpu_util(int cpu, int delta) |
| 1919 | { |
Joonwoo Park | 93a51bf | 2017-01-20 11:10:15 -0800 | [diff] [blame] | 1920 | u64 util = cpu_rq(cpu)->cfs.avg.util_avg; |
Steve Muckle | 608d494 | 2015-06-25 14:12:33 +0100 | [diff] [blame] | 1921 | unsigned long capacity = capacity_orig_of(cpu); |
| 1922 | |
Srivatsa Vaddagiri | 26c2154 | 2016-05-31 09:08:38 -0700 | [diff] [blame] | 1923 | #ifdef CONFIG_SCHED_WALT |
Amit Pundir | 102f7f4 | 2016-08-24 11:52:17 +0530 | [diff] [blame] | 1924 | if (!walt_disabled && sysctl_sched_use_walt_cpu_util) { |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 1925 | util = cpu_rq(cpu)->walt_stats.cumulative_runnable_avg; |
Joonwoo Park | 93a51bf | 2017-01-20 11:10:15 -0800 | [diff] [blame] | 1926 | util = div64_u64(util, |
| 1927 | sched_ravg_window >> SCHED_CAPACITY_SHIFT); |
Amit Pundir | 102f7f4 | 2016-08-24 11:52:17 +0530 | [diff] [blame] | 1928 | } |
Srivatsa Vaddagiri | 26c2154 | 2016-05-31 09:08:38 -0700 | [diff] [blame] | 1929 | #endif |
Steve Muckle | 608d494 | 2015-06-25 14:12:33 +0100 | [diff] [blame] | 1930 | delta += util; |
| 1931 | if (delta < 0) |
| 1932 | return 0; |
| 1933 | |
| 1934 | return (delta >= capacity) ? capacity : delta; |
| 1935 | } |
| 1936 | |
| 1937 | static inline unsigned long cpu_util(int cpu) |
| 1938 | { |
| 1939 | return __cpu_util(cpu, 0); |
| 1940 | } |
| 1941 | |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1942 | struct sched_walt_cpu_load { |
| 1943 | unsigned long prev_window_util; |
| 1944 | unsigned long nl; |
| 1945 | unsigned long pl; |
Vikram Mulukutla | a65aafe | 2017-06-05 13:37:45 -0700 | [diff] [blame] | 1946 | u64 ws; |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1947 | }; |
| 1948 | |
Joonwoo Park | e19cd6f | 2017-02-03 14:32:49 -0800 | [diff] [blame] | 1949 | static inline unsigned long cpu_util_cum(int cpu, int delta) |
| 1950 | { |
| 1951 | u64 util = cpu_rq(cpu)->cfs.avg.util_avg; |
| 1952 | unsigned long capacity = capacity_orig_of(cpu); |
| 1953 | |
| 1954 | #ifdef CONFIG_SCHED_WALT |
| 1955 | if (!walt_disabled && sysctl_sched_use_walt_cpu_util) { |
| 1956 | util = cpu_rq(cpu)->cum_window_demand; |
| 1957 | util = div64_u64(util, |
| 1958 | sched_ravg_window >> SCHED_CAPACITY_SHIFT); |
| 1959 | } |
| 1960 | #endif |
| 1961 | delta += util; |
| 1962 | if (delta < 0) |
| 1963 | return 0; |
| 1964 | |
| 1965 | return (delta >= capacity) ? capacity : delta; |
| 1966 | } |
| 1967 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1968 | #ifdef CONFIG_SCHED_WALT |
| 1969 | u64 freq_policy_load(struct rq *rq); |
| 1970 | #endif |
| 1971 | |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1972 | static inline unsigned long |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 1973 | cpu_util_freq_pelt(int cpu) |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1974 | { |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1975 | struct rq *rq = cpu_rq(cpu); |
Maria Yu | 4837b1a | 2017-09-22 16:02:01 +0800 | [diff] [blame] | 1976 | u64 util = rq->cfs.avg.util_avg; |
Joonwoo Park | 4266ccd | 2016-12-08 16:12:12 -0800 | [diff] [blame] | 1977 | unsigned long capacity = capacity_orig_of(cpu); |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1978 | |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 1979 | util *= (100 + per_cpu(sched_load_boost, cpu)); |
| 1980 | do_div(util, 100); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 1981 | |
Joonwoo Park | 4266ccd | 2016-12-08 16:12:12 -0800 | [diff] [blame] | 1982 | return (util >= capacity) ? capacity : util; |
Joonwoo Park | 19c0075 | 2017-04-27 14:37:35 -0700 | [diff] [blame] | 1983 | } |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 1984 | |
| 1985 | #ifdef CONFIG_SCHED_WALT |
Lingutla Chandrasekhar | d60cdac | 2018-05-25 15:22:59 +0530 | [diff] [blame] | 1986 | extern u64 walt_load_reported_window; |
Pavankumar Kondeti | 7fa1540 | 2018-05-08 12:15:08 +0530 | [diff] [blame] | 1987 | |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 1988 | static inline unsigned long |
| 1989 | cpu_util_freq_walt(int cpu, struct sched_walt_cpu_load *walt_load) |
| 1990 | { |
| 1991 | u64 util, util_unboosted; |
| 1992 | struct rq *rq = cpu_rq(cpu); |
| 1993 | unsigned long capacity = capacity_orig_of(cpu); |
| 1994 | int boost; |
| 1995 | |
| 1996 | if (walt_disabled || !sysctl_sched_use_walt_cpu_util) |
| 1997 | return cpu_util_freq_pelt(cpu); |
| 1998 | |
| 1999 | boost = per_cpu(sched_load_boost, cpu); |
| 2000 | util_unboosted = util = freq_policy_load(rq); |
| 2001 | util = div64_u64(util * (100 + boost), |
| 2002 | walt_cpu_util_freq_divisor); |
| 2003 | |
| 2004 | if (walt_load) { |
| 2005 | u64 nl = cpu_rq(cpu)->nt_prev_runnable_sum + |
| 2006 | rq->grp_time.nt_prev_runnable_sum; |
| 2007 | u64 pl = rq->walt_stats.pred_demands_sum; |
| 2008 | |
| 2009 | /* do_pl_notif() needs unboosted signals */ |
| 2010 | rq->old_busy_time = div64_u64(util_unboosted, |
| 2011 | sched_ravg_window >> |
| 2012 | SCHED_CAPACITY_SHIFT); |
| 2013 | rq->old_estimated_time = div64_u64(pl, sched_ravg_window >> |
| 2014 | SCHED_CAPACITY_SHIFT); |
| 2015 | |
| 2016 | nl = div64_u64(nl * (100 + boost), |
| 2017 | walt_cpu_util_freq_divisor); |
| 2018 | pl = div64_u64(pl * (100 + boost), |
| 2019 | walt_cpu_util_freq_divisor); |
| 2020 | |
| 2021 | walt_load->prev_window_util = util; |
| 2022 | walt_load->nl = nl; |
| 2023 | walt_load->pl = pl; |
Lingutla Chandrasekhar | d60cdac | 2018-05-25 15:22:59 +0530 | [diff] [blame] | 2024 | walt_load->ws = walt_load_reported_window; |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | return (util >= capacity) ? capacity : util; |
| 2028 | } |
| 2029 | |
| 2030 | static inline unsigned long |
| 2031 | cpu_util_freq(int cpu, struct sched_walt_cpu_load *walt_load) |
| 2032 | { |
| 2033 | return cpu_util_freq_walt(cpu, walt_load); |
| 2034 | } |
| 2035 | |
| 2036 | #else |
| 2037 | |
| 2038 | static inline unsigned long |
| 2039 | cpu_util_freq(int cpu, struct sched_walt_cpu_load *walt_load) |
| 2040 | { |
| 2041 | return cpu_util_freq_pelt(cpu); |
| 2042 | } |
| 2043 | |
Pavankumar Kondeti | b1bd5e3 | 2018-04-03 19:34:03 +0530 | [diff] [blame] | 2044 | #define sched_ravg_window TICK_NSEC |
| 2045 | #define sysctl_sched_use_walt_cpu_util 0 |
| 2046 | |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 2047 | #endif /* CONFIG_SCHED_WALT */ |
| 2048 | |
Pavankumar Kondeti | 12912ba | 2017-11-24 10:21:46 +0530 | [diff] [blame] | 2049 | extern unsigned long |
| 2050 | boosted_cpu_util(int cpu, struct sched_walt_cpu_load *walt_load); |
Steve Muckle | 608d494 | 2015-06-25 14:12:33 +0100 | [diff] [blame] | 2051 | #endif |
| 2052 | |
Joonwoo Park | 2ae888b | 2017-01-12 17:46:00 -0800 | [diff] [blame] | 2053 | extern unsigned int capacity_margin_freq; |
| 2054 | |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 2055 | static inline unsigned long |
| 2056 | add_capacity_margin(unsigned long cpu_capacity, int cpu) |
Joonwoo Park | 2ae888b | 2017-01-12 17:46:00 -0800 | [diff] [blame] | 2057 | { |
Joonwoo Park | 858d575 | 2017-08-21 12:09:49 -0700 | [diff] [blame] | 2058 | cpu_capacity = cpu_capacity * capacity_margin_freq * |
| 2059 | (100 + per_cpu(sched_load_boost, cpu)); |
| 2060 | cpu_capacity /= 100; |
Joonwoo Park | 2ae888b | 2017-01-12 17:46:00 -0800 | [diff] [blame] | 2061 | cpu_capacity /= SCHED_CAPACITY_SCALE; |
| 2062 | return cpu_capacity; |
| 2063 | } |
| 2064 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2065 | static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) |
| 2066 | { |
Vincent Guittot | b5b4860 | 2015-02-27 16:54:08 +0100 | [diff] [blame] | 2067 | rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq)); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2068 | } |
| 2069 | #else |
| 2070 | static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { } |
| 2071 | static inline void sched_avg_update(struct rq *rq) { } |
| 2072 | #endif |
| 2073 | |
Patrick Bellasi | d248900 | 2016-07-28 18:44:40 +0100 | [diff] [blame] | 2074 | extern struct rq *lock_rq_of(struct task_struct *p, struct rq_flags *flags); |
| 2075 | extern void unlock_rq_of(struct rq *rq, struct task_struct *p, struct rq_flags *flags); |
| 2076 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2077 | #ifdef CONFIG_SMP |
| 2078 | #ifdef CONFIG_PREEMPT |
| 2079 | |
| 2080 | static inline void double_rq_lock(struct rq *rq1, struct rq *rq2); |
| 2081 | |
| 2082 | /* |
| 2083 | * fair double_lock_balance: Safely acquires both rq->locks in a fair |
| 2084 | * way at the expense of forcing extra atomic operations in all |
| 2085 | * invocations. This assures that the double_lock is acquired using the |
| 2086 | * same underlying policy as the spinlock_t on this architecture, which |
| 2087 | * reduces latency compared to the unfair variant below. However, it |
| 2088 | * also adds more overhead and therefore may reduce throughput. |
| 2089 | */ |
| 2090 | static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest) |
| 2091 | __releases(this_rq->lock) |
| 2092 | __acquires(busiest->lock) |
| 2093 | __acquires(this_rq->lock) |
| 2094 | { |
| 2095 | raw_spin_unlock(&this_rq->lock); |
| 2096 | double_rq_lock(this_rq, busiest); |
| 2097 | |
| 2098 | return 1; |
| 2099 | } |
| 2100 | |
| 2101 | #else |
| 2102 | /* |
| 2103 | * Unfair double_lock_balance: Optimizes throughput at the expense of |
| 2104 | * latency by eliminating extra atomic operations when the locks are |
| 2105 | * already in proper order on entry. This favors lower cpu-ids and will |
| 2106 | * grant the double lock to lower cpus over higher ids under contention, |
| 2107 | * regardless of entry order into the function. |
| 2108 | */ |
| 2109 | static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest) |
| 2110 | __releases(this_rq->lock) |
| 2111 | __acquires(busiest->lock) |
| 2112 | __acquires(this_rq->lock) |
| 2113 | { |
| 2114 | int ret = 0; |
| 2115 | |
| 2116 | if (unlikely(!raw_spin_trylock(&busiest->lock))) { |
| 2117 | if (busiest < this_rq) { |
| 2118 | raw_spin_unlock(&this_rq->lock); |
| 2119 | raw_spin_lock(&busiest->lock); |
| 2120 | raw_spin_lock_nested(&this_rq->lock, |
| 2121 | SINGLE_DEPTH_NESTING); |
| 2122 | ret = 1; |
| 2123 | } else |
| 2124 | raw_spin_lock_nested(&busiest->lock, |
| 2125 | SINGLE_DEPTH_NESTING); |
| 2126 | } |
| 2127 | return ret; |
| 2128 | } |
| 2129 | |
| 2130 | #endif /* CONFIG_PREEMPT */ |
| 2131 | |
| 2132 | /* |
| 2133 | * double_lock_balance - lock the busiest runqueue, this_rq is locked already. |
| 2134 | */ |
| 2135 | static inline int double_lock_balance(struct rq *this_rq, struct rq *busiest) |
| 2136 | { |
| 2137 | if (unlikely(!irqs_disabled())) { |
| 2138 | /* printk() doesn't work good under rq->lock */ |
| 2139 | raw_spin_unlock(&this_rq->lock); |
| 2140 | BUG_ON(1); |
| 2141 | } |
| 2142 | |
| 2143 | return _double_lock_balance(this_rq, busiest); |
| 2144 | } |
| 2145 | |
| 2146 | static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest) |
| 2147 | __releases(busiest->lock) |
| 2148 | { |
Todd Kjos | a31778a | 2016-07-04 15:04:45 +0100 | [diff] [blame] | 2149 | if (this_rq != busiest) |
| 2150 | raw_spin_unlock(&busiest->lock); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2151 | lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); |
| 2152 | } |
| 2153 | |
Peter Zijlstra | 7460231 | 2013-10-10 20:17:22 +0200 | [diff] [blame] | 2154 | static inline void double_lock(spinlock_t *l1, spinlock_t *l2) |
| 2155 | { |
| 2156 | if (l1 > l2) |
| 2157 | swap(l1, l2); |
| 2158 | |
| 2159 | spin_lock(l1); |
| 2160 | spin_lock_nested(l2, SINGLE_DEPTH_NESTING); |
| 2161 | } |
| 2162 | |
Mike Galbraith | 60e69ee | 2014-04-07 10:55:15 +0200 | [diff] [blame] | 2163 | static inline void double_lock_irq(spinlock_t *l1, spinlock_t *l2) |
| 2164 | { |
| 2165 | if (l1 > l2) |
| 2166 | swap(l1, l2); |
| 2167 | |
| 2168 | spin_lock_irq(l1); |
| 2169 | spin_lock_nested(l2, SINGLE_DEPTH_NESTING); |
| 2170 | } |
| 2171 | |
Peter Zijlstra | 7460231 | 2013-10-10 20:17:22 +0200 | [diff] [blame] | 2172 | static inline void double_raw_lock(raw_spinlock_t *l1, raw_spinlock_t *l2) |
| 2173 | { |
| 2174 | if (l1 > l2) |
| 2175 | swap(l1, l2); |
| 2176 | |
| 2177 | raw_spin_lock(l1); |
| 2178 | raw_spin_lock_nested(l2, SINGLE_DEPTH_NESTING); |
| 2179 | } |
| 2180 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2181 | /* |
| 2182 | * double_rq_lock - safely lock two runqueues |
| 2183 | * |
| 2184 | * Note this does not disable interrupts like task_rq_lock, |
| 2185 | * you need to do so manually before calling. |
| 2186 | */ |
| 2187 | static inline void double_rq_lock(struct rq *rq1, struct rq *rq2) |
| 2188 | __acquires(rq1->lock) |
| 2189 | __acquires(rq2->lock) |
| 2190 | { |
| 2191 | BUG_ON(!irqs_disabled()); |
| 2192 | if (rq1 == rq2) { |
| 2193 | raw_spin_lock(&rq1->lock); |
| 2194 | __acquire(rq2->lock); /* Fake it out ;) */ |
| 2195 | } else { |
| 2196 | if (rq1 < rq2) { |
| 2197 | raw_spin_lock(&rq1->lock); |
| 2198 | raw_spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING); |
| 2199 | } else { |
| 2200 | raw_spin_lock(&rq2->lock); |
| 2201 | raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | /* |
| 2207 | * double_rq_unlock - safely unlock two runqueues |
| 2208 | * |
| 2209 | * Note this does not restore interrupts like task_rq_unlock, |
| 2210 | * you need to do so manually after calling. |
| 2211 | */ |
| 2212 | static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2) |
| 2213 | __releases(rq1->lock) |
| 2214 | __releases(rq2->lock) |
| 2215 | { |
| 2216 | raw_spin_unlock(&rq1->lock); |
| 2217 | if (rq1 != rq2) |
| 2218 | raw_spin_unlock(&rq2->lock); |
| 2219 | else |
| 2220 | __release(rq2->lock); |
| 2221 | } |
| 2222 | |
John Dias | e2c5c98 | 2016-09-15 08:52:27 -0700 | [diff] [blame] | 2223 | /* |
| 2224 | * task_may_not_preempt - check whether a task may not be preemptible soon |
| 2225 | */ |
| 2226 | extern bool task_may_not_preempt(struct task_struct *task, int cpu); |
| 2227 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2228 | #else /* CONFIG_SMP */ |
| 2229 | |
| 2230 | /* |
| 2231 | * double_rq_lock - safely lock two runqueues |
| 2232 | * |
| 2233 | * Note this does not disable interrupts like task_rq_lock, |
| 2234 | * you need to do so manually before calling. |
| 2235 | */ |
| 2236 | static inline void double_rq_lock(struct rq *rq1, struct rq *rq2) |
| 2237 | __acquires(rq1->lock) |
| 2238 | __acquires(rq2->lock) |
| 2239 | { |
| 2240 | BUG_ON(!irqs_disabled()); |
| 2241 | BUG_ON(rq1 != rq2); |
| 2242 | raw_spin_lock(&rq1->lock); |
| 2243 | __acquire(rq2->lock); /* Fake it out ;) */ |
| 2244 | } |
| 2245 | |
| 2246 | /* |
| 2247 | * double_rq_unlock - safely unlock two runqueues |
| 2248 | * |
| 2249 | * Note this does not restore interrupts like task_rq_unlock, |
| 2250 | * you need to do so manually after calling. |
| 2251 | */ |
| 2252 | static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2) |
| 2253 | __releases(rq1->lock) |
| 2254 | __releases(rq2->lock) |
| 2255 | { |
| 2256 | BUG_ON(rq1 != rq2); |
| 2257 | raw_spin_unlock(&rq1->lock); |
| 2258 | __release(rq2->lock); |
| 2259 | } |
| 2260 | |
| 2261 | #endif |
| 2262 | |
| 2263 | extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq); |
| 2264 | extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq); |
Srikar Dronamraju | 6b55c96 | 2015-06-25 22:51:41 +0530 | [diff] [blame] | 2265 | |
| 2266 | #ifdef CONFIG_SCHED_DEBUG |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2267 | extern void print_cfs_stats(struct seq_file *m, int cpu); |
| 2268 | extern void print_rt_stats(struct seq_file *m, int cpu); |
Wanpeng Li | acb3213 | 2014-10-31 06:39:33 +0800 | [diff] [blame] | 2269 | extern void print_dl_stats(struct seq_file *m, int cpu); |
Srikar Dronamraju | 6b55c96 | 2015-06-25 22:51:41 +0530 | [diff] [blame] | 2270 | extern void |
| 2271 | print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq); |
Srikar Dronamraju | 397f237 | 2015-06-25 22:51:43 +0530 | [diff] [blame] | 2272 | |
| 2273 | #ifdef CONFIG_NUMA_BALANCING |
| 2274 | extern void |
| 2275 | show_numa_stats(struct task_struct *p, struct seq_file *m); |
| 2276 | extern void |
| 2277 | print_numa_stats(struct seq_file *m, int node, unsigned long tsf, |
| 2278 | unsigned long tpf, unsigned long gsf, unsigned long gpf); |
| 2279 | #endif /* CONFIG_NUMA_BALANCING */ |
| 2280 | #endif /* CONFIG_SCHED_DEBUG */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2281 | |
| 2282 | extern void init_cfs_rq(struct cfs_rq *cfs_rq); |
Abel Vesa | 07c54f7 | 2015-03-03 13:50:27 +0200 | [diff] [blame] | 2283 | extern void init_rt_rq(struct rt_rq *rt_rq); |
| 2284 | extern void init_dl_rq(struct dl_rq *dl_rq); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2285 | |
Ben Segall | 1ee14e6 | 2013-10-16 11:16:12 -0700 | [diff] [blame] | 2286 | extern void cfs_bandwidth_usage_inc(void); |
| 2287 | extern void cfs_bandwidth_usage_dec(void); |
Suresh Siddha | 1c792db | 2011-12-01 17:07:32 -0800 | [diff] [blame] | 2288 | |
Frederic Weisbecker | 3451d02 | 2011-08-10 23:21:01 +0200 | [diff] [blame] | 2289 | #ifdef CONFIG_NO_HZ_COMMON |
Suresh Siddha | 1c792db | 2011-12-01 17:07:32 -0800 | [diff] [blame] | 2290 | enum rq_nohz_flag_bits { |
| 2291 | NOHZ_TICK_STOPPED, |
| 2292 | NOHZ_BALANCE_KICK, |
| 2293 | }; |
| 2294 | |
Syed Rameez Mustafa | dddcab7 | 2016-09-07 16:18:27 -0700 | [diff] [blame] | 2295 | #define NOHZ_KICK_ANY 0 |
| 2296 | #define NOHZ_KICK_RESTRICT 1 |
| 2297 | |
Suresh Siddha | 1c792db | 2011-12-01 17:07:32 -0800 | [diff] [blame] | 2298 | #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags) |
Thomas Gleixner | 20a5c8c | 2016-03-10 12:54:20 +0100 | [diff] [blame] | 2299 | |
| 2300 | extern void nohz_balance_exit_idle(unsigned int cpu); |
| 2301 | #else |
| 2302 | static inline void nohz_balance_exit_idle(unsigned int cpu) { } |
Suresh Siddha | 1c792db | 2011-12-01 17:07:32 -0800 | [diff] [blame] | 2303 | #endif |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2304 | |
| 2305 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2306 | struct irqtime { |
Frederic Weisbecker | aee0c9e | 2017-04-25 16:10:48 +0200 | [diff] [blame] | 2307 | u64 total; |
Frederic Weisbecker | 034cd8a | 2017-01-31 04:09:32 +0100 | [diff] [blame] | 2308 | u64 tick_delta; |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2309 | u64 irq_start_time; |
| 2310 | struct u64_stats_sync sync; |
| 2311 | }; |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2312 | |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2313 | DECLARE_PER_CPU(struct irqtime, cpu_irqtime); |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2314 | |
Frederic Weisbecker | aee0c9e | 2017-04-25 16:10:48 +0200 | [diff] [blame] | 2315 | /* |
| 2316 | * Returns the irqtime minus the softirq time computed by ksoftirqd. |
| 2317 | * Otherwise ksoftirqd's sum_exec_runtime is substracted its own runtime |
| 2318 | * and never move forward. |
| 2319 | */ |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2320 | static inline u64 irq_time_read(int cpu) |
| 2321 | { |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2322 | struct irqtime *irqtime = &per_cpu(cpu_irqtime, cpu); |
| 2323 | unsigned int seq; |
| 2324 | u64 total; |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2325 | |
| 2326 | do { |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2327 | seq = __u64_stats_fetch_begin(&irqtime->sync); |
Frederic Weisbecker | aee0c9e | 2017-04-25 16:10:48 +0200 | [diff] [blame] | 2328 | total = irqtime->total; |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2329 | } while (__u64_stats_fetch_retry(&irqtime->sync, seq)); |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2330 | |
Frederic Weisbecker | 19d23dbf | 2016-09-26 02:29:20 +0200 | [diff] [blame] | 2331 | return total; |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2332 | } |
Frederic Weisbecker | 73fbec6 | 2012-06-16 15:57:37 +0200 | [diff] [blame] | 2333 | #endif /* CONFIG_IRQ_TIME_ACCOUNTING */ |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2334 | |
Vikram Mulukutla | a65aafe | 2017-06-05 13:37:45 -0700 | [diff] [blame] | 2335 | #ifdef CONFIG_SCHED_WALT |
Pavankumar Kondeti | faa0444 | 2018-06-25 16:13:39 +0530 | [diff] [blame] | 2336 | u64 sched_ktime_clock(void); |
Vikram Mulukutla | c7b54b8 | 2017-07-12 11:34:54 -0700 | [diff] [blame] | 2337 | void note_task_waking(struct task_struct *p, u64 wallclock); |
Vikram Mulukutla | a65aafe | 2017-06-05 13:37:45 -0700 | [diff] [blame] | 2338 | #else /* CONFIG_SCHED_WALT */ |
Pavankumar Kondeti | faa0444 | 2018-06-25 16:13:39 +0530 | [diff] [blame] | 2339 | static inline u64 sched_ktime_clock(void) |
| 2340 | { |
Santosh Mardi | 6b12e30 | 2020-03-12 09:18:34 +0530 | [diff] [blame] | 2341 | return sched_clock(); |
Pavankumar Kondeti | faa0444 | 2018-06-25 16:13:39 +0530 | [diff] [blame] | 2342 | } |
Vikram Mulukutla | c7b54b8 | 2017-07-12 11:34:54 -0700 | [diff] [blame] | 2343 | static inline void note_task_waking(struct task_struct *p, u64 wallclock) { } |
Vikram Mulukutla | a65aafe | 2017-06-05 13:37:45 -0700 | [diff] [blame] | 2344 | #endif /* CONFIG_SCHED_WALT */ |
| 2345 | |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2346 | #ifdef CONFIG_CPU_FREQ |
| 2347 | DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data); |
| 2348 | |
| 2349 | /** |
| 2350 | * cpufreq_update_util - Take a note about CPU utilization changes. |
Rafael J. Wysocki | 12bde33 | 2016-08-10 03:11:17 +0200 | [diff] [blame] | 2351 | * @rq: Runqueue to carry out the update for. |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 2352 | * @flags: Update reason flags. |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2353 | * |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 2354 | * This function is called by the scheduler on the CPU whose utilization is |
| 2355 | * being updated. |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2356 | * |
| 2357 | * It can only be called from RCU-sched read-side critical sections. |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2358 | * |
| 2359 | * The way cpufreq is currently arranged requires it to evaluate the CPU |
| 2360 | * performance state (frequency/voltage) on a regular basis to prevent it from |
| 2361 | * being stuck in a completely inadequate performance level for too long. |
| 2362 | * That is not guaranteed to happen if the updates are only triggered from CFS, |
| 2363 | * though, because they may not be coming in if RT or deadline tasks are active |
| 2364 | * all the time (or there are RT and DL tasks only). |
| 2365 | * |
| 2366 | * As a workaround for that issue, this function is called by the RT and DL |
| 2367 | * sched classes to trigger extra cpufreq updates to prevent it from stalling, |
| 2368 | * but that really is a band-aid. Going forward it should be replaced with |
| 2369 | * solutions targeted more specifically at RT and DL tasks. |
| 2370 | */ |
Rafael J. Wysocki | 12bde33 | 2016-08-10 03:11:17 +0200 | [diff] [blame] | 2371 | static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2372 | { |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 2373 | struct update_util_data *data; |
Santosh Mardi | 6b12e30 | 2020-03-12 09:18:34 +0530 | [diff] [blame] | 2374 | u64 clock; |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 2375 | |
Vikram Mulukutla | ab968a4 | 2017-05-08 19:18:22 -0700 | [diff] [blame] | 2376 | #ifdef CONFIG_SCHED_WALT |
Vikram Mulukutla | f668669 | 2017-06-06 11:58:27 -0700 | [diff] [blame] | 2377 | if (!(flags & SCHED_CPUFREQ_WALT)) |
| 2378 | return; |
Santosh Mardi | 6b12e30 | 2020-03-12 09:18:34 +0530 | [diff] [blame] | 2379 | clock = sched_ktime_clock(); |
| 2380 | #else |
| 2381 | clock = rq_clock(rq); |
Vikram Mulukutla | 4b54aae | 2017-03-20 13:41:37 -0700 | [diff] [blame] | 2382 | #endif |
| 2383 | |
Vikram Mulukutla | bab4188 | 2017-05-09 17:49:47 -0700 | [diff] [blame] | 2384 | data = rcu_dereference_sched(*per_cpu_ptr(&cpufreq_update_util_data, |
| 2385 | cpu_of(rq))); |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 2386 | if (data) |
Santosh Mardi | 6b12e30 | 2020-03-12 09:18:34 +0530 | [diff] [blame] | 2387 | data->func(data, clock, flags); |
Rafael J. Wysocki | 12bde33 | 2016-08-10 03:11:17 +0200 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | static inline void cpufreq_update_this_cpu(struct rq *rq, unsigned int flags) |
| 2391 | { |
| 2392 | if (cpu_of(rq) == smp_processor_id()) |
| 2393 | cpufreq_update_util(rq, flags); |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2394 | } |
| 2395 | #else |
Rafael J. Wysocki | 12bde33 | 2016-08-10 03:11:17 +0200 | [diff] [blame] | 2396 | static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} |
| 2397 | static inline void cpufreq_update_this_cpu(struct rq *rq, unsigned int flags) {} |
Rafael J. Wysocki | adaf9fc | 2016-03-10 20:44:47 +0100 | [diff] [blame] | 2398 | #endif /* CONFIG_CPU_FREQ */ |
Linus Torvalds | be53f58 | 2016-03-24 09:42:50 -0700 | [diff] [blame] | 2399 | |
Rafael J. Wysocki | 9bdcb44 | 2016-04-02 01:09:12 +0200 | [diff] [blame] | 2400 | #ifdef arch_scale_freq_capacity |
| 2401 | #ifndef arch_scale_freq_invariant |
| 2402 | #define arch_scale_freq_invariant() (true) |
| 2403 | #endif |
| 2404 | #else /* arch_scale_freq_capacity */ |
| 2405 | #define arch_scale_freq_invariant() (false) |
| 2406 | #endif |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2407 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2408 | #ifdef CONFIG_SCHED_WALT |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2409 | |
| 2410 | static inline int cluster_first_cpu(struct sched_cluster *cluster) |
| 2411 | { |
| 2412 | return cpumask_first(&cluster->cpus); |
| 2413 | } |
| 2414 | |
| 2415 | struct related_thread_group { |
| 2416 | int id; |
| 2417 | raw_spinlock_t lock; |
| 2418 | struct list_head tasks; |
| 2419 | struct list_head list; |
| 2420 | struct sched_cluster *preferred_cluster; |
| 2421 | struct rcu_head rcu; |
| 2422 | u64 last_update; |
| 2423 | }; |
| 2424 | |
| 2425 | extern struct list_head cluster_head; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2426 | extern struct sched_cluster *sched_cluster[NR_CPUS]; |
| 2427 | |
| 2428 | #define for_each_sched_cluster(cluster) \ |
| 2429 | list_for_each_entry_rcu(cluster, &cluster_head, list) |
| 2430 | |
| 2431 | #define WINDOW_STATS_RECENT 0 |
| 2432 | #define WINDOW_STATS_MAX 1 |
| 2433 | #define WINDOW_STATS_MAX_RECENT_AVG 2 |
| 2434 | #define WINDOW_STATS_AVG 3 |
| 2435 | #define WINDOW_STATS_INVALID_POLICY 4 |
| 2436 | |
| 2437 | #define SCHED_UPMIGRATE_MIN_NICE 15 |
| 2438 | #define EXITING_TASK_MARKER 0xdeaddead |
| 2439 | |
| 2440 | #define UP_MIGRATION 1 |
| 2441 | #define DOWN_MIGRATION 2 |
| 2442 | #define IRQLOAD_MIGRATION 3 |
| 2443 | |
| 2444 | extern struct mutex policy_mutex; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2445 | extern unsigned int sched_disable_window_stats; |
| 2446 | extern unsigned int max_possible_freq; |
| 2447 | extern unsigned int min_max_freq; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2448 | extern unsigned int max_possible_efficiency; |
| 2449 | extern unsigned int min_possible_efficiency; |
| 2450 | extern unsigned int max_capacity; |
| 2451 | extern unsigned int min_capacity; |
| 2452 | extern unsigned int max_load_scale_factor; |
| 2453 | extern unsigned int max_possible_capacity; |
| 2454 | extern unsigned int min_max_possible_capacity; |
| 2455 | extern unsigned int max_power_cost; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2456 | extern unsigned int up_down_migrate_scale_factor; |
| 2457 | extern unsigned int sysctl_sched_restrict_cluster_spill; |
| 2458 | extern unsigned int sched_pred_alert_load; |
| 2459 | extern struct sched_cluster init_cluster; |
| 2460 | extern unsigned int __read_mostly sched_short_sleep_task_threshold; |
| 2461 | extern unsigned int __read_mostly sched_long_cpu_selection_threshold; |
| 2462 | extern unsigned int __read_mostly sched_big_waker_task_load; |
| 2463 | extern unsigned int __read_mostly sched_small_wakee_task_load; |
| 2464 | extern unsigned int __read_mostly sched_spill_load; |
| 2465 | extern unsigned int __read_mostly sched_upmigrate; |
| 2466 | extern unsigned int __read_mostly sched_downmigrate; |
| 2467 | extern unsigned int __read_mostly sysctl_sched_spill_nr_run; |
| 2468 | extern unsigned int __read_mostly sched_load_granule; |
| 2469 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2470 | extern int register_cpu_cycle_counter_cb(struct cpu_cycle_counter_cb *cb); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2471 | extern int update_preferred_cluster(struct related_thread_group *grp, |
| 2472 | struct task_struct *p, u32 old_load); |
| 2473 | extern void set_preferred_cluster(struct related_thread_group *grp); |
| 2474 | extern void add_new_task_to_grp(struct task_struct *new); |
| 2475 | extern unsigned int update_freq_aggregate_threshold(unsigned int threshold); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2476 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2477 | static inline int cpu_capacity(int cpu) |
| 2478 | { |
| 2479 | return cpu_rq(cpu)->cluster->capacity; |
| 2480 | } |
| 2481 | |
| 2482 | static inline int cpu_max_possible_capacity(int cpu) |
| 2483 | { |
| 2484 | return cpu_rq(cpu)->cluster->max_possible_capacity; |
| 2485 | } |
| 2486 | |
| 2487 | static inline int cpu_load_scale_factor(int cpu) |
| 2488 | { |
| 2489 | return cpu_rq(cpu)->cluster->load_scale_factor; |
| 2490 | } |
| 2491 | |
| 2492 | static inline int cpu_efficiency(int cpu) |
| 2493 | { |
| 2494 | return cpu_rq(cpu)->cluster->efficiency; |
| 2495 | } |
| 2496 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2497 | static inline unsigned int cpu_min_freq(int cpu) |
| 2498 | { |
| 2499 | return cpu_rq(cpu)->cluster->min_freq; |
| 2500 | } |
| 2501 | |
| 2502 | static inline unsigned int cluster_max_freq(struct sched_cluster *cluster) |
| 2503 | { |
| 2504 | /* |
| 2505 | * Governor and thermal driver don't know the other party's mitigation |
| 2506 | * voting. So struct cluster saves both and return min() for current |
| 2507 | * cluster fmax. |
| 2508 | */ |
| 2509 | return min(cluster->max_mitigated_freq, cluster->max_freq); |
| 2510 | } |
| 2511 | |
| 2512 | static inline unsigned int cpu_max_freq(int cpu) |
| 2513 | { |
| 2514 | return cluster_max_freq(cpu_rq(cpu)->cluster); |
| 2515 | } |
| 2516 | |
| 2517 | static inline unsigned int cpu_max_possible_freq(int cpu) |
| 2518 | { |
| 2519 | return cpu_rq(cpu)->cluster->max_possible_freq; |
| 2520 | } |
| 2521 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2522 | /* Keep track of max/min capacity possible across CPUs "currently" */ |
| 2523 | static inline void __update_min_max_capacity(void) |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2524 | { |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2525 | int i; |
| 2526 | int max_cap = 0, min_cap = INT_MAX; |
| 2527 | |
Pavankumar Kondeti | f51d539 | 2018-11-28 11:57:29 +0530 | [diff] [blame] | 2528 | for_each_possible_cpu(i) { |
| 2529 | |
| 2530 | if (!cpu_active(i)) |
| 2531 | continue; |
| 2532 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2533 | max_cap = max(max_cap, cpu_capacity(i)); |
| 2534 | min_cap = min(min_cap, cpu_capacity(i)); |
| 2535 | } |
| 2536 | |
| 2537 | max_capacity = max_cap; |
| 2538 | min_capacity = min_cap; |
| 2539 | } |
| 2540 | |
| 2541 | /* |
| 2542 | * Return load_scale_factor of a cpu in reference to "most" efficient cpu, so |
| 2543 | * that "most" efficient cpu gets a load_scale_factor of 1 |
| 2544 | */ |
| 2545 | static inline unsigned long |
| 2546 | load_scale_cpu_efficiency(struct sched_cluster *cluster) |
| 2547 | { |
| 2548 | return DIV_ROUND_UP(1024 * max_possible_efficiency, |
| 2549 | cluster->efficiency); |
| 2550 | } |
| 2551 | |
| 2552 | /* |
| 2553 | * Return load_scale_factor of a cpu in reference to cpu with best max_freq |
| 2554 | * (max_possible_freq), so that one with best max_freq gets a load_scale_factor |
| 2555 | * of 1. |
| 2556 | */ |
| 2557 | static inline unsigned long load_scale_cpu_freq(struct sched_cluster *cluster) |
| 2558 | { |
| 2559 | return DIV_ROUND_UP(1024 * max_possible_freq, |
| 2560 | cluster_max_freq(cluster)); |
| 2561 | } |
| 2562 | |
| 2563 | static inline int compute_load_scale_factor(struct sched_cluster *cluster) |
| 2564 | { |
| 2565 | int load_scale = 1024; |
| 2566 | |
| 2567 | /* |
| 2568 | * load_scale_factor accounts for the fact that task load |
| 2569 | * is in reference to "best" performing cpu. Task's load will need to be |
| 2570 | * scaled (up) by a factor to determine suitability to be placed on a |
| 2571 | * (little) cpu. |
| 2572 | */ |
| 2573 | load_scale *= load_scale_cpu_efficiency(cluster); |
| 2574 | load_scale >>= 10; |
| 2575 | |
| 2576 | load_scale *= load_scale_cpu_freq(cluster); |
| 2577 | load_scale >>= 10; |
| 2578 | |
| 2579 | return load_scale; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | static inline int cpu_max_power_cost(int cpu) |
| 2583 | { |
| 2584 | return cpu_rq(cpu)->cluster->max_power_cost; |
| 2585 | } |
| 2586 | |
| 2587 | static inline int cpu_min_power_cost(int cpu) |
| 2588 | { |
| 2589 | return cpu_rq(cpu)->cluster->min_power_cost; |
| 2590 | } |
| 2591 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2592 | static inline bool hmp_capable(void) |
| 2593 | { |
| 2594 | return max_possible_capacity != min_max_possible_capacity; |
| 2595 | } |
| 2596 | |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 2597 | static inline bool is_max_capacity_cpu(int cpu) |
| 2598 | { |
| 2599 | return cpu_max_possible_capacity(cpu) == max_possible_capacity; |
| 2600 | } |
| 2601 | |
Pavankumar Kondeti | 271e314 | 2017-06-23 14:20:24 +0530 | [diff] [blame] | 2602 | static inline bool is_min_capacity_cpu(int cpu) |
| 2603 | { |
| 2604 | return cpu_max_possible_capacity(cpu) == min_max_possible_capacity; |
| 2605 | } |
| 2606 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2607 | /* |
| 2608 | * 'load' is in reference to "best cpu" at its best frequency. |
| 2609 | * Scale that in reference to a given cpu, accounting for how bad it is |
| 2610 | * in reference to "best cpu". |
| 2611 | */ |
| 2612 | static inline u64 scale_load_to_cpu(u64 task_load, int cpu) |
| 2613 | { |
| 2614 | u64 lsf = cpu_load_scale_factor(cpu); |
| 2615 | |
| 2616 | if (lsf != 1024) { |
| 2617 | task_load *= lsf; |
| 2618 | task_load /= 1024; |
| 2619 | } |
| 2620 | |
| 2621 | return task_load; |
| 2622 | } |
| 2623 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2624 | /* |
| 2625 | * Return 'capacity' of a cpu in reference to "least" efficient cpu, such that |
| 2626 | * least efficient cpu gets capacity of 1024 |
| 2627 | */ |
| 2628 | static unsigned long |
| 2629 | capacity_scale_cpu_efficiency(struct sched_cluster *cluster) |
| 2630 | { |
| 2631 | return (1024 * cluster->efficiency) / min_possible_efficiency; |
| 2632 | } |
| 2633 | |
| 2634 | /* |
| 2635 | * Return 'capacity' of a cpu in reference to cpu with lowest max_freq |
| 2636 | * (min_max_freq), such that one with lowest max_freq gets capacity of 1024. |
| 2637 | */ |
| 2638 | static unsigned long capacity_scale_cpu_freq(struct sched_cluster *cluster) |
| 2639 | { |
| 2640 | return (1024 * cluster_max_freq(cluster)) / min_max_freq; |
| 2641 | } |
| 2642 | |
| 2643 | static inline int compute_capacity(struct sched_cluster *cluster) |
| 2644 | { |
| 2645 | int capacity = 1024; |
| 2646 | |
| 2647 | capacity *= capacity_scale_cpu_efficiency(cluster); |
| 2648 | capacity >>= 10; |
| 2649 | |
| 2650 | capacity *= capacity_scale_cpu_freq(cluster); |
| 2651 | capacity >>= 10; |
| 2652 | |
| 2653 | return capacity; |
| 2654 | } |
| 2655 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2656 | static inline unsigned int task_load(struct task_struct *p) |
| 2657 | { |
| 2658 | return p->ravg.demand; |
| 2659 | } |
| 2660 | |
Pavankumar Kondeti | fe1a696 | 2017-07-25 11:08:17 +0530 | [diff] [blame] | 2661 | static inline unsigned int task_pl(struct task_struct *p) |
| 2662 | { |
| 2663 | return p->ravg.pred_demand; |
| 2664 | } |
| 2665 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2666 | #define pct_to_real(tunable) \ |
| 2667 | (div64_u64((u64)tunable * (u64)max_task_load(), 100)) |
| 2668 | |
| 2669 | #define real_to_pct(tunable) \ |
| 2670 | (div64_u64((u64)tunable * (u64)100, (u64)max_task_load())) |
| 2671 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2672 | static inline bool task_in_related_thread_group(struct task_struct *p) |
| 2673 | { |
| 2674 | return !!(rcu_access_pointer(p->grp) != NULL); |
| 2675 | } |
| 2676 | |
| 2677 | static inline |
| 2678 | struct related_thread_group *task_related_thread_group(struct task_struct *p) |
| 2679 | { |
| 2680 | return rcu_dereference(p->grp); |
| 2681 | } |
| 2682 | |
| 2683 | #define PRED_DEMAND_DELTA ((s64)new_pred_demand - p->ravg.pred_demand) |
| 2684 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2685 | /* Is frequency of two cpus synchronized with each other? */ |
| 2686 | static inline int same_freq_domain(int src_cpu, int dst_cpu) |
| 2687 | { |
| 2688 | struct rq *rq = cpu_rq(src_cpu); |
| 2689 | |
| 2690 | if (src_cpu == dst_cpu) |
| 2691 | return 1; |
| 2692 | |
| 2693 | return cpumask_test_cpu(dst_cpu, &rq->freq_domain_cpumask); |
| 2694 | } |
| 2695 | |
| 2696 | #define BOOST_KICK 0 |
| 2697 | #define CPU_RESERVED 1 |
| 2698 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2699 | extern int sched_boost(void); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2700 | extern int preferred_cluster(struct sched_cluster *cluster, |
| 2701 | struct task_struct *p); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2702 | extern struct sched_cluster *rq_cluster(struct rq *rq); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2703 | extern void reset_task_stats(struct task_struct *p); |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2704 | extern void clear_top_tasks_bitmap(unsigned long *bitmap); |
| 2705 | |
| 2706 | #if defined(CONFIG_SCHED_TUNE) && defined(CONFIG_CGROUP_SCHEDTUNE) |
| 2707 | extern bool task_sched_boost(struct task_struct *p); |
| 2708 | extern int sync_cgroup_colocation(struct task_struct *p, bool insert); |
| 2709 | extern bool same_schedtune(struct task_struct *tsk1, struct task_struct *tsk2); |
| 2710 | extern void update_cgroup_boost_settings(void); |
| 2711 | extern void restore_cgroup_boost_settings(void); |
| 2712 | |
| 2713 | #else |
| 2714 | static inline bool |
| 2715 | same_schedtune(struct task_struct *tsk1, struct task_struct *tsk2) |
| 2716 | { |
| 2717 | return true; |
| 2718 | } |
| 2719 | |
| 2720 | static inline bool task_sched_boost(struct task_struct *p) |
| 2721 | { |
| 2722 | return true; |
| 2723 | } |
| 2724 | |
| 2725 | static inline void update_cgroup_boost_settings(void) { } |
| 2726 | static inline void restore_cgroup_boost_settings(void) { } |
| 2727 | #endif |
| 2728 | |
| 2729 | extern int alloc_related_thread_groups(void); |
| 2730 | |
| 2731 | extern unsigned long all_cluster_ids[]; |
| 2732 | |
Joonwoo Park | e77a201 | 2016-12-06 18:12:43 -0800 | [diff] [blame] | 2733 | extern void check_for_migration(struct rq *rq, struct task_struct *p); |
| 2734 | |
| 2735 | static inline int is_reserved(int cpu) |
| 2736 | { |
| 2737 | struct rq *rq = cpu_rq(cpu); |
| 2738 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2739 | return test_bit(CPU_RESERVED, &rq->walt_flags); |
Joonwoo Park | e77a201 | 2016-12-06 18:12:43 -0800 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | static inline int mark_reserved(int cpu) |
| 2743 | { |
| 2744 | struct rq *rq = cpu_rq(cpu); |
| 2745 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2746 | return test_and_set_bit(CPU_RESERVED, &rq->walt_flags); |
Joonwoo Park | e77a201 | 2016-12-06 18:12:43 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | static inline void clear_reserved(int cpu) |
| 2750 | { |
| 2751 | struct rq *rq = cpu_rq(cpu); |
| 2752 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2753 | clear_bit(CPU_RESERVED, &rq->walt_flags); |
Joonwoo Park | e77a201 | 2016-12-06 18:12:43 -0800 | [diff] [blame] | 2754 | } |
| 2755 | |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2756 | static inline bool |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2757 | task_in_cum_window_demand(struct rq *rq, struct task_struct *p) |
| 2758 | { |
Pavankumar Kondeti | 0cebff0 | 2017-07-21 16:28:12 +0530 | [diff] [blame] | 2759 | return cpu_of(rq) == task_cpu(p) && (p->on_rq || p->last_sleep_ts >= |
| 2760 | rq->window_start); |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2761 | } |
| 2762 | |
Pavankumar Kondeti | 0cebff0 | 2017-07-21 16:28:12 +0530 | [diff] [blame] | 2763 | static inline void walt_fixup_cum_window_demand(struct rq *rq, s64 delta) |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2764 | { |
| 2765 | rq->cum_window_demand += delta; |
Pavankumar Kondeti | 0cebff0 | 2017-07-21 16:28:12 +0530 | [diff] [blame] | 2766 | if (unlikely((s64)rq->cum_window_demand < 0)) |
| 2767 | rq->cum_window_demand = 0; |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
Vikram Mulukutla | d0ba188 | 2017-02-03 12:56:26 -0800 | [diff] [blame] | 2770 | extern void update_cpu_cluster_capacity(const cpumask_t *cpus); |
| 2771 | |
| 2772 | extern unsigned long thermal_cap(int cpu); |
| 2773 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2774 | extern void clear_walt_request(int cpu); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 2775 | |
| 2776 | extern int got_boost_kick(void); |
| 2777 | extern void clear_boost_kick(int cpu); |
| 2778 | extern enum sched_boost_policy sched_boost_policy(void); |
| 2779 | extern void sched_boost_parse_dt(void); |
Syed Rameez Mustafa | 25de011 | 2017-05-10 12:09:15 -0700 | [diff] [blame] | 2780 | extern void clear_ed_task(struct task_struct *p, struct rq *rq); |
| 2781 | extern bool early_detection_notify(struct rq *rq, u64 wallclock); |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 2782 | |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2783 | static inline unsigned int power_cost(int cpu, bool max) |
Pavankumar Kondeti | f9026cd | 2017-06-07 15:03:32 +0530 | [diff] [blame] | 2784 | { |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2785 | struct sched_group_energy *sge = sge_array[cpu][SD_LEVEL1]; |
| 2786 | |
| 2787 | if (!sge || !sge->nr_cap_states) |
| 2788 | return cpu_max_possible_capacity(cpu); |
| 2789 | |
| 2790 | if (max) |
| 2791 | return sge->cap_states[sge->nr_cap_states - 1].power; |
| 2792 | else |
| 2793 | return sge->cap_states[0].power; |
Pavankumar Kondeti | f9026cd | 2017-06-07 15:03:32 +0530 | [diff] [blame] | 2794 | } |
Pavankumar Kondeti | f9026cd | 2017-06-07 15:03:32 +0530 | [diff] [blame] | 2795 | |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2796 | extern void walt_sched_energy_populated_callback(void); |
Pavankumar Kondeti | f51d539 | 2018-11-28 11:57:29 +0530 | [diff] [blame] | 2797 | extern void walt_update_min_max_capacity(void); |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2798 | |
Abhijeet Dharmapurikar | 53ee423 | 2018-06-15 09:34:34 -0700 | [diff] [blame] | 2799 | static inline enum sched_boost_policy task_boost_policy(struct task_struct *p) |
| 2800 | { |
| 2801 | enum sched_boost_policy boost_on_big = task_sched_boost(p) ? |
| 2802 | sched_boost_policy() : SCHED_BOOST_NONE; |
| 2803 | |
| 2804 | if (boost_on_big) { |
| 2805 | /* |
| 2806 | * Filter out tasks less than min task util threshold |
| 2807 | * under conservative boost. |
| 2808 | */ |
| 2809 | if (sysctl_sched_boost == CONSERVATIVE_BOOST && |
| 2810 | task_util(p) <= |
| 2811 | sysctl_sched_min_task_util_for_boost_colocation) |
| 2812 | boost_on_big = SCHED_BOOST_NONE; |
| 2813 | } |
| 2814 | |
| 2815 | return boost_on_big; |
| 2816 | } |
| 2817 | |
Satya Durga Srinivasu Prabhala | c18b403 | 2018-04-17 11:21:23 -0700 | [diff] [blame] | 2818 | extern void walt_map_freq_to_load(void); |
| 2819 | |
| 2820 | static inline bool is_min_capacity_cluster(struct sched_cluster *cluster) |
| 2821 | { |
| 2822 | return is_min_capacity_cpu(cluster_first_cpu(cluster)); |
| 2823 | } |
| 2824 | |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2825 | #else /* CONFIG_SCHED_WALT */ |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2826 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2827 | struct walt_sched_stats; |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2828 | struct related_thread_group; |
| 2829 | struct sched_cluster; |
| 2830 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2831 | static inline bool task_sched_boost(struct task_struct *p) |
| 2832 | { |
| 2833 | return true; |
| 2834 | } |
Abhijeet Dharmapurikar | 53ee423 | 2018-06-15 09:34:34 -0700 | [diff] [blame] | 2835 | static inline enum sched_boost_policy task_boost_policy(struct task_struct *p) |
| 2836 | { |
| 2837 | return SCHED_BOOST_NONE; |
| 2838 | } |
Joonwoo Park | e77a201 | 2016-12-06 18:12:43 -0800 | [diff] [blame] | 2839 | static inline void check_for_migration(struct rq *rq, struct task_struct *p) { } |
| 2840 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2841 | static inline int sched_boost(void) |
| 2842 | { |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
Pavankumar Kondeti | 271e314 | 2017-06-23 14:20:24 +0530 | [diff] [blame] | 2846 | static inline bool hmp_capable(void) { return false; } |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 2847 | static inline bool is_max_capacity_cpu(int cpu) { return true; } |
Pavankumar Kondeti | 271e314 | 2017-06-23 14:20:24 +0530 | [diff] [blame] | 2848 | static inline bool is_min_capacity_cpu(int cpu) { return true; } |
Pavankumar Kondeti | 00530928 | 2017-05-10 15:43:29 +0530 | [diff] [blame] | 2849 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2850 | static inline int |
| 2851 | preferred_cluster(struct sched_cluster *cluster, struct task_struct *p) |
| 2852 | { |
| 2853 | return 1; |
| 2854 | } |
| 2855 | |
| 2856 | static inline struct sched_cluster *rq_cluster(struct rq *rq) |
| 2857 | { |
| 2858 | return NULL; |
| 2859 | } |
| 2860 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2861 | static inline u64 scale_load_to_cpu(u64 load, int cpu) |
| 2862 | { |
| 2863 | return load; |
| 2864 | } |
| 2865 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2866 | static inline int cpu_capacity(int cpu) |
| 2867 | { |
| 2868 | return SCHED_CAPACITY_SCALE; |
| 2869 | } |
| 2870 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2871 | static inline void set_preferred_cluster(struct related_thread_group *grp) { } |
| 2872 | |
| 2873 | static inline bool task_in_related_thread_group(struct task_struct *p) |
| 2874 | { |
| 2875 | return false; |
| 2876 | } |
| 2877 | |
| 2878 | static inline |
| 2879 | struct related_thread_group *task_related_thread_group(struct task_struct *p) |
| 2880 | { |
| 2881 | return NULL; |
| 2882 | } |
| 2883 | |
| 2884 | static inline u32 task_load(struct task_struct *p) { return 0; } |
Pavankumar Kondeti | fe1a696 | 2017-07-25 11:08:17 +0530 | [diff] [blame] | 2885 | static inline u32 task_pl(struct task_struct *p) { return 0; } |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2886 | |
| 2887 | static inline int update_preferred_cluster(struct related_thread_group *grp, |
| 2888 | struct task_struct *p, u32 old_load) |
| 2889 | { |
| 2890 | return 0; |
| 2891 | } |
| 2892 | |
| 2893 | static inline void add_new_task_to_grp(struct task_struct *new) {} |
| 2894 | |
| 2895 | #define PRED_DEMAND_DELTA (0) |
| 2896 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2897 | static inline int same_freq_domain(int src_cpu, int dst_cpu) |
| 2898 | { |
| 2899 | return 1; |
| 2900 | } |
| 2901 | |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2902 | static inline void clear_reserved(int cpu) { } |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2903 | static inline int alloc_related_thread_groups(void) { return 0; } |
| 2904 | |
| 2905 | #define trace_sched_cpu_load(...) |
| 2906 | #define trace_sched_cpu_load_lb(...) |
| 2907 | #define trace_sched_cpu_load_cgroup(...) |
| 2908 | #define trace_sched_cpu_load_wakeup(...) |
| 2909 | |
Pavankumar Kondeti | 0cebff0 | 2017-07-21 16:28:12 +0530 | [diff] [blame] | 2910 | static inline void walt_fixup_cum_window_demand(struct rq *rq, s64 delta) { } |
Joonwoo Park | 84a8088 | 2017-02-03 11:15:31 -0800 | [diff] [blame] | 2911 | |
Vikram Mulukutla | d0ba188 | 2017-02-03 12:56:26 -0800 | [diff] [blame] | 2912 | static inline void update_cpu_cluster_capacity(const cpumask_t *cpus) { } |
| 2913 | |
| 2914 | #ifdef CONFIG_SMP |
| 2915 | static inline unsigned long thermal_cap(int cpu) |
| 2916 | { |
| 2917 | return cpu_rq(cpu)->cpu_capacity_orig; |
| 2918 | } |
Pavankumar Kondeti | 79830a2 | 2017-11-20 11:34:10 +0530 | [diff] [blame] | 2919 | |
| 2920 | static inline int cpu_max_power_cost(int cpu) |
| 2921 | { |
| 2922 | return capacity_orig_of(cpu); |
| 2923 | } |
Vikram Mulukutla | d0ba188 | 2017-02-03 12:56:26 -0800 | [diff] [blame] | 2924 | #endif |
| 2925 | |
Pavankumar Kondeti | 84f72d7 | 2017-07-20 11:00:45 +0530 | [diff] [blame] | 2926 | static inline void clear_walt_request(int cpu) { } |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 2927 | |
Pavankumar Kondeti | 55beff9 | 2018-04-03 14:39:46 +0530 | [diff] [blame] | 2928 | static inline int is_reserved(int cpu) |
| 2929 | { |
| 2930 | return 0; |
| 2931 | } |
| 2932 | |
Syed Rameez Mustafa | 20acfe7 | 2017-01-30 09:35:46 +0530 | [diff] [blame] | 2933 | static inline int got_boost_kick(void) |
| 2934 | { |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | static inline void clear_boost_kick(int cpu) { } |
| 2939 | |
| 2940 | static inline enum sched_boost_policy sched_boost_policy(void) |
| 2941 | { |
| 2942 | return SCHED_BOOST_NONE; |
| 2943 | } |
| 2944 | |
| 2945 | static inline void sched_boost_parse_dt(void) { } |
| 2946 | |
Syed Rameez Mustafa | 25de011 | 2017-05-10 12:09:15 -0700 | [diff] [blame] | 2947 | static inline void clear_ed_task(struct task_struct *p, struct rq *rq) { } |
| 2948 | |
| 2949 | static inline bool early_detection_notify(struct rq *rq, u64 wallclock) |
| 2950 | { |
| 2951 | return 0; |
| 2952 | } |
| 2953 | |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2954 | static inline unsigned int power_cost(int cpu, bool max) |
Pavankumar Kondeti | f9026cd | 2017-06-07 15:03:32 +0530 | [diff] [blame] | 2955 | { |
| 2956 | return SCHED_CAPACITY_SCALE; |
| 2957 | } |
| 2958 | |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2959 | static inline void walt_sched_energy_populated_callback(void) { } |
Pavankumar Kondeti | f51d539 | 2018-11-28 11:57:29 +0530 | [diff] [blame] | 2960 | static inline void walt_update_min_max_capacity(void) { } |
Pavankumar Kondeti | c5927f1 | 2017-10-11 12:36:12 +0530 | [diff] [blame] | 2961 | |
Satya Durga Srinivasu Prabhala | c18b403 | 2018-04-17 11:21:23 -0700 | [diff] [blame] | 2962 | static inline void walt_map_freq_to_load(void) { } |
Joonwoo Park | f7d6cd4 | 2017-01-17 15:19:43 -0800 | [diff] [blame] | 2963 | #endif /* CONFIG_SCHED_WALT */ |
Vikram Mulukutla | d056dbc | 2017-02-07 18:58:07 -0800 | [diff] [blame] | 2964 | |
Joonwoo Park | c5ddd4a | 2017-01-12 17:56:46 -0800 | [diff] [blame] | 2965 | static inline bool energy_aware(void) |
| 2966 | { |
| 2967 | return sched_feat(ENERGY_AWARE); |
| 2968 | } |
Joonwoo Park | a5e601e | 2017-09-20 16:13:03 -0700 | [diff] [blame] | 2969 | |
| 2970 | #ifdef CONFIG_SCHED_CORE_ROTATE |
| 2971 | struct find_first_cpu_bit_env { |
| 2972 | unsigned long *avoid_prev_cpu_last; |
| 2973 | int *rotate_cpu_start; |
| 2974 | int interval; |
| 2975 | spinlock_t *rotate_lock; |
| 2976 | }; |
| 2977 | |
| 2978 | int |
| 2979 | find_first_cpu_bit(struct task_struct *p, const cpumask_t *search_cpus, |
| 2980 | struct sched_group *sg_target, bool *avoid_prev_cpu, |
| 2981 | bool *do_rotate, struct find_first_cpu_bit_env *env); |
Pavankumar Kondeti | c72d3a4 | 2017-11-14 15:35:35 +0530 | [diff] [blame] | 2982 | #else |
| 2983 | #define find_first_cpu_bit(...) -1 |
Joonwoo Park | a5e601e | 2017-09-20 16:13:03 -0700 | [diff] [blame] | 2984 | #endif |
Maria Yu | 702cec9 | 2019-08-13 17:12:33 +0800 | [diff] [blame] | 2985 | |
| 2986 | #ifdef CONFIG_SMP |
| 2987 | static inline void sched_irq_work_queue(struct irq_work *work) |
| 2988 | { |
| 2989 | if (likely(cpu_online(raw_smp_processor_id()))) |
| 2990 | irq_work_queue(work); |
| 2991 | else |
| 2992 | irq_work_queue_on(work, cpumask_any(cpu_online_mask)); |
| 2993 | } |
| 2994 | #endif |