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 2B8FA375F8B for ; Mon, 4 May 2026 10:02:24 +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=1777888947; cv=none; b=YusLldpTwnNM2iUy25JJ2uiaYhMEzHTWaraYr7CZ3JrE7YOfuYhLAk/zW9iml1OkW0cUumeMGANGBLl69wB4pwhK5fDy0ytgO8l8vM0RXEIMDueEecVUMS2S0EAa5U4IkS8mQ9QV5vVILFpS8cY6NRnh9hcY52WjbbC3rNs5eho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777888947; c=relaxed/simple; bh=R6PAP3bN86kHrPIeVb/5aph+wZ8YGgBF8s+/uNsM1p4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u0Omrs0ch9h/UgLXehemMFb5HrKu7bFipzRe6MnuLRCIEIfeZvTYrDIMEurhOcp/mRitxGql0ZSMSTfyJryXUlAsa9a5zNNIYXEO+KeRDGg6Y6axRdMF1PmQi/dtkEZZX7FeaTsglvrvOvvfO1RqGy9LvAoirZBaBWgyo0s31oc= 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=dPF2JQ1u; 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="dPF2JQ1u" 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=bOKufWJi2TLGWgAlowJUroRYc4AWzlAu/PjI6GN/c8E=; b=dPF2JQ1usZCURyxKL5+pe2DcC7 DtoMrjY8JEstdanDiTiOxR6znwpdbLOYDsZQslyNS40YmL0ItnaUAbyd8Sdgmlte9dsHAKYRJ1Y+1 nusACvShSqOIs0gayjPgB7dskX97V0WEb4fm5nwFypb57Aqfv4tpPCLu5pJEeA2K+ATF8fuacYuTl 5bfGs8cDYJIbufOFV48/tp3Gzn1Ib5God0DZXFpah4h0U9QgcXdsWmjo6VmX0065RGQF+lDfQtzjv cMgB4BKgMMazTqC2BQwVwyEVMmD73fOkACQL/tN2b//ppc9sDqGWfOGGwIUlhqrnHWAyj83U8e3kc Rg1/pYSg==; 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 1wJq81-00000000hFb-31OC; Mon, 04 May 2026 10:02:17 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 417F3300969; Mon, 04 May 2026 12:02:17 +0200 (CEST) Date: Mon, 4 May 2026 12:02:17 +0200 From: Peter Zijlstra To: Vincent Guittot Cc: mingo@redhat.com, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, qyousef@layalina.io Subject: Re: [PATCH v2] sched/fair: Fix wakeup_preempt_fair for not waking up task Message-ID: <20260504100217.GS3126523@noisy.programming.kicks-ass.net> References: <20260503104503.1732682-1-vincent.guittot@linaro.org> 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: <20260503104503.1732682-1-vincent.guittot@linaro.org> On Sun, May 03, 2026 at 12:45:03PM +0200, Vincent Guittot wrote: > The assumption that p is always enqueued and not delayed, is only true for > wakeup. If p was moved while delayed, pick_next_entity will dequeue it > and the cfs might become empty. Test if there are still queued tasks > before trying again to determine if p could be the next one to be picked. > > There are at least 2 cases: > > When cfs becomes idle, it tries to pull tasks but if those pulled tasks are > delayed, they will be dequeued when attached to cfs. > attach_tasks() -> attach_task() -> wakeup_preempt(rq, p, 0); > > A misfit task running on cfs A triggers a load balance to be pulled on a > better cpu, the load balance on cfs B starts an active load balance to > pulled the running misfit task. If there is a delayed dequeue task on cfs A > , it can be pulled instead of the previously running misfit task. > attach_one_task() -> attach_task() -> wakeup_preempt(rq, p, 0); > > Fixes: ac8e69e69363 ("sched/fair: Fix wakeup_preempt_fair() vs delayed dequeue") > Signed-off-by: Vincent Guittot > --- > > Change since v1: > - Use cfs_rq->nr_queued instead of WF_TTWU flag to cover all cases instead > of just wakeup. > > I'm preparing patches to cover those useless newly idle and active load > balance task migration. > > kernel/sched/fair.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 728965851842..24087b0f25f6 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -9145,9 +9145,10 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f > > /* > * Because p is enqueued, nse being null can only mean that we > - * dequeued a delayed task. > + * dequeued a delayed task. If there are still entities queued in > + * cfs, check if the next one will be p. > */ > - if (!nse) > + if (!nse && cfs_rq->nr_queued) > goto pick; > > if (sched_feat(RUN_TO_PARITY)) Right, that works. Thanks!