From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 C944D47798B for ; Thu, 22 Jan 2026 07:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769068359; cv=none; b=u40nlChb49OYlfYVSq3B0HUxw8//NcdFkCJ+zrGTMb8O/TZ/1eMOBdDNJR6ZHgDk/sgalJ+Xhj2flh0wYq/bSP9gSxTjyTIp5LgZmJgWqlKqokfofvVs+ORBAq0gN01HTvGyhzZBbQi+istnKgdJK8L0EPrL3pGEgQM/Y+svaOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769068359; c=relaxed/simple; bh=75Ad+QclACgiSHdEF5bviF9HhMJyCF4ecnke9YPqVQQ=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=GtCFoZTL7IQbr+DX8spkzXY8q3FdmrqfBq4GOraRY7QoQ+nhW26Z9rq2Emjm9AZ4Vd5ZLvvk12unoq55y28Kr0LehgmJ3EY0uLr8+KjwQ/Nkq3kBX3GMOmPCz5dlIvIO1+WwKb32lWzeBeCDZGW1oBSQn3mxIaJx5KxsiyBTK3M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Zrk+yMDp; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Zrk+yMDp" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=pj8txwsBhq0e62cGzGAqBVRjVAaypqnAe1xxnbdm46w=; b=Zrk+yMDpcc1Ke0nBC1hO6lIcahaeqLVv4LGJNCk7+0dPaiOwHCuYT7Kq14N23bvw5W24YQMpy YSaKOH9fpfAHPg8FFo8PsGuwh0+OjHu6uswavRPPYzhLIRCa7S+HS1cHzKmowCqrFeqQr2uxI6C LPMC5PXzkud/aOzN4GPcbjM= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4dxY981HvKzLlXw; Thu, 22 Jan 2026 15:49:00 +0800 (CST) Received: from dggpemf100009.china.huawei.com (unknown [7.185.36.128]) by mail.maildlp.com (Postfix) with ESMTPS id DC0D940565; Thu, 22 Jan 2026 15:52:23 +0800 (CST) Received: from [10.67.109.25] (10.67.109.25) by dggpemf100009.china.huawei.com (7.185.36.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 22 Jan 2026 15:52:23 +0800 Message-ID: <25b32c05-7155-4290-8e16-64548fd27ce6@huawei.com> Date: Thu, 22 Jan 2026 15:52:22 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/eevdf: Update se->vprot in reweight_entity() To: Vincent Guittot CC: K Prateek Nayak , , , , , , , , , , , References: <20260120123113.3518950-1-wangtao554@huawei.com> <8e7aadf8-b7a0-4500-ad2d-507665007694@amd.com> <15d8374f-b1a5-4946-829d-8e9c6ef39272@huawei.com> From: "wangtao (EQ)" In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf100009.china.huawei.com (7.185.36.128) Hi Vincent, Thanks for the feedback. Vincent Guittot 写道: > On Wed, 21 Jan 2026 at 10:33, wangtao (EQ) wrote: >> >> Hello Prateek, >> >> K Prateek Nayak 写道: >>> Hello Wang, >>> >>> On 1/20/2026 6:01 PM, Wang Tao wrote: >>>> In the EEVDF framework with Run-to-Parity protection, `se->vprot` is an >>>> independent variable defining the virtual protection timestamp. >>>> >>>> When `reweight_entity()` is called (e.g., via nice/renice), it performs >>>> the following actions to preserve Lag consistency: >>>> 1. Scales `se->vlag` based on the new weight. >>>> 2. Calls `place_entity()`, which recalculates `se->vruntime` based on >>>> the new weight and scaled lag. >>>> >>>> However, the current implementation fails to update `se->vprot`, leading >>>> to mismatches between the task's actual runtime and its expected duration. >>> >>> I don't think that is correct. "vprot" allows for "min_slice" worth of >>> runtime from the beginning of the pick however, if we do a >>> set_protect_slice() after reweight, we'll essentially grant another >>> "min_slice" worth of time from the current "se->vruntime" (or until >>> deadline if it is sooner) which is not correct. >>> >>>> >>>> This patch fixes the issue by calling `set_protect_slice()` at the end of >>>> `reweight_entity()`. This ensures that a new, valid protection slice is >>>> committed based on the updated `vruntime` and the new weight, restoring >>>> Run-to-Parity consistency immediately after a weight change. >>>> >>>> Fixes: 63304558ba5d ("sched/eevdf: Curb wakeup-preemption") >>>> Suggested-by: Zhang Qiao >>>> Signed-off-by: Wang Tao >>>> --- >>>> kernel/sched/fair.c | 2 ++ >>>> 1 file changed, 2 insertions(+) >>>> >>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>>> index e71302282671..bdd8c4e688ae 100644 >>>> --- a/kernel/sched/fair.c >>>> +++ b/kernel/sched/fair.c >>>> @@ -3792,6 +3792,8 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, >>> >>> At the beginning of reweight_entity, we should first check if >>> protect_slice() for curr is true or not: >>> >>> bool protect_slice = curr && protect_slice(se); >>> >>>> if (!curr) >>>> __enqueue_entity(cfs_rq, se); >>>> cfs_rq->nr_queued++; >>>> + if (curr) >>>> + set_protect_slice(cfs_rq, se); >>> >>> >>> If protect_slice() was true to begin with, we should do: >>> >>> if (protect_slice) >>> se->vprot = min_vruntime(se->vprot, se->deadline); >>> >>> This ensures that if our deadline has moved back, we only protect until >>> the new deadline and the scheduler can re-evaluate after that. If there >>> was an entity with a shorter slice at the beginning of the pick, the >>> "vprot" should still reflect the old value that was calculated using >>> "se->vruntime" at the time of the pick. >>> >> >> Regarding your suggestion, I have a concern. >> When a task's weight changes, I believe its "vprot" should also change >> accordingly. If we keep the original "vprot" unchanged, the task's >> actual runtime will not reach the expected "vprot". >> >> For example, if the weight decreases, the "vruntime" increases faster. >> If "vprot" is not updated, the task will hit the limit much earlier than >> expected in physical time. > > Ok but it's the safest way to stay in the min runnable slice limit so > you need to demonstrate that its lag will remain below. > Run to parity already goes close to this limit by not looking at a new > running entity at every tick so we need to be sure to not break this > rule. > I fully agree that staying within the Lag limit is paramount and we must ensure the scheduler invariant is preserved. >> >> Therefore, I made this modification to ensure the protection slice is >> valid. I would like to hear your thoughts on this. >> >> if (protect_slice) { >> se->vprot -= se->vruntime; >> se->vprot = div_s64(se->vprot * se->load.weight, weight); >> se->vprot += se->vruntime; >> >> se->vprot = min_vruntime(se->vprot, se->deadline); > > Why not use update_protect_slice() like when a new task with a shorter > slice is added ? I looked into reusing update_protect_slice(), but there is a mathematical hurdle specific to reweight_entity(): the coordinate space distortion. In reweight_entity(), se->vruntime is scaled to match the new weight, but se->vprot remains in the old weight's coordinate system. If we simply call update_protect_slice() or compare them directly, we are comparing values with different virtual time speeds, which leads to incorrect truncation. > >> } >> >> Best Regards, >> Tao > To address your safety concerns while fixing the coordinate mismatch, I have implemented some changes: Capture: Calculate the remaining physical slice before se->vruntime is updated (while both are still in the old coordinate system). Scale: Project this physical slice to the new weight's virtual domain. Clamp (Safety): Apply the new slice to the new vruntime, but strictly clamp it with min_vruntime(..., se->deadline). This approach preserves the physical time promise (fixing the bug) but includes the min_vruntime guardrail you suggested to ensure we never exceed the deadline/lag limit. Does this align with what you had in mind? Best, Tao diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bdd8c4e688ae..52dc7deea7a1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3755,10 +3755,17 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, unsigned long weight) { bool curr = cfs_rq->curr == se; + bool protect_slice = curr && protect_slice(se); + u64 vslice_rem = 0; if (se->on_rq) { + + if (protect_slice) { + vslice_rem = se->vprot - se->vruntime; + } + update_entity_lag(cfs_rq, se); se->deadline -= se->vruntime; se->rel_deadline = 1; @@ -3792,8 +3799,13 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, if (!curr) __enqueue_entity(cfs_rq, se); cfs_rq->nr_queued++; - if (curr) - set_protect_slice(cfs_rq, se); + + if (protect_slice && vslice_rem > 0) { + vslice_rem = div_s64(vslice_rem * se->load.weight, weight); + se->vprot == se->vruntime + vslice_rem; + + se->vprot = min_vruntime(se->vprot, se->deadline); + } } }