From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 10A5138D008 for ; Thu, 2 Apr 2026 13:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775135647; cv=none; b=oLM8LRBb6o10fISfjtqYlneo5RX3MPbz4SsW3CFhl3Ifd/PPkv7wz3N1Q9+ujcTur0ZP8H3xLaeJh229n7z7pPUfWSvAxyDW1VfsBK9boF5+PbGc+BqEjm3PIFtiuWjrNFQdPg0Ycy5mMrsNzIFRvZjp5egCq4tjA8GY/0MVekg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775135647; c=relaxed/simple; bh=uW9/kbg3spi2OZ/2nCSEz/ZXUcQjBPoNQpF4TBXRyKw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zy/Dt6MY292lIo0NmxWGRIOPEBEpVXSaUFBddzRouZITGbnmc5Bxr5P6VRV7EXVb0a1fYNbcx66ZXQ/lF0BJqgaTinzdwVYVtecicyCVU6Yp0oGzzFMDezqGzjQ+ph9TSvaObvMbhhaosAnB00VxXtzzOQWgOzLDugxscqON76U= 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=eIfR4vZC; arc=none smtp.client-ip=90.155.92.199 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="eIfR4vZC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=E7p9Ygo4qlPcstmHRiw1IdorQPp2MSTsJUNf6KwM3Uo=; b=eIfR4vZCWWJImFxd+woul12k4Z ubi34ww4lXcDl0xqW41rtbWIsrR9yTWOQfzaXqvp1nWiURJNZRtqUmNFsS7p2GnGpcSijZQ2oBTMv TrLeVdssB3cPinN9toXN5qECRUcnbpgk3/42IyCI0znsJvmB/RyDS6AVatDYLgr4v5nBucTzsmE/F dVWAs/C3ii45UO8AZAfQJ34t9JT3CMNSrn6FQAWRhamJzpsYhF5+/q5NTmt9+5o/LqulLXSN0LYpl OVgTLZ+iEWRwylFCmu2x7BnkJukR7bZ1HgZlIY6gR2ScGQ+CN97b20k+vWPqe6qkGto62k4lU5EiP /bRtjp8w==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1w8Hs0-00000002VvM-3Hrx; Thu, 02 Apr 2026 13:14:00 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 614FB3005E5; Thu, 02 Apr 2026 15:13:59 +0200 (CEST) Date: Thu, 2 Apr 2026 15:13:59 +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: <20260402131359.GZ2872@noisy.programming.kicks-ass.net> References: <20260331162352.551501-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: <20260331162352.551501-1-vincent.guittot@linaro.org> On Tue, Mar 31, 2026 at 06:23:52PM +0200, Vincent Guittot wrote: > +/* > + * Delayed dequeue aims to reduce the negative lag of a dequeued task. > + * While updating the lag of an entity, check that negative lag didn't increase > + * during the delayed dequeue period which would be unfair. > + * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO is > + * set. > + * > + * Return true if the lag has been adjusted. > + */ > +static bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) > { > + s64 vlag; > + > WARN_ON_ONCE(!se->on_rq); > > - se->vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); > + vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); > + > + if (se->sched_delayed) > + /* previous vlag < 0 otherwise se would not be delayed */ > + se->vlag = clamp(vlag, se->vlag, sched_feat(DELAY_ZERO) ? 0 : S64_MAX); > + else > + se->vlag = vlag; > + > + return (vlag != se->vlag); > } Would you mind terribly if I write this like so? --- --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -841,29 +841,32 @@ static s64 entity_lag(struct cfs_rq *cfs } /* - * Delayed dequeue aims to reduce the negative lag of a dequeued task. - * While updating the lag of an entity, check that negative lag didn't increase + * Delayed dequeue aims to reduce the negative lag of a dequeued task. While + * updating the lag of an entity, check that negative lag didn't increase * during the delayed dequeue period which would be unfair. - * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO is - * set. + * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO + * is set. * * Return true if the lag has been adjusted. */ -static bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) +static __always_inline +bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se) { - s64 vlag; + s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); + bool ret; WARN_ON_ONCE(!se->on_rq); - vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq)); - - if (se->sched_delayed) + if (se->sched_delayed) { /* previous vlag < 0 otherwise se would not be delayed */ - se->vlag = clamp(vlag, se->vlag, sched_feat(DELAY_ZERO) ? 0 : S64_MAX); - else - se->vlag = vlag; + vlag = max(vlag, se->vlag); + if (sched_feat(DELAY_ZERO)) + vlag = min(vlag, 0); + } + ret = (vlag == se->vlag); + se->vlag = vlag; - return (vlag != se->vlag); + return ret; } /*