Re: [PATCH v2 05/12] sched/fair: Optimize __update_sched_avg()

From: Peter Zijlstra
Date: Tue May 03 2016 - 04:49:23 EST


On Tue, May 03, 2016 at 05:54:31AM +0800, Yuyang Du wrote:
> __update_sched_avg() has these steps:
> 1. add the left of the last incomplete period
> 2. decay old sum
> 3. accumulate new sum since last_update_time
> 4. add the current incomplete period
> 5. update averages
>
> Previously, we separately computed steps 1, 3, and 4, leading to
> each one of them ugly in codes and costly in overhead. But actually
> they all do the same thing, so we combine them together. The result
> will be much cleaner codes and less CPU cycles.

I would very much like to see an explanation of how we can fold all that
here. Without me having to untangle the code first.

That also helps me to verify if the code does indeed implement what you
meant it to, etc..