From nobody Mon Oct 6 13:37:48 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A4242D322A for ; Tue, 22 Jul 2025 07:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753167995; cv=none; b=IiyPSO+i5sKMHJxiDmahRoG3BlDO/pQ2GWWzpmWP/LzYmLnI6rrdwLLl+knO1NaN+8ikNr/0JVpzFuFXVp2UZ6z4NuNMnblRzr0udKoo00yTb8jH9SweiecLsP8nEOyaNDN3IH1uMGCawATtisjhsklgPa3/N6OSyDZ18wm7YYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753167995; c=relaxed/simple; bh=wvTAnQeRXy+r30kCTxX8NcmOQRho8sKwbikQzT9qPFQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Fb2o98p+LQpBSAyAoM6tsGGfY+7/WWNi6B5PPTKPX46y69qMZyC3xceiRff6CSfJyF/gejb1WqI3WNTomuwtOcKrRegfw/4F3A6mNMdR4vRnnIwO8T5iQ1FwydgAOSTFWloOglnTtgfRIXwkZLhPvwSpRGTwY5q/rpt9OAPDghc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=e2z55kgo; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="e2z55kgo" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31332dc2b59so4329632a91.0 for ; Tue, 22 Jul 2025 00:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753167991; x=1753772791; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ygMaExwRMEeYx9gdRiHqQ6erryKlsSCGj1l8MO3EJcQ=; b=e2z55kgo7yffhLJQqtgX85zuCRUxWrFRFFPst+gwkhwb6N3nxT/j7gB+F1L3mAyamV xHkvyB/IhY845COMAjaUofiV20rV9ppCaYFfeeujxS/KyzfR+6fTAQzCWnRmWZ4hHZbT rF92xpuazri36F+JkqliTmfMB1b3C42j/3T8KnDGHmmvF1h75TXiE7jhMClzSIrM0zML oqp1H4Ll/yqlNAYg0jZlnc1RuMpGFamGnuPN6d4Osd+q8HEks3umOcciUGN5R8UZuBIl Ms1mN1SatIW2ZtWfHcjhMhlGb8t5SPMxyhKxTsUZYJoS633/IIpP9lqVz1iaEe2qQ4R2 9QRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753167991; x=1753772791; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ygMaExwRMEeYx9gdRiHqQ6erryKlsSCGj1l8MO3EJcQ=; b=n4jNfqkgOLePa23ITALJ6x9d+XAkuXPRl6LVVZD8qDzLYk81C31B/AsgzeuaC0j7Z5 2hgJZHDnNCIZSN0loFjjihddDE4eFanVtMn0UBD6xhIniuGRVAbU0c52rMBzUKfmqbmS XxYsZywfKG9VfaJg+5n/euD85LwLdn5nmefI8K1+Tddl0/KcJmPVI4qPv4C5F8T1i+f0 tIddZJCBRd8O47yJu0ObiqJAPVczYFDybfaW1SyW7KleNQdmdo2tySe/T1pD7o09bijU +9ZnImaTNuw+dPKsiyXfW2DrKaZJawpI4JexhOYBWZa3GLK4czYDV/cHizS40GztPQHM YXow== X-Gm-Message-State: AOJu0YzEetDYBn31r8fPXkGiMmq1Nac0fy0XbgYTXhmqp5tFoKSt1+kQ 47pATu/0VRMYtUOD/eABte+9pc72U/x0QwWNt/DCPSPwMh0th3PBVHXQWXROcavC/a72lpTUJ7W jUXaa3FpKb3UYJAvvhDMX0PWYObJdREaO8u/gJgosLvMAl4T/5iEgw1fAU8vM5ya+vfY0CBSijV O2/CM2g/MOZNzjfXOdOdCNxp6k3yztpzlwuRMigqBTPgFf9jJY X-Google-Smtp-Source: AGHT+IEs+x/V4ASQZ2RMVn1S+cWwfSY9FFD0LcIcwgP9AeEIgsPB+YebA+7EY/Puf37am12JdW0r8MkLCK3A X-Received: from pjk3.prod.google.com ([2002:a17:90b:5583:b0:31c:2fe4:33be]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a81:b0:312:e618:bd53 with SMTP id 98e67ed59e1d1-31c9e76c013mr32415571a91.26.1753167991326; Tue, 22 Jul 2025 00:06:31 -0700 (PDT) Date: Tue, 22 Jul 2025 07:05:52 +0000 In-Reply-To: <20250722070600.3267819-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250722070600.3267819-1-jstultz@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250722070600.3267819-7-jstultz@google.com> Subject: [RFC][PATCH v20 6/6] sched: Migrate whole chain in proxy_migrate_task() From: John Stultz To: LKML Cc: John Stultz , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Mel Gorman , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , Daniel Lezcano , Suleiman Souhlal , kuyo chang , hupu , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: John Stultz --- 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 v18: * Add init_task initialization of migration_node as suggested by Suleiman Cc: Joel Fernandes Cc: Qais Yousef Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Valentin Schneider Cc: Steven Rostedt Cc: Ben Segall Cc: Zimuzo Ezeozue Cc: Mel Gorman Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Cc: Metin Kaya Cc: Xuewen Yan Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: Daniel Lezcano Cc: Suleiman Souhlal Cc: kuyo chang Cc: hupu Cc: kernel-team@android.com --- include/linux/sched.h | 1 + init/init_task.c | 1 + kernel/fork.c | 1 + kernel/sched/core.c | 25 +++++++++++++++++-------- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 675e2f89ec0f8..e9242dfa5f271 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1240,6 +1240,7 @@ 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 */ + struct list_head migration_node; raw_spinlock_t blocked_lock; =20 #ifdef CONFIG_DETECT_HUNG_TASK_BLOCKER diff --git a/init/init_task.c b/init/init_task.c index 627bbd8953e88..65e0f90285966 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -176,6 +176,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = =3D { #endif .blocked_on_state =3D BO_RUNNABLE, .blocked_donor =3D NULL, + .migration_node =3D LIST_HEAD_INIT(init_task.migration_node), #ifdef CONFIG_RT_MUTEXES .pi_waiters =3D RB_ROOT_CACHED, .pi_top_task =3D NULL, diff --git a/kernel/fork.c b/kernel/fork.c index 61a2ac850faf0..892940ea52958 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2127,6 +2127,7 @@ __latent_entropy struct task_struct *copy_process( p->blocked_on_state =3D BO_RUNNABLE; p->blocked_on =3D NULL; /* not blocked yet */ p->blocked_donor =3D NULL; /* nobody is boosting p yet */ + INIT_LIST_HEAD(&p->migration_node); =20 #ifdef CONFIG_BCACHE p->sequential_io =3D 0; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2c3a4b9518927..c1d813a9cde96 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6741,6 +6741,7 @@ static void proxy_migrate_task(struct rq *rq, struct = rq_flags *rf, struct task_struct *p, int target_cpu) { struct rq *target_rq =3D cpu_rq(target_cpu); + LIST_HEAD(migrate_list); =20 lockdep_assert_rq_held(rq); =20 @@ -6768,19 +6769,27 @@ static void proxy_migrate_task(struct rq *rq, struc= t rq_flags *rf, rq_set_donor(rq, rq->idle); set_next_task(rq, rq->idle); =20 - WARN_ON(p =3D=3D rq->curr); - - deactivate_task(rq, p, 0); - proxy_set_task_cpu(p, target_cpu); - + for (; p; p =3D p->blocked_donor) { + WARN_ON(p =3D=3D 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 =3D list_first_entry(&migrate_list, struct task_struct, migration_node= ); + list_del_init(&p->migration_node); =20 - 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); --=20 2.50.0.727.gbf7dc18ff4-goog