From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 719682FE591 for ; Thu, 2 Apr 2026 15:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775142547; cv=none; b=N6NaFTg5yETu9tpoQ50Y2SDaSXMYWF0w/oDFfxrU5Amxjow35bZUFrysGZLjSpwy08DBZpxZhX3RhIkvyK1GEMmmgFSjW2wrJHDWiVCpyU8S+5UTz3pft5yYlPHbkPsYcUVOl1L+e9TEmqRRPmjSSf3MIOqzjKyTFEY/FunOHtg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775142547; c=relaxed/simple; bh=bjhI/pjUQZSVNVLL6y2pP7+CQ0QvRnuL4IDWM5VCUXU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VOQi8nvJL57rQV7nbkhsQJsF4rUg8E3+Tfx/zhHDnGRfjpxPA0DvWgEtlqCAa0N7zolSg8jD1d+BYDJzBrfM9xnlhq91GtLzwIJu2yvNrW+ArzzpXLjKkc6qW3oewpYfuP2Okd5hikEoZmEZIENR6TDR+pIDh2Wi8YE/Z24lAnc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=t8uKDpJw; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="t8uKDpJw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=uI66TeFRfA69OdeapQ5FTEAWqz9oceZe1CLDZmE4IlA=; b=t8uKDpJwm3SEXwRKQjvwWtBOZs p1Lu84zxxqMBNFHzNBr1EQwRv6uGpE6xhyMuT5DHk4fWxBjoaA8EPiFI8B9OLRW9ipGkJMbUaMpR9 1nqx65KGSdtOHPptKv2XelHxQE47Zplq/PSmXhqt/qyLxnTLjVX19Akuz803/WfZSemfg87ELXPHC Q8qP4aXfAQRJQyy9TH1ZCddmebQP+lDynebMVZWVKwbRQeuxhE8HqdNtP9SQyqgq4fASZmdWR7p59 wh6ZfjlsOrSzMdewG+w+u/JO10dwr0HrAhaiyCtxElZmsvK0m7F+YhwVjwz0hxldFdwxKecRrXZeT KKrKS8Sw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1w8JfB-0000000CTw6-3xBt; Thu, 02 Apr 2026 15:08:54 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6572E3032EA; Thu, 02 Apr 2026 17:08:48 +0200 (CEST) Date: Thu, 2 Apr 2026 17:08:48 +0200 From: Peter Zijlstra To: John Stultz Cc: LKML , 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 , K Prateek Nayak , Thomas Gleixner , Daniel Lezcano , Suleiman Souhlal , kuyo chang , hupu , kernel-team@android.com Subject: Re: [PATCH v26 10/10] sched: Handle blocked-waiter migration (and return migration) Message-ID: <20260402150848.GP3739106@noisy.programming.kicks-ass.net> References: <20260324191337.1841376-1-jstultz@google.com> <20260324191337.1841376-11-jstultz@google.com> <20260402144302.GU3738010@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260402144302.GU3738010@noisy.programming.kicks-ass.net> On Thu, Apr 02, 2026 at 04:43:02PM +0200, Peter Zijlstra wrote: > > So with that other issue cured, I'm back to staring at this thing.... > > On Tue, Mar 24, 2026 at 07:13:25PM +0000, John Stultz wrote: > > +static bool proxy_deactivate(struct rq *rq, struct task_struct *donor) > > { > > unsigned long state = READ_ONCE(donor->__state); > > > > @@ -6598,17 +6610,140 @@ static bool __proxy_deactivate(struct rq *rq, struct task_struct *donor) > > return try_to_block_task(rq, donor, &state, true); > > } > > > > > @@ -6741,7 +6900,17 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > > /* Handle actions we need to do outside of the guard() scope */ > > switch (action) { > > case DEACTIVATE_DONOR: > > - return proxy_deactivate(rq, donor); > > + if (proxy_deactivate(rq, donor)) > > + return NULL; > > + /* If deactivate fails, force return */ > > + p = donor; > > + fallthrough; > > I was going to reply to Prateek's email and was going over the whole > ttwu path because of that, and that got me looking at this. > > What happens here if donor is migrated; the current CPU no longer valid > and we fail proxy_deactivate() because of a pending signal? Something like so? --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2160,7 +2160,7 @@ void deactivate_task(struct rq *rq, stru dequeue_task(rq, p, flags); } -static void block_task(struct rq *rq, struct task_struct *p, int flags) +static void _block_task(struct rq *rq, struct task_struct *p, int flags) { if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags)) __block_task(rq, p); @@ -6503,6 +6503,31 @@ pick_next_task(struct rq *rq, struct tas #define SM_PREEMPT 1 #define SM_RTLOCK_WAIT 2 +static bool block_task(struct rq *rq, struct task_struct *p, unsigned long task_state) +{ + int flags = DEQUEUE_NOCLOCK; + + p->sched_contributes_to_load = + (task_state & TASK_UNINTERRUPTIBLE) && + !(task_state & TASK_NOLOAD) && + !(task_state & TASK_FROZEN); + + if (unlikely(is_special_task_state(task_state))) + flags |= DEQUEUE_SPECIAL; + + /* + * __schedule() ttwu() + * prev_state = prev->state; if (p->on_rq && ...) + * if (prev_state) goto out; + * p->on_rq = 0; smp_acquire__after_ctrl_dep(); + * p->state = TASK_WAKING + * + * Where __schedule() and ttwu() have matching control dependencies. + * + * After this, schedule() must not care about p->state any more. + */ + _block_task(rq, p, flags); +} /* * Helper function for __schedule() * @@ -6515,7 +6540,6 @@ static bool try_to_block_task(struct rq unsigned long *task_state_p, bool should_block) { unsigned long task_state = *task_state_p; - int flags = DEQUEUE_NOCLOCK; if (signal_pending_state(task_state, p)) { WRITE_ONCE(p->__state, TASK_RUNNING); @@ -6535,26 +6559,7 @@ static bool try_to_block_task(struct rq if (!should_block) return false; - p->sched_contributes_to_load = - (task_state & TASK_UNINTERRUPTIBLE) && - !(task_state & TASK_NOLOAD) && - !(task_state & TASK_FROZEN); - - if (unlikely(is_special_task_state(task_state))) - flags |= DEQUEUE_SPECIAL; - - /* - * __schedule() ttwu() - * prev_state = prev->state; if (p->on_rq && ...) - * if (prev_state) goto out; - * p->on_rq = 0; smp_acquire__after_ctrl_dep(); - * p->state = TASK_WAKING - * - * Where __schedule() and ttwu() have matching control dependencies. - * - * After this, schedule() must not care about p->state any more. - */ - block_task(rq, p, flags); + block_task(rq, p, task_state); return true; } @@ -6599,7 +6604,8 @@ static bool proxy_deactivate(struct rq * * need to be changed from next *before* we deactivate. */ proxy_resched_idle(rq); - return try_to_block_task(rq, donor, &state, true); + block_task(rq, donor, state); + return true; } static inline void proxy_release_rq_lock(struct rq *rq, struct rq_flags *rf)