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