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