Re: [PATCH v2] sched/eevdf: Reduce the computation frequency of avg_vruntime

From: Peter Zijlstra
Date: Fri Oct 11 2024 - 04:52:32 EST


On Fri, Oct 11, 2024 at 02:24:49PM +0800, Xavier wrote:
> The current code subtracts the value of curr from avg_vruntime and avg_load
> during runtime. Then, every time avg_vruntime() is called, it adds the
> value of curr to the avg_vruntime and avg_load. Afterward, it divides these
> and adds min_vruntime to obtain the actual avg_vruntime.
>
> Analysis of the code indicates that avg_vruntime only changes significantly
> during update_curr(), update_min_vruntime(), and when tasks are enqueued or
> dequeued. Therefore, it is sufficient to recalculate and store avg_vruntime
> only in these specific scenarios. This optimization ensures that accessing
> avg_vruntime() does not necessitate a recalculation each time, thereby
> enhancing the efficiency of the code.
>
> There is no need to subtract curr’s load from avg_load during runtime.
> Instead, we only need to calculate the incremental change and update
> avg_vruntime whenever curr’s time is updated.
>
> To better represent their functions, rename the original avg_vruntime and
> avg_load to tot_vruntime and tot_load, respectively, which more accurately
> describes their roles in the computation.
>
> Signed-off-by: Xavier <xavier_qy@xxxxxxx>

This makes the code more complicated for no shown benefit.