Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Real-Time Scheduling Class (mapped to the SCHED_FIFO and SCHED_RR |
| 3 | * policies) |
| 4 | */ |
| 5 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 6 | #include "sched.h" |
| 7 | |
| 8 | #include <linux/slab.h> |
| 9 | |
Clark Williams | ce0dbbb | 2013-02-07 09:47:04 -0600 | [diff] [blame] | 10 | int sched_rr_timeslice = RR_TIMESLICE; |
| 11 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 12 | static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun); |
| 13 | |
| 14 | struct rt_bandwidth def_rt_bandwidth; |
| 15 | |
| 16 | static enum hrtimer_restart sched_rt_period_timer(struct hrtimer *timer) |
| 17 | { |
| 18 | struct rt_bandwidth *rt_b = |
| 19 | container_of(timer, struct rt_bandwidth, rt_period_timer); |
| 20 | ktime_t now; |
| 21 | int overrun; |
| 22 | int idle = 0; |
| 23 | |
| 24 | for (;;) { |
| 25 | now = hrtimer_cb_get_time(timer); |
| 26 | overrun = hrtimer_forward(timer, now, rt_b->rt_period); |
| 27 | |
| 28 | if (!overrun) |
| 29 | break; |
| 30 | |
| 31 | idle = do_sched_rt_period_timer(rt_b, overrun); |
| 32 | } |
| 33 | |
| 34 | return idle ? HRTIMER_NORESTART : HRTIMER_RESTART; |
| 35 | } |
| 36 | |
| 37 | void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime) |
| 38 | { |
| 39 | rt_b->rt_period = ns_to_ktime(period); |
| 40 | rt_b->rt_runtime = runtime; |
| 41 | |
| 42 | raw_spin_lock_init(&rt_b->rt_runtime_lock); |
| 43 | |
| 44 | hrtimer_init(&rt_b->rt_period_timer, |
| 45 | CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 46 | rt_b->rt_period_timer.function = sched_rt_period_timer; |
| 47 | } |
| 48 | |
| 49 | static void start_rt_bandwidth(struct rt_bandwidth *rt_b) |
| 50 | { |
| 51 | if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) |
| 52 | return; |
| 53 | |
| 54 | if (hrtimer_active(&rt_b->rt_period_timer)) |
| 55 | return; |
| 56 | |
| 57 | raw_spin_lock(&rt_b->rt_runtime_lock); |
| 58 | start_bandwidth_timer(&rt_b->rt_period_timer, rt_b->rt_period); |
| 59 | raw_spin_unlock(&rt_b->rt_runtime_lock); |
| 60 | } |
| 61 | |
| 62 | void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq) |
| 63 | { |
| 64 | struct rt_prio_array *array; |
| 65 | int i; |
| 66 | |
| 67 | array = &rt_rq->active; |
| 68 | for (i = 0; i < MAX_RT_PRIO; i++) { |
| 69 | INIT_LIST_HEAD(array->queue + i); |
| 70 | __clear_bit(i, array->bitmap); |
| 71 | } |
| 72 | /* delimiter for bitsearch: */ |
| 73 | __set_bit(MAX_RT_PRIO, array->bitmap); |
| 74 | |
| 75 | #if defined CONFIG_SMP |
| 76 | rt_rq->highest_prio.curr = MAX_RT_PRIO; |
| 77 | rt_rq->highest_prio.next = MAX_RT_PRIO; |
| 78 | rt_rq->rt_nr_migratory = 0; |
| 79 | rt_rq->overloaded = 0; |
| 80 | plist_head_init(&rt_rq->pushable_tasks); |
| 81 | #endif |
| 82 | |
| 83 | rt_rq->rt_time = 0; |
| 84 | rt_rq->rt_throttled = 0; |
| 85 | rt_rq->rt_runtime = 0; |
| 86 | raw_spin_lock_init(&rt_rq->rt_runtime_lock); |
| 87 | } |
| 88 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 89 | #ifdef CONFIG_RT_GROUP_SCHED |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 90 | static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b) |
| 91 | { |
| 92 | hrtimer_cancel(&rt_b->rt_period_timer); |
| 93 | } |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 94 | |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 95 | #define rt_entity_is_task(rt_se) (!(rt_se)->my_q) |
| 96 | |
Peter Zijlstra | 8f48894 | 2009-07-24 12:25:30 +0200 | [diff] [blame] | 97 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) |
| 98 | { |
| 99 | #ifdef CONFIG_SCHED_DEBUG |
| 100 | WARN_ON_ONCE(!rt_entity_is_task(rt_se)); |
| 101 | #endif |
| 102 | return container_of(rt_se, struct task_struct, rt); |
| 103 | } |
| 104 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 105 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) |
| 106 | { |
| 107 | return rt_rq->rq; |
| 108 | } |
| 109 | |
| 110 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) |
| 111 | { |
| 112 | return rt_se->rt_rq; |
| 113 | } |
| 114 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 115 | void free_rt_sched_group(struct task_group *tg) |
| 116 | { |
| 117 | int i; |
| 118 | |
| 119 | if (tg->rt_se) |
| 120 | destroy_rt_bandwidth(&tg->rt_bandwidth); |
| 121 | |
| 122 | for_each_possible_cpu(i) { |
| 123 | if (tg->rt_rq) |
| 124 | kfree(tg->rt_rq[i]); |
| 125 | if (tg->rt_se) |
| 126 | kfree(tg->rt_se[i]); |
| 127 | } |
| 128 | |
| 129 | kfree(tg->rt_rq); |
| 130 | kfree(tg->rt_se); |
| 131 | } |
| 132 | |
| 133 | void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq, |
| 134 | struct sched_rt_entity *rt_se, int cpu, |
| 135 | struct sched_rt_entity *parent) |
| 136 | { |
| 137 | struct rq *rq = cpu_rq(cpu); |
| 138 | |
| 139 | rt_rq->highest_prio.curr = MAX_RT_PRIO; |
| 140 | rt_rq->rt_nr_boosted = 0; |
| 141 | rt_rq->rq = rq; |
| 142 | rt_rq->tg = tg; |
| 143 | |
| 144 | tg->rt_rq[cpu] = rt_rq; |
| 145 | tg->rt_se[cpu] = rt_se; |
| 146 | |
| 147 | if (!rt_se) |
| 148 | return; |
| 149 | |
| 150 | if (!parent) |
| 151 | rt_se->rt_rq = &rq->rt; |
| 152 | else |
| 153 | rt_se->rt_rq = parent->my_q; |
| 154 | |
| 155 | rt_se->my_q = rt_rq; |
| 156 | rt_se->parent = parent; |
| 157 | INIT_LIST_HEAD(&rt_se->run_list); |
| 158 | } |
| 159 | |
| 160 | int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) |
| 161 | { |
| 162 | struct rt_rq *rt_rq; |
| 163 | struct sched_rt_entity *rt_se; |
| 164 | int i; |
| 165 | |
| 166 | tg->rt_rq = kzalloc(sizeof(rt_rq) * nr_cpu_ids, GFP_KERNEL); |
| 167 | if (!tg->rt_rq) |
| 168 | goto err; |
| 169 | tg->rt_se = kzalloc(sizeof(rt_se) * nr_cpu_ids, GFP_KERNEL); |
| 170 | if (!tg->rt_se) |
| 171 | goto err; |
| 172 | |
| 173 | init_rt_bandwidth(&tg->rt_bandwidth, |
| 174 | ktime_to_ns(def_rt_bandwidth.rt_period), 0); |
| 175 | |
| 176 | for_each_possible_cpu(i) { |
| 177 | rt_rq = kzalloc_node(sizeof(struct rt_rq), |
| 178 | GFP_KERNEL, cpu_to_node(i)); |
| 179 | if (!rt_rq) |
| 180 | goto err; |
| 181 | |
| 182 | rt_se = kzalloc_node(sizeof(struct sched_rt_entity), |
| 183 | GFP_KERNEL, cpu_to_node(i)); |
| 184 | if (!rt_se) |
| 185 | goto err_free_rq; |
| 186 | |
| 187 | init_rt_rq(rt_rq, cpu_rq(i)); |
| 188 | rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime; |
| 189 | init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]); |
| 190 | } |
| 191 | |
| 192 | return 1; |
| 193 | |
| 194 | err_free_rq: |
| 195 | kfree(rt_rq); |
| 196 | err: |
| 197 | return 0; |
| 198 | } |
| 199 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 200 | #else /* CONFIG_RT_GROUP_SCHED */ |
| 201 | |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 202 | #define rt_entity_is_task(rt_se) (1) |
| 203 | |
Peter Zijlstra | 8f48894 | 2009-07-24 12:25:30 +0200 | [diff] [blame] | 204 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) |
| 205 | { |
| 206 | return container_of(rt_se, struct task_struct, rt); |
| 207 | } |
| 208 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 209 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) |
| 210 | { |
| 211 | return container_of(rt_rq, struct rq, rt); |
| 212 | } |
| 213 | |
| 214 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) |
| 215 | { |
| 216 | struct task_struct *p = rt_task_of(rt_se); |
| 217 | struct rq *rq = task_rq(p); |
| 218 | |
| 219 | return &rq->rt; |
| 220 | } |
| 221 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 222 | void free_rt_sched_group(struct task_group *tg) { } |
| 223 | |
| 224 | int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) |
| 225 | { |
| 226 | return 1; |
| 227 | } |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 228 | #endif /* CONFIG_RT_GROUP_SCHED */ |
| 229 | |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 230 | #ifdef CONFIG_SMP |
Ingo Molnar | 84de427 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 231 | |
Peter Zijlstra | 38033c3 | 2014-01-23 20:32:21 +0100 | [diff] [blame^] | 232 | static int pull_rt_task(struct rq *this_rq); |
| 233 | |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 234 | static inline int rt_overloaded(struct rq *rq) |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 235 | { |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 236 | return atomic_read(&rq->rd->rto_count); |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 237 | } |
Ingo Molnar | 84de427 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 238 | |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 239 | static inline void rt_set_overload(struct rq *rq) |
| 240 | { |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 241 | if (!rq->online) |
| 242 | return; |
| 243 | |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 244 | cpumask_set_cpu(rq->cpu, rq->rd->rto_mask); |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 245 | /* |
| 246 | * Make sure the mask is visible before we set |
| 247 | * the overload count. That is checked to determine |
| 248 | * if we should look at the mask. It would be a shame |
| 249 | * if we looked at the mask, but the mask was not |
| 250 | * updated yet. |
Peter Zijlstra | 7c3f2ab | 2013-10-15 12:35:07 +0200 | [diff] [blame] | 251 | * |
| 252 | * Matched by the barrier in pull_rt_task(). |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 253 | */ |
Peter Zijlstra | 7c3f2ab | 2013-10-15 12:35:07 +0200 | [diff] [blame] | 254 | smp_wmb(); |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 255 | atomic_inc(&rq->rd->rto_count); |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 256 | } |
Ingo Molnar | 84de427 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 257 | |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 258 | static inline void rt_clear_overload(struct rq *rq) |
| 259 | { |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 260 | if (!rq->online) |
| 261 | return; |
| 262 | |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 263 | /* the order here really doesn't matter */ |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 264 | atomic_dec(&rq->rd->rto_count); |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 265 | cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 266 | } |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 267 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 268 | static void update_rt_migration(struct rt_rq *rt_rq) |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 269 | { |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 270 | if (rt_rq->rt_nr_migratory && rt_rq->rt_nr_total > 1) { |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 271 | if (!rt_rq->overloaded) { |
| 272 | rt_set_overload(rq_of_rt_rq(rt_rq)); |
| 273 | rt_rq->overloaded = 1; |
Gregory Haskins | cdc8eb9 | 2008-01-25 21:08:23 +0100 | [diff] [blame] | 274 | } |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 275 | } else if (rt_rq->overloaded) { |
| 276 | rt_clear_overload(rq_of_rt_rq(rt_rq)); |
| 277 | rt_rq->overloaded = 0; |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 278 | } |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 279 | } |
Steven Rostedt | 4fd2917 | 2008-01-25 21:08:06 +0100 | [diff] [blame] | 280 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 281 | static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 282 | { |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 283 | struct task_struct *p; |
| 284 | |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 285 | if (!rt_entity_is_task(rt_se)) |
| 286 | return; |
| 287 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 288 | p = rt_task_of(rt_se); |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 289 | rt_rq = &rq_of_rt_rq(rt_rq)->rt; |
| 290 | |
| 291 | rt_rq->rt_nr_total++; |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 292 | if (p->nr_cpus_allowed > 1) |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 293 | rt_rq->rt_nr_migratory++; |
| 294 | |
| 295 | update_rt_migration(rt_rq); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 298 | static void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 299 | { |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 300 | struct task_struct *p; |
| 301 | |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 302 | if (!rt_entity_is_task(rt_se)) |
| 303 | return; |
| 304 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 305 | p = rt_task_of(rt_se); |
Peter Zijlstra | a1ba4d8 | 2009-04-01 18:40:15 +0200 | [diff] [blame] | 306 | rt_rq = &rq_of_rt_rq(rt_rq)->rt; |
| 307 | |
| 308 | rt_rq->rt_nr_total--; |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 309 | if (p->nr_cpus_allowed > 1) |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 310 | rt_rq->rt_nr_migratory--; |
| 311 | |
| 312 | update_rt_migration(rt_rq); |
| 313 | } |
| 314 | |
Steven Rostedt | 5181f4a4 | 2011-06-16 21:55:23 -0400 | [diff] [blame] | 315 | static inline int has_pushable_tasks(struct rq *rq) |
| 316 | { |
| 317 | return !plist_head_empty(&rq->rt.pushable_tasks); |
| 318 | } |
| 319 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 320 | static void enqueue_pushable_task(struct rq *rq, struct task_struct *p) |
| 321 | { |
| 322 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); |
| 323 | plist_node_init(&p->pushable_tasks, p->prio); |
| 324 | plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); |
Steven Rostedt | 5181f4a4 | 2011-06-16 21:55:23 -0400 | [diff] [blame] | 325 | |
| 326 | /* Update the highest prio pushable task */ |
| 327 | if (p->prio < rq->rt.highest_prio.next) |
| 328 | rq->rt.highest_prio.next = p->prio; |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static void dequeue_pushable_task(struct rq *rq, struct task_struct *p) |
| 332 | { |
| 333 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 334 | |
Steven Rostedt | 5181f4a4 | 2011-06-16 21:55:23 -0400 | [diff] [blame] | 335 | /* Update the new highest prio pushable task */ |
| 336 | if (has_pushable_tasks(rq)) { |
| 337 | p = plist_first_entry(&rq->rt.pushable_tasks, |
| 338 | struct task_struct, pushable_tasks); |
| 339 | rq->rt.highest_prio.next = p->prio; |
| 340 | } else |
| 341 | rq->rt.highest_prio.next = MAX_RT_PRIO; |
Ingo Molnar | bcf08df | 2008-04-19 12:11:10 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 344 | #else |
| 345 | |
Peter Zijlstra | ceacc2c | 2009-01-16 14:46:40 +0100 | [diff] [blame] | 346 | static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) |
| 347 | { |
| 348 | } |
| 349 | |
| 350 | static inline void dequeue_pushable_task(struct rq *rq, struct task_struct *p) |
| 351 | { |
| 352 | } |
| 353 | |
Gregory Haskins | b07430a | 2009-01-14 08:55:39 -0500 | [diff] [blame] | 354 | static inline |
Peter Zijlstra | ceacc2c | 2009-01-16 14:46:40 +0100 | [diff] [blame] | 355 | void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 356 | { |
| 357 | } |
| 358 | |
Gregory Haskins | b07430a | 2009-01-14 08:55:39 -0500 | [diff] [blame] | 359 | static inline |
Peter Zijlstra | ceacc2c | 2009-01-16 14:46:40 +0100 | [diff] [blame] | 360 | void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 361 | { |
| 362 | } |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 363 | |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 364 | #endif /* CONFIG_SMP */ |
| 365 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 366 | static inline int on_rt_rq(struct sched_rt_entity *rt_se) |
| 367 | { |
| 368 | return !list_empty(&rt_se->run_list); |
| 369 | } |
| 370 | |
Peter Zijlstra | 052f1dc | 2008-02-13 15:45:40 +0100 | [diff] [blame] | 371 | #ifdef CONFIG_RT_GROUP_SCHED |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 372 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 373 | static inline u64 sched_rt_runtime(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 374 | { |
| 375 | if (!rt_rq->tg) |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 376 | return RUNTIME_INF; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 377 | |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 378 | return rt_rq->rt_runtime; |
| 379 | } |
| 380 | |
| 381 | static inline u64 sched_rt_period(struct rt_rq *rt_rq) |
| 382 | { |
| 383 | return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 386 | typedef struct task_group *rt_rq_iter_t; |
| 387 | |
Yong Zhang | 1c09ab0 | 2011-06-28 10:51:31 +0800 | [diff] [blame] | 388 | static inline struct task_group *next_task_group(struct task_group *tg) |
| 389 | { |
| 390 | do { |
| 391 | tg = list_entry_rcu(tg->list.next, |
| 392 | typeof(struct task_group), list); |
| 393 | } while (&tg->list != &task_groups && task_group_is_autogroup(tg)); |
| 394 | |
| 395 | if (&tg->list == &task_groups) |
| 396 | tg = NULL; |
| 397 | |
| 398 | return tg; |
| 399 | } |
| 400 | |
| 401 | #define for_each_rt_rq(rt_rq, iter, rq) \ |
| 402 | for (iter = container_of(&task_groups, typeof(*iter), list); \ |
| 403 | (iter = next_task_group(iter)) && \ |
| 404 | (rt_rq = iter->rt_rq[cpu_of(rq)]);) |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 405 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 406 | #define for_each_sched_rt_entity(rt_se) \ |
| 407 | for (; rt_se; rt_se = rt_se->parent) |
| 408 | |
| 409 | static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) |
| 410 | { |
| 411 | return rt_se->my_q; |
| 412 | } |
| 413 | |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 414 | static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 415 | static void dequeue_rt_entity(struct sched_rt_entity *rt_se); |
| 416 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 417 | static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 418 | { |
Dario Faggioli | f6121f4 | 2008-10-03 17:40:46 +0200 | [diff] [blame] | 419 | struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; |
Yong Zhang | 74b7eb5 | 2010-01-29 14:57:52 +0800 | [diff] [blame] | 420 | struct sched_rt_entity *rt_se; |
| 421 | |
Balbir Singh | 0c3b916 | 2011-03-03 17:04:35 +0530 | [diff] [blame] | 422 | int cpu = cpu_of(rq_of_rt_rq(rt_rq)); |
| 423 | |
| 424 | rt_se = rt_rq->tg->rt_se[cpu]; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 425 | |
Dario Faggioli | f6121f4 | 2008-10-03 17:40:46 +0200 | [diff] [blame] | 426 | if (rt_rq->rt_nr_running) { |
| 427 | if (rt_se && !on_rt_rq(rt_se)) |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 428 | enqueue_rt_entity(rt_se, false); |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 429 | if (rt_rq->highest_prio.curr < curr->prio) |
Peter Zijlstra | 1020387 | 2008-01-25 21:08:32 +0100 | [diff] [blame] | 430 | resched_task(curr); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 434 | static void sched_rt_rq_dequeue(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 435 | { |
Yong Zhang | 74b7eb5 | 2010-01-29 14:57:52 +0800 | [diff] [blame] | 436 | struct sched_rt_entity *rt_se; |
Balbir Singh | 0c3b916 | 2011-03-03 17:04:35 +0530 | [diff] [blame] | 437 | int cpu = cpu_of(rq_of_rt_rq(rt_rq)); |
Yong Zhang | 74b7eb5 | 2010-01-29 14:57:52 +0800 | [diff] [blame] | 438 | |
Balbir Singh | 0c3b916 | 2011-03-03 17:04:35 +0530 | [diff] [blame] | 439 | rt_se = rt_rq->tg->rt_se[cpu]; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 440 | |
| 441 | if (rt_se && on_rt_rq(rt_se)) |
| 442 | dequeue_rt_entity(rt_se); |
| 443 | } |
| 444 | |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 445 | static inline int rt_rq_throttled(struct rt_rq *rt_rq) |
| 446 | { |
| 447 | return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted; |
| 448 | } |
| 449 | |
| 450 | static int rt_se_boosted(struct sched_rt_entity *rt_se) |
| 451 | { |
| 452 | struct rt_rq *rt_rq = group_rt_rq(rt_se); |
| 453 | struct task_struct *p; |
| 454 | |
| 455 | if (rt_rq) |
| 456 | return !!rt_rq->rt_nr_boosted; |
| 457 | |
| 458 | p = rt_task_of(rt_se); |
| 459 | return p->prio != p->normal_prio; |
| 460 | } |
| 461 | |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 462 | #ifdef CONFIG_SMP |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 463 | static inline const struct cpumask *sched_rt_period_mask(void) |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 464 | { |
Nathan Zimmer | 424c93f | 2013-05-09 11:24:03 -0500 | [diff] [blame] | 465 | return this_rq()->rd->span; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 466 | } |
| 467 | #else |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 468 | static inline const struct cpumask *sched_rt_period_mask(void) |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 469 | { |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 470 | return cpu_online_mask; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 471 | } |
| 472 | #endif |
| 473 | |
| 474 | static inline |
| 475 | struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu) |
| 476 | { |
| 477 | return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu]; |
| 478 | } |
| 479 | |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 480 | static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq) |
| 481 | { |
| 482 | return &rt_rq->tg->rt_bandwidth; |
| 483 | } |
| 484 | |
Dhaval Giani | 55e12e5 | 2008-06-24 23:39:43 +0530 | [diff] [blame] | 485 | #else /* !CONFIG_RT_GROUP_SCHED */ |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 486 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 487 | static inline u64 sched_rt_runtime(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 488 | { |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 489 | return rt_rq->rt_runtime; |
| 490 | } |
| 491 | |
| 492 | static inline u64 sched_rt_period(struct rt_rq *rt_rq) |
| 493 | { |
| 494 | return ktime_to_ns(def_rt_bandwidth.rt_period); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 497 | typedef struct rt_rq *rt_rq_iter_t; |
| 498 | |
| 499 | #define for_each_rt_rq(rt_rq, iter, rq) \ |
| 500 | for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL) |
| 501 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 502 | #define for_each_sched_rt_entity(rt_se) \ |
| 503 | for (; rt_se; rt_se = NULL) |
| 504 | |
| 505 | static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) |
| 506 | { |
| 507 | return NULL; |
| 508 | } |
| 509 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 510 | static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 511 | { |
John Blackwood | f3ade83 | 2008-08-26 15:09:43 -0400 | [diff] [blame] | 512 | if (rt_rq->rt_nr_running) |
| 513 | resched_task(rq_of_rt_rq(rt_rq)->curr); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 516 | static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 517 | { |
| 518 | } |
| 519 | |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 520 | static inline int rt_rq_throttled(struct rt_rq *rt_rq) |
| 521 | { |
| 522 | return rt_rq->rt_throttled; |
| 523 | } |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 524 | |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 525 | static inline const struct cpumask *sched_rt_period_mask(void) |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 526 | { |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 527 | return cpu_online_mask; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static inline |
| 531 | struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu) |
| 532 | { |
| 533 | return &cpu_rq(cpu)->rt; |
| 534 | } |
| 535 | |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 536 | static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq) |
| 537 | { |
| 538 | return &def_rt_bandwidth; |
| 539 | } |
| 540 | |
Dhaval Giani | 55e12e5 | 2008-06-24 23:39:43 +0530 | [diff] [blame] | 541 | #endif /* CONFIG_RT_GROUP_SCHED */ |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 542 | |
Peter Zijlstra | b79f383 | 2008-06-19 14:22:25 +0200 | [diff] [blame] | 543 | #ifdef CONFIG_SMP |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 544 | /* |
| 545 | * We ran out of runtime, see if we can borrow some from our neighbours. |
| 546 | */ |
Peter Zijlstra | b79f383 | 2008-06-19 14:22:25 +0200 | [diff] [blame] | 547 | static int do_balance_runtime(struct rt_rq *rt_rq) |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 548 | { |
| 549 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
Shawn Bohrer | aa7f673 | 2013-01-14 11:55:31 -0600 | [diff] [blame] | 550 | struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd; |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 551 | int i, weight, more = 0; |
| 552 | u64 rt_period; |
| 553 | |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 554 | weight = cpumask_weight(rd->span); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 555 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 556 | raw_spin_lock(&rt_b->rt_runtime_lock); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 557 | rt_period = ktime_to_ns(rt_b->rt_period); |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 558 | for_each_cpu(i, rd->span) { |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 559 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); |
| 560 | s64 diff; |
| 561 | |
| 562 | if (iter == rt_rq) |
| 563 | continue; |
| 564 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 565 | raw_spin_lock(&iter->rt_runtime_lock); |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 566 | /* |
| 567 | * Either all rqs have inf runtime and there's nothing to steal |
| 568 | * or __disable_runtime() below sets a specific rq to inf to |
| 569 | * indicate its been disabled and disalow stealing. |
| 570 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 571 | if (iter->rt_runtime == RUNTIME_INF) |
| 572 | goto next; |
| 573 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 574 | /* |
| 575 | * From runqueues with spare time, take 1/n part of their |
| 576 | * spare time, but no more than our period. |
| 577 | */ |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 578 | diff = iter->rt_runtime - iter->rt_time; |
| 579 | if (diff > 0) { |
Peter Zijlstra | 58838cf | 2008-07-24 12:43:13 +0200 | [diff] [blame] | 580 | diff = div_u64((u64)diff, weight); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 581 | if (rt_rq->rt_runtime + diff > rt_period) |
| 582 | diff = rt_period - rt_rq->rt_runtime; |
| 583 | iter->rt_runtime -= diff; |
| 584 | rt_rq->rt_runtime += diff; |
| 585 | more = 1; |
| 586 | if (rt_rq->rt_runtime == rt_period) { |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 587 | raw_spin_unlock(&iter->rt_runtime_lock); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 588 | break; |
| 589 | } |
| 590 | } |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 591 | next: |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 592 | raw_spin_unlock(&iter->rt_runtime_lock); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 593 | } |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 594 | raw_spin_unlock(&rt_b->rt_runtime_lock); |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 595 | |
| 596 | return more; |
| 597 | } |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 598 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 599 | /* |
| 600 | * Ensure this RQ takes back all the runtime it lend to its neighbours. |
| 601 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 602 | static void __disable_runtime(struct rq *rq) |
| 603 | { |
| 604 | struct root_domain *rd = rq->rd; |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 605 | rt_rq_iter_t iter; |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 606 | struct rt_rq *rt_rq; |
| 607 | |
| 608 | if (unlikely(!scheduler_running)) |
| 609 | return; |
| 610 | |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 611 | for_each_rt_rq(rt_rq, iter, rq) { |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 612 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
| 613 | s64 want; |
| 614 | int i; |
| 615 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 616 | raw_spin_lock(&rt_b->rt_runtime_lock); |
| 617 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 618 | /* |
| 619 | * Either we're all inf and nobody needs to borrow, or we're |
| 620 | * already disabled and thus have nothing to do, or we have |
| 621 | * exactly the right amount of runtime to take out. |
| 622 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 623 | if (rt_rq->rt_runtime == RUNTIME_INF || |
| 624 | rt_rq->rt_runtime == rt_b->rt_runtime) |
| 625 | goto balanced; |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 626 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 627 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 628 | /* |
| 629 | * Calculate the difference between what we started out with |
| 630 | * and what we current have, that's the amount of runtime |
| 631 | * we lend and now have to reclaim. |
| 632 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 633 | want = rt_b->rt_runtime - rt_rq->rt_runtime; |
| 634 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 635 | /* |
| 636 | * Greedy reclaim, take back as much as we can. |
| 637 | */ |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 638 | for_each_cpu(i, rd->span) { |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 639 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); |
| 640 | s64 diff; |
| 641 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 642 | /* |
| 643 | * Can't reclaim from ourselves or disabled runqueues. |
| 644 | */ |
Peter Zijlstra | f1679d0 | 2008-08-14 15:49:00 +0200 | [diff] [blame] | 645 | if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 646 | continue; |
| 647 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 648 | raw_spin_lock(&iter->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 649 | if (want > 0) { |
| 650 | diff = min_t(s64, iter->rt_runtime, want); |
| 651 | iter->rt_runtime -= diff; |
| 652 | want -= diff; |
| 653 | } else { |
| 654 | iter->rt_runtime -= want; |
| 655 | want -= want; |
| 656 | } |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 657 | raw_spin_unlock(&iter->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 658 | |
| 659 | if (!want) |
| 660 | break; |
| 661 | } |
| 662 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 663 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 664 | /* |
| 665 | * We cannot be left wanting - that would mean some runtime |
| 666 | * leaked out of the system. |
| 667 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 668 | BUG_ON(want); |
| 669 | balanced: |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 670 | /* |
| 671 | * Disable all the borrow logic by pretending we have inf |
| 672 | * runtime - in which case borrowing doesn't make sense. |
| 673 | */ |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 674 | rt_rq->rt_runtime = RUNTIME_INF; |
Peter Boonstoppel | a4c96ae | 2012-08-09 15:34:47 -0700 | [diff] [blame] | 675 | rt_rq->rt_throttled = 0; |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 676 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
| 677 | raw_spin_unlock(&rt_b->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 681 | static void __enable_runtime(struct rq *rq) |
| 682 | { |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 683 | rt_rq_iter_t iter; |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 684 | struct rt_rq *rt_rq; |
| 685 | |
| 686 | if (unlikely(!scheduler_running)) |
| 687 | return; |
| 688 | |
Peter Zijlstra | 78333cd | 2008-09-23 15:33:43 +0200 | [diff] [blame] | 689 | /* |
| 690 | * Reset each runqueue's bandwidth settings |
| 691 | */ |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 692 | for_each_rt_rq(rt_rq, iter, rq) { |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 693 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
| 694 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 695 | raw_spin_lock(&rt_b->rt_runtime_lock); |
| 696 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 697 | rt_rq->rt_runtime = rt_b->rt_runtime; |
| 698 | rt_rq->rt_time = 0; |
Zhang, Yanmin | baf2573 | 2008-09-09 11:26:33 +0800 | [diff] [blame] | 699 | rt_rq->rt_throttled = 0; |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 700 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
| 701 | raw_spin_unlock(&rt_b->rt_runtime_lock); |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 705 | static int balance_runtime(struct rt_rq *rt_rq) |
| 706 | { |
| 707 | int more = 0; |
| 708 | |
Peter Zijlstra | 4a6184c | 2011-10-06 22:39:14 +0200 | [diff] [blame] | 709 | if (!sched_feat(RT_RUNTIME_SHARE)) |
| 710 | return more; |
| 711 | |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 712 | if (rt_rq->rt_time > rt_rq->rt_runtime) { |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 713 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 714 | more = do_balance_runtime(rt_rq); |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 715 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | return more; |
| 719 | } |
Dhaval Giani | 55e12e5 | 2008-06-24 23:39:43 +0530 | [diff] [blame] | 720 | #else /* !CONFIG_SMP */ |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 721 | static inline int balance_runtime(struct rt_rq *rt_rq) |
| 722 | { |
| 723 | return 0; |
| 724 | } |
Dhaval Giani | 55e12e5 | 2008-06-24 23:39:43 +0530 | [diff] [blame] | 725 | #endif /* CONFIG_SMP */ |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 726 | |
| 727 | static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun) |
| 728 | { |
Peter Zijlstra | 42c62a5 | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 729 | int i, idle = 1, throttled = 0; |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 730 | const struct cpumask *span; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 731 | |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 732 | span = sched_rt_period_mask(); |
Mike Galbraith | e221d02 | 2012-08-07 10:02:38 +0200 | [diff] [blame] | 733 | #ifdef CONFIG_RT_GROUP_SCHED |
| 734 | /* |
| 735 | * FIXME: isolated CPUs should really leave the root task group, |
| 736 | * whether they are isolcpus or were isolated via cpusets, lest |
| 737 | * the timer run on a CPU which does not service all runqueues, |
| 738 | * potentially leaving other CPUs indefinitely throttled. If |
| 739 | * isolation is really required, the user will turn the throttle |
| 740 | * off to kill the perturbations it causes anyway. Meanwhile, |
| 741 | * this maintains functionality for boot and/or troubleshooting. |
| 742 | */ |
| 743 | if (rt_b == &root_task_group.rt_bandwidth) |
| 744 | span = cpu_online_mask; |
| 745 | #endif |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 746 | for_each_cpu(i, span) { |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 747 | int enqueue = 0; |
| 748 | struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i); |
| 749 | struct rq *rq = rq_of_rt_rq(rt_rq); |
| 750 | |
Thomas Gleixner | 05fa785 | 2009-11-17 14:28:38 +0100 | [diff] [blame] | 751 | raw_spin_lock(&rq->lock); |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 752 | if (rt_rq->rt_time) { |
| 753 | u64 runtime; |
| 754 | |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 755 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | eff6549 | 2008-06-19 14:22:26 +0200 | [diff] [blame] | 756 | if (rt_rq->rt_throttled) |
| 757 | balance_runtime(rt_rq); |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 758 | runtime = rt_rq->rt_runtime; |
| 759 | rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime); |
| 760 | if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { |
| 761 | rt_rq->rt_throttled = 0; |
| 762 | enqueue = 1; |
Mike Galbraith | 61eadef | 2011-04-29 08:36:50 +0200 | [diff] [blame] | 763 | |
| 764 | /* |
| 765 | * Force a clock update if the CPU was idle, |
| 766 | * lest wakeup -> unthrottle time accumulate. |
| 767 | */ |
| 768 | if (rt_rq->rt_nr_running && rq->curr == rq->idle) |
| 769 | rq->skip_clock_update = -1; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 770 | } |
| 771 | if (rt_rq->rt_time || rt_rq->rt_nr_running) |
| 772 | idle = 0; |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 773 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
Balbir Singh | 0c3b916 | 2011-03-03 17:04:35 +0530 | [diff] [blame] | 774 | } else if (rt_rq->rt_nr_running) { |
Peter Zijlstra | 8a8cde1 | 2008-06-19 14:22:28 +0200 | [diff] [blame] | 775 | idle = 0; |
Balbir Singh | 0c3b916 | 2011-03-03 17:04:35 +0530 | [diff] [blame] | 776 | if (!rt_rq_throttled(rt_rq)) |
| 777 | enqueue = 1; |
| 778 | } |
Peter Zijlstra | 42c62a5 | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 779 | if (rt_rq->rt_throttled) |
| 780 | throttled = 1; |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 781 | |
| 782 | if (enqueue) |
| 783 | sched_rt_rq_enqueue(rt_rq); |
Thomas Gleixner | 05fa785 | 2009-11-17 14:28:38 +0100 | [diff] [blame] | 784 | raw_spin_unlock(&rq->lock); |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 785 | } |
| 786 | |
Peter Zijlstra | 42c62a5 | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 787 | if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)) |
| 788 | return 1; |
| 789 | |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 790 | return idle; |
| 791 | } |
| 792 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 793 | static inline int rt_se_prio(struct sched_rt_entity *rt_se) |
| 794 | { |
Peter Zijlstra | 052f1dc | 2008-02-13 15:45:40 +0100 | [diff] [blame] | 795 | #ifdef CONFIG_RT_GROUP_SCHED |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 796 | struct rt_rq *rt_rq = group_rt_rq(rt_se); |
| 797 | |
| 798 | if (rt_rq) |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 799 | return rt_rq->highest_prio.curr; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 800 | #endif |
| 801 | |
| 802 | return rt_task_of(rt_se)->prio; |
| 803 | } |
| 804 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 805 | static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 806 | { |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 807 | u64 runtime = sched_rt_runtime(rt_rq); |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 808 | |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 809 | if (rt_rq->rt_throttled) |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 810 | return rt_rq_throttled(rt_rq); |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 811 | |
Shan Hai | 5b680fd | 2011-11-29 11:03:56 +0800 | [diff] [blame] | 812 | if (runtime >= sched_rt_period(rt_rq)) |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 813 | return 0; |
| 814 | |
Peter Zijlstra | b79f383 | 2008-06-19 14:22:25 +0200 | [diff] [blame] | 815 | balance_runtime(rt_rq); |
| 816 | runtime = sched_rt_runtime(rt_rq); |
| 817 | if (runtime == RUNTIME_INF) |
| 818 | return 0; |
Peter Zijlstra | ac086bc | 2008-04-19 19:44:58 +0200 | [diff] [blame] | 819 | |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 820 | if (rt_rq->rt_time > runtime) { |
Peter Zijlstra | 7abc63b | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 821 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
| 822 | |
| 823 | /* |
| 824 | * Don't actually throttle groups that have no runtime assigned |
| 825 | * but accrue some time due to boosting. |
| 826 | */ |
| 827 | if (likely(rt_b->rt_runtime)) { |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 828 | static bool once = false; |
| 829 | |
Peter Zijlstra | 7abc63b | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 830 | rt_rq->rt_throttled = 1; |
Peter Zijlstra | 3ccf3e8 | 2012-02-27 10:47:00 +0100 | [diff] [blame] | 831 | |
| 832 | if (!once) { |
| 833 | once = true; |
| 834 | printk_sched("sched: RT throttling activated\n"); |
| 835 | } |
Peter Zijlstra | 7abc63b | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 836 | } else { |
| 837 | /* |
| 838 | * In case we did anyway, make it go away, |
| 839 | * replenishment is a joke, since it will replenish us |
| 840 | * with exactly 0 ns. |
| 841 | */ |
| 842 | rt_rq->rt_time = 0; |
| 843 | } |
| 844 | |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 845 | if (rt_rq_throttled(rt_rq)) { |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 846 | sched_rt_rq_dequeue(rt_rq); |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 847 | return 1; |
| 848 | } |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 854 | /* |
| 855 | * Update the current task's runtime statistics. Skip current tasks that |
| 856 | * are not in our scheduling class. |
| 857 | */ |
Alexey Dobriyan | a995744 | 2007-10-15 17:00:13 +0200 | [diff] [blame] | 858 | static void update_curr_rt(struct rq *rq) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 859 | { |
| 860 | struct task_struct *curr = rq->curr; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 861 | struct sched_rt_entity *rt_se = &curr->rt; |
| 862 | struct rt_rq *rt_rq = rt_rq_of_se(rt_se); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 863 | u64 delta_exec; |
| 864 | |
Peter Zijlstra | 06c3bc6 | 2011-02-02 13:19:48 +0100 | [diff] [blame] | 865 | if (curr->sched_class != &rt_sched_class) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 866 | return; |
| 867 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 868 | delta_exec = rq_clock_task(rq) - curr->se.exec_start; |
Kirill Tkhai | fc79e24 | 2013-01-30 16:50:36 +0400 | [diff] [blame] | 869 | if (unlikely((s64)delta_exec <= 0)) |
| 870 | return; |
Ingo Molnar | 6cfb0d5 | 2007-08-02 17:41:40 +0200 | [diff] [blame] | 871 | |
Peter Zijlstra | 42c62a5 | 2011-10-18 22:03:48 +0200 | [diff] [blame] | 872 | schedstat_set(curr->se.statistics.exec_max, |
| 873 | max(curr->se.statistics.exec_max, delta_exec)); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 874 | |
| 875 | curr->se.sum_exec_runtime += delta_exec; |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 876 | account_group_exec_runtime(curr, delta_exec); |
| 877 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 878 | curr->se.exec_start = rq_clock_task(rq); |
Srivatsa Vaddagiri | d842de8 | 2007-12-02 20:04:49 +0100 | [diff] [blame] | 879 | cpuacct_charge(curr, delta_exec); |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 880 | |
Peter Zijlstra | e9e9250 | 2009-09-01 10:34:37 +0200 | [diff] [blame] | 881 | sched_rt_avg_update(rq, delta_exec); |
| 882 | |
Peter Zijlstra | 0b148fa | 2008-08-19 12:33:04 +0200 | [diff] [blame] | 883 | if (!rt_bandwidth_enabled()) |
| 884 | return; |
| 885 | |
Dhaval Giani | 354d60c | 2008-04-19 19:44:59 +0200 | [diff] [blame] | 886 | for_each_sched_rt_entity(rt_se) { |
| 887 | rt_rq = rt_rq_of_se(rt_se); |
| 888 | |
Peter Zijlstra | cc2991c | 2008-08-19 12:33:03 +0200 | [diff] [blame] | 889 | if (sched_rt_runtime(rt_rq) != RUNTIME_INF) { |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 890 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | cc2991c | 2008-08-19 12:33:03 +0200 | [diff] [blame] | 891 | rt_rq->rt_time += delta_exec; |
| 892 | if (sched_rt_runtime_exceeded(rt_rq)) |
| 893 | resched_task(curr); |
Thomas Gleixner | 0986b11 | 2009-11-17 15:32:06 +0100 | [diff] [blame] | 894 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | cc2991c | 2008-08-19 12:33:03 +0200 | [diff] [blame] | 895 | } |
Dhaval Giani | 354d60c | 2008-04-19 19:44:59 +0200 | [diff] [blame] | 896 | } |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 897 | } |
| 898 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 899 | #if defined CONFIG_SMP |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 900 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 901 | static void |
| 902 | inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) |
Steven Rostedt | 63489e4 | 2008-01-25 21:08:03 +0100 | [diff] [blame] | 903 | { |
Gregory Haskins | 4d98427 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 904 | struct rq *rq = rq_of_rt_rq(rt_rq); |
Gregory Haskins | 4d98427 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 905 | |
Kirill Tkhai | 757dfca | 2013-11-27 19:59:13 +0400 | [diff] [blame] | 906 | #ifdef CONFIG_RT_GROUP_SCHED |
| 907 | /* |
| 908 | * Change rq's cpupri only if rt_rq is the top queue. |
| 909 | */ |
| 910 | if (&rq->rt != rt_rq) |
| 911 | return; |
| 912 | #endif |
Steven Rostedt | 5181f4a4 | 2011-06-16 21:55:23 -0400 | [diff] [blame] | 913 | if (rq->online && prio < prev_prio) |
| 914 | cpupri_set(&rq->rd->cpupri, rq->cpu, prio); |
Steven Rostedt | 63489e4 | 2008-01-25 21:08:03 +0100 | [diff] [blame] | 915 | } |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 916 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 917 | static void |
| 918 | dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) |
Steven Rostedt | 63489e4 | 2008-01-25 21:08:03 +0100 | [diff] [blame] | 919 | { |
Gregory Haskins | 4d98427 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 920 | struct rq *rq = rq_of_rt_rq(rt_rq); |
Gregory Haskins | 6e0534f | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 921 | |
Kirill Tkhai | 757dfca | 2013-11-27 19:59:13 +0400 | [diff] [blame] | 922 | #ifdef CONFIG_RT_GROUP_SCHED |
| 923 | /* |
| 924 | * Change rq's cpupri only if rt_rq is the top queue. |
| 925 | */ |
| 926 | if (&rq->rt != rt_rq) |
| 927 | return; |
| 928 | #endif |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 929 | if (rq->online && rt_rq->highest_prio.curr != prev_prio) |
| 930 | cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr); |
| 931 | } |
| 932 | |
| 933 | #else /* CONFIG_SMP */ |
| 934 | |
| 935 | static inline |
| 936 | void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {} |
| 937 | static inline |
| 938 | void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {} |
| 939 | |
| 940 | #endif /* CONFIG_SMP */ |
| 941 | |
Steven Rostedt | 63489e4 | 2008-01-25 21:08:03 +0100 | [diff] [blame] | 942 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 943 | static void |
| 944 | inc_rt_prio(struct rt_rq *rt_rq, int prio) |
| 945 | { |
| 946 | int prev_prio = rt_rq->highest_prio.curr; |
Steven Rostedt | 63489e4 | 2008-01-25 21:08:03 +0100 | [diff] [blame] | 947 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 948 | if (prio < prev_prio) |
| 949 | rt_rq->highest_prio.curr = prio; |
| 950 | |
| 951 | inc_rt_prio_smp(rt_rq, prio, prev_prio); |
| 952 | } |
| 953 | |
| 954 | static void |
| 955 | dec_rt_prio(struct rt_rq *rt_rq, int prio) |
| 956 | { |
| 957 | int prev_prio = rt_rq->highest_prio.curr; |
| 958 | |
| 959 | if (rt_rq->rt_nr_running) { |
| 960 | |
| 961 | WARN_ON(prio < prev_prio); |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 962 | |
| 963 | /* |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 964 | * This may have been our highest task, and therefore |
| 965 | * we may have some recomputation to do |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 966 | */ |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 967 | if (prio == prev_prio) { |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 968 | struct rt_prio_array *array = &rt_rq->active; |
| 969 | |
| 970 | rt_rq->highest_prio.curr = |
Steven Rostedt | 764a9d6 | 2008-01-25 21:08:04 +0100 | [diff] [blame] | 971 | sched_find_first_bit(array->bitmap); |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 972 | } |
| 973 | |
Steven Rostedt | 764a9d6 | 2008-01-25 21:08:04 +0100 | [diff] [blame] | 974 | } else |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 975 | rt_rq->highest_prio.curr = MAX_RT_PRIO; |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 976 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 977 | dec_rt_prio_smp(rt_rq, prio, prev_prio); |
| 978 | } |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 979 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 980 | #else |
| 981 | |
| 982 | static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {} |
| 983 | static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {} |
| 984 | |
| 985 | #endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */ |
| 986 | |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 987 | #ifdef CONFIG_RT_GROUP_SCHED |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 988 | |
| 989 | static void |
| 990 | inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 991 | { |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 992 | if (rt_se_boosted(rt_se)) |
Steven Rostedt | 764a9d6 | 2008-01-25 21:08:04 +0100 | [diff] [blame] | 993 | rt_rq->rt_nr_boosted++; |
Peter Zijlstra | 052f1dc | 2008-02-13 15:45:40 +0100 | [diff] [blame] | 994 | |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 995 | if (rt_rq->tg) |
| 996 | start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | static void |
| 1000 | dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 1001 | { |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 1002 | if (rt_se_boosted(rt_se)) |
| 1003 | rt_rq->rt_nr_boosted--; |
| 1004 | |
| 1005 | WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | #else /* CONFIG_RT_GROUP_SCHED */ |
| 1009 | |
| 1010 | static void |
| 1011 | inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 1012 | { |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1013 | start_rt_bandwidth(&def_rt_bandwidth); |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | static inline |
| 1017 | void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {} |
| 1018 | |
| 1019 | #endif /* CONFIG_RT_GROUP_SCHED */ |
| 1020 | |
| 1021 | static inline |
| 1022 | void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 1023 | { |
| 1024 | int prio = rt_se_prio(rt_se); |
| 1025 | |
| 1026 | WARN_ON(!rt_prio(prio)); |
| 1027 | rt_rq->rt_nr_running++; |
| 1028 | |
| 1029 | inc_rt_prio(rt_rq, prio); |
| 1030 | inc_rt_migration(rt_se, rt_rq); |
| 1031 | inc_rt_group(rt_se, rt_rq); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
Peter Zijlstra | 23b0fdf | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 1034 | static inline |
| 1035 | void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 1036 | { |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1037 | WARN_ON(!rt_prio(rt_se_prio(rt_se))); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1038 | WARN_ON(!rt_rq->rt_nr_running); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1039 | rt_rq->rt_nr_running--; |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1040 | |
Gregory Haskins | 398a153 | 2009-01-14 09:10:04 -0500 | [diff] [blame] | 1041 | dec_rt_prio(rt_rq, rt_se_prio(rt_se)); |
| 1042 | dec_rt_migration(rt_se, rt_rq); |
| 1043 | dec_rt_group(rt_se, rt_rq); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 1046 | static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1047 | { |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1048 | struct rt_rq *rt_rq = rt_rq_of_se(rt_se); |
| 1049 | struct rt_prio_array *array = &rt_rq->active; |
| 1050 | struct rt_rq *group_rq = group_rt_rq(rt_se); |
Dmitry Adamushko | 20b6331 | 2008-06-11 00:58:30 +0200 | [diff] [blame] | 1051 | struct list_head *queue = array->queue + rt_se_prio(rt_se); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1052 | |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1053 | /* |
| 1054 | * Don't enqueue the group if its throttled, or when empty. |
| 1055 | * The latter is a consequence of the former when a child group |
| 1056 | * get throttled and the current group doesn't have any other |
| 1057 | * active members. |
| 1058 | */ |
| 1059 | if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1060 | return; |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1061 | |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 1062 | if (head) |
| 1063 | list_add(&rt_se->run_list, queue); |
| 1064 | else |
| 1065 | list_add_tail(&rt_se->run_list, queue); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1066 | __set_bit(rt_se_prio(rt_se), array->bitmap); |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1067 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1068 | inc_rt_tasks(rt_se, rt_rq); |
| 1069 | } |
| 1070 | |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1071 | static void __dequeue_rt_entity(struct sched_rt_entity *rt_se) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1072 | { |
| 1073 | struct rt_rq *rt_rq = rt_rq_of_se(rt_se); |
| 1074 | struct rt_prio_array *array = &rt_rq->active; |
| 1075 | |
| 1076 | list_del_init(&rt_se->run_list); |
| 1077 | if (list_empty(array->queue + rt_se_prio(rt_se))) |
| 1078 | __clear_bit(rt_se_prio(rt_se), array->bitmap); |
| 1079 | |
| 1080 | dec_rt_tasks(rt_se, rt_rq); |
| 1081 | } |
| 1082 | |
| 1083 | /* |
| 1084 | * Because the prio of an upper entry depends on the lower |
| 1085 | * entries, we must remove entries top - down. |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1086 | */ |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1087 | static void dequeue_rt_stack(struct sched_rt_entity *rt_se) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1088 | { |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1089 | struct sched_rt_entity *back = NULL; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1090 | |
Peter Zijlstra | 58d6c2d | 2008-04-19 19:45:00 +0200 | [diff] [blame] | 1091 | for_each_sched_rt_entity(rt_se) { |
| 1092 | rt_se->back = back; |
| 1093 | back = rt_se; |
| 1094 | } |
| 1095 | |
| 1096 | for (rt_se = back; rt_se; rt_se = rt_se->back) { |
| 1097 | if (on_rt_rq(rt_se)) |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1098 | __dequeue_rt_entity(rt_se); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 1102 | static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head) |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1103 | { |
| 1104 | dequeue_rt_stack(rt_se); |
| 1105 | for_each_sched_rt_entity(rt_se) |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 1106 | __enqueue_rt_entity(rt_se, head); |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | static void dequeue_rt_entity(struct sched_rt_entity *rt_se) |
| 1110 | { |
| 1111 | dequeue_rt_stack(rt_se); |
| 1112 | |
| 1113 | for_each_sched_rt_entity(rt_se) { |
| 1114 | struct rt_rq *rt_rq = group_rt_rq(rt_se); |
| 1115 | |
| 1116 | if (rt_rq && rt_rq->rt_nr_running) |
Thomas Gleixner | 37dad3f | 2010-01-20 20:59:01 +0000 | [diff] [blame] | 1117 | __enqueue_rt_entity(rt_se, false); |
Peter Zijlstra | 58d6c2d | 2008-04-19 19:45:00 +0200 | [diff] [blame] | 1118 | } |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /* |
| 1122 | * Adding/removing a task to/from a priority array: |
| 1123 | */ |
Thomas Gleixner | ea87bb7 | 2010-01-20 20:58:57 +0000 | [diff] [blame] | 1124 | static void |
Peter Zijlstra | 371fd7e | 2010-03-24 16:38:48 +0100 | [diff] [blame] | 1125 | enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1126 | { |
| 1127 | struct sched_rt_entity *rt_se = &p->rt; |
| 1128 | |
Peter Zijlstra | 371fd7e | 2010-03-24 16:38:48 +0100 | [diff] [blame] | 1129 | if (flags & ENQUEUE_WAKEUP) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1130 | rt_se->timeout = 0; |
| 1131 | |
Peter Zijlstra | 371fd7e | 2010-03-24 16:38:48 +0100 | [diff] [blame] | 1132 | enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD); |
Peter Zijlstra | c09595f | 2008-06-27 13:41:14 +0200 | [diff] [blame] | 1133 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1134 | if (!task_current(rq, p) && p->nr_cpus_allowed > 1) |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1135 | enqueue_pushable_task(rq, p); |
Paul Turner | 953bfcd | 2011-07-21 09:43:27 -0700 | [diff] [blame] | 1136 | |
| 1137 | inc_nr_running(rq); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1138 | } |
| 1139 | |
Peter Zijlstra | 371fd7e | 2010-03-24 16:38:48 +0100 | [diff] [blame] | 1140 | static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1141 | { |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1142 | struct sched_rt_entity *rt_se = &p->rt; |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1143 | |
| 1144 | update_curr_rt(rq); |
Peter Zijlstra | ad2a3f1 | 2008-06-19 09:06:57 +0200 | [diff] [blame] | 1145 | dequeue_rt_entity(rt_se); |
Peter Zijlstra | c09595f | 2008-06-27 13:41:14 +0200 | [diff] [blame] | 1146 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1147 | dequeue_pushable_task(rq, p); |
Paul Turner | 953bfcd | 2011-07-21 09:43:27 -0700 | [diff] [blame] | 1148 | |
| 1149 | dec_nr_running(rq); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /* |
Richard Weinberger | 6068631 | 2011-11-12 18:07:57 +0100 | [diff] [blame] | 1153 | * Put task to the head or the end of the run list without the overhead of |
| 1154 | * dequeue followed by enqueue. |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1155 | */ |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1156 | static void |
| 1157 | requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1158 | { |
Ingo Molnar | 1cdad71 | 2008-06-19 09:09:15 +0200 | [diff] [blame] | 1159 | if (on_rt_rq(rt_se)) { |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1160 | struct rt_prio_array *array = &rt_rq->active; |
| 1161 | struct list_head *queue = array->queue + rt_se_prio(rt_se); |
| 1162 | |
| 1163 | if (head) |
| 1164 | list_move(&rt_se->run_list, queue); |
| 1165 | else |
| 1166 | list_move_tail(&rt_se->run_list, queue); |
Ingo Molnar | 1cdad71 | 2008-06-19 09:09:15 +0200 | [diff] [blame] | 1167 | } |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1168 | } |
| 1169 | |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1170 | static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1171 | { |
| 1172 | struct sched_rt_entity *rt_se = &p->rt; |
| 1173 | struct rt_rq *rt_rq; |
| 1174 | |
| 1175 | for_each_sched_rt_entity(rt_se) { |
| 1176 | rt_rq = rt_rq_of_se(rt_se); |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1177 | requeue_rt_entity(rt_rq, rt_se, head); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | static void yield_task_rt(struct rq *rq) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1182 | { |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1183 | requeue_task_rt(rq, rq->curr, 0); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Gregory Haskins | e7693a3 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1186 | #ifdef CONFIG_SMP |
Gregory Haskins | 318e089 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1187 | static int find_lowest_rq(struct task_struct *task); |
| 1188 | |
Peter Zijlstra | 0017d73 | 2010-03-24 18:34:10 +0100 | [diff] [blame] | 1189 | static int |
Peter Zijlstra | ac66f54 | 2013-10-07 11:29:16 +0100 | [diff] [blame] | 1190 | select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags) |
Gregory Haskins | e7693a3 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1191 | { |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1192 | struct task_struct *curr; |
| 1193 | struct rq *rq; |
Steven Rostedt | c37495f | 2011-06-16 21:55:22 -0400 | [diff] [blame] | 1194 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1195 | if (p->nr_cpus_allowed == 1) |
Mike Galbraith | 76854c7 | 2011-11-22 15:18:24 +0100 | [diff] [blame] | 1196 | goto out; |
| 1197 | |
Steven Rostedt | c37495f | 2011-06-16 21:55:22 -0400 | [diff] [blame] | 1198 | /* For anything but wake ups, just return the task_cpu */ |
| 1199 | if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK) |
| 1200 | goto out; |
| 1201 | |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1202 | rq = cpu_rq(cpu); |
| 1203 | |
| 1204 | rcu_read_lock(); |
| 1205 | curr = ACCESS_ONCE(rq->curr); /* unlocked access */ |
| 1206 | |
Gregory Haskins | 318e089 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1207 | /* |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1208 | * If the current task on @p's runqueue is an RT task, then |
Steven Rostedt | e1f47d8 | 2008-01-25 21:08:12 +0100 | [diff] [blame] | 1209 | * try to see if we can wake this RT task up on another |
| 1210 | * runqueue. Otherwise simply start this RT task |
| 1211 | * on its current runqueue. |
| 1212 | * |
Steven Rostedt | 43fa546 | 2010-09-20 22:40:03 -0400 | [diff] [blame] | 1213 | * We want to avoid overloading runqueues. If the woken |
| 1214 | * task is a higher priority, then it will stay on this CPU |
| 1215 | * and the lower prio task should be moved to another CPU. |
| 1216 | * Even though this will probably make the lower prio task |
| 1217 | * lose its cache, we do not want to bounce a higher task |
| 1218 | * around just because it gave up its CPU, perhaps for a |
| 1219 | * lock? |
| 1220 | * |
| 1221 | * For equal prio tasks, we just let the scheduler sort it out. |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1222 | * |
Gregory Haskins | 318e089 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1223 | * Otherwise, just let it ride on the affined RQ and the |
| 1224 | * post-schedule router will push the preempted task away |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1225 | * |
| 1226 | * This test is optimistic, if we get it wrong the load-balancer |
| 1227 | * will have to sort it out. |
Gregory Haskins | 318e089 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1228 | */ |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1229 | if (curr && unlikely(rt_task(curr)) && |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1230 | (curr->nr_cpus_allowed < 2 || |
Shawn Bohrer | 6bfa687 | 2013-10-04 14:24:53 -0500 | [diff] [blame] | 1231 | curr->prio <= p->prio)) { |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1232 | int target = find_lowest_rq(p); |
| 1233 | |
| 1234 | if (target != -1) |
| 1235 | cpu = target; |
| 1236 | } |
| 1237 | rcu_read_unlock(); |
| 1238 | |
Steven Rostedt | c37495f | 2011-06-16 21:55:22 -0400 | [diff] [blame] | 1239 | out: |
Peter Zijlstra | 7608dec | 2011-04-05 17:23:46 +0200 | [diff] [blame] | 1240 | return cpu; |
Gregory Haskins | e7693a3 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1241 | } |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1242 | |
| 1243 | static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) |
| 1244 | { |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1245 | if (rq->curr->nr_cpus_allowed == 1) |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1246 | return; |
| 1247 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1248 | if (p->nr_cpus_allowed != 1 |
Rusty Russell | 13b8bd0 | 2009-03-25 15:01:22 +1030 | [diff] [blame] | 1249 | && cpupri_find(&rq->rd->cpupri, p, NULL)) |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1250 | return; |
| 1251 | |
Rusty Russell | 13b8bd0 | 2009-03-25 15:01:22 +1030 | [diff] [blame] | 1252 | if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL)) |
| 1253 | return; |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1254 | |
| 1255 | /* |
| 1256 | * There appears to be other cpus that can accept |
| 1257 | * current and none to run 'p', so lets reschedule |
| 1258 | * to try and push current away: |
| 1259 | */ |
| 1260 | requeue_task_rt(rq, p, 1); |
| 1261 | resched_task(rq->curr); |
| 1262 | } |
| 1263 | |
Gregory Haskins | e7693a3 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1264 | #endif /* CONFIG_SMP */ |
| 1265 | |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1266 | /* |
| 1267 | * Preempt the current task with a newly woken task if needed: |
| 1268 | */ |
Peter Zijlstra | 7d47872 | 2009-09-14 19:55:44 +0200 | [diff] [blame] | 1269 | static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1270 | { |
Gregory Haskins | 45c01e8 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 1271 | if (p->prio < rq->curr->prio) { |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1272 | resched_task(rq->curr); |
Gregory Haskins | 45c01e8 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 1273 | return; |
| 1274 | } |
| 1275 | |
| 1276 | #ifdef CONFIG_SMP |
| 1277 | /* |
| 1278 | * If: |
| 1279 | * |
| 1280 | * - the newly woken task is of equal priority to the current task |
| 1281 | * - the newly woken task is non-migratable while current is migratable |
| 1282 | * - current will be preempted on the next reschedule |
| 1283 | * |
| 1284 | * we should check to see if current can readily move to a different |
| 1285 | * cpu. If so, we will reschedule to allow the push logic to try |
| 1286 | * to move current somewhere else, making room for our non-migratable |
| 1287 | * task. |
| 1288 | */ |
Hillf Danton | 8dd0de8 | 2011-06-14 18:36:24 -0400 | [diff] [blame] | 1289 | if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr)) |
Dmitry Adamushko | 7ebefa8 | 2008-07-01 23:32:15 +0200 | [diff] [blame] | 1290 | check_preempt_equal_prio(rq, p); |
Gregory Haskins | 45c01e8 | 2008-05-12 21:20:41 +0200 | [diff] [blame] | 1291 | #endif |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1294 | static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq, |
| 1295 | struct rt_rq *rt_rq) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1296 | { |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1297 | struct rt_prio_array *array = &rt_rq->active; |
| 1298 | struct sched_rt_entity *next = NULL; |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1299 | struct list_head *queue; |
| 1300 | int idx; |
| 1301 | |
| 1302 | idx = sched_find_first_bit(array->bitmap); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1303 | BUG_ON(idx >= MAX_RT_PRIO); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1304 | |
| 1305 | queue = array->queue + idx; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1306 | next = list_entry(queue->next, struct sched_rt_entity, run_list); |
Dmitry Adamushko | 326587b | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 1307 | |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1308 | return next; |
| 1309 | } |
| 1310 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1311 | static struct task_struct *_pick_next_task_rt(struct rq *rq) |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1312 | { |
| 1313 | struct sched_rt_entity *rt_se; |
| 1314 | struct task_struct *p; |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1315 | struct rt_rq *rt_rq = &rq->rt; |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1316 | |
| 1317 | do { |
| 1318 | rt_se = pick_next_rt_entity(rq, rt_rq); |
Dmitry Adamushko | 326587b | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 1319 | BUG_ON(!rt_se); |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1320 | rt_rq = group_rt_rq(rt_se); |
| 1321 | } while (rt_rq); |
| 1322 | |
| 1323 | p = rt_task_of(rt_se); |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 1324 | p->se.exec_start = rq_clock_task(rq); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1325 | |
| 1326 | return p; |
| 1327 | } |
| 1328 | |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1329 | static struct task_struct * |
| 1330 | pick_next_task_rt(struct rq *rq, struct task_struct *prev) |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1331 | { |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1332 | struct task_struct *p; |
| 1333 | struct rt_rq *rt_rq = &rq->rt; |
| 1334 | |
Peter Zijlstra | 38033c3 | 2014-01-23 20:32:21 +0100 | [diff] [blame^] | 1335 | #ifdef CONFIG_SMP |
| 1336 | /* Try to pull RT tasks here if we lower this rq's prio */ |
| 1337 | if (rq->rt.highest_prio.curr > prev->prio) |
| 1338 | pull_rt_task(rq); |
| 1339 | #endif |
| 1340 | |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1341 | if (!rt_rq->rt_nr_running) |
| 1342 | return NULL; |
| 1343 | |
| 1344 | if (rt_rq_throttled(rt_rq)) |
| 1345 | return NULL; |
| 1346 | |
| 1347 | if (prev) |
| 1348 | prev->sched_class->put_prev_task(rq, prev); |
| 1349 | |
| 1350 | p = _pick_next_task_rt(rq); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1351 | |
| 1352 | /* The running task is never eligible for pushing */ |
| 1353 | if (p) |
| 1354 | dequeue_pushable_task(rq, p); |
| 1355 | |
Ingo Molnar | bcf08df | 2008-04-19 12:11:10 +0200 | [diff] [blame] | 1356 | #ifdef CONFIG_SMP |
Gregory Haskins | 3f029d3 | 2009-07-29 11:08:47 -0400 | [diff] [blame] | 1357 | /* |
| 1358 | * We detect this state here so that we can avoid taking the RQ |
| 1359 | * lock again later if there is no need to push |
| 1360 | */ |
| 1361 | rq->post_schedule = has_pushable_tasks(rq); |
Ingo Molnar | bcf08df | 2008-04-19 12:11:10 +0200 | [diff] [blame] | 1362 | #endif |
Gregory Haskins | 3f029d3 | 2009-07-29 11:08:47 -0400 | [diff] [blame] | 1363 | |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1364 | return p; |
| 1365 | } |
| 1366 | |
Ingo Molnar | 31ee529 | 2007-08-09 11:16:49 +0200 | [diff] [blame] | 1367 | static void put_prev_task_rt(struct rq *rq, struct task_struct *p) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1368 | { |
Ingo Molnar | f1e14ef | 2007-08-09 11:16:48 +0200 | [diff] [blame] | 1369 | update_curr_rt(rq); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * The previous task needs to be made eligible for pushing |
| 1373 | * if it is still active |
| 1374 | */ |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1375 | if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1376 | enqueue_pushable_task(rq, p); |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1377 | } |
| 1378 | |
Peter Williams | 681f3e6 | 2007-10-24 18:23:51 +0200 | [diff] [blame] | 1379 | #ifdef CONFIG_SMP |
Peter Zijlstra | 6f505b1 | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1380 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1381 | /* Only try algorithms three times */ |
| 1382 | #define RT_MAX_TRIES 3 |
| 1383 | |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1384 | static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) |
| 1385 | { |
| 1386 | if (!task_running(rq, p) && |
Kirill Tkhai | 60334ca | 2013-01-31 18:56:17 +0400 | [diff] [blame] | 1387 | cpumask_test_cpu(cpu, tsk_cpus_allowed(p))) |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1388 | return 1; |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1392 | /* |
| 1393 | * Return the highest pushable rq's task, which is suitable to be executed |
| 1394 | * on the cpu, NULL otherwise |
| 1395 | */ |
| 1396 | static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1397 | { |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1398 | struct plist_head *head = &rq->rt.pushable_tasks; |
| 1399 | struct task_struct *p; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1400 | |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1401 | if (!has_pushable_tasks(rq)) |
| 1402 | return NULL; |
Peter Zijlstra | 3d07467 | 2010-03-10 17:07:24 +0100 | [diff] [blame] | 1403 | |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1404 | plist_for_each_entry(p, head, pushable_tasks) { |
| 1405 | if (pick_rt_task(rq, p, cpu)) |
| 1406 | return p; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1409 | return NULL; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Rusty Russell | 0e3900e | 2008-11-25 02:35:13 +1030 | [diff] [blame] | 1412 | static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1413 | |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1414 | static int find_lowest_rq(struct task_struct *task) |
| 1415 | { |
| 1416 | struct sched_domain *sd; |
Rusty Russell | 96f874e2 | 2008-11-25 02:35:14 +1030 | [diff] [blame] | 1417 | struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask); |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1418 | int this_cpu = smp_processor_id(); |
| 1419 | int cpu = task_cpu(task); |
| 1420 | |
Steven Rostedt | 0da938c | 2011-06-14 18:36:25 -0400 | [diff] [blame] | 1421 | /* Make sure the mask is initialized first */ |
| 1422 | if (unlikely(!lowest_mask)) |
| 1423 | return -1; |
| 1424 | |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1425 | if (task->nr_cpus_allowed == 1) |
Gregory Haskins | 6e0534f | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 1426 | return -1; /* No other targets possible */ |
| 1427 | |
| 1428 | if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask)) |
Gregory Haskins | 06f90db | 2008-01-25 21:08:13 +0100 | [diff] [blame] | 1429 | return -1; /* No targets found */ |
| 1430 | |
| 1431 | /* |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1432 | * At this point we have built a mask of cpus representing the |
| 1433 | * lowest priority tasks in the system. Now we want to elect |
| 1434 | * the best one based on our affinity and topology. |
| 1435 | * |
| 1436 | * We prioritize the last cpu that the task executed on since |
| 1437 | * it is most likely cache-hot in that location. |
| 1438 | */ |
Rusty Russell | 96f874e2 | 2008-11-25 02:35:14 +1030 | [diff] [blame] | 1439 | if (cpumask_test_cpu(cpu, lowest_mask)) |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1440 | return cpu; |
| 1441 | |
| 1442 | /* |
| 1443 | * Otherwise, we consult the sched_domains span maps to figure |
| 1444 | * out which cpu is logically closest to our hot cache data. |
| 1445 | */ |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1446 | if (!cpumask_test_cpu(this_cpu, lowest_mask)) |
| 1447 | this_cpu = -1; /* Skip this_cpu opt if not among lowest */ |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1448 | |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1449 | rcu_read_lock(); |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1450 | for_each_domain(cpu, sd) { |
| 1451 | if (sd->flags & SD_WAKE_AFFINE) { |
| 1452 | int best_cpu; |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1453 | |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1454 | /* |
| 1455 | * "this_cpu" is cheaper to preempt than a |
| 1456 | * remote processor. |
| 1457 | */ |
| 1458 | if (this_cpu != -1 && |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1459 | cpumask_test_cpu(this_cpu, sched_domain_span(sd))) { |
| 1460 | rcu_read_unlock(); |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1461 | return this_cpu; |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1462 | } |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1463 | |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1464 | best_cpu = cpumask_first_and(lowest_mask, |
| 1465 | sched_domain_span(sd)); |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1466 | if (best_cpu < nr_cpu_ids) { |
| 1467 | rcu_read_unlock(); |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1468 | return best_cpu; |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1469 | } |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1470 | } |
| 1471 | } |
Xiaotian Feng | cd4ae6a | 2011-04-22 18:53:54 +0800 | [diff] [blame] | 1472 | rcu_read_unlock(); |
Gregory Haskins | 6e1254d | 2008-01-25 21:08:11 +0100 | [diff] [blame] | 1473 | |
| 1474 | /* |
| 1475 | * And finally, if there were no matches within the domains |
| 1476 | * just give the caller *something* to work with from the compatible |
| 1477 | * locations. |
| 1478 | */ |
Rusty Russell | e2c8806 | 2009-11-03 14:53:15 +1030 | [diff] [blame] | 1479 | if (this_cpu != -1) |
| 1480 | return this_cpu; |
| 1481 | |
| 1482 | cpu = cpumask_any(lowest_mask); |
| 1483 | if (cpu < nr_cpu_ids) |
| 1484 | return cpu; |
| 1485 | return -1; |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1486 | } |
| 1487 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1488 | /* Will lock the rq it finds */ |
Ingo Molnar | 4df64c0 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 1489 | static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1490 | { |
| 1491 | struct rq *lowest_rq = NULL; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1492 | int tries; |
Ingo Molnar | 4df64c0 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 1493 | int cpu; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1494 | |
| 1495 | for (tries = 0; tries < RT_MAX_TRIES; tries++) { |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1496 | cpu = find_lowest_rq(task); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1497 | |
Gregory Haskins | 2de0b46 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1498 | if ((cpu == -1) || (cpu == rq->cpu)) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1501 | lowest_rq = cpu_rq(cpu); |
| 1502 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1503 | /* if the prio of this runqueue changed, try again */ |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1504 | if (double_lock_balance(rq, lowest_rq)) { |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1505 | /* |
| 1506 | * We had to unlock the run queue. In |
| 1507 | * the mean time, task could have |
| 1508 | * migrated already or had its affinity changed. |
| 1509 | * Also make sure that it wasn't scheduled on its rq. |
| 1510 | */ |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1511 | if (unlikely(task_rq(task) != rq || |
Rusty Russell | 96f874e2 | 2008-11-25 02:35:14 +1030 | [diff] [blame] | 1512 | !cpumask_test_cpu(lowest_rq->cpu, |
Peter Zijlstra | fa17b50 | 2011-06-16 12:23:22 +0200 | [diff] [blame] | 1513 | tsk_cpus_allowed(task)) || |
Gregory Haskins | 07b4032 | 2008-01-25 21:08:10 +0100 | [diff] [blame] | 1514 | task_running(rq, task) || |
Peter Zijlstra | fd2f441 | 2011-04-05 17:23:44 +0200 | [diff] [blame] | 1515 | !task->on_rq)) { |
Ingo Molnar | 4df64c0 | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 1516 | |
Peter Zijlstra | 7f1b439 | 2012-05-17 21:19:46 +0200 | [diff] [blame] | 1517 | double_unlock_balance(rq, lowest_rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1518 | lowest_rq = NULL; |
| 1519 | break; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | /* If this rq is still suitable use it. */ |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1524 | if (lowest_rq->rt.highest_prio.curr > task->prio) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1525 | break; |
| 1526 | |
| 1527 | /* try again */ |
Peter Zijlstra | 1b12bbc | 2008-08-11 09:30:22 +0200 | [diff] [blame] | 1528 | double_unlock_balance(rq, lowest_rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1529 | lowest_rq = NULL; |
| 1530 | } |
| 1531 | |
| 1532 | return lowest_rq; |
| 1533 | } |
| 1534 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1535 | static struct task_struct *pick_next_pushable_task(struct rq *rq) |
| 1536 | { |
| 1537 | struct task_struct *p; |
| 1538 | |
| 1539 | if (!has_pushable_tasks(rq)) |
| 1540 | return NULL; |
| 1541 | |
| 1542 | p = plist_first_entry(&rq->rt.pushable_tasks, |
| 1543 | struct task_struct, pushable_tasks); |
| 1544 | |
| 1545 | BUG_ON(rq->cpu != task_cpu(p)); |
| 1546 | BUG_ON(task_current(rq, p)); |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1547 | BUG_ON(p->nr_cpus_allowed <= 1); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1548 | |
Peter Zijlstra | fd2f441 | 2011-04-05 17:23:44 +0200 | [diff] [blame] | 1549 | BUG_ON(!p->on_rq); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1550 | BUG_ON(!rt_task(p)); |
| 1551 | |
| 1552 | return p; |
| 1553 | } |
| 1554 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1555 | /* |
| 1556 | * If the current CPU has more than one RT task, see if the non |
| 1557 | * running task can migrate over to a CPU that is running a task |
| 1558 | * of lesser priority. |
| 1559 | */ |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1560 | static int push_rt_task(struct rq *rq) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1561 | { |
| 1562 | struct task_struct *next_task; |
| 1563 | struct rq *lowest_rq; |
Hillf Danton | 311e800 | 2011-06-16 21:55:20 -0400 | [diff] [blame] | 1564 | int ret = 0; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1565 | |
Gregory Haskins | a22d7fc | 2008-01-25 21:08:12 +0100 | [diff] [blame] | 1566 | if (!rq->rt.overloaded) |
| 1567 | return 0; |
| 1568 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1569 | next_task = pick_next_pushable_task(rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1570 | if (!next_task) |
| 1571 | return 0; |
| 1572 | |
Peter Zijlstra | 4924627 | 2010-10-17 21:46:10 +0200 | [diff] [blame] | 1573 | retry: |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1574 | if (unlikely(next_task == rq->curr)) { |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1575 | WARN_ON(1); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1576 | return 0; |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1577 | } |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1578 | |
| 1579 | /* |
| 1580 | * It's possible that the next_task slipped in of |
| 1581 | * higher priority than current. If that's the case |
| 1582 | * just reschedule current. |
| 1583 | */ |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1584 | if (unlikely(next_task->prio < rq->curr->prio)) { |
| 1585 | resched_task(rq->curr); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1586 | return 0; |
| 1587 | } |
| 1588 | |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1589 | /* We might release rq lock */ |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1590 | get_task_struct(next_task); |
| 1591 | |
| 1592 | /* find_lock_lowest_rq locks the rq if found */ |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1593 | lowest_rq = find_lock_lowest_rq(next_task, rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1594 | if (!lowest_rq) { |
| 1595 | struct task_struct *task; |
| 1596 | /* |
Hillf Danton | 311e800 | 2011-06-16 21:55:20 -0400 | [diff] [blame] | 1597 | * find_lock_lowest_rq releases rq->lock |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1598 | * so it is possible that next_task has migrated. |
| 1599 | * |
| 1600 | * We need to make sure that the task is still on the same |
| 1601 | * run-queue and is also still the next task eligible for |
| 1602 | * pushing. |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1603 | */ |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1604 | task = pick_next_pushable_task(rq); |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1605 | if (task_cpu(next_task) == rq->cpu && task == next_task) { |
| 1606 | /* |
Hillf Danton | 311e800 | 2011-06-16 21:55:20 -0400 | [diff] [blame] | 1607 | * The task hasn't migrated, and is still the next |
| 1608 | * eligible task, but we failed to find a run-queue |
| 1609 | * to push it to. Do not retry in this case, since |
| 1610 | * other cpus will pull from us when ready. |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1611 | */ |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1612 | goto out; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1613 | } |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1614 | |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1615 | if (!task) |
| 1616 | /* No more tasks, just exit */ |
| 1617 | goto out; |
| 1618 | |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1619 | /* |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1620 | * Something has shifted, try again. |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1621 | */ |
Gregory Haskins | 1563513 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1622 | put_task_struct(next_task); |
| 1623 | next_task = task; |
| 1624 | goto retry; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1625 | } |
| 1626 | |
Gregory Haskins | 697f0a4 | 2008-01-25 21:08:09 +0100 | [diff] [blame] | 1627 | deactivate_task(rq, next_task, 0); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1628 | set_task_cpu(next_task, lowest_rq->cpu); |
| 1629 | activate_task(lowest_rq, next_task, 0); |
Hillf Danton | 311e800 | 2011-06-16 21:55:20 -0400 | [diff] [blame] | 1630 | ret = 1; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1631 | |
| 1632 | resched_task(lowest_rq->curr); |
| 1633 | |
Peter Zijlstra | 1b12bbc | 2008-08-11 09:30:22 +0200 | [diff] [blame] | 1634 | double_unlock_balance(rq, lowest_rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1635 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1636 | out: |
| 1637 | put_task_struct(next_task); |
| 1638 | |
Hillf Danton | 311e800 | 2011-06-16 21:55:20 -0400 | [diff] [blame] | 1639 | return ret; |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1642 | static void push_rt_tasks(struct rq *rq) |
| 1643 | { |
| 1644 | /* push_rt_task will return true if it moved an RT */ |
| 1645 | while (push_rt_task(rq)) |
| 1646 | ; |
| 1647 | } |
| 1648 | |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1649 | static int pull_rt_task(struct rq *this_rq) |
| 1650 | { |
Ingo Molnar | 80bf317 | 2008-01-25 21:08:17 +0100 | [diff] [blame] | 1651 | int this_cpu = this_rq->cpu, ret = 0, cpu; |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1652 | struct task_struct *p; |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1653 | struct rq *src_rq; |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1654 | |
Gregory Haskins | 637f508 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1655 | if (likely(!rt_overloaded(this_rq))) |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1656 | return 0; |
| 1657 | |
Peter Zijlstra | 7c3f2ab | 2013-10-15 12:35:07 +0200 | [diff] [blame] | 1658 | /* |
| 1659 | * Match the barrier from rt_set_overloaded; this guarantees that if we |
| 1660 | * see overloaded we must also see the rto_mask bit. |
| 1661 | */ |
| 1662 | smp_rmb(); |
| 1663 | |
Rusty Russell | c6c4927 | 2008-11-25 02:35:05 +1030 | [diff] [blame] | 1664 | for_each_cpu(cpu, this_rq->rd->rto_mask) { |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1665 | if (this_cpu == cpu) |
| 1666 | continue; |
| 1667 | |
| 1668 | src_rq = cpu_rq(cpu); |
Gregory Haskins | 74ab8e4 | 2008-12-29 09:39:50 -0500 | [diff] [blame] | 1669 | |
| 1670 | /* |
| 1671 | * Don't bother taking the src_rq->lock if the next highest |
| 1672 | * task is known to be lower-priority than our current task. |
| 1673 | * This may look racy, but if this value is about to go |
| 1674 | * logically higher, the src_rq will push this task away. |
| 1675 | * And if its going logically lower, we do not care |
| 1676 | */ |
| 1677 | if (src_rq->rt.highest_prio.next >= |
| 1678 | this_rq->rt.highest_prio.curr) |
| 1679 | continue; |
| 1680 | |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1681 | /* |
| 1682 | * We can potentially drop this_rq's lock in |
| 1683 | * double_lock_balance, and another CPU could |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1684 | * alter this_rq |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1685 | */ |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1686 | double_lock_balance(this_rq, src_rq); |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1687 | |
| 1688 | /* |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1689 | * We can pull only a task, which is pushable |
| 1690 | * on its rq, and no others. |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1691 | */ |
Kirill Tkhai | e23ee74 | 2013-06-07 15:37:43 -0400 | [diff] [blame] | 1692 | p = pick_highest_pushable_task(src_rq, this_cpu); |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1693 | |
| 1694 | /* |
| 1695 | * Do we have an RT task that preempts |
| 1696 | * the to-be-scheduled task? |
| 1697 | */ |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1698 | if (p && (p->prio < this_rq->rt.highest_prio.curr)) { |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1699 | WARN_ON(p == src_rq->curr); |
Peter Zijlstra | fd2f441 | 2011-04-05 17:23:44 +0200 | [diff] [blame] | 1700 | WARN_ON(!p->on_rq); |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1701 | |
| 1702 | /* |
| 1703 | * There's a chance that p is higher in priority |
| 1704 | * than what's currently running on its cpu. |
| 1705 | * This is just that p is wakeing up and hasn't |
| 1706 | * had a chance to schedule. We only pull |
| 1707 | * p if it is lower in priority than the |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1708 | * current task on the run queue |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1709 | */ |
Gregory Haskins | a872894 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1710 | if (p->prio < src_rq->curr->prio) |
Mike Galbraith | 614ee1f | 2008-01-25 21:08:30 +0100 | [diff] [blame] | 1711 | goto skip; |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1712 | |
| 1713 | ret = 1; |
| 1714 | |
| 1715 | deactivate_task(src_rq, p, 0); |
| 1716 | set_task_cpu(p, this_cpu); |
| 1717 | activate_task(this_rq, p, 0); |
| 1718 | /* |
| 1719 | * We continue with the search, just in |
| 1720 | * case there's an even higher prio task |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1721 | * in another runqueue. (low likelihood |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1722 | * but possible) |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1723 | */ |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1724 | } |
Peter Zijlstra | 4924627 | 2010-10-17 21:46:10 +0200 | [diff] [blame] | 1725 | skip: |
Peter Zijlstra | 1b12bbc | 2008-08-11 09:30:22 +0200 | [diff] [blame] | 1726 | double_unlock_balance(this_rq, src_rq); |
Steven Rostedt | f65eda4 | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
Steven Rostedt | 9a897c5 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1732 | static void post_schedule_rt(struct rq *rq) |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1733 | { |
Gregory Haskins | 967fc04 | 2008-12-29 09:39:52 -0500 | [diff] [blame] | 1734 | push_rt_tasks(rq); |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1735 | } |
| 1736 | |
Gregory Haskins | 8ae121a | 2008-04-23 07:13:29 -0400 | [diff] [blame] | 1737 | /* |
| 1738 | * If we are not running and we are not going to reschedule soon, we should |
| 1739 | * try to push tasks away now |
| 1740 | */ |
Peter Zijlstra | efbbd05 | 2009-12-16 18:04:40 +0100 | [diff] [blame] | 1741 | static void task_woken_rt(struct rq *rq, struct task_struct *p) |
Steven Rostedt | 4642daf | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1742 | { |
Steven Rostedt | 9a897c5 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1743 | if (!task_running(rq, p) && |
Gregory Haskins | 8ae121a | 2008-04-23 07:13:29 -0400 | [diff] [blame] | 1744 | !test_tsk_need_resched(rq->curr) && |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1745 | has_pushable_tasks(rq) && |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1746 | p->nr_cpus_allowed > 1 && |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1747 | (dl_task(rq->curr) || rt_task(rq->curr)) && |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1748 | (rq->curr->nr_cpus_allowed < 2 || |
Shawn Bohrer | 3be209a | 2011-09-12 09:28:04 -0500 | [diff] [blame] | 1749 | rq->curr->prio <= p->prio)) |
Steven Rostedt | 4642daf | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1750 | push_rt_tasks(rq); |
| 1751 | } |
| 1752 | |
Mike Travis | cd8ba7c | 2008-03-26 14:23:49 -0700 | [diff] [blame] | 1753 | static void set_cpus_allowed_rt(struct task_struct *p, |
Rusty Russell | 96f874e2 | 2008-11-25 02:35:14 +1030 | [diff] [blame] | 1754 | const struct cpumask *new_mask) |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1755 | { |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1756 | struct rq *rq; |
| 1757 | int weight; |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1758 | |
| 1759 | BUG_ON(!rt_task(p)); |
| 1760 | |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1761 | if (!p->on_rq) |
| 1762 | return; |
| 1763 | |
| 1764 | weight = cpumask_weight(new_mask); |
| 1765 | |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1766 | /* |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1767 | * Only update if the process changes its state from whether it |
| 1768 | * can migrate or not. |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1769 | */ |
Peter Zijlstra | 29baa74 | 2012-04-23 12:11:21 +0200 | [diff] [blame] | 1770 | if ((p->nr_cpus_allowed > 1) == (weight > 1)) |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1771 | return; |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1772 | |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1773 | rq = task_rq(p); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1774 | |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1775 | /* |
| 1776 | * The process used to be able to migrate OR it can now migrate |
| 1777 | */ |
| 1778 | if (weight <= 1) { |
| 1779 | if (!task_current(rq, p)) |
| 1780 | dequeue_pushable_task(rq, p); |
| 1781 | BUG_ON(!rq->rt.rt_nr_migratory); |
| 1782 | rq->rt.rt_nr_migratory--; |
| 1783 | } else { |
| 1784 | if (!task_current(rq, p)) |
| 1785 | enqueue_pushable_task(rq, p); |
| 1786 | rq->rt.rt_nr_migratory++; |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1787 | } |
Kirill Tkhai | 8d3d5ad | 2012-04-11 09:06:04 +0400 | [diff] [blame] | 1788 | |
| 1789 | update_rt_migration(&rq->rt); |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 1790 | } |
Ingo Molnar | deeeccd | 2008-01-25 21:08:15 +0100 | [diff] [blame] | 1791 | |
Ingo Molnar | bdd7c81 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1792 | /* Assumes rq->lock is held */ |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 1793 | static void rq_online_rt(struct rq *rq) |
Ingo Molnar | bdd7c81 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1794 | { |
| 1795 | if (rq->rt.overloaded) |
| 1796 | rt_set_overload(rq); |
Gregory Haskins | 6e0534f | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 1797 | |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 1798 | __enable_runtime(rq); |
| 1799 | |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1800 | cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr); |
Ingo Molnar | bdd7c81 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | /* Assumes rq->lock is held */ |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 1804 | static void rq_offline_rt(struct rq *rq) |
Ingo Molnar | bdd7c81 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1805 | { |
| 1806 | if (rq->rt.overloaded) |
| 1807 | rt_clear_overload(rq); |
Gregory Haskins | 6e0534f | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 1808 | |
Peter Zijlstra | 7def2be | 2008-06-05 14:49:58 +0200 | [diff] [blame] | 1809 | __disable_runtime(rq); |
| 1810 | |
Gregory Haskins | 6e0534f | 2008-05-12 21:21:01 +0200 | [diff] [blame] | 1811 | cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID); |
Ingo Molnar | bdd7c81 | 2008-01-25 21:08:18 +0100 | [diff] [blame] | 1812 | } |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1813 | |
| 1814 | /* |
| 1815 | * When switch from the rt queue, we bring ourselves to a position |
| 1816 | * that we might want to pull RT tasks from other runqueues. |
| 1817 | */ |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 1818 | static void switched_from_rt(struct rq *rq, struct task_struct *p) |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1819 | { |
| 1820 | /* |
| 1821 | * If there are other RT tasks then we will reschedule |
| 1822 | * and the scheduling of the other RT tasks will handle |
| 1823 | * the balancing. But if we are the last RT task |
| 1824 | * we may need to handle the pulling of RT tasks |
| 1825 | * now. |
| 1826 | */ |
Kirill Tkhai | 1158ddb | 2012-11-23 00:02:15 +0400 | [diff] [blame] | 1827 | if (!p->on_rq || rq->rt.rt_nr_running) |
| 1828 | return; |
| 1829 | |
| 1830 | if (pull_rt_task(rq)) |
| 1831 | resched_task(rq->curr); |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1832 | } |
Rusty Russell | 3d8cbdf | 2008-11-25 09:58:41 +1030 | [diff] [blame] | 1833 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1834 | void init_sched_rt_class(void) |
Rusty Russell | 3d8cbdf | 2008-11-25 09:58:41 +1030 | [diff] [blame] | 1835 | { |
| 1836 | unsigned int i; |
| 1837 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1838 | for_each_possible_cpu(i) { |
Yinghai Lu | eaa9584 | 2009-06-06 14:51:36 -0700 | [diff] [blame] | 1839 | zalloc_cpumask_var_node(&per_cpu(local_cpu_mask, i), |
Mike Travis | 6ca09df | 2008-12-31 18:08:45 -0800 | [diff] [blame] | 1840 | GFP_KERNEL, cpu_to_node(i)); |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1841 | } |
Rusty Russell | 3d8cbdf | 2008-11-25 09:58:41 +1030 | [diff] [blame] | 1842 | } |
Steven Rostedt | e8fa136 | 2008-01-25 21:08:05 +0100 | [diff] [blame] | 1843 | #endif /* CONFIG_SMP */ |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1844 | |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1845 | /* |
| 1846 | * When switching a task to RT, we may overload the runqueue |
| 1847 | * with RT tasks. In this case we try to push them off to |
| 1848 | * other runqueues. |
| 1849 | */ |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 1850 | static void switched_to_rt(struct rq *rq, struct task_struct *p) |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1851 | { |
| 1852 | int check_resched = 1; |
| 1853 | |
| 1854 | /* |
| 1855 | * If we are already running, then there's nothing |
| 1856 | * that needs to be done. But if we are not running |
| 1857 | * we may need to preempt the current running task. |
| 1858 | * If that current running task is also an RT task |
| 1859 | * then see if we can move to another run queue. |
| 1860 | */ |
Peter Zijlstra | fd2f441 | 2011-04-05 17:23:44 +0200 | [diff] [blame] | 1861 | if (p->on_rq && rq->curr != p) { |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1862 | #ifdef CONFIG_SMP |
| 1863 | if (rq->rt.overloaded && push_rt_task(rq) && |
| 1864 | /* Don't resched if we changed runqueues */ |
| 1865 | rq != task_rq(p)) |
| 1866 | check_resched = 0; |
| 1867 | #endif /* CONFIG_SMP */ |
| 1868 | if (check_resched && p->prio < rq->curr->prio) |
| 1869 | resched_task(rq->curr); |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | /* |
| 1874 | * Priority of the task has changed. This may cause |
| 1875 | * us to initiate a push or pull. |
| 1876 | */ |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 1877 | static void |
| 1878 | prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio) |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1879 | { |
Peter Zijlstra | fd2f441 | 2011-04-05 17:23:44 +0200 | [diff] [blame] | 1880 | if (!p->on_rq) |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 1881 | return; |
| 1882 | |
| 1883 | if (rq->curr == p) { |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1884 | #ifdef CONFIG_SMP |
| 1885 | /* |
| 1886 | * If our priority decreases while running, we |
| 1887 | * may need to pull tasks to this runqueue. |
| 1888 | */ |
| 1889 | if (oldprio < p->prio) |
| 1890 | pull_rt_task(rq); |
| 1891 | /* |
| 1892 | * If there's a higher priority task waiting to run |
Steven Rostedt | 6fa46fa | 2008-03-05 10:00:12 -0500 | [diff] [blame] | 1893 | * then reschedule. Note, the above pull_rt_task |
| 1894 | * can release the rq lock and p could migrate. |
| 1895 | * Only reschedule if p is still on the same runqueue. |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1896 | */ |
Gregory Haskins | e864c49 | 2008-12-29 09:39:49 -0500 | [diff] [blame] | 1897 | if (p->prio > rq->rt.highest_prio.curr && rq->curr == p) |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1898 | resched_task(p); |
| 1899 | #else |
| 1900 | /* For UP simply resched on drop of prio */ |
| 1901 | if (oldprio < p->prio) |
| 1902 | resched_task(p); |
| 1903 | #endif /* CONFIG_SMP */ |
| 1904 | } else { |
| 1905 | /* |
| 1906 | * This task is not running, but if it is |
| 1907 | * greater than the current running task |
| 1908 | * then reschedule. |
| 1909 | */ |
| 1910 | if (p->prio < rq->curr->prio) |
| 1911 | resched_task(rq->curr); |
| 1912 | } |
| 1913 | } |
| 1914 | |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1915 | static void watchdog(struct rq *rq, struct task_struct *p) |
| 1916 | { |
| 1917 | unsigned long soft, hard; |
| 1918 | |
Jiri Slaby | 78d7d40 | 2010-03-05 13:42:54 -0800 | [diff] [blame] | 1919 | /* max may change after cur was read, this will be fixed next tick */ |
| 1920 | soft = task_rlimit(p, RLIMIT_RTTIME); |
| 1921 | hard = task_rlimit_max(p, RLIMIT_RTTIME); |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1922 | |
| 1923 | if (soft != RLIM_INFINITY) { |
| 1924 | unsigned long next; |
| 1925 | |
Ying Xue | 57d2aa0 | 2012-07-17 15:03:43 +0800 | [diff] [blame] | 1926 | if (p->rt.watchdog_stamp != jiffies) { |
| 1927 | p->rt.timeout++; |
| 1928 | p->rt.watchdog_stamp = jiffies; |
| 1929 | } |
| 1930 | |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1931 | next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ); |
Peter Zijlstra | 5a52dd5 | 2008-01-25 21:08:32 +0100 | [diff] [blame] | 1932 | if (p->rt.timeout > next) |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 1933 | p->cputime_expires.sched_exp = p->se.sum_exec_runtime; |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1934 | } |
| 1935 | } |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 1936 | |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 1937 | static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1938 | { |
Colin Cross | 454c799 | 2012-05-16 21:34:23 -0700 | [diff] [blame] | 1939 | struct sched_rt_entity *rt_se = &p->rt; |
| 1940 | |
Peter Zijlstra | 67e2be0 | 2007-12-20 15:01:17 +0100 | [diff] [blame] | 1941 | update_curr_rt(rq); |
| 1942 | |
Peter Zijlstra | 78f2c7d | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1943 | watchdog(rq, p); |
| 1944 | |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1945 | /* |
| 1946 | * RR tasks need a special form of timeslice management. |
| 1947 | * FIFO tasks have no timeslices. |
| 1948 | */ |
| 1949 | if (p->policy != SCHED_RR) |
| 1950 | return; |
| 1951 | |
Peter Zijlstra | fa71706 | 2008-01-25 21:08:27 +0100 | [diff] [blame] | 1952 | if (--p->rt.time_slice) |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1953 | return; |
| 1954 | |
Clark Williams | ce0dbbb | 2013-02-07 09:47:04 -0600 | [diff] [blame] | 1955 | p->rt.time_slice = sched_rr_timeslice; |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1956 | |
Dmitry Adamushko | 98fbc79 | 2007-08-24 20:39:10 +0200 | [diff] [blame] | 1957 | /* |
Li Bin | e9aa39b | 2013-10-21 20:15:43 +0800 | [diff] [blame] | 1958 | * Requeue to the end of queue if we (and all of our ancestors) are not |
| 1959 | * the only element on the queue |
Dmitry Adamushko | 98fbc79 | 2007-08-24 20:39:10 +0200 | [diff] [blame] | 1960 | */ |
Colin Cross | 454c799 | 2012-05-16 21:34:23 -0700 | [diff] [blame] | 1961 | for_each_sched_rt_entity(rt_se) { |
| 1962 | if (rt_se->run_list.prev != rt_se->run_list.next) { |
| 1963 | requeue_task_rt(rq, p, 0); |
| 1964 | set_tsk_need_resched(p); |
| 1965 | return; |
| 1966 | } |
Dmitry Adamushko | 98fbc79 | 2007-08-24 20:39:10 +0200 | [diff] [blame] | 1967 | } |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1968 | } |
| 1969 | |
Srivatsa Vaddagiri | 83b699e | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 1970 | static void set_curr_task_rt(struct rq *rq) |
| 1971 | { |
| 1972 | struct task_struct *p = rq->curr; |
| 1973 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 1974 | p->se.exec_start = rq_clock_task(rq); |
Gregory Haskins | 917b627 | 2008-12-29 09:39:53 -0500 | [diff] [blame] | 1975 | |
| 1976 | /* The running task is never eligible for pushing */ |
| 1977 | dequeue_pushable_task(rq, p); |
Srivatsa Vaddagiri | 83b699e | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
H Hartley Sweeten | 6d686f4 | 2010-01-13 20:21:52 -0700 | [diff] [blame] | 1980 | static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task) |
Peter Williams | 0d721ce | 2009-09-21 01:31:53 +0000 | [diff] [blame] | 1981 | { |
| 1982 | /* |
| 1983 | * Time slice is 0 for SCHED_FIFO tasks |
| 1984 | */ |
| 1985 | if (task->policy == SCHED_RR) |
Clark Williams | ce0dbbb | 2013-02-07 09:47:04 -0600 | [diff] [blame] | 1986 | return sched_rr_timeslice; |
Peter Williams | 0d721ce | 2009-09-21 01:31:53 +0000 | [diff] [blame] | 1987 | else |
| 1988 | return 0; |
| 1989 | } |
| 1990 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1991 | const struct sched_class rt_sched_class = { |
Ingo Molnar | 5522d5d | 2007-10-15 17:00:12 +0200 | [diff] [blame] | 1992 | .next = &fair_sched_class, |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 1993 | .enqueue_task = enqueue_task_rt, |
| 1994 | .dequeue_task = dequeue_task_rt, |
| 1995 | .yield_task = yield_task_rt, |
| 1996 | |
| 1997 | .check_preempt_curr = check_preempt_curr_rt, |
| 1998 | |
| 1999 | .pick_next_task = pick_next_task_rt, |
| 2000 | .put_prev_task = put_prev_task_rt, |
| 2001 | |
Peter Williams | 681f3e6 | 2007-10-24 18:23:51 +0200 | [diff] [blame] | 2002 | #ifdef CONFIG_SMP |
Li Zefan | 4ce72a2 | 2008-10-22 15:25:26 +0800 | [diff] [blame] | 2003 | .select_task_rq = select_task_rq_rt, |
| 2004 | |
Gregory Haskins | 73fe6aa | 2008-01-25 21:08:07 +0100 | [diff] [blame] | 2005 | .set_cpus_allowed = set_cpus_allowed_rt, |
Gregory Haskins | 1f11eb6a | 2008-06-04 15:04:05 -0400 | [diff] [blame] | 2006 | .rq_online = rq_online_rt, |
| 2007 | .rq_offline = rq_offline_rt, |
Steven Rostedt | 9a897c5 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 2008 | .post_schedule = post_schedule_rt, |
Peter Zijlstra | efbbd05 | 2009-12-16 18:04:40 +0100 | [diff] [blame] | 2009 | .task_woken = task_woken_rt, |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 2010 | .switched_from = switched_from_rt, |
Peter Williams | 681f3e6 | 2007-10-24 18:23:51 +0200 | [diff] [blame] | 2011 | #endif |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 2012 | |
Srivatsa Vaddagiri | 83b699e | 2007-10-15 17:00:08 +0200 | [diff] [blame] | 2013 | .set_curr_task = set_curr_task_rt, |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 2014 | .task_tick = task_tick_rt, |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 2015 | |
Peter Williams | 0d721ce | 2009-09-21 01:31:53 +0000 | [diff] [blame] | 2016 | .get_rr_interval = get_rr_interval_rt, |
| 2017 | |
Steven Rostedt | cb46984 | 2008-01-25 21:08:22 +0100 | [diff] [blame] | 2018 | .prio_changed = prio_changed_rt, |
| 2019 | .switched_to = switched_to_rt, |
Ingo Molnar | bb44e5d | 2007-07-09 18:51:58 +0200 | [diff] [blame] | 2020 | }; |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 2021 | |
| 2022 | #ifdef CONFIG_SCHED_DEBUG |
| 2023 | extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq); |
| 2024 | |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 2025 | void print_rt_stats(struct seq_file *m, int cpu) |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 2026 | { |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 2027 | rt_rq_iter_t iter; |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 2028 | struct rt_rq *rt_rq; |
| 2029 | |
| 2030 | rcu_read_lock(); |
Cheng Xu | ec514c4 | 2011-05-14 14:20:02 +0800 | [diff] [blame] | 2031 | for_each_rt_rq(rt_rq, iter, cpu_rq(cpu)) |
Peter Zijlstra | ada18de | 2008-06-19 14:22:24 +0200 | [diff] [blame] | 2032 | print_rt_rq(m, cpu, rt_rq); |
| 2033 | rcu_read_unlock(); |
| 2034 | } |
Dhaval Giani | 55e12e5 | 2008-06-24 23:39:43 +0530 | [diff] [blame] | 2035 | #endif /* CONFIG_SCHED_DEBUG */ |