diff options
Diffstat (limited to 'kernel/sched_rt.c')
-rw-r--r-- | kernel/sched_rt.c | 192 |
1 files changed, 136 insertions, 56 deletions
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index e40e7fe43170..58cf5d18dfdc 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
@@ -183,6 +183,25 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq) | |||
183 | return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); | 183 | return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); |
184 | } | 184 | } |
185 | 185 | ||
186 | typedef struct task_group *rt_rq_iter_t; | ||
187 | |||
188 | #define for_each_rt_rq(rt_rq, iter, rq) \ | ||
189 | for (iter = list_entry_rcu(task_groups.next, typeof(*iter), list); \ | ||
190 | (&iter->list != &task_groups) && \ | ||
191 | (rt_rq = iter->rt_rq[cpu_of(rq)]); \ | ||
192 | iter = list_entry_rcu(iter->list.next, typeof(*iter), list)) | ||
193 | |||
194 | static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq) | ||
195 | { | ||
196 | list_add_rcu(&rt_rq->leaf_rt_rq_list, | ||
197 | &rq_of_rt_rq(rt_rq)->leaf_rt_rq_list); | ||
198 | } | ||
199 | |||
200 | static inline void list_del_leaf_rt_rq(struct rt_rq *rt_rq) | ||
201 | { | ||
202 | list_del_rcu(&rt_rq->leaf_rt_rq_list); | ||
203 | } | ||
204 | |||
186 | #define for_each_leaf_rt_rq(rt_rq, rq) \ | 205 | #define for_each_leaf_rt_rq(rt_rq, rq) \ |
187 | list_for_each_entry_rcu(rt_rq, &rq->leaf_rt_rq_list, leaf_rt_rq_list) | 206 | list_for_each_entry_rcu(rt_rq, &rq->leaf_rt_rq_list, leaf_rt_rq_list) |
188 | 207 | ||
@@ -199,11 +218,12 @@ static void dequeue_rt_entity(struct sched_rt_entity *rt_se); | |||
199 | 218 | ||
200 | static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) | 219 | static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) |
201 | { | 220 | { |
202 | int this_cpu = smp_processor_id(); | ||
203 | struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; | 221 | struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; |
204 | struct sched_rt_entity *rt_se; | 222 | struct sched_rt_entity *rt_se; |
205 | 223 | ||
206 | rt_se = rt_rq->tg->rt_se[this_cpu]; | 224 | int cpu = cpu_of(rq_of_rt_rq(rt_rq)); |
225 | |||
226 | rt_se = rt_rq->tg->rt_se[cpu]; | ||
207 | 227 | ||
208 | if (rt_rq->rt_nr_running) { | 228 | if (rt_rq->rt_nr_running) { |
209 | if (rt_se && !on_rt_rq(rt_se)) | 229 | if (rt_se && !on_rt_rq(rt_se)) |
@@ -215,10 +235,10 @@ static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) | |||
215 | 235 | ||
216 | static void sched_rt_rq_dequeue(struct rt_rq *rt_rq) | 236 | static void sched_rt_rq_dequeue(struct rt_rq *rt_rq) |
217 | { | 237 | { |
218 | int this_cpu = smp_processor_id(); | ||
219 | struct sched_rt_entity *rt_se; | 238 | struct sched_rt_entity *rt_se; |
239 | int cpu = cpu_of(rq_of_rt_rq(rt_rq)); | ||
220 | 240 | ||
221 | rt_se = rt_rq->tg->rt_se[this_cpu]; | 241 | rt_se = rt_rq->tg->rt_se[cpu]; |
222 | 242 | ||
223 | if (rt_se && on_rt_rq(rt_se)) | 243 | if (rt_se && on_rt_rq(rt_se)) |
224 | dequeue_rt_entity(rt_se); | 244 | dequeue_rt_entity(rt_se); |
@@ -276,6 +296,19 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq) | |||
276 | return ktime_to_ns(def_rt_bandwidth.rt_period); | 296 | return ktime_to_ns(def_rt_bandwidth.rt_period); |
277 | } | 297 | } |
278 | 298 | ||
299 | typedef struct rt_rq *rt_rq_iter_t; | ||
300 | |||
301 | #define for_each_rt_rq(rt_rq, iter, rq) \ | ||
302 | for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL) | ||
303 | |||
304 | static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq) | ||
305 | { | ||
306 | } | ||
307 | |||
308 | static inline void list_del_leaf_rt_rq(struct rt_rq *rt_rq) | ||
309 | { | ||
310 | } | ||
311 | |||
279 | #define for_each_leaf_rt_rq(rt_rq, rq) \ | 312 | #define for_each_leaf_rt_rq(rt_rq, rq) \ |
280 | for (rt_rq = &rq->rt; rt_rq; rt_rq = NULL) | 313 | for (rt_rq = &rq->rt; rt_rq; rt_rq = NULL) |
281 | 314 | ||
@@ -382,12 +415,13 @@ next: | |||
382 | static void __disable_runtime(struct rq *rq) | 415 | static void __disable_runtime(struct rq *rq) |
383 | { | 416 | { |
384 | struct root_domain *rd = rq->rd; | 417 | struct root_domain *rd = rq->rd; |
418 | rt_rq_iter_t iter; | ||
385 | struct rt_rq *rt_rq; | 419 | struct rt_rq *rt_rq; |
386 | 420 | ||
387 | if (unlikely(!scheduler_running)) | 421 | if (unlikely(!scheduler_running)) |
388 | return; | 422 | return; |
389 | 423 | ||
390 | for_each_leaf_rt_rq(rt_rq, rq) { | 424 | for_each_rt_rq(rt_rq, iter, rq) { |
391 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); | 425 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
392 | s64 want; | 426 | s64 want; |
393 | int i; | 427 | int i; |
@@ -467,6 +501,7 @@ static void disable_runtime(struct rq *rq) | |||
467 | 501 | ||
468 | static void __enable_runtime(struct rq *rq) | 502 | static void __enable_runtime(struct rq *rq) |
469 | { | 503 | { |
504 | rt_rq_iter_t iter; | ||
470 | struct rt_rq *rt_rq; | 505 | struct rt_rq *rt_rq; |
471 | 506 | ||
472 | if (unlikely(!scheduler_running)) | 507 | if (unlikely(!scheduler_running)) |
@@ -475,7 +510,7 @@ static void __enable_runtime(struct rq *rq) | |||
475 | /* | 510 | /* |
476 | * Reset each runqueue's bandwidth settings | 511 | * Reset each runqueue's bandwidth settings |
477 | */ | 512 | */ |
478 | for_each_leaf_rt_rq(rt_rq, rq) { | 513 | for_each_rt_rq(rt_rq, iter, rq) { |
479 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); | 514 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
480 | 515 | ||
481 | raw_spin_lock(&rt_b->rt_runtime_lock); | 516 | raw_spin_lock(&rt_b->rt_runtime_lock); |
@@ -542,12 +577,22 @@ static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun) | |||
542 | if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { | 577 | if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { |
543 | rt_rq->rt_throttled = 0; | 578 | rt_rq->rt_throttled = 0; |
544 | enqueue = 1; | 579 | enqueue = 1; |
580 | |||
581 | /* | ||
582 | * Force a clock update if the CPU was idle, | ||
583 | * lest wakeup -> unthrottle time accumulate. | ||
584 | */ | ||
585 | if (rt_rq->rt_nr_running && rq->curr == rq->idle) | ||
586 | rq->skip_clock_update = -1; | ||
545 | } | 587 | } |
546 | if (rt_rq->rt_time || rt_rq->rt_nr_running) | 588 | if (rt_rq->rt_time || rt_rq->rt_nr_running) |
547 | idle = 0; | 589 | idle = 0; |
548 | raw_spin_unlock(&rt_rq->rt_runtime_lock); | 590 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
549 | } else if (rt_rq->rt_nr_running) | 591 | } else if (rt_rq->rt_nr_running) { |
550 | idle = 0; | 592 | idle = 0; |
593 | if (!rt_rq_throttled(rt_rq)) | ||
594 | enqueue = 1; | ||
595 | } | ||
551 | 596 | ||
552 | if (enqueue) | 597 | if (enqueue) |
553 | sched_rt_rq_enqueue(rt_rq); | 598 | sched_rt_rq_enqueue(rt_rq); |
@@ -606,10 +651,10 @@ static void update_curr_rt(struct rq *rq) | |||
606 | struct rt_rq *rt_rq = rt_rq_of_se(rt_se); | 651 | struct rt_rq *rt_rq = rt_rq_of_se(rt_se); |
607 | u64 delta_exec; | 652 | u64 delta_exec; |
608 | 653 | ||
609 | if (!task_has_rt_policy(curr)) | 654 | if (curr->sched_class != &rt_sched_class) |
610 | return; | 655 | return; |
611 | 656 | ||
612 | delta_exec = rq->clock - curr->se.exec_start; | 657 | delta_exec = rq->clock_task - curr->se.exec_start; |
613 | if (unlikely((s64)delta_exec < 0)) | 658 | if (unlikely((s64)delta_exec < 0)) |
614 | delta_exec = 0; | 659 | delta_exec = 0; |
615 | 660 | ||
@@ -618,7 +663,7 @@ static void update_curr_rt(struct rq *rq) | |||
618 | curr->se.sum_exec_runtime += delta_exec; | 663 | curr->se.sum_exec_runtime += delta_exec; |
619 | account_group_exec_runtime(curr, delta_exec); | 664 | account_group_exec_runtime(curr, delta_exec); |
620 | 665 | ||
621 | curr->se.exec_start = rq->clock; | 666 | curr->se.exec_start = rq->clock_task; |
622 | cpuacct_charge(curr, delta_exec); | 667 | cpuacct_charge(curr, delta_exec); |
623 | 668 | ||
624 | sched_rt_avg_update(rq, delta_exec); | 669 | sched_rt_avg_update(rq, delta_exec); |
@@ -825,6 +870,9 @@ static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head) | |||
825 | if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) | 870 | if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) |
826 | return; | 871 | return; |
827 | 872 | ||
873 | if (!rt_rq->rt_nr_running) | ||
874 | list_add_leaf_rt_rq(rt_rq); | ||
875 | |||
828 | if (head) | 876 | if (head) |
829 | list_add(&rt_se->run_list, queue); | 877 | list_add(&rt_se->run_list, queue); |
830 | else | 878 | else |
@@ -844,6 +892,8 @@ static void __dequeue_rt_entity(struct sched_rt_entity *rt_se) | |||
844 | __clear_bit(rt_se_prio(rt_se), array->bitmap); | 892 | __clear_bit(rt_se_prio(rt_se), array->bitmap); |
845 | 893 | ||
846 | dec_rt_tasks(rt_se, rt_rq); | 894 | dec_rt_tasks(rt_se, rt_rq); |
895 | if (!rt_rq->rt_nr_running) | ||
896 | list_del_leaf_rt_rq(rt_rq); | ||
847 | } | 897 | } |
848 | 898 | ||
849 | /* | 899 | /* |
@@ -949,40 +999,55 @@ static void yield_task_rt(struct rq *rq) | |||
949 | static int find_lowest_rq(struct task_struct *task); | 999 | static int find_lowest_rq(struct task_struct *task); |
950 | 1000 | ||
951 | static int | 1001 | static int |
952 | select_task_rq_rt(struct rq *rq, struct task_struct *p, int sd_flag, int flags) | 1002 | select_task_rq_rt(struct task_struct *p, int sd_flag, int flags) |
953 | { | 1003 | { |
1004 | struct task_struct *curr; | ||
1005 | struct rq *rq; | ||
1006 | int cpu; | ||
1007 | |||
954 | if (sd_flag != SD_BALANCE_WAKE) | 1008 | if (sd_flag != SD_BALANCE_WAKE) |
955 | return smp_processor_id(); | 1009 | return smp_processor_id(); |
956 | 1010 | ||
1011 | cpu = task_cpu(p); | ||
1012 | rq = cpu_rq(cpu); | ||
1013 | |||
1014 | rcu_read_lock(); | ||
1015 | curr = ACCESS_ONCE(rq->curr); /* unlocked access */ | ||
1016 | |||
957 | /* | 1017 | /* |
958 | * If the current task is an RT task, then | 1018 | * If the current task on @p's runqueue is an RT task, then |
959 | * try to see if we can wake this RT task up on another | 1019 | * try to see if we can wake this RT task up on another |
960 | * runqueue. Otherwise simply start this RT task | 1020 | * runqueue. Otherwise simply start this RT task |
961 | * on its current runqueue. | 1021 | * on its current runqueue. |
962 | * | 1022 | * |
963 | * We want to avoid overloading runqueues. Even if | 1023 | * We want to avoid overloading runqueues. If the woken |
964 | * the RT task is of higher priority than the current RT task. | 1024 | * task is a higher priority, then it will stay on this CPU |
965 | * RT tasks behave differently than other tasks. If | 1025 | * and the lower prio task should be moved to another CPU. |
966 | * one gets preempted, we try to push it off to another queue. | 1026 | * Even though this will probably make the lower prio task |
967 | * So trying to keep a preempting RT task on the same | 1027 | * lose its cache, we do not want to bounce a higher task |
968 | * cache hot CPU will force the running RT task to | 1028 | * around just because it gave up its CPU, perhaps for a |
969 | * a cold CPU. So we waste all the cache for the lower | 1029 | * lock? |
970 | * RT task in hopes of saving some of a RT task | 1030 | * |
971 | * that is just being woken and probably will have | 1031 | * For equal prio tasks, we just let the scheduler sort it out. |
972 | * cold cache anyway. | 1032 | * |
1033 | * Otherwise, just let it ride on the affined RQ and the | ||
1034 | * post-schedule router will push the preempted task away | ||
1035 | * | ||
1036 | * This test is optimistic, if we get it wrong the load-balancer | ||
1037 | * will have to sort it out. | ||
973 | */ | 1038 | */ |
974 | if (unlikely(rt_task(rq->curr)) && | 1039 | if (curr && unlikely(rt_task(curr)) && |
1040 | (curr->rt.nr_cpus_allowed < 2 || | ||
1041 | curr->prio < p->prio) && | ||
975 | (p->rt.nr_cpus_allowed > 1)) { | 1042 | (p->rt.nr_cpus_allowed > 1)) { |
976 | int cpu = find_lowest_rq(p); | 1043 | int target = find_lowest_rq(p); |
977 | 1044 | ||
978 | return (cpu == -1) ? task_cpu(p) : cpu; | 1045 | if (target != -1) |
1046 | cpu = target; | ||
979 | } | 1047 | } |
1048 | rcu_read_unlock(); | ||
980 | 1049 | ||
981 | /* | 1050 | return cpu; |
982 | * Otherwise, just let it ride on the affined RQ and the | ||
983 | * post-schedule router will push the preempted task away | ||
984 | */ | ||
985 | return task_cpu(p); | ||
986 | } | 1051 | } |
987 | 1052 | ||
988 | static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) | 1053 | static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) |
@@ -1031,7 +1096,7 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flag | |||
1031 | * to move current somewhere else, making room for our non-migratable | 1096 | * to move current somewhere else, making room for our non-migratable |
1032 | * task. | 1097 | * task. |
1033 | */ | 1098 | */ |
1034 | if (p->prio == rq->curr->prio && !need_resched()) | 1099 | if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr)) |
1035 | check_preempt_equal_prio(rq, p); | 1100 | check_preempt_equal_prio(rq, p); |
1036 | #endif | 1101 | #endif |
1037 | } | 1102 | } |
@@ -1074,7 +1139,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq) | |||
1074 | } while (rt_rq); | 1139 | } while (rt_rq); |
1075 | 1140 | ||
1076 | p = rt_task_of(rt_se); | 1141 | p = rt_task_of(rt_se); |
1077 | p->se.exec_start = rq->clock; | 1142 | p->se.exec_start = rq->clock_task; |
1078 | 1143 | ||
1079 | return p; | 1144 | return p; |
1080 | } | 1145 | } |
@@ -1107,7 +1172,7 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) | |||
1107 | * The previous task needs to be made eligible for pushing | 1172 | * The previous task needs to be made eligible for pushing |
1108 | * if it is still active | 1173 | * if it is still active |
1109 | */ | 1174 | */ |
1110 | if (p->se.on_rq && p->rt.nr_cpus_allowed > 1) | 1175 | if (on_rt_rq(&p->rt) && p->rt.nr_cpus_allowed > 1) |
1111 | enqueue_pushable_task(rq, p); | 1176 | enqueue_pushable_task(rq, p); |
1112 | } | 1177 | } |
1113 | 1178 | ||
@@ -1139,7 +1204,7 @@ static struct task_struct *pick_next_highest_task_rt(struct rq *rq, int cpu) | |||
1139 | for_each_leaf_rt_rq(rt_rq, rq) { | 1204 | for_each_leaf_rt_rq(rt_rq, rq) { |
1140 | array = &rt_rq->active; | 1205 | array = &rt_rq->active; |
1141 | idx = sched_find_first_bit(array->bitmap); | 1206 | idx = sched_find_first_bit(array->bitmap); |
1142 | next_idx: | 1207 | next_idx: |
1143 | if (idx >= MAX_RT_PRIO) | 1208 | if (idx >= MAX_RT_PRIO) |
1144 | continue; | 1209 | continue; |
1145 | if (next && next->prio < idx) | 1210 | if (next && next->prio < idx) |
@@ -1174,6 +1239,10 @@ static int find_lowest_rq(struct task_struct *task) | |||
1174 | int this_cpu = smp_processor_id(); | 1239 | int this_cpu = smp_processor_id(); |
1175 | int cpu = task_cpu(task); | 1240 | int cpu = task_cpu(task); |
1176 | 1241 | ||
1242 | /* Make sure the mask is initialized first */ | ||
1243 | if (unlikely(!lowest_mask)) | ||
1244 | return -1; | ||
1245 | |||
1177 | if (task->rt.nr_cpus_allowed == 1) | 1246 | if (task->rt.nr_cpus_allowed == 1) |
1178 | return -1; /* No other targets possible */ | 1247 | return -1; /* No other targets possible */ |
1179 | 1248 | ||
@@ -1198,6 +1267,7 @@ static int find_lowest_rq(struct task_struct *task) | |||
1198 | if (!cpumask_test_cpu(this_cpu, lowest_mask)) | 1267 | if (!cpumask_test_cpu(this_cpu, lowest_mask)) |
1199 | this_cpu = -1; /* Skip this_cpu opt if not among lowest */ | 1268 | this_cpu = -1; /* Skip this_cpu opt if not among lowest */ |
1200 | 1269 | ||
1270 | rcu_read_lock(); | ||
1201 | for_each_domain(cpu, sd) { | 1271 | for_each_domain(cpu, sd) { |
1202 | if (sd->flags & SD_WAKE_AFFINE) { | 1272 | if (sd->flags & SD_WAKE_AFFINE) { |
1203 | int best_cpu; | 1273 | int best_cpu; |
@@ -1207,15 +1277,20 @@ static int find_lowest_rq(struct task_struct *task) | |||
1207 | * remote processor. | 1277 | * remote processor. |
1208 | */ | 1278 | */ |
1209 | if (this_cpu != -1 && | 1279 | if (this_cpu != -1 && |
1210 | cpumask_test_cpu(this_cpu, sched_domain_span(sd))) | 1280 | cpumask_test_cpu(this_cpu, sched_domain_span(sd))) { |
1281 | rcu_read_unlock(); | ||
1211 | return this_cpu; | 1282 | return this_cpu; |
1283 | } | ||
1212 | 1284 | ||
1213 | best_cpu = cpumask_first_and(lowest_mask, | 1285 | best_cpu = cpumask_first_and(lowest_mask, |
1214 | sched_domain_span(sd)); | 1286 | sched_domain_span(sd)); |
1215 | if (best_cpu < nr_cpu_ids) | 1287 | if (best_cpu < nr_cpu_ids) { |
1288 | rcu_read_unlock(); | ||
1216 | return best_cpu; | 1289 | return best_cpu; |
1290 | } | ||
1217 | } | 1291 | } |
1218 | } | 1292 | } |
1293 | rcu_read_unlock(); | ||
1219 | 1294 | ||
1220 | /* | 1295 | /* |
1221 | * And finally, if there were no matches within the domains | 1296 | * And finally, if there were no matches within the domains |
@@ -1258,7 +1333,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) | |||
1258 | !cpumask_test_cpu(lowest_rq->cpu, | 1333 | !cpumask_test_cpu(lowest_rq->cpu, |
1259 | &task->cpus_allowed) || | 1334 | &task->cpus_allowed) || |
1260 | task_running(rq, task) || | 1335 | task_running(rq, task) || |
1261 | !task->se.on_rq)) { | 1336 | !task->on_rq)) { |
1262 | 1337 | ||
1263 | raw_spin_unlock(&lowest_rq->lock); | 1338 | raw_spin_unlock(&lowest_rq->lock); |
1264 | lowest_rq = NULL; | 1339 | lowest_rq = NULL; |
@@ -1292,7 +1367,7 @@ static struct task_struct *pick_next_pushable_task(struct rq *rq) | |||
1292 | BUG_ON(task_current(rq, p)); | 1367 | BUG_ON(task_current(rq, p)); |
1293 | BUG_ON(p->rt.nr_cpus_allowed <= 1); | 1368 | BUG_ON(p->rt.nr_cpus_allowed <= 1); |
1294 | 1369 | ||
1295 | BUG_ON(!p->se.on_rq); | 1370 | BUG_ON(!p->on_rq); |
1296 | BUG_ON(!rt_task(p)); | 1371 | BUG_ON(!rt_task(p)); |
1297 | 1372 | ||
1298 | return p; | 1373 | return p; |
@@ -1315,7 +1390,7 @@ static int push_rt_task(struct rq *rq) | |||
1315 | if (!next_task) | 1390 | if (!next_task) |
1316 | return 0; | 1391 | return 0; |
1317 | 1392 | ||
1318 | retry: | 1393 | retry: |
1319 | if (unlikely(next_task == rq->curr)) { | 1394 | if (unlikely(next_task == rq->curr)) { |
1320 | WARN_ON(1); | 1395 | WARN_ON(1); |
1321 | return 0; | 1396 | return 0; |
@@ -1349,7 +1424,7 @@ static int push_rt_task(struct rq *rq) | |||
1349 | task = pick_next_pushable_task(rq); | 1424 | task = pick_next_pushable_task(rq); |
1350 | if (task_cpu(next_task) == rq->cpu && task == next_task) { | 1425 | if (task_cpu(next_task) == rq->cpu && task == next_task) { |
1351 | /* | 1426 | /* |
1352 | * If we get here, the task hasnt moved at all, but | 1427 | * If we get here, the task hasn't moved at all, but |
1353 | * it has failed to push. We will not try again, | 1428 | * it has failed to push. We will not try again, |
1354 | * since the other cpus will pull from us when they | 1429 | * since the other cpus will pull from us when they |
1355 | * are ready. | 1430 | * are ready. |
@@ -1438,7 +1513,7 @@ static int pull_rt_task(struct rq *this_rq) | |||
1438 | */ | 1513 | */ |
1439 | if (p && (p->prio < this_rq->rt.highest_prio.curr)) { | 1514 | if (p && (p->prio < this_rq->rt.highest_prio.curr)) { |
1440 | WARN_ON(p == src_rq->curr); | 1515 | WARN_ON(p == src_rq->curr); |
1441 | WARN_ON(!p->se.on_rq); | 1516 | WARN_ON(!p->on_rq); |
1442 | 1517 | ||
1443 | /* | 1518 | /* |
1444 | * There's a chance that p is higher in priority | 1519 | * There's a chance that p is higher in priority |
@@ -1459,11 +1534,11 @@ static int pull_rt_task(struct rq *this_rq) | |||
1459 | /* | 1534 | /* |
1460 | * We continue with the search, just in | 1535 | * We continue with the search, just in |
1461 | * case there's an even higher prio task | 1536 | * case there's an even higher prio task |
1462 | * in another runqueue. (low likelyhood | 1537 | * in another runqueue. (low likelihood |
1463 | * but possible) | 1538 | * but possible) |
1464 | */ | 1539 | */ |
1465 | } | 1540 | } |
1466 | skip: | 1541 | skip: |
1467 | double_unlock_balance(this_rq, src_rq); | 1542 | double_unlock_balance(this_rq, src_rq); |
1468 | } | 1543 | } |
1469 | 1544 | ||
@@ -1491,7 +1566,10 @@ static void task_woken_rt(struct rq *rq, struct task_struct *p) | |||
1491 | if (!task_running(rq, p) && | 1566 | if (!task_running(rq, p) && |
1492 | !test_tsk_need_resched(rq->curr) && | 1567 | !test_tsk_need_resched(rq->curr) && |
1493 | has_pushable_tasks(rq) && | 1568 | has_pushable_tasks(rq) && |
1494 | p->rt.nr_cpus_allowed > 1) | 1569 | p->rt.nr_cpus_allowed > 1 && |
1570 | rt_task(rq->curr) && | ||
1571 | (rq->curr->rt.nr_cpus_allowed < 2 || | ||
1572 | rq->curr->prio < p->prio)) | ||
1495 | push_rt_tasks(rq); | 1573 | push_rt_tasks(rq); |
1496 | } | 1574 | } |
1497 | 1575 | ||
@@ -1506,7 +1584,7 @@ static void set_cpus_allowed_rt(struct task_struct *p, | |||
1506 | * Update the migration status of the RQ if we have an RT task | 1584 | * Update the migration status of the RQ if we have an RT task |
1507 | * which is running AND changing its weight value. | 1585 | * which is running AND changing its weight value. |
1508 | */ | 1586 | */ |
1509 | if (p->se.on_rq && (weight != p->rt.nr_cpus_allowed)) { | 1587 | if (p->on_rq && (weight != p->rt.nr_cpus_allowed)) { |
1510 | struct rq *rq = task_rq(p); | 1588 | struct rq *rq = task_rq(p); |
1511 | 1589 | ||
1512 | if (!task_current(rq, p)) { | 1590 | if (!task_current(rq, p)) { |
@@ -1567,8 +1645,7 @@ static void rq_offline_rt(struct rq *rq) | |||
1567 | * When switch from the rt queue, we bring ourselves to a position | 1645 | * When switch from the rt queue, we bring ourselves to a position |
1568 | * that we might want to pull RT tasks from other runqueues. | 1646 | * that we might want to pull RT tasks from other runqueues. |
1569 | */ | 1647 | */ |
1570 | static void switched_from_rt(struct rq *rq, struct task_struct *p, | 1648 | static void switched_from_rt(struct rq *rq, struct task_struct *p) |
1571 | int running) | ||
1572 | { | 1649 | { |
1573 | /* | 1650 | /* |
1574 | * If there are other RT tasks then we will reschedule | 1651 | * If there are other RT tasks then we will reschedule |
@@ -1577,7 +1654,7 @@ static void switched_from_rt(struct rq *rq, struct task_struct *p, | |||
1577 | * we may need to handle the pulling of RT tasks | 1654 | * we may need to handle the pulling of RT tasks |
1578 | * now. | 1655 | * now. |
1579 | */ | 1656 | */ |
1580 | if (!rq->rt.rt_nr_running) | 1657 | if (p->on_rq && !rq->rt.rt_nr_running) |
1581 | pull_rt_task(rq); | 1658 | pull_rt_task(rq); |
1582 | } | 1659 | } |
1583 | 1660 | ||
@@ -1596,8 +1673,7 @@ static inline void init_sched_rt_class(void) | |||
1596 | * with RT tasks. In this case we try to push them off to | 1673 | * with RT tasks. In this case we try to push them off to |
1597 | * other runqueues. | 1674 | * other runqueues. |
1598 | */ | 1675 | */ |
1599 | static void switched_to_rt(struct rq *rq, struct task_struct *p, | 1676 | static void switched_to_rt(struct rq *rq, struct task_struct *p) |
1600 | int running) | ||
1601 | { | 1677 | { |
1602 | int check_resched = 1; | 1678 | int check_resched = 1; |
1603 | 1679 | ||
@@ -1608,7 +1684,7 @@ static void switched_to_rt(struct rq *rq, struct task_struct *p, | |||
1608 | * If that current running task is also an RT task | 1684 | * If that current running task is also an RT task |
1609 | * then see if we can move to another run queue. | 1685 | * then see if we can move to another run queue. |
1610 | */ | 1686 | */ |
1611 | if (!running) { | 1687 | if (p->on_rq && rq->curr != p) { |
1612 | #ifdef CONFIG_SMP | 1688 | #ifdef CONFIG_SMP |
1613 | if (rq->rt.overloaded && push_rt_task(rq) && | 1689 | if (rq->rt.overloaded && push_rt_task(rq) && |
1614 | /* Don't resched if we changed runqueues */ | 1690 | /* Don't resched if we changed runqueues */ |
@@ -1624,10 +1700,13 @@ static void switched_to_rt(struct rq *rq, struct task_struct *p, | |||
1624 | * Priority of the task has changed. This may cause | 1700 | * Priority of the task has changed. This may cause |
1625 | * us to initiate a push or pull. | 1701 | * us to initiate a push or pull. |
1626 | */ | 1702 | */ |
1627 | static void prio_changed_rt(struct rq *rq, struct task_struct *p, | 1703 | static void |
1628 | int oldprio, int running) | 1704 | prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio) |
1629 | { | 1705 | { |
1630 | if (running) { | 1706 | if (!p->on_rq) |
1707 | return; | ||
1708 | |||
1709 | if (rq->curr == p) { | ||
1631 | #ifdef CONFIG_SMP | 1710 | #ifdef CONFIG_SMP |
1632 | /* | 1711 | /* |
1633 | * If our priority decreases while running, we | 1712 | * If our priority decreases while running, we |
@@ -1709,7 +1788,7 @@ static void set_curr_task_rt(struct rq *rq) | |||
1709 | { | 1788 | { |
1710 | struct task_struct *p = rq->curr; | 1789 | struct task_struct *p = rq->curr; |
1711 | 1790 | ||
1712 | p->se.exec_start = rq->clock; | 1791 | p->se.exec_start = rq->clock_task; |
1713 | 1792 | ||
1714 | /* The running task is never eligible for pushing */ | 1793 | /* The running task is never eligible for pushing */ |
1715 | dequeue_pushable_task(rq, p); | 1794 | dequeue_pushable_task(rq, p); |
@@ -1763,10 +1842,11 @@ extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq); | |||
1763 | 1842 | ||
1764 | static void print_rt_stats(struct seq_file *m, int cpu) | 1843 | static void print_rt_stats(struct seq_file *m, int cpu) |
1765 | { | 1844 | { |
1845 | rt_rq_iter_t iter; | ||
1766 | struct rt_rq *rt_rq; | 1846 | struct rt_rq *rt_rq; |
1767 | 1847 | ||
1768 | rcu_read_lock(); | 1848 | rcu_read_lock(); |
1769 | for_each_leaf_rt_rq(rt_rq, cpu_rq(cpu)) | 1849 | for_each_rt_rq(rt_rq, iter, cpu_rq(cpu)) |
1770 | print_rt_rq(m, cpu, rt_rq); | 1850 | print_rt_rq(m, cpu, rt_rq); |
1771 | rcu_read_unlock(); | 1851 | rcu_read_unlock(); |
1772 | } | 1852 | } |