diff options
| author | Ingo Molnar <mingo@elte.hu> | 2009-04-05 19:41:22 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2009-04-05 19:41:22 -0400 |
| commit | 9efe21cb82b5dbe3b0b2ae4de4eccc64ecb94e95 (patch) | |
| tree | 7ff8833745d2f268f897f6fa4a27263b4a572245 /kernel/sched_rt.c | |
| parent | de18836e447c2dc30120c0919b8db8ddc0401cc4 (diff) | |
| parent | 0221c81b1b8eb0cbb6b30a0ced52ead32d2b4e4c (diff) | |
Merge branch 'linus' into irq/threaded
Conflicts:
include/linux/irq.h
kernel/irq/handle.c
Diffstat (limited to 'kernel/sched_rt.c')
| -rw-r--r-- | kernel/sched_rt.c | 537 |
1 files changed, 374 insertions, 163 deletions
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index da932f4c8524..299d012b4394 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
| @@ -3,6 +3,40 @@ | |||
| 3 | * policies) | 3 | * policies) |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) | ||
| 7 | { | ||
| 8 | return container_of(rt_se, struct task_struct, rt); | ||
| 9 | } | ||
| 10 | |||
| 11 | #ifdef CONFIG_RT_GROUP_SCHED | ||
| 12 | |||
| 13 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | ||
| 14 | { | ||
| 15 | return rt_rq->rq; | ||
| 16 | } | ||
| 17 | |||
| 18 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) | ||
| 19 | { | ||
| 20 | return rt_se->rt_rq; | ||
| 21 | } | ||
| 22 | |||
| 23 | #else /* CONFIG_RT_GROUP_SCHED */ | ||
| 24 | |||
| 25 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | ||
| 26 | { | ||
| 27 | return container_of(rt_rq, struct rq, rt); | ||
| 28 | } | ||
| 29 | |||
| 30 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) | ||
| 31 | { | ||
| 32 | struct task_struct *p = rt_task_of(rt_se); | ||
| 33 | struct rq *rq = task_rq(p); | ||
| 34 | |||
| 35 | return &rq->rt; | ||
| 36 | } | ||
| 37 | |||
| 38 | #endif /* CONFIG_RT_GROUP_SCHED */ | ||
| 39 | |||
| 6 | #ifdef CONFIG_SMP | 40 | #ifdef CONFIG_SMP |
| 7 | 41 | ||
| 8 | static inline int rt_overloaded(struct rq *rq) | 42 | static inline int rt_overloaded(struct rq *rq) |
| @@ -37,25 +71,69 @@ static inline void rt_clear_overload(struct rq *rq) | |||
| 37 | cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); | 71 | cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); |
| 38 | } | 72 | } |
| 39 | 73 | ||
| 40 | static void update_rt_migration(struct rq *rq) | 74 | static void update_rt_migration(struct rt_rq *rt_rq) |
| 41 | { | 75 | { |
| 42 | if (rq->rt.rt_nr_migratory && (rq->rt.rt_nr_running > 1)) { | 76 | if (rt_rq->rt_nr_migratory && (rt_rq->rt_nr_running > 1)) { |
| 43 | if (!rq->rt.overloaded) { | 77 | if (!rt_rq->overloaded) { |
| 44 | rt_set_overload(rq); | 78 | rt_set_overload(rq_of_rt_rq(rt_rq)); |
| 45 | rq->rt.overloaded = 1; | 79 | rt_rq->overloaded = 1; |
| 46 | } | 80 | } |
| 47 | } else if (rq->rt.overloaded) { | 81 | } else if (rt_rq->overloaded) { |
| 48 | rt_clear_overload(rq); | 82 | rt_clear_overload(rq_of_rt_rq(rt_rq)); |
| 49 | rq->rt.overloaded = 0; | 83 | rt_rq->overloaded = 0; |
| 50 | } | 84 | } |
| 51 | } | 85 | } |
| 52 | #endif /* CONFIG_SMP */ | ||
| 53 | 86 | ||
| 54 | static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) | 87 | static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) |
| 88 | { | ||
| 89 | if (rt_se->nr_cpus_allowed > 1) | ||
| 90 | rt_rq->rt_nr_migratory++; | ||
| 91 | |||
| 92 | update_rt_migration(rt_rq); | ||
| 93 | } | ||
| 94 | |||
| 95 | static void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 96 | { | ||
| 97 | if (rt_se->nr_cpus_allowed > 1) | ||
| 98 | rt_rq->rt_nr_migratory--; | ||
| 99 | |||
| 100 | update_rt_migration(rt_rq); | ||
| 101 | } | ||
| 102 | |||
| 103 | static void enqueue_pushable_task(struct rq *rq, struct task_struct *p) | ||
| 104 | { | ||
| 105 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); | ||
| 106 | plist_node_init(&p->pushable_tasks, p->prio); | ||
| 107 | plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); | ||
| 108 | } | ||
| 109 | |||
| 110 | static void dequeue_pushable_task(struct rq *rq, struct task_struct *p) | ||
| 111 | { | ||
| 112 | plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); | ||
| 113 | } | ||
| 114 | |||
| 115 | #else | ||
| 116 | |||
| 117 | static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) | ||
| 55 | { | 118 | { |
| 56 | return container_of(rt_se, struct task_struct, rt); | ||
| 57 | } | 119 | } |
| 58 | 120 | ||
| 121 | static inline void dequeue_pushable_task(struct rq *rq, struct task_struct *p) | ||
| 122 | { | ||
| 123 | } | ||
| 124 | |||
| 125 | static inline | ||
| 126 | void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 127 | { | ||
| 128 | } | ||
| 129 | |||
| 130 | static inline | ||
| 131 | void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 132 | { | ||
| 133 | } | ||
| 134 | |||
| 135 | #endif /* CONFIG_SMP */ | ||
| 136 | |||
| 59 | static inline int on_rt_rq(struct sched_rt_entity *rt_se) | 137 | static inline int on_rt_rq(struct sched_rt_entity *rt_se) |
| 60 | { | 138 | { |
| 61 | return !list_empty(&rt_se->run_list); | 139 | return !list_empty(&rt_se->run_list); |
| @@ -79,16 +157,6 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq) | |||
| 79 | #define for_each_leaf_rt_rq(rt_rq, rq) \ | 157 | #define for_each_leaf_rt_rq(rt_rq, rq) \ |
| 80 | list_for_each_entry_rcu(rt_rq, &rq->leaf_rt_rq_list, leaf_rt_rq_list) | 158 | list_for_each_entry_rcu(rt_rq, &rq->leaf_rt_rq_list, leaf_rt_rq_list) |
| 81 | 159 | ||
| 82 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | ||
| 83 | { | ||
| 84 | return rt_rq->rq; | ||
| 85 | } | ||
| 86 | |||
| 87 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) | ||
| 88 | { | ||
| 89 | return rt_se->rt_rq; | ||
| 90 | } | ||
| 91 | |||
| 92 | #define for_each_sched_rt_entity(rt_se) \ | 160 | #define for_each_sched_rt_entity(rt_se) \ |
| 93 | for (; rt_se; rt_se = rt_se->parent) | 161 | for (; rt_se; rt_se = rt_se->parent) |
| 94 | 162 | ||
| @@ -108,7 +176,7 @@ static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) | |||
| 108 | if (rt_rq->rt_nr_running) { | 176 | if (rt_rq->rt_nr_running) { |
| 109 | if (rt_se && !on_rt_rq(rt_se)) | 177 | if (rt_se && !on_rt_rq(rt_se)) |
| 110 | enqueue_rt_entity(rt_se); | 178 | enqueue_rt_entity(rt_se); |
| 111 | if (rt_rq->highest_prio < curr->prio) | 179 | if (rt_rq->highest_prio.curr < curr->prio) |
| 112 | resched_task(curr); | 180 | resched_task(curr); |
| 113 | } | 181 | } |
| 114 | } | 182 | } |
| @@ -176,19 +244,6 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq) | |||
| 176 | #define for_each_leaf_rt_rq(rt_rq, rq) \ | 244 | #define for_each_leaf_rt_rq(rt_rq, rq) \ |
| 177 | for (rt_rq = &rq->rt; rt_rq; rt_rq = NULL) | 245 | for (rt_rq = &rq->rt; rt_rq; rt_rq = NULL) |
| 178 | 246 | ||
| 179 | static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq) | ||
| 180 | { | ||
| 181 | return container_of(rt_rq, struct rq, rt); | ||
| 182 | } | ||
| 183 | |||
| 184 | static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se) | ||
| 185 | { | ||
| 186 | struct task_struct *p = rt_task_of(rt_se); | ||
| 187 | struct rq *rq = task_rq(p); | ||
| 188 | |||
| 189 | return &rq->rt; | ||
| 190 | } | ||
| 191 | |||
| 192 | #define for_each_sched_rt_entity(rt_se) \ | 247 | #define for_each_sched_rt_entity(rt_se) \ |
| 193 | for (; rt_se; rt_se = NULL) | 248 | for (; rt_se; rt_se = NULL) |
| 194 | 249 | ||
| @@ -473,7 +528,7 @@ static inline int rt_se_prio(struct sched_rt_entity *rt_se) | |||
| 473 | struct rt_rq *rt_rq = group_rt_rq(rt_se); | 528 | struct rt_rq *rt_rq = group_rt_rq(rt_se); |
| 474 | 529 | ||
| 475 | if (rt_rq) | 530 | if (rt_rq) |
| 476 | return rt_rq->highest_prio; | 531 | return rt_rq->highest_prio.curr; |
| 477 | #endif | 532 | #endif |
| 478 | 533 | ||
| 479 | return rt_task_of(rt_se)->prio; | 534 | return rt_task_of(rt_se)->prio; |
| @@ -547,91 +602,174 @@ static void update_curr_rt(struct rq *rq) | |||
| 547 | } | 602 | } |
| 548 | } | 603 | } |
| 549 | 604 | ||
| 550 | static inline | 605 | #if defined CONFIG_SMP |
| 551 | void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | 606 | |
| 607 | static struct task_struct *pick_next_highest_task_rt(struct rq *rq, int cpu); | ||
| 608 | |||
| 609 | static inline int next_prio(struct rq *rq) | ||
| 552 | { | 610 | { |
| 553 | WARN_ON(!rt_prio(rt_se_prio(rt_se))); | 611 | struct task_struct *next = pick_next_highest_task_rt(rq, rq->cpu); |
| 554 | rt_rq->rt_nr_running++; | 612 | |
| 555 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED | 613 | if (next && rt_prio(next->prio)) |
| 556 | if (rt_se_prio(rt_se) < rt_rq->highest_prio) { | 614 | return next->prio; |
| 557 | #ifdef CONFIG_SMP | 615 | else |
| 558 | struct rq *rq = rq_of_rt_rq(rt_rq); | 616 | return MAX_RT_PRIO; |
| 559 | #endif | 617 | } |
| 618 | |||
| 619 | static void | ||
| 620 | inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) | ||
| 621 | { | ||
| 622 | struct rq *rq = rq_of_rt_rq(rt_rq); | ||
| 623 | |||
| 624 | if (prio < prev_prio) { | ||
| 625 | |||
| 626 | /* | ||
| 627 | * If the new task is higher in priority than anything on the | ||
| 628 | * run-queue, we know that the previous high becomes our | ||
| 629 | * next-highest. | ||
| 630 | */ | ||
| 631 | rt_rq->highest_prio.next = prev_prio; | ||
| 560 | 632 | ||
| 561 | rt_rq->highest_prio = rt_se_prio(rt_se); | ||
| 562 | #ifdef CONFIG_SMP | ||
| 563 | if (rq->online) | 633 | if (rq->online) |
| 564 | cpupri_set(&rq->rd->cpupri, rq->cpu, | 634 | cpupri_set(&rq->rd->cpupri, rq->cpu, prio); |
| 565 | rt_se_prio(rt_se)); | ||
| 566 | #endif | ||
| 567 | } | ||
| 568 | #endif | ||
| 569 | #ifdef CONFIG_SMP | ||
| 570 | if (rt_se->nr_cpus_allowed > 1) { | ||
| 571 | struct rq *rq = rq_of_rt_rq(rt_rq); | ||
| 572 | 635 | ||
| 573 | rq->rt.rt_nr_migratory++; | 636 | } else if (prio == rt_rq->highest_prio.curr) |
| 574 | } | 637 | /* |
| 638 | * If the next task is equal in priority to the highest on | ||
| 639 | * the run-queue, then we implicitly know that the next highest | ||
| 640 | * task cannot be any lower than current | ||
| 641 | */ | ||
| 642 | rt_rq->highest_prio.next = prio; | ||
| 643 | else if (prio < rt_rq->highest_prio.next) | ||
| 644 | /* | ||
| 645 | * Otherwise, we need to recompute next-highest | ||
| 646 | */ | ||
| 647 | rt_rq->highest_prio.next = next_prio(rq); | ||
| 648 | } | ||
| 575 | 649 | ||
| 576 | update_rt_migration(rq_of_rt_rq(rt_rq)); | 650 | static void |
| 577 | #endif | 651 | dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) |
| 578 | #ifdef CONFIG_RT_GROUP_SCHED | 652 | { |
| 579 | if (rt_se_boosted(rt_se)) | 653 | struct rq *rq = rq_of_rt_rq(rt_rq); |
| 580 | rt_rq->rt_nr_boosted++; | ||
| 581 | 654 | ||
| 582 | if (rt_rq->tg) | 655 | if (rt_rq->rt_nr_running && (prio <= rt_rq->highest_prio.next)) |
| 583 | start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); | 656 | rt_rq->highest_prio.next = next_prio(rq); |
| 584 | #else | 657 | |
| 585 | start_rt_bandwidth(&def_rt_bandwidth); | 658 | if (rq->online && rt_rq->highest_prio.curr != prev_prio) |
| 586 | #endif | 659 | cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr); |
| 587 | } | 660 | } |
| 588 | 661 | ||
| 662 | #else /* CONFIG_SMP */ | ||
| 663 | |||
| 589 | static inline | 664 | static inline |
| 590 | void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | 665 | void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {} |
| 591 | { | 666 | static inline |
| 592 | #ifdef CONFIG_SMP | 667 | void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {} |
| 593 | int highest_prio = rt_rq->highest_prio; | 668 | |
| 594 | #endif | 669 | #endif /* CONFIG_SMP */ |
| 595 | 670 | ||
| 596 | WARN_ON(!rt_prio(rt_se_prio(rt_se))); | ||
| 597 | WARN_ON(!rt_rq->rt_nr_running); | ||
| 598 | rt_rq->rt_nr_running--; | ||
| 599 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED | 671 | #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED |
| 672 | static void | ||
| 673 | inc_rt_prio(struct rt_rq *rt_rq, int prio) | ||
| 674 | { | ||
| 675 | int prev_prio = rt_rq->highest_prio.curr; | ||
| 676 | |||
| 677 | if (prio < prev_prio) | ||
| 678 | rt_rq->highest_prio.curr = prio; | ||
| 679 | |||
| 680 | inc_rt_prio_smp(rt_rq, prio, prev_prio); | ||
| 681 | } | ||
| 682 | |||
| 683 | static void | ||
| 684 | dec_rt_prio(struct rt_rq *rt_rq, int prio) | ||
| 685 | { | ||
| 686 | int prev_prio = rt_rq->highest_prio.curr; | ||
| 687 | |||
| 600 | if (rt_rq->rt_nr_running) { | 688 | if (rt_rq->rt_nr_running) { |
| 601 | struct rt_prio_array *array; | ||
| 602 | 689 | ||
| 603 | WARN_ON(rt_se_prio(rt_se) < rt_rq->highest_prio); | 690 | WARN_ON(prio < prev_prio); |
| 604 | if (rt_se_prio(rt_se) == rt_rq->highest_prio) { | 691 | |
| 605 | /* recalculate */ | 692 | /* |
| 606 | array = &rt_rq->active; | 693 | * This may have been our highest task, and therefore |
| 607 | rt_rq->highest_prio = | 694 | * we may have some recomputation to do |
| 695 | */ | ||
| 696 | if (prio == prev_prio) { | ||
| 697 | struct rt_prio_array *array = &rt_rq->active; | ||
| 698 | |||
| 699 | rt_rq->highest_prio.curr = | ||
| 608 | sched_find_first_bit(array->bitmap); | 700 | sched_find_first_bit(array->bitmap); |
| 609 | } /* otherwise leave rq->highest prio alone */ | 701 | } |
| 702 | |||
| 610 | } else | 703 | } else |
| 611 | rt_rq->highest_prio = MAX_RT_PRIO; | 704 | rt_rq->highest_prio.curr = MAX_RT_PRIO; |
| 612 | #endif | ||
| 613 | #ifdef CONFIG_SMP | ||
| 614 | if (rt_se->nr_cpus_allowed > 1) { | ||
| 615 | struct rq *rq = rq_of_rt_rq(rt_rq); | ||
| 616 | rq->rt.rt_nr_migratory--; | ||
| 617 | } | ||
| 618 | 705 | ||
| 619 | if (rt_rq->highest_prio != highest_prio) { | 706 | dec_rt_prio_smp(rt_rq, prio, prev_prio); |
| 620 | struct rq *rq = rq_of_rt_rq(rt_rq); | 707 | } |
| 621 | 708 | ||
| 622 | if (rq->online) | 709 | #else |
| 623 | cpupri_set(&rq->rd->cpupri, rq->cpu, | 710 | |
| 624 | rt_rq->highest_prio); | 711 | static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {} |
| 625 | } | 712 | static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {} |
| 713 | |||
| 714 | #endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */ | ||
| 626 | 715 | ||
| 627 | update_rt_migration(rq_of_rt_rq(rt_rq)); | ||
| 628 | #endif /* CONFIG_SMP */ | ||
| 629 | #ifdef CONFIG_RT_GROUP_SCHED | 716 | #ifdef CONFIG_RT_GROUP_SCHED |
| 717 | |||
| 718 | static void | ||
| 719 | inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 720 | { | ||
| 721 | if (rt_se_boosted(rt_se)) | ||
| 722 | rt_rq->rt_nr_boosted++; | ||
| 723 | |||
| 724 | if (rt_rq->tg) | ||
| 725 | start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); | ||
| 726 | } | ||
| 727 | |||
| 728 | static void | ||
| 729 | dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 730 | { | ||
| 630 | if (rt_se_boosted(rt_se)) | 731 | if (rt_se_boosted(rt_se)) |
| 631 | rt_rq->rt_nr_boosted--; | 732 | rt_rq->rt_nr_boosted--; |
| 632 | 733 | ||
| 633 | WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); | 734 | WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); |
| 634 | #endif | 735 | } |
| 736 | |||
| 737 | #else /* CONFIG_RT_GROUP_SCHED */ | ||
| 738 | |||
| 739 | static void | ||
| 740 | inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 741 | { | ||
| 742 | start_rt_bandwidth(&def_rt_bandwidth); | ||
| 743 | } | ||
| 744 | |||
| 745 | static inline | ||
| 746 | void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {} | ||
| 747 | |||
| 748 | #endif /* CONFIG_RT_GROUP_SCHED */ | ||
| 749 | |||
| 750 | static inline | ||
| 751 | void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 752 | { | ||
| 753 | int prio = rt_se_prio(rt_se); | ||
| 754 | |||
| 755 | WARN_ON(!rt_prio(prio)); | ||
| 756 | rt_rq->rt_nr_running++; | ||
| 757 | |||
| 758 | inc_rt_prio(rt_rq, prio); | ||
| 759 | inc_rt_migration(rt_se, rt_rq); | ||
| 760 | inc_rt_group(rt_se, rt_rq); | ||
| 761 | } | ||
| 762 | |||
| 763 | static inline | ||
| 764 | void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) | ||
| 765 | { | ||
| 766 | WARN_ON(!rt_prio(rt_se_prio(rt_se))); | ||
| 767 | WARN_ON(!rt_rq->rt_nr_running); | ||
| 768 | rt_rq->rt_nr_running--; | ||
| 769 | |||
| 770 | dec_rt_prio(rt_rq, rt_se_prio(rt_se)); | ||
| 771 | dec_rt_migration(rt_se, rt_rq); | ||
| 772 | dec_rt_group(rt_se, rt_rq); | ||
| 635 | } | 773 | } |
| 636 | 774 | ||
| 637 | static void __enqueue_rt_entity(struct sched_rt_entity *rt_se) | 775 | static void __enqueue_rt_entity(struct sched_rt_entity *rt_se) |
| @@ -718,6 +856,9 @@ static void enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup) | |||
| 718 | 856 | ||
| 719 | enqueue_rt_entity(rt_se); | 857 | enqueue_rt_entity(rt_se); |
| 720 | 858 | ||
| 859 | if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1) | ||
| 860 | enqueue_pushable_task(rq, p); | ||
| 861 | |||
| 721 | inc_cpu_load(rq, p->se.load.weight); | 862 | inc_cpu_load(rq, p->se.load.weight); |
| 722 | } | 863 | } |
| 723 | 864 | ||
| @@ -728,6 +869,8 @@ static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) | |||
| 728 | update_curr_rt(rq); | 869 | update_curr_rt(rq); |
| 729 | dequeue_rt_entity(rt_se); | 870 | dequeue_rt_entity(rt_se); |
| 730 | 871 | ||
| 872 | dequeue_pushable_task(rq, p); | ||
| 873 | |||
| 731 | dec_cpu_load(rq, p->se.load.weight); | 874 | dec_cpu_load(rq, p->se.load.weight); |
| 732 | } | 875 | } |
| 733 | 876 | ||
| @@ -878,7 +1021,7 @@ static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq, | |||
| 878 | return next; | 1021 | return next; |
| 879 | } | 1022 | } |
| 880 | 1023 | ||
| 881 | static struct task_struct *pick_next_task_rt(struct rq *rq) | 1024 | static struct task_struct *_pick_next_task_rt(struct rq *rq) |
| 882 | { | 1025 | { |
| 883 | struct sched_rt_entity *rt_se; | 1026 | struct sched_rt_entity *rt_se; |
| 884 | struct task_struct *p; | 1027 | struct task_struct *p; |
| @@ -900,6 +1043,18 @@ static struct task_struct *pick_next_task_rt(struct rq *rq) | |||
| 900 | 1043 | ||
| 901 | p = rt_task_of(rt_se); | 1044 | p = rt_task_of(rt_se); |
| 902 | p->se.exec_start = rq->clock; | 1045 | p->se.exec_start = rq->clock; |
| 1046 | |||
| 1047 | return p; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | static struct task_struct *pick_next_task_rt(struct rq *rq) | ||
| 1051 | { | ||
| 1052 | struct task_struct *p = _pick_next_task_rt(rq); | ||
| 1053 | |||
| 1054 | /* The running task is never eligible for pushing */ | ||
| 1055 | if (p) | ||
| 1056 | dequeue_pushable_task(rq, p); | ||
| 1057 | |||
| 903 | return p; | 1058 | return p; |
| 904 | } | 1059 | } |
| 905 | 1060 | ||
| @@ -907,6 +1062,13 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) | |||
| 907 | { | 1062 | { |
| 908 | update_curr_rt(rq); | 1063 | update_curr_rt(rq); |
| 909 | p->se.exec_start = 0; | 1064 | p->se.exec_start = 0; |
| 1065 | |||
| 1066 | /* | ||
| 1067 | * The previous task needs to be made eligible for pushing | ||
| 1068 | * if it is still active | ||
| 1069 | */ | ||
| 1070 | if (p->se.on_rq && p->rt.nr_cpus_allowed > 1) | ||
| 1071 | enqueue_pushable_task(rq, p); | ||
| 910 | } | 1072 | } |
| 911 | 1073 | ||
| 912 | #ifdef CONFIG_SMP | 1074 | #ifdef CONFIG_SMP |
| @@ -1080,7 +1242,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) | |||
| 1080 | } | 1242 | } |
| 1081 | 1243 | ||
| 1082 | /* If this rq is still suitable use it. */ | 1244 | /* If this rq is still suitable use it. */ |
| 1083 | if (lowest_rq->rt.highest_prio > task->prio) | 1245 | if (lowest_rq->rt.highest_prio.curr > task->prio) |
| 1084 | break; | 1246 | break; |
| 1085 | 1247 | ||
| 1086 | /* try again */ | 1248 | /* try again */ |
| @@ -1091,6 +1253,31 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) | |||
| 1091 | return lowest_rq; | 1253 | return lowest_rq; |
| 1092 | } | 1254 | } |
| 1093 | 1255 | ||
| 1256 | static inline int has_pushable_tasks(struct rq *rq) | ||
| 1257 | { | ||
| 1258 | return !plist_head_empty(&rq->rt.pushable_tasks); | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | static struct task_struct *pick_next_pushable_task(struct rq *rq) | ||
| 1262 | { | ||
| 1263 | struct task_struct *p; | ||
| 1264 | |||
| 1265 | if (!has_pushable_tasks(rq)) | ||
| 1266 | return NULL; | ||
| 1267 | |||
| 1268 | p = plist_first_entry(&rq->rt.pushable_tasks, | ||
| 1269 | struct task_struct, pushable_tasks); | ||
| 1270 | |||
| 1271 | BUG_ON(rq->cpu != task_cpu(p)); | ||
| 1272 | BUG_ON(task_current(rq, p)); | ||
| 1273 | BUG_ON(p->rt.nr_cpus_allowed <= 1); | ||
| 1274 | |||
| 1275 | BUG_ON(!p->se.on_rq); | ||
| 1276 | BUG_ON(!rt_task(p)); | ||
| 1277 | |||
| 1278 | return p; | ||
| 1279 | } | ||
| 1280 | |||
| 1094 | /* | 1281 | /* |
| 1095 | * If the current CPU has more than one RT task, see if the non | 1282 | * If the current CPU has more than one RT task, see if the non |
| 1096 | * running task can migrate over to a CPU that is running a task | 1283 | * running task can migrate over to a CPU that is running a task |
| @@ -1100,13 +1287,11 @@ static int push_rt_task(struct rq *rq) | |||
| 1100 | { | 1287 | { |
| 1101 | struct task_struct *next_task; | 1288 | struct task_struct *next_task; |
| 1102 | struct rq *lowest_rq; | 1289 | struct rq *lowest_rq; |
| 1103 | int ret = 0; | ||
| 1104 | int paranoid = RT_MAX_TRIES; | ||
| 1105 | 1290 | ||
| 1106 | if (!rq->rt.overloaded) | 1291 | if (!rq->rt.overloaded) |
| 1107 | return 0; | 1292 | return 0; |
| 1108 | 1293 | ||
| 1109 | next_task = pick_next_highest_task_rt(rq, -1); | 1294 | next_task = pick_next_pushable_task(rq); |
| 1110 | if (!next_task) | 1295 | if (!next_task) |
| 1111 | return 0; | 1296 | return 0; |
| 1112 | 1297 | ||
| @@ -1135,16 +1320,34 @@ static int push_rt_task(struct rq *rq) | |||
| 1135 | struct task_struct *task; | 1320 | struct task_struct *task; |
| 1136 | /* | 1321 | /* |
| 1137 | * find lock_lowest_rq releases rq->lock | 1322 | * find lock_lowest_rq releases rq->lock |
| 1138 | * so it is possible that next_task has changed. | 1323 | * so it is possible that next_task has migrated. |
| 1139 | * If it has, then try again. | 1324 | * |
| 1325 | * We need to make sure that the task is still on the same | ||
| 1326 | * run-queue and is also still the next task eligible for | ||
| 1327 | * pushing. | ||
| 1140 | */ | 1328 | */ |
| 1141 | task = pick_next_highest_task_rt(rq, -1); | 1329 | task = pick_next_pushable_task(rq); |
| 1142 | if (unlikely(task != next_task) && task && paranoid--) { | 1330 | if (task_cpu(next_task) == rq->cpu && task == next_task) { |
| 1143 | put_task_struct(next_task); | 1331 | /* |
| 1144 | next_task = task; | 1332 | * If we get here, the task hasnt moved at all, but |
| 1145 | goto retry; | 1333 | * it has failed to push. We will not try again, |
| 1334 | * since the other cpus will pull from us when they | ||
| 1335 | * are ready. | ||
| 1336 | */ | ||
| 1337 | dequeue_pushable_task(rq, next_task); | ||
| 1338 | goto out; | ||
| 1146 | } | 1339 | } |
| 1147 | goto out; | 1340 | |
| 1341 | if (!task) | ||
| 1342 | /* No more tasks, just exit */ | ||
| 1343 | goto out; | ||
| 1344 | |||
| 1345 | /* | ||
| 1346 | * Something has shifted, try again. | ||
| 1347 | */ | ||
| 1348 | put_task_struct(next_task); | ||
| 1349 | next_task = task; | ||
| 1350 | goto retry; | ||
| 1148 | } | 1351 | } |
| 1149 | 1352 | ||
| 1150 | deactivate_task(rq, next_task, 0); | 1353 | deactivate_task(rq, next_task, 0); |
| @@ -1155,23 +1358,12 @@ static int push_rt_task(struct rq *rq) | |||
| 1155 | 1358 | ||
| 1156 | double_unlock_balance(rq, lowest_rq); | 1359 | double_unlock_balance(rq, lowest_rq); |
| 1157 | 1360 | ||
| 1158 | ret = 1; | ||
| 1159 | out: | 1361 | out: |
| 1160 | put_task_struct(next_task); | 1362 | put_task_struct(next_task); |
| 1161 | 1363 | ||
| 1162 | return ret; | 1364 | return 1; |
| 1163 | } | 1365 | } |
| 1164 | 1366 | ||
| 1165 | /* | ||
| 1166 | * TODO: Currently we just use the second highest prio task on | ||
| 1167 | * the queue, and stop when it can't migrate (or there's | ||
| 1168 | * no more RT tasks). There may be a case where a lower | ||
| 1169 | * priority RT task has a different affinity than the | ||
| 1170 | * higher RT task. In this case the lower RT task could | ||
| 1171 | * possibly be able to migrate where as the higher priority | ||
| 1172 | * RT task could not. We currently ignore this issue. | ||
| 1173 | * Enhancements are welcome! | ||
| 1174 | */ | ||
| 1175 | static void push_rt_tasks(struct rq *rq) | 1367 | static void push_rt_tasks(struct rq *rq) |
| 1176 | { | 1368 | { |
| 1177 | /* push_rt_task will return true if it moved an RT */ | 1369 | /* push_rt_task will return true if it moved an RT */ |
| @@ -1182,33 +1374,35 @@ static void push_rt_tasks(struct rq *rq) | |||
| 1182 | static int pull_rt_task(struct rq *this_rq) | 1374 | static int pull_rt_task(struct rq *this_rq) |
| 1183 | { | 1375 | { |
| 1184 | int this_cpu = this_rq->cpu, ret = 0, cpu; | 1376 | int this_cpu = this_rq->cpu, ret = 0, cpu; |
| 1185 | struct task_struct *p, *next; | 1377 | struct task_struct *p; |
| 1186 | struct rq *src_rq; | 1378 | struct rq *src_rq; |
| 1187 | 1379 | ||
| 1188 | if (likely(!rt_overloaded(this_rq))) | 1380 | if (likely(!rt_overloaded(this_rq))) |
| 1189 | return 0; | 1381 | return 0; |
| 1190 | 1382 | ||
| 1191 | next = pick_next_task_rt(this_rq); | ||
| 1192 | |||
| 1193 | for_each_cpu(cpu, this_rq->rd->rto_mask) { | 1383 | for_each_cpu(cpu, this_rq->rd->rto_mask) { |
| 1194 | if (this_cpu == cpu) | 1384 | if (this_cpu == cpu) |
| 1195 | continue; | 1385 | continue; |
| 1196 | 1386 | ||
| 1197 | src_rq = cpu_rq(cpu); | 1387 | src_rq = cpu_rq(cpu); |
| 1388 | |||
| 1389 | /* | ||
| 1390 | * Don't bother taking the src_rq->lock if the next highest | ||
| 1391 | * task is known to be lower-priority than our current task. | ||
| 1392 | * This may look racy, but if this value is about to go | ||
| 1393 | * logically higher, the src_rq will push this task away. | ||
| 1394 | * And if its going logically lower, we do not care | ||
| 1395 | */ | ||
| 1396 | if (src_rq->rt.highest_prio.next >= | ||
| 1397 | this_rq->rt.highest_prio.curr) | ||
| 1398 | continue; | ||
| 1399 | |||
| 1198 | /* | 1400 | /* |
| 1199 | * We can potentially drop this_rq's lock in | 1401 | * We can potentially drop this_rq's lock in |
| 1200 | * double_lock_balance, and another CPU could | 1402 | * double_lock_balance, and another CPU could |
| 1201 | * steal our next task - hence we must cause | 1403 | * alter this_rq |
| 1202 | * the caller to recalculate the next task | ||
| 1203 | * in that case: | ||
| 1204 | */ | 1404 | */ |
| 1205 | if (double_lock_balance(this_rq, src_rq)) { | 1405 | double_lock_balance(this_rq, src_rq); |
| 1206 | struct task_struct *old_next = next; | ||
| 1207 | |||
| 1208 | next = pick_next_task_rt(this_rq); | ||
| 1209 | if (next != old_next) | ||
| 1210 | ret = 1; | ||
| 1211 | } | ||
| 1212 | 1406 | ||
| 1213 | /* | 1407 | /* |
| 1214 | * Are there still pullable RT tasks? | 1408 | * Are there still pullable RT tasks? |
| @@ -1222,7 +1416,7 @@ static int pull_rt_task(struct rq *this_rq) | |||
| 1222 | * Do we have an RT task that preempts | 1416 | * Do we have an RT task that preempts |
| 1223 | * the to-be-scheduled task? | 1417 | * the to-be-scheduled task? |
| 1224 | */ | 1418 | */ |
| 1225 | if (p && (!next || (p->prio < next->prio))) { | 1419 | if (p && (p->prio < this_rq->rt.highest_prio.curr)) { |
| 1226 | WARN_ON(p == src_rq->curr); | 1420 | WARN_ON(p == src_rq->curr); |
| 1227 | WARN_ON(!p->se.on_rq); | 1421 | WARN_ON(!p->se.on_rq); |
| 1228 | 1422 | ||
| @@ -1232,12 +1426,9 @@ static int pull_rt_task(struct rq *this_rq) | |||
| 1232 | * This is just that p is wakeing up and hasn't | 1426 | * This is just that p is wakeing up and hasn't |
| 1233 | * had a chance to schedule. We only pull | 1427 | * had a chance to schedule. We only pull |
| 1234 | * p if it is lower in priority than the | 1428 | * p if it is lower in priority than the |
| 1235 | * current task on the run queue or | 1429 | * current task on the run queue |
| 1236 | * this_rq next task is lower in prio than | ||
| 1237 | * the current task on that rq. | ||
| 1238 | */ | 1430 | */ |
| 1239 | if (p->prio < src_rq->curr->prio || | 1431 | if (p->prio < src_rq->curr->prio) |
| 1240 | (next && next->prio < src_rq->curr->prio)) | ||
| 1241 | goto skip; | 1432 | goto skip; |
| 1242 | 1433 | ||
| 1243 | ret = 1; | 1434 | ret = 1; |
| @@ -1250,13 +1441,7 @@ static int pull_rt_task(struct rq *this_rq) | |||
| 1250 | * case there's an even higher prio task | 1441 | * case there's an even higher prio task |
| 1251 | * in another runqueue. (low likelyhood | 1442 | * in another runqueue. (low likelyhood |
| 1252 | * but possible) | 1443 | * but possible) |
| 1253 | * | ||
| 1254 | * Update next so that we won't pick a task | ||
| 1255 | * on another cpu with a priority lower (or equal) | ||
| 1256 | * than the one we just picked. | ||
| 1257 | */ | 1444 | */ |
| 1258 | next = p; | ||
| 1259 | |||
| 1260 | } | 1445 | } |
| 1261 | skip: | 1446 | skip: |
| 1262 | double_unlock_balance(this_rq, src_rq); | 1447 | double_unlock_balance(this_rq, src_rq); |
| @@ -1268,24 +1453,27 @@ static int pull_rt_task(struct rq *this_rq) | |||
| 1268 | static void pre_schedule_rt(struct rq *rq, struct task_struct *prev) | 1453 | static void pre_schedule_rt(struct rq *rq, struct task_struct *prev) |
| 1269 | { | 1454 | { |
| 1270 | /* Try to pull RT tasks here if we lower this rq's prio */ | 1455 | /* Try to pull RT tasks here if we lower this rq's prio */ |
| 1271 | if (unlikely(rt_task(prev)) && rq->rt.highest_prio > prev->prio) | 1456 | if (unlikely(rt_task(prev)) && rq->rt.highest_prio.curr > prev->prio) |
| 1272 | pull_rt_task(rq); | 1457 | pull_rt_task(rq); |
| 1273 | } | 1458 | } |
| 1274 | 1459 | ||
| 1460 | /* | ||
| 1461 | * assumes rq->lock is held | ||
| 1462 | */ | ||
| 1463 | static int needs_post_schedule_rt(struct rq *rq) | ||
| 1464 | { | ||
| 1465 | return has_pushable_tasks(rq); | ||
| 1466 | } | ||
| 1467 | |||
| 1275 | static void post_schedule_rt(struct rq *rq) | 1468 | static void post_schedule_rt(struct rq *rq) |
| 1276 | { | 1469 | { |
| 1277 | /* | 1470 | /* |
| 1278 | * If we have more than one rt_task queued, then | 1471 | * This is only called if needs_post_schedule_rt() indicates that |
| 1279 | * see if we can push the other rt_tasks off to other CPUS. | 1472 | * we need to push tasks away |
| 1280 | * Note we may release the rq lock, and since | ||
| 1281 | * the lock was owned by prev, we need to release it | ||
| 1282 | * first via finish_lock_switch and then reaquire it here. | ||
| 1283 | */ | 1473 | */ |
| 1284 | if (unlikely(rq->rt.overloaded)) { | 1474 | spin_lock_irq(&rq->lock); |
| 1285 | spin_lock_irq(&rq->lock); | 1475 | push_rt_tasks(rq); |
| 1286 | push_rt_tasks(rq); | 1476 | spin_unlock_irq(&rq->lock); |
| 1287 | spin_unlock_irq(&rq->lock); | ||
| 1288 | } | ||
| 1289 | } | 1477 | } |
| 1290 | 1478 | ||
| 1291 | /* | 1479 | /* |
| @@ -1296,7 +1484,8 @@ static void task_wake_up_rt(struct rq *rq, struct task_struct *p) | |||
| 1296 | { | 1484 | { |
| 1297 | if (!task_running(rq, p) && | 1485 | if (!task_running(rq, p) && |
| 1298 | !test_tsk_need_resched(rq->curr) && | 1486 | !test_tsk_need_resched(rq->curr) && |
| 1299 | rq->rt.overloaded) | 1487 | has_pushable_tasks(rq) && |
| 1488 | p->rt.nr_cpus_allowed > 1) | ||
| 1300 | push_rt_tasks(rq); | 1489 | push_rt_tasks(rq); |
| 1301 | } | 1490 | } |
| 1302 | 1491 | ||
| @@ -1332,6 +1521,24 @@ static void set_cpus_allowed_rt(struct task_struct *p, | |||
| 1332 | if (p->se.on_rq && (weight != p->rt.nr_cpus_allowed)) { | 1521 | if (p->se.on_rq && (weight != p->rt.nr_cpus_allowed)) { |
| 1333 | struct rq *rq = task_rq(p); | 1522 | struct rq *rq = task_rq(p); |
| 1334 | 1523 | ||
| 1524 | if (!task_current(rq, p)) { | ||
| 1525 | /* | ||
| 1526 | * Make sure we dequeue this task from the pushable list | ||
| 1527 | * before going further. It will either remain off of | ||
| 1528 | * the list because we are no longer pushable, or it | ||
| 1529 | * will be requeued. | ||
| 1530 | */ | ||
| 1531 | if (p->rt.nr_cpus_allowed > 1) | ||
| 1532 | dequeue_pushable_task(rq, p); | ||
| 1533 | |||
| 1534 | /* | ||
| 1535 | * Requeue if our weight is changing and still > 1 | ||
| 1536 | */ | ||
| 1537 | if (weight > 1) | ||
| 1538 | enqueue_pushable_task(rq, p); | ||
| 1539 | |||
| 1540 | } | ||
| 1541 | |||
| 1335 | if ((p->rt.nr_cpus_allowed <= 1) && (weight > 1)) { | 1542 | if ((p->rt.nr_cpus_allowed <= 1) && (weight > 1)) { |
| 1336 | rq->rt.rt_nr_migratory++; | 1543 | rq->rt.rt_nr_migratory++; |
| 1337 | } else if ((p->rt.nr_cpus_allowed > 1) && (weight <= 1)) { | 1544 | } else if ((p->rt.nr_cpus_allowed > 1) && (weight <= 1)) { |
| @@ -1339,7 +1546,7 @@ static void set_cpus_allowed_rt(struct task_struct *p, | |||
| 1339 | rq->rt.rt_nr_migratory--; | 1546 | rq->rt.rt_nr_migratory--; |
| 1340 | } | 1547 | } |
| 1341 | 1548 | ||
| 1342 | update_rt_migration(rq); | 1549 | update_rt_migration(&rq->rt); |
| 1343 | } | 1550 | } |
| 1344 | 1551 | ||
| 1345 | cpumask_copy(&p->cpus_allowed, new_mask); | 1552 | cpumask_copy(&p->cpus_allowed, new_mask); |
| @@ -1354,7 +1561,7 @@ static void rq_online_rt(struct rq *rq) | |||
| 1354 | 1561 | ||
| 1355 | __enable_runtime(rq); | 1562 | __enable_runtime(rq); |
| 1356 | 1563 | ||
| 1357 | cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio); | 1564 | cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr); |
| 1358 | } | 1565 | } |
| 1359 | 1566 | ||
| 1360 | /* Assumes rq->lock is held */ | 1567 | /* Assumes rq->lock is held */ |
| @@ -1446,7 +1653,7 @@ static void prio_changed_rt(struct rq *rq, struct task_struct *p, | |||
| 1446 | * can release the rq lock and p could migrate. | 1653 | * can release the rq lock and p could migrate. |
| 1447 | * Only reschedule if p is still on the same runqueue. | 1654 | * Only reschedule if p is still on the same runqueue. |
| 1448 | */ | 1655 | */ |
| 1449 | if (p->prio > rq->rt.highest_prio && rq->curr == p) | 1656 | if (p->prio > rq->rt.highest_prio.curr && rq->curr == p) |
| 1450 | resched_task(p); | 1657 | resched_task(p); |
| 1451 | #else | 1658 | #else |
| 1452 | /* For UP simply resched on drop of prio */ | 1659 | /* For UP simply resched on drop of prio */ |
| @@ -1517,6 +1724,9 @@ static void set_curr_task_rt(struct rq *rq) | |||
| 1517 | struct task_struct *p = rq->curr; | 1724 | struct task_struct *p = rq->curr; |
| 1518 | 1725 | ||
| 1519 | p->se.exec_start = rq->clock; | 1726 | p->se.exec_start = rq->clock; |
| 1727 | |||
| 1728 | /* The running task is never eligible for pushing */ | ||
| 1729 | dequeue_pushable_task(rq, p); | ||
| 1520 | } | 1730 | } |
| 1521 | 1731 | ||
| 1522 | static const struct sched_class rt_sched_class = { | 1732 | static const struct sched_class rt_sched_class = { |
| @@ -1539,6 +1749,7 @@ static const struct sched_class rt_sched_class = { | |||
| 1539 | .rq_online = rq_online_rt, | 1749 | .rq_online = rq_online_rt, |
| 1540 | .rq_offline = rq_offline_rt, | 1750 | .rq_offline = rq_offline_rt, |
| 1541 | .pre_schedule = pre_schedule_rt, | 1751 | .pre_schedule = pre_schedule_rt, |
| 1752 | .needs_post_schedule = needs_post_schedule_rt, | ||
| 1542 | .post_schedule = post_schedule_rt, | 1753 | .post_schedule = post_schedule_rt, |
| 1543 | .task_wake_up = task_wake_up_rt, | 1754 | .task_wake_up = task_wake_up_rt, |
| 1544 | .switched_from = switched_from_rt, | 1755 | .switched_from = switched_from_rt, |
