Re: [PATCH v4 1/2] sched/fair: set rq->idle_stamp at the end of the sched_balance_newidle
From: Shijie Huang
Date: Sun Nov 30 2025 - 21:48:58 EST
On 28/11/2025 17:31, Peter Zijlstra wrote:
This changelog tells me what the patch does, something I can see from
reading the patch itself. However, it completely fails at the purpose of
a changelog, which is to elucidate the reader as to the reasons for
doing so.
How about to change the changelog as following:
"
In current newidle balance, the rq->idle_stamp may set to a non-zero value
if it cannot pull any task.
In the wakeup, it will detect the rq->idle_stamp, and updates
the rq->avg_idle, then ends the CPU idle status by setting rq->idle_stamp
to zero.
Besides the wakeup, current code does not end the CPU idle status
when a task is moved to the idle CPU, such as fork/clone, execve,
or other cases.
In order to fix this issue, we want to add a hook(update_rq_avg_idle())
in the enqueue_task(). With this hook, if a task is moved to the idle CPU,
it will update the rq->avg_idle. Unfortunately, this hook is also called
in the newidle balance:
sched_balance_newidle() --> sched_balance_rq() --> ... --> enqueue_task()
If we still set rq->idle_stamp at the beginning of sched_balance_newidle(),
the rq->avg_idle will not be updated correctly.
In order to make it work correctly, save the idle_stamp at the beginning
of sched_balance_newidle(). If newidle balance cannot pull any task,
set the saved value for rq->idle_stamp. With this method,
the newidle balance still work correctly, and the hook in enqueue_task()
also works correctly.
"
Thanks
Huang Shijie