From nobody Thu Apr 2 15:37:59 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 B0BC92DCC1F for ; Fri, 27 Mar 2026 18:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634546; cv=none; b=qWNLIYQYiieV41n9WsMMNn17yhGcPHo7hzMRGaVlOvsgdf/PVsG25yV9u1hntTfVIaPtmrxZluCtBDBj7wsATy87KEzVwnqaKzChxuxWJp7z1qz6tG0bo1ezXvIDlg0ZDfPybVpxWDNYNRdYDDvtO3k7TUT7bvUibQ7gvDFTdsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774634546; c=relaxed/simple; bh=mT4yq+cknGmkvCYDp3p+jL8cV7qpV6Otq2MLyntKl3w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=D/M/1lG1znk4exlHwiHczWnD7iHVOvp7bVhGuOkj+54xEoslp8Fd/vcHyQs5nCtCT18Yb9RnyNnQf1XjRg4BeeDSCHXTMdiQLMQZDGyRPRlVUrC7AWmjJs3MMScnrfcV4RgCCDQIOB4i8Ae5u7gY0rkvURZY/4o0rI+/W2oGEmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=B/F6rsyQ; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B/F6rsyQ" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-48558d6ef83so23173495e9.3 for ; Fri, 27 Mar 2026 11:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774634543; x=1775239343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xrJa1G0dXkAcWg2NZSafb9PpamKlp28zqphexuXwhak=; b=B/F6rsyQtxsf25iEIcG0iMrby4uwfUhiqNzJLrRrPEE3Y12303J5R0om1N1ldwQ2n0 4Eap01j+UNjVpavS8LSus56VpXKpP81nlUTmrvt88CL22IEUFRTFj4WUOZDEsnEBgVp1 vPlBU5CxVgCO/0IYZVRdVhK2b6xMVd1sj3N0FlanrfLXFjv2Lywt7qnpGkoJkK/0IZ5F /muQSxPoUi7WDLC75L/1aj342yoy4MPAvPCRNqkxodGU7rV5dBwdXRXulehEoi+Pn6q5 6tb9d+43qC5hzVsLbcoZuXwVqj46FROOK1UB2KSN+hs2Cj4U4KCENGwM0TlEgMcUsazB dYiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774634543; x=1775239343; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xrJa1G0dXkAcWg2NZSafb9PpamKlp28zqphexuXwhak=; b=DqtgENphtTObMlH/7JEfCDtDlApsauh7+/ehtW/hwcoprBastmyRGM2oJeV0bdEcpp RsTJHFSjyekLEq5yFd889dzoPrNjNfU7uGk61tukDT1i5vSL2uXc4JoNmalWHVMa0e/r wZOLNZJdNL4RZwbuJtjrOcc0xamKAqsa0nAOSoT5pnIRDZ+hgu7zaSxWvtncqvxl0lTh 6BvR0rVTGyDTh5e/0v5TgDb+NmtqYtZVnjZbgMZrbk666YjsViJwugcuJ/4teHpAgZQ6 X1n2TGu3PXxu9Eaqtz8YmubmtFQeIglnpA0aE8Aes6wTTpjzArxy591Rdnmbe5beXQMP 88Vg== X-Forwarded-Encrypted: i=1; AJvYcCVAHOYKVOJCY9vQi+DwgtTHstR9lep34vAQY5O7clnuJ5RW3x2AiDdM5J8WB6G+giwil5h/BERQdp36Bz8=@vger.kernel.org X-Gm-Message-State: AOJu0YzuZ716O9NrLZZZyqQQSfg7N9fikltXpjT+O1W0HBW2G/BQjiyT Km5TEhTIHH9Qun1HpniLEJ3t6lqsZN0O8Sn0eww9PYHioM6j0WnoXF/0DFMuiZzlsNo= X-Gm-Gg: ATEYQzy9BPxotlC7N+xavyxMYbDYRYKHh6E1LA67w0Is8FbMpJTj76cN9XXtVgRkHKx VCqZDHkQQEsyqFHEHGeBnNYBkC9i9SCH3+ZCu+9rjNF2ALqRImcwuzWXDvKC/HhNbfo8WsTsacQ wpssNhUhrYSK7+Y8FBWzMEqwzeccnaLtKds7wEgeW66KHxAsxid8hbDSbT8+jXjRWwDIfX4co5P wpv1qD/C/fR6z6FQuQ9A4Trzjaz2ol0/7uzpoCOp0g1pUdLGMl6ghTwslNTT/iazIgAvv+gpknO MVmxfiiHKVO3H9vX0s5TXzQs23+jas0MawAS+9WikR2qrf3px8dCgcWxsidQl66Pu7LzzfBdERk x8q5ViBLnWJVB7r9NoQUzMu7O9+PI8oamM3scAefdixh0PuQmgJcksCwrvUv6PPcsi79D0K+8vH fJcNLCnoQMhj9kFfi12tDbTVUmqjuM2mOo X-Received: by 2002:a05:600c:8589:b0:485:39d1:b500 with SMTP id 5b1f17b1804b1-48727eef71bmr48611335e9.16.1774634542844; Fri, 27 Mar 2026 11:02:22 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:85e4:ca27:7d44:213c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722d23679sm207798595e9.9.2026.03.27.11.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 11:02:22 -0700 (PDT) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, 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 Cc: Vincent Guittot Subject: [PATCH] sched: fair: Prevent negative lag increase during delayed dequeue Date: Fri, 27 Mar 2026 19:02:19 +0100 Message-ID: <20260327180219.2879905-1-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Delayed dequeue feature aims to reduce the negative lag of a dequeued task while sleeping but it can happens that newly enqueued tasks will move backward the avg vruntime and increase its negative lag. When the delayed dequeued task wakes up, it has more neg lag compared to being dequeued immediately or to other delayed or not tasks that have been dequeued just before theses new enqueues. Ensure that the negative lag of a delayed dequeued task doesn't increase during its delayed dequeued phase while waiting for its neg lag to diseappear. Similarly, we remove any positive lag that the delayed dequeued task could have gain during thsi period. Short slice tasks are particularly impacted in overloaded system. Test on snapdragon rb5: hackbench -T -p -l 16000000 -g 2 1> /dev/null & cyclictest -t 1 -i 2777 -D 333 --policy=3Dfair --mlock -h 20000 -q The scheduling latency of cyclictest is: tip/sched/core tip/sched/core +this patch cyclictest slice (ms) (default)2.8 8 8 hackbench slice (ms) (default)2.8 20 20 Total Samples | 115632 119733 119806 Average (us) | 364 64(-82%) 61(- 5%) Median (P50) (us) | 60 56(- 7%) 56( 0%) 90th Percentile (us) | 1166 62(-95%) 62( 0%) 99th Percentile (us) | 4192 73(-98%) 72(- 1%) 99.9th Percentile (us) | 8528 2707(-68%) 1300(-52%) Maximum (us) | 17735 14273(-20%) 13525(- 5%) Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 226509231e67..efa9dfa8c583 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5595,6 +5595,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_en= tity *se, int flags) if (sched_feat(DELAY_DEQUEUE) && delay && !entity_eligible(cfs_rq, se)) { update_load_avg(cfs_rq, se, 0); + update_entity_lag(cfs_rq, se); set_delayed(se); return false; } @@ -7089,12 +7090,16 @@ requeue_delayed_entity(struct sched_entity *se) WARN_ON_ONCE(!se->on_rq); =20 if (sched_feat(DELAY_ZERO)) { + s64 vlag, prev_vlag =3D se->vlag; update_entity_lag(cfs_rq, se); - if (se->vlag > 0) { + /* prev_vlag < 0 otherwise se would not be delayed */ + vlag =3D clamp(se->vlag, prev_vlag, 0); + + if (vlag !=3D se->vlag) { cfs_rq->nr_queued--; if (se !=3D cfs_rq->curr) __dequeue_entity(cfs_rq, se); - se->vlag =3D 0; + se->vlag =3D vlag; place_entity(cfs_rq, se, 0); if (se !=3D cfs_rq->curr) __enqueue_entity(cfs_rq, se); --=20 2.43.0