History

sched: Make class_schedulers avoid pushing current, and get rid of proxy_tag_curr()

With proxy-execution, the scheduler selects the donor, but for blocked donors, we end up running the lock owner. This caused some complexity, because the class schedulers make sure to remove the task they pick from their pushable task lists, which prevents the donor from being migrated, but there wasn't then anything to prevent rq->curr from being migrated if rq->curr != rq->donor. This was sort of hacked around by calling proxy_tag_curr() on the rq->curr task if we were running something other then the donor. proxy_tag_curr() did a dequeue/enqueue pair on the rq->curr task, allowing the class schedulers to remove it from their pushable list. The dequeue/enqueue pair was wasteful, and additonally K Prateek highlighted that we didn't properly undo things when we stopped proxying, leaving the lock owner off the pushable list. After some alternative approaches were considered, Peter suggested just having the RT/DL classes just avoid migrating when task_on_cpu(). So rework pick_next_pushable_dl_task() and the rt pick_next_pushable_task() functions so that they skip over the first pushable task if it is on_cpu. Then just drop all of the proxy_tag_curr() logic.

John Stultz committed 7 months ago

Commit e0ca8991 parent 98539143 files · +28 −29Browse files

Unified · Split

3 files
  1. kernel/sched/core.c +0 −24
  2. kernel/sched/deadline.c +16 −2
  3. kernel/sched/rt.c +12 −3
kernel/sched/core.c+0−24
@@ -6702,23 +6702,6 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) · 6701 unmodified lines
67026702 }
67036703 #endif /* SCHED_PROXY_EXEC */
67046704
6705−static inline void proxy_tag_curr(struct rq *rq, struct task_struct *owner)
6706−{
6707− if (!sched_proxy_exec())
6708− return;
6709− /*
6710− * pick_next_task() calls set_next_task() on the chosen task
6711− * at some point, which ensures it is not push/pullable.
6712− * However, the chosen/donor task *and* the mutex owner form an
6713− * atomic pair wrt push/pull.
6714− *
6715− * Make sure owner we run is not pushable. Unfortunately we can
6716− * only deal with that by means of a dequeue/enqueue cycle. :-/
6717− */
6718− dequeue_task(rq, owner, DEQUEUE_NOCLOCK | DEQUEUE_SAVE);
6719− enqueue_task(rq, owner, ENQUEUE_NOCLOCK | ENQUEUE_RESTORE);
6720−}
6721−
67226705 /*
67236706 * __schedule() is the main scheduler function.
67246707 *
@@ -6871,9 +6854,6 @@ keep_resched: · 146 unmodified lines
68716854 */
68726855 RCU_INIT_POINTER(rq->curr, next);
68736856
6874− if (!task_current_donor(rq, next))
6875− proxy_tag_curr(rq, next);
6876−
68776857 /*
68786858 * The membarrier system call requires each architecture
68796859 * to have a full memory barrier after updating
@@ -6907,10 +6887,6 @@ keep_resched: · 27 unmodified lines
69076887 /* Also unlocks the rq: */
69086888 rq = context_switch(rq, prev, next, &rf);
69096889 } else {
6910− /* In case next was already curr but just got blocked_donor */
6911− if (!task_current_donor(rq, next))
6912− proxy_tag_curr(rq, next);
6913−
69146890 rq_unpin_lock(rq, &rf);
69156891 __balance_callbacks(rq, NULL);
69166892 raw_spin_rq_unlock_irq(rq);
kernel/sched/deadline.c+16−2
@@ -2805,12 +2805,26 @@ static int find_later_rq(struct task_struct *task) · 2804 unmodified lines
28052805
28062806 static struct task_struct *pick_next_pushable_dl_task(struct rq *rq)
28072807 {
2808− struct task_struct *p;
2808+ struct task_struct *i, *p = NULL;
2809+ struct rb_node *next_node;
28092810
28102811 if (!has_pushable_dl_tasks(rq))
28112812 return NULL;
28122813
2813− p = __node_2_pdl(rb_first_cached(&rq->dl.pushable_dl_tasks_root));
2814+ next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
2815+ while (next_node) {
2816+ i = __node_2_pdl(next_node);
2817+ /* make sure task isn't on_cpu (possible with proxy-exec) */
2818+ if (!task_on_cpu(rq, i)) {
2819+ p = i;
2820+ break;
2821+ }
2822+
2823+ next_node = rb_next(next_node);
2824+ }
2825+
2826+ if (!p)
2827+ return NULL;
28142828
28152829 WARN_ON_ONCE(rq->cpu != task_cpu(p));
28162830 WARN_ON_ONCE(task_current(rq, p));
kernel/sched/rt.c+12−3
@@ -1858,13 +1858,22 @@ static int find_lowest_rq(struct task_struct *task) · 1857 unmodified lines
18581858
18591859 static struct task_struct *pick_next_pushable_task(struct rq *rq)
18601860 {
1861− struct task_struct *p;
1861+ struct plist_head *head = &rq->rt.pushable_tasks;
1862+ struct task_struct *i, *p = NULL;
18621863
18631864 if (!has_pushable_tasks(rq))
18641865 return NULL;
18651866
1866− p = plist_first_entry(&rq->rt.pushable_tasks,
1867− struct task_struct, pushable_tasks);
1867+ plist_for_each_entry(i, head, pushable_tasks) {
1868+ /* make sure task isn't on_cpu (possible with proxy-exec) */
1869+ if (!task_on_cpu(rq, i)) {
1870+ p = i;
1871+ break;
1872+ }
1873+ }
1874+
1875+ if (!p)
1876+ return NULL;
18681877
18691878 BUG_ON(rq->cpu != task_cpu(p));
18701879 BUG_ON(task_current(rq, p));