ANDROID: sched: Migrate whole chain in proxy_migrate_task()

Instead of migrating one task each time through find_proxy_task(),
we can walk up the blocked_donor ptrs and migrate the entire
current chain in one go.

This was broken out of earlier patches and held back while the
series was being stabilized, but I wanted to re-introduce it.

Cc: Joel Fernandes <joelaf@google.com>
Cc: Qais Yousef <qyousef@layalina.io>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Zimuzo Ezeozue <zezeozue@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Will Deacon <will@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Metin Kaya <Metin.Kaya@arm.com>
Cc: Xuewen Yan <xuewen.yan94@gmail.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: kernel-team@android.com
Change-Id: Ia920b2d4161b47b10b5d0774fb1e3283e92bbf0f
Signed-off-by: John Stultz <jstultz@google.com>
Bug: 306081722
---
v12:
* Earlier this was re-using blocked_node, but I hit
  a race with activating blocked entities, and to
  avoid it introduced a new migration_node listhead
This commit is contained in:
John Stultz
2023-12-06 20:05:15 -08:00
parent 465f85fe91
commit 95c9e8505a
3 changed files with 23 additions and 8 deletions
+3
View File
@@ -1213,6 +1213,9 @@ struct task_struct {
enum blocked_on_state blocked_on_state;
struct mutex *blocked_on; /* lock we're blocked on */
struct task_struct *blocked_donor; /* task that is boosting this task */
#ifdef CONFIG_SCHED_PROXY_EXEC
struct list_head migration_node;
#endif
raw_spinlock_t blocked_lock;
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
+3
View File
@@ -2366,6 +2366,9 @@ __latent_entropy struct task_struct *copy_process(
p->blocked_on_state = BO_RUNNABLE;
p->blocked_on = NULL; /* not blocked yet */
p->blocked_donor = NULL; /* nobody is boosting p yet */
#ifdef CONFIG_SCHED_PROXY_EXEC
INIT_LIST_HEAD(&p->migration_node);
#endif
#ifdef CONFIG_BCACHE
p->sequential_io = 0;
p->sequential_io_avg = 0;
+17 -8
View File
@@ -6851,6 +6851,7 @@ static bool proxy_deactivate(struct rq *rq, struct task_struct *donor)
static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf,
struct task_struct *p, int target_cpu)
{
LIST_HEAD(migrate_list);
struct rq *target_rq;
lockdep_assert_rq_held(rq);
@@ -6880,19 +6881,27 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf,
rq_set_donor(rq, rq->curr);
set_next_task(rq, rq->curr);
WARN_ON(p == rq->curr);
deactivate_task(rq, p, 0);
proxy_set_task_cpu(p, target_cpu);
for (; p; p = p->blocked_donor) {
WARN_ON(p == rq->curr);
deactivate_task(rq, p, 0);
proxy_set_task_cpu(p, target_cpu);
/*
* We can abuse blocked_node to migrate the thing,
* because @p was still on the rq.
*/
list_add(&p->migration_node, &migrate_list);
}
zap_balance_callbacks(rq);
rq_unpin_lock(rq, rf);
raw_spin_rq_unlock(rq);
raw_spin_rq_lock(target_rq);
while (!list_empty(&migrate_list)) {
p = list_first_entry(&migrate_list, struct task_struct, migration_node);
list_del_init(&p->migration_node);
activate_task(target_rq, p, 0);
wakeup_preempt(target_rq, p, 0);
activate_task(target_rq, p, 0);
wakeup_preempt(target_rq, p, 0);
}
raw_spin_rq_unlock(target_rq);
raw_spin_rq_lock(rq);
rq_repin_lock(rq, rf);