From nobody Tue Apr 7 14:18:23 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 80961341062 for ; Fri, 13 Mar 2026 02:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773369031; cv=none; b=V5fBKxiX/f/CDBHYF0JfXto3hDOhwZ7B6Zsc5WcwylOXzoWtTWWE7tpNsuMYNhoxMXC9hW71fkGW1UAsUxPvx2SEMwr7NdhXh9nddtTPA06tfNCrf3ZaNFbCTdezCcupQnSF5ze3lkQ62Ds7h6K6q70O9Wim7GAE5mjBy9ik1nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773369031; c=relaxed/simple; bh=rr82F+ga7KGmv1C4psrqbuFWVIMbe1J8ngMGoRHGr9g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KryYuSPVcQJDTTePzZ3rIXOa5U8XtBEBH4IB8i6FuHezQ+gmqNvxS9PlU3E0t7XBNKARncyWq6nqh3hgE3GcDX22W33pR3Z1rMDalc4k5mcifSxuV5a4clwU6RkWFt/mgWx+joO6tUD5SURo9RprAncW4RvLJcqiGV49WNsyjdo= 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=V2m+b1X5; arc=none smtp.client-ip=209.85.214.202 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="V2m+b1X5" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2aebfa0af7dso81978935ad.1 for ; Thu, 12 Mar 2026 19:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773369028; x=1773973828; 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=lOjdGJLqTDMVlzYMP2N+jeP6HMxGKcLcSbSRz38UF7s=; b=V2m+b1X5z0eQiagKzJ9m7/FNFKkW28GysDYC4+0rXBRyq8BKJHkYe+hxHq8lraEWFN AZIqPk8s+gXvWrMYu7cisZRXifF7bIUJ652TUQFBkH93q1BEQ5a1Fa4OYXh9+2IvzWpu zla4jf87En8+CPZTrYBlYb0sMCRh7meQm8oKJVa62aVoxMjsOPpinc/PmGIQywbDagSn web1TtVgE3DZOgZiTdDOKLVpaYuEoEZrt8pnxQnbF4/UexKfuW4N729dbP/xWWHVCGVj 57rKmzavSf7F0zwEsqtJFImGDDJF1nHeBYrRxZdunDcAh0CAsw+G2J5PnFh9KuTojz8+ 1Hug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773369028; x=1773973828; 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=lOjdGJLqTDMVlzYMP2N+jeP6HMxGKcLcSbSRz38UF7s=; b=I6XG84pmpIv1MoEQLTi2XomQ12LGZY8GFEKvhNpZ8MpxrWnoi4b9TXLZC5MOAB084u QMWW/Zb2mhRDEE3n5JVaEIWyKbn5c2RnCWzeJvT7AM+X/qJEyzz3Mf/4OBK7l+Wn7k02 Qa1DhIyKuq/bcsFn2eWl7YQ2uCgAZ+rbHjdqaAb3GJdsO2Iv+i3N2F6mzMKhNetiNu0m pboAr93uec+Hjhd88Xf8zRBHtxeJxYQoZkQ0uK2dCD6F65iTY+tDBbhG0wbGbVJzEh6r 3NGKHmo7yy11qWgk1ecklrmXTujrJ6QwwUyR2Ll5fa8qVeClIt3jjsKoKrL/yE2pjFny +5Qw== X-Gm-Message-State: AOJu0Yzy2nTINibHOcUQJ8A084Bok5BHw+ymxKkN4lS7+T2YA2YmBptM lGVfcCjmve1VyhDaYqEIfrpJYc25dlV4GePKBIYU/nKWTwq+q59/0uIHnmha0TPbSoYPVcrmRvm vvAaI+j5li6dCGFGksu3w33T9KpLuWo7V50y3/D3mLhLyIv6GBmkOXxjg0L1XBQ54BBgQRvSuqB CV+btywRRF8swcRIQE0OPIWMSolc2m0j6SzZ6sJ37YvqToerPG X-Received: from plhu10.prod.google.com ([2002:a17:903:124a:b0:2ae:6338:73ca]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:182:b0:2a7:c188:bd1f with SMTP id d9443c01a7336-2aecac549e8mr15834725ad.40.1773369027312; Thu, 12 Mar 2026 19:30:27 -0700 (PDT) Date: Fri, 13 Mar 2026 02:30:02 +0000 In-Reply-To: <20260313023022.2902479-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: <20260313023022.2902479-1-jstultz@google.com> X-Mailer: git-send-email 2.53.0.880.g73c4285caa-goog Message-ID: <20260313023022.2902479-2-jstultz@google.com> Subject: [PATCH v25 1/9] sched: Make class_schedulers avoid pushing current, and get rid of proxy_tag_curr() From: John Stultz To: LKML Cc: John Stultz , K Prateek Nayak , Peter Zijlstra , Joel Fernandes , Qais Yousef , Ingo Molnar , 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 , 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" 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 !=3D 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. Fixes: be39617e38e0 ("sched: Fix proxy/current (push,pull)ability") Reported-by: K Prateek Nayak Closes: https://lore.kernel.org/lkml/e735cae0-2cc9-4bae-b761-fcb082ed3e94@a= md.com/ Suggested-by: Peter Zijlstra Signed-off-by: John Stultz --- 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 --- kernel/sched/core.c | 24 ------------------------ kernel/sched/deadline.c | 16 ++++++++++++++-- kernel/sched/rt.c | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b7f77c165a6e0..d86d648a75a4b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6702,23 +6702,6 @@ find_proxy_task(struct rq *rq, struct task_struct *d= onor, struct rq_flags *rf) } #endif /* SCHED_PROXY_EXEC */ =20 -static inline void proxy_tag_curr(struct rq *rq, struct task_struct *owner) -{ - if (!sched_proxy_exec()) - return; - /* - * pick_next_task() calls set_next_task() on the chosen task - * at some point, which ensures it is not push/pullable. - * However, the chosen/donor task *and* the mutex owner form an - * atomic pair wrt push/pull. - * - * Make sure owner we run is not pushable. Unfortunately we can - * only deal with that by means of a dequeue/enqueue cycle. :-/ - */ - dequeue_task(rq, owner, DEQUEUE_NOCLOCK | DEQUEUE_SAVE); - enqueue_task(rq, owner, ENQUEUE_NOCLOCK | ENQUEUE_RESTORE); -} - /* * __schedule() is the main scheduler function. * @@ -6871,9 +6854,6 @@ static void __sched notrace __schedule(int sched_mode) */ RCU_INIT_POINTER(rq->curr, next); =20 - if (!task_current_donor(rq, next)) - proxy_tag_curr(rq, next); - /* * The membarrier system call requires each architecture * to have a full memory barrier after updating @@ -6907,10 +6887,6 @@ static void __sched notrace __schedule(int sched_mod= e) /* Also unlocks the rq: */ rq =3D context_switch(rq, prev, next, &rf); } else { - /* In case next was already curr but just got blocked_donor */ - if (!task_current_donor(rq, next)) - proxy_tag_curr(rq, next); - rq_unpin_lock(rq, &rf); __balance_callbacks(rq, NULL); raw_spin_rq_unlock_irq(rq); diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index d08b004293234..4e746f4de6529 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2801,12 +2801,24 @@ static int find_later_rq(struct task_struct *task) =20 static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) { - struct task_struct *p; + struct task_struct *p =3D NULL; + struct rb_node *next_node; =20 if (!has_pushable_dl_tasks(rq)) return NULL; =20 - p =3D __node_2_pdl(rb_first_cached(&rq->dl.pushable_dl_tasks_root)); + next_node =3D rb_first_cached(&rq->dl.pushable_dl_tasks_root); + while (next_node) { + p =3D __node_2_pdl(next_node); + /* make sure task isn't on_cpu (possible with proxy-exec) */ + if (!task_on_cpu(rq, p)) + break; + + next_node =3D rb_next(next_node); + } + + if (!p) + return NULL; =20 WARN_ON_ONCE(rq->cpu !=3D task_cpu(p)); WARN_ON_ONCE(task_current(rq, p)); diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index f69e1f16d9238..61569b622d1a3 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1853,13 +1853,22 @@ static int find_lowest_rq(struct task_struct *task) =20 static struct task_struct *pick_next_pushable_task(struct rq *rq) { - struct task_struct *p; + struct plist_head *head =3D &rq->rt.pushable_tasks; + struct task_struct *i, *p =3D NULL; =20 if (!has_pushable_tasks(rq)) return NULL; =20 - p =3D plist_first_entry(&rq->rt.pushable_tasks, - struct task_struct, pushable_tasks); + plist_for_each_entry(i, head, pushable_tasks) { + /* make sure task isn't on_cpu (possible with proxy-exec) */ + if (!task_on_cpu(rq, i)) { + p =3D i; + break; + } + } + + if (!p) + return NULL; =20 BUG_ON(rq->cpu !=3D task_cpu(p)); BUG_ON(task_current(rq, p)); --=20 2.53.0.880.g73c4285caa-goog