From nobody Tue Dec 16 11:06:54 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94CE5E7544A for ; Tue, 3 Oct 2023 10:42:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231148AbjJCKmq (ORCPT ); Tue, 3 Oct 2023 06:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjJCKmo (ORCPT ); Tue, 3 Oct 2023 06:42:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C870D3; Tue, 3 Oct 2023 03:42:39 -0700 (PDT) Date: Tue, 03 Oct 2023 10:42:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696329758; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WxE0dPjXVRoqzOKIikXrexpeB8LT3+xgtw9e0GJ98CA=; b=PI1VAnl5vXp/p41cdckqyCLKsAZHnORC58uYnD/1x4DUn5TRUYk0BwSTPGajCrS6KDKzHq mjr3pegcPsyhfiKvHCIAvs784DsGofxTwXimlxj6vpDkGCc8UEFNJTeea8wTqA8rsw6hGV tT/Oa1LxqGQdIu9EInYqnGQngdppKcmq4r8Rik8x8F1lO/DKEBR/7uBxMFfHRo80Rnm88y t3Tld6roh+bzaz2gali/D3hv0Pr3H0JZcN3tbEXOzyOBMrtohx4Isj7jW+diwfwHzRDO4j 65HYUUSfFTwxhNBLGMfjIHcnJiP8aFHtl1ahxcfBvSgWWDnTheJ28jWbh8CVyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696329758; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WxE0dPjXVRoqzOKIikXrexpeB8LT3+xgtw9e0GJ98CA=; b=DbCMkLaBbmLuSH6+/uwvUGZk0OE1J0UpZ+F8cNEN8OSloOHYbAK2CE/mGWh8PHUCfZRo5Z YzzQ2SpGkc71wjBA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] sched/eevdf: Fix avg_vruntime() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169632975777.3135.1926466016577986434.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/urgent branch of tip: Commit-ID: 650cad561cce04b62a8c8e0446b685ef171bc3bb Gitweb: https://git.kernel.org/tip/650cad561cce04b62a8c8e0446b685ef1= 71bc3bb Author: Peter Zijlstra AuthorDate: Tue, 26 Sep 2023 14:29:50 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 03 Oct 2023 12:32:29 +02:00 sched/eevdf: Fix avg_vruntime() The expectation is that placing a task at avg_vruntime() makes it eligible. Turns out there is a corner case where this is not the case. Specifically, avg_vruntime() relies on the fact that integer division is a flooring function (eg. it discards the remainder). By this property the value returned is slightly left of the true average. However! when the average is a negative (relative to min_vruntime) the effect is flipped and it becomes a ceil, with the result that the returned value is just right of the average and thus not eligible. Fixes: af4cf40470c2 ("sched/fair: Add cfs_rq::avg_vruntime") Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/fair.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7d73652..ef7490c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -664,6 +664,10 @@ void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 de= lta) cfs_rq->avg_vruntime -=3D cfs_rq->avg_load * delta; } =20 +/* + * Specifically: avg_runtime() + 0 must result in entity_eligible() :=3D t= rue + * For this to be so, the result of this function must have a left bias. + */ u64 avg_vruntime(struct cfs_rq *cfs_rq) { struct sched_entity *curr =3D cfs_rq->curr; @@ -677,8 +681,12 @@ u64 avg_vruntime(struct cfs_rq *cfs_rq) load +=3D weight; } =20 - if (load) + if (load) { + /* sign flips effective floor / ceil */ + if (avg < 0) + avg -=3D (load - 1); avg =3D div_s64(avg, load); + } =20 return cfs_rq->min_vruntime + avg; }