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 A08F4368971 for ; Thu, 23 Apr 2026 09:41:22 +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=1776937285; cv=none; b=LnIDhJDqDahNUYg1MAzGPlXNQliGm1RGT1Vci84IINgK0QMcS7CbbdY+R89w/txVzKXg+bYx+VHe2IYRY4lVJq6XVqbjwxKtL/95/Gf8dIW9ohNpzgNfM9vLvMYvS8d1nq5eIQRvHy6mPaZxbaPRBHQXW5jAYX2XluKAoP1tZ/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776937285; c=relaxed/simple; bh=ohJdf3Xt7+6lm1Jj988ZyqMafAV/Avipw3zW23RnVvk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fJ+Ua27WxPnk7f/SWt1xHfZDByereG5PS8WvyWxkQ3rjDntPPoG2rXv6u8sLEJKI6ROTp9+nDCGsnR1gVGfl2IU5f/INMlCRiN//LzS0Txu9MBbY5ztw2ZpShpknCmmmMWnlqH81pKC3dJoBgzl2fcfO07QrorvLVALLzlPX6XI= 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=F7KQf2ll; 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="F7KQf2ll" 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=vA9wn86BU8IJasIjzDvLlZwVx6CT63+ntc40Dlfl2KY=; b=F7KQf2llffYTBvIDUgUSLJPGi4 GiRj4lHSBzXB6YveEEB8yp91klarRmMUCzVHjAiUHCWJ5/sZ+xiXbScr0pzJ0KIpErguC3fwRlhGL DBF9/CY1fyKXHFuFekfM1/ibHMF3fNNdfUI0C0gpj6IVZL6/1bIRwEDmbsYYD83o5+nUtIeOCwo2s Vr1PlR814PPtYMa0KnWp2hgSJ614vWroLI8Jb7sKzon0xkMOFUpma1NkB8+M/w8qjWvzdP82U/Aw8 LR8FJYMx5vp2SpHGR3XQvhxSO0RInSrU24P/9g9OX/kcgH0uyGU+YS3snoNsM5vHb3v/EG+ivoKBS jTZXlgWw==; 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 1wFqYX-0000000DCWC-0ngx; Thu, 23 Apr 2026 09:41:09 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id C9F9E300BD2; Thu, 23 Apr 2026 11:41:07 +0200 (CEST) Date: Thu, 23 Apr 2026 11:41:07 +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, shubhang@os.amperecomputing.com Subject: Re: [PATCH v2] sched: fair: Prevent negative lag increase during delayed dequeue Message-ID: <20260423094107.GT3102624@noisy.programming.kicks-ass.net> References: <20260331162352.551501-1-vincent.guittot@linaro.org> <20260402131359.GZ2872@noisy.programming.kicks-ass.net> <20260422133914.GP3102624@noisy.programming.kicks-ass.net> <20260422142410.GS3102624@noisy.programming.kicks-ass.net> <20260422142828.GJ3102924@noisy.programming.kicks-ass.net> <20260422222043.GB3179637@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: On Thu, Apr 23, 2026 at 09:28:22AM +0200, Vincent Guittot wrote: > On Thu, 23 Apr 2026 at 00:20, Peter Zijlstra wrote: > > > > On Wed, Apr 22, 2026 at 04:28:28PM +0200, Peter Zijlstra wrote: > > > > > Let me ponder this a bit... > > > > Like this? Or am I still making a mess of things? AFAICT this is the > > exact same as your initial version. > > > > --- > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 69361c63353a..24e8c78b110a 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -847,13 +847,13 @@ static s64 entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se, u64 avrunt > > * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO > > * is set. > > * > > - * Return true if the lag has been adjusted. > > + * Return true if the lag of a delayed entity has been adjusted. > > */ > > static __always_inline > > bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) > > { > > s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); > > - bool ret; > > + bool ret = false; > > > > WARN_ON_ONCE(!se->on_rq); > > > > @@ -862,8 +862,9 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) > > vlag = max(vlag, se->vlag); > > if (sched_feat(DELAY_ZERO)) > > vlag = min(vlag, 0); > > + > > + ret = (vlag != se->vlag); > > No this is not enough. Argh yes. I think I finally see. How about this then? --- diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 69361c63353a..f4d1457d1837 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -847,13 +847,19 @@ static s64 entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se, u64 avrunt * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO * is set. * - * Return true if the lag has been adjusted. + * Return true if the vlag has been modified. Specifically: + * + * se->vlag != avg_vruntime() - se->vruntime + * + * This can be due to clamping in entity_lag() or clamping due to + * sched_delayed. Either way, when vlag is modified and the entity is + * retained, the tree needs to be adjusted. */ static __always_inline bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) { - s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); - bool ret; + u64 avruntime = avg_vruntime(cfs_rq); + s64 vlag = entity_lag(cfs_rq, se, avruntime); WARN_ON_ONCE(!se->on_rq); @@ -863,10 +869,9 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) if (sched_feat(DELAY_ZERO)) vlag = min(vlag, 0); } - ret = (vlag == se->vlag); se->vlag = vlag; - return ret; + return avruntime - vlag != se->vruntime; } /*