From nobody Mon Feb 9 00:42:24 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 59D2E189BB6; Sun, 14 Dec 2025 07:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765698406; cv=none; b=kB4nSi3k5KUlD79fB2CQ7v2b+AyLxPLR2znZAXPVuPGNrs4PbEMCc0X9v0WWeZ5WR0th8PqM2J+5C1M0/xTl2y7PvAP5NRGpUadS7CwukLq1b4Fx4PUHFeImjSID4VKCXumsWD9T+fpl8FuzCN7RF5blxNL7dwW+N8SLmqB26zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765698406; c=relaxed/simple; bh=VrO7Jf+IQEekIzWg4x8DcCVFG/F+CZFNXxD7/ZMqJjk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=cmajSZBmML5S7wc41z2H0FGx16Cp74l73+xayyj0SvrBcxtbyjXTHRWQyxYnyEHZXpmgBxVtFKHNh2d1/Sxmgw/ppqBKVObPE38ATDDGUGYRXXJa8jD7IlYgMVJ4nosjJetPa62W5/jq5d3v4L6h5SM/40wLu9PQTbvHu6j2E/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NGfBJtsL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=owhO/4iS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NGfBJtsL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="owhO/4iS" Date: Sun, 14 Dec 2025 07:46:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1765698396; 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: in-reply-to:in-reply-to:references:references; bh=4J5vb2Os6a8n0SnjXBtF3b2g8SnSCax3VdYssFZx3Q0=; b=NGfBJtsLOFkWl3kIKJyxXjG13JV23g40SEmcXM8rt3OkQm/cE+PZOZsUx5GP4p5FxuwYnh LL2Y5Q685XjQx0MV3WgrUBFz0sI8G1odEgCchl87yzg+6wgOVAnQcxrTq1lE1G3rXfiWVZ pbDoP4BQoutx1jig53X4o8dGwoa+yMJhDYxteOSnGXBv8ZwrvGGnaOUsCsR+G61SnkfXK3 aMZ45ex5Ix6wMtZsGMP8p1e++f2hiPoyq/207+39rKNhRj4kb0vPeJsV7/RRt/ZVbag2jg 7iMmQyBozW5+5iPtfI9+MridxUoTUzD+k9UGfaJCrN450RBvZVZM48TPV+S2Uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1765698396; 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: in-reply-to:in-reply-to:references:references; bh=4J5vb2Os6a8n0SnjXBtF3b2g8SnSCax3VdYssFZx3Q0=; b=owhO/4iS5bda3OdCoal3BFLMTGbeky0U1xC41XUPAgrFn9xa5zn/hiJtDcv6VbthbmQcMN 304ZoXvpHrYMQ/Ag== From: "tip-bot2 for Ingo Molnar" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: Rename cfs_rq::avg_vruntime to ::sum_w_vruntime, and helper functions Cc: Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20251201064647.1851919-7-mingo@kernel.org> References: <20251201064647.1851919-7-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <176569839540.498.6609559122617417834.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 8e9aa35061d3fc0b5ab4e9b6247a0dfa600212eb Gitweb: https://git.kernel.org/tip/8e9aa35061d3fc0b5ab4e9b6247a0dfa6= 00212eb Author: Ingo Molnar AuthorDate: Tue, 02 Dec 2025 16:09:23 +01:00 Committer: Ingo Molnar CommitterDate: Sun, 14 Dec 2025 08:25:03 +01:00 sched/fair: Rename cfs_rq::avg_vruntime to ::sum_w_vruntime, and helper fun= ctions The ::avg_vruntime field is a misnomer: it says it's an 'average vruntime', but in reality it's the momentary sum of the weighted vruntimes of all queued tasks, which is at least a division away from being an average. This is clear from comments about the math of fair scheduling: * \Sum (v_i - v0) * w_i :=3D cfs_rq->avg_vruntime This confusion is increased by the cfs_avg_vruntime() function, which does perform the division and returns a true average. The sum of all weighted vruntimes should be named thusly, so rename the field to ::sum_w_vruntime. (As arguably ::sum_weighted_vruntime would be a bit of a mouthful.) Understanding the scheduler is hard enough already, without extra layers of obfuscated naming. ;-) Also rename related helper functions: sum_vruntime_add() =3D> sum_w_vruntime_add() sum_vruntime_sub() =3D> sum_w_vruntime_sub() sum_vruntime_update() =3D> sum_w_vruntime_update() With the notable exception of cfs_avg_vruntime(), which was named accurately. Signed-off-by: Ingo Molnar Link: https://patch.msgid.link/20251201064647.1851919-7-mingo@kernel.org --- kernel/sched/fair.c | 26 +++++++++++++------------- kernel/sched/sched.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8e21a95..050ed08 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -607,7 +607,7 @@ static inline s64 entity_key(struct cfs_rq *cfs_rq, str= uct sched_entity *se) * Which we track using: * * v0 :=3D cfs_rq->zero_vruntime - * \Sum (v_i - v0) * w_i :=3D cfs_rq->avg_vruntime + * \Sum (v_i - v0) * w_i :=3D cfs_rq->sum_w_vruntime * \Sum w_i :=3D cfs_rq->sum_weight * * Since zero_vruntime closely tracks the per-task service, these @@ -619,32 +619,32 @@ static inline s64 entity_key(struct cfs_rq *cfs_rq, s= truct sched_entity *se) * As measured, the max (key * weight) value was ~44 bits for a kernel bui= ld. */ static void -avg_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se) +sum_w_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se) { unsigned long weight =3D scale_load_down(se->load.weight); s64 key =3D entity_key(cfs_rq, se); =20 - cfs_rq->avg_vruntime +=3D key * weight; + cfs_rq->sum_w_vruntime +=3D key * weight; cfs_rq->sum_weight +=3D weight; } =20 static void -avg_vruntime_sub(struct cfs_rq *cfs_rq, struct sched_entity *se) +sum_w_vruntime_sub(struct cfs_rq *cfs_rq, struct sched_entity *se) { unsigned long weight =3D scale_load_down(se->load.weight); s64 key =3D entity_key(cfs_rq, se); =20 - cfs_rq->avg_vruntime -=3D key * weight; + cfs_rq->sum_w_vruntime -=3D key * weight; cfs_rq->sum_weight -=3D weight; } =20 static inline -void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) +void sum_w_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) { /* - * v' =3D v + d =3D=3D> avg_vruntime' =3D avg_runtime - d*sum_weight + * v' =3D v + d =3D=3D> sum_w_vruntime' =3D sum_runtime - d*sum_weight */ - cfs_rq->avg_vruntime -=3D cfs_rq->sum_weight * delta; + cfs_rq->sum_w_vruntime -=3D cfs_rq->sum_weight * delta; } =20 /* @@ -654,7 +654,7 @@ void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 del= ta) u64 avg_vruntime(struct cfs_rq *cfs_rq) { struct sched_entity *curr =3D cfs_rq->curr; - s64 avg =3D cfs_rq->avg_vruntime; + s64 avg =3D cfs_rq->sum_w_vruntime; long load =3D cfs_rq->sum_weight; =20 if (curr && curr->on_rq) { @@ -722,7 +722,7 @@ static void update_entity_lag(struct cfs_rq *cfs_rq, st= ruct sched_entity *se) static int vruntime_eligible(struct cfs_rq *cfs_rq, u64 vruntime) { struct sched_entity *curr =3D cfs_rq->curr; - s64 avg =3D cfs_rq->avg_vruntime; + s64 avg =3D cfs_rq->sum_w_vruntime; long load =3D cfs_rq->sum_weight; =20 if (curr && curr->on_rq) { @@ -745,7 +745,7 @@ static void update_zero_vruntime(struct cfs_rq *cfs_rq) u64 vruntime =3D avg_vruntime(cfs_rq); s64 delta =3D (s64)(vruntime - cfs_rq->zero_vruntime); =20 - avg_vruntime_update(cfs_rq, delta); + sum_w_vruntime_update(cfs_rq, delta); =20 cfs_rq->zero_vruntime =3D vruntime; } @@ -819,7 +819,7 @@ RB_DECLARE_CALLBACKS(static, min_vruntime_cb, struct sc= hed_entity, */ static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *s= e) { - avg_vruntime_add(cfs_rq, se); + sum_w_vruntime_add(cfs_rq, se); update_zero_vruntime(cfs_rq); se->min_vruntime =3D se->vruntime; se->min_slice =3D se->slice; @@ -831,7 +831,7 @@ static void __dequeue_entity(struct cfs_rq *cfs_rq, str= uct sched_entity *se) { rb_erase_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline, &min_vruntime_cb); - avg_vruntime_sub(cfs_rq, se); + sum_w_vruntime_sub(cfs_rq, se); update_zero_vruntime(cfs_rq); } =20 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e3e9974..bdb1e74 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -678,7 +678,7 @@ struct cfs_rq { unsigned int h_nr_runnable; /* SCHED_{NORMAL,BATCH,IDLE} */ unsigned int h_nr_idle; /* SCHED_IDLE */ =20 - s64 avg_vruntime; + s64 sum_w_vruntime; u64 sum_weight; =20 u64 zero_vruntime;