RE: [PATCH v2] cpuidle: Use nanoseconds as the unit of time

From: Doug Smythies
Date: Sun Nov 10 2019 - 13:09:48 EST


On 2019.11.10 09:24 Rafael J. Wysocki wrote:
> On Sunday, November 10, 2019 5:48:21 PM CET Rafael J. Wysocki wrote:
>> On Fri, Nov 8, 2019 at 6:04 PM Doug Smythies <dsmythies@xxxxxxxxx> wrote:
>>>
>>> On 2019.11.08 01:45 Rafael J. Wysocki wrote:
>>>> On Fri, Nov 8, 2019 at 9:45 AM Doug Smythies <dsmythies@xxxxxxxxx> wrote:
>>>>
>>> ...
>>>>> I have been running this v2 today, with both menu and teo
>>>>> governors. Acquiring some baseline reference data to compare
>>>>> to now. The menu governor response seems different (Supporting
>>>>> information/graphs will come later).
>>>>
>>>> That may be good or bad, depending in what way it is different. :-)
>>>
>>> My thinking was that the differences should be minimal between
>>> the baseline (linux-next as of 2019.11.07) and plus your two patches.
>>> Because this was a change of units, but not functionality.
>>> Such is the case with the teo governor, but not the menu governor.
>>> I have not tried the ladder or haltpoll governors, and don't intend to.
>>>
>>> Now to attempt to isolate the issue in the code, which might take
>>> considerable time.
>>
>> Thanks!
>>
>> It looks like I have overlooked a unit conversion in menu or done a
>> unit conversion twice somewhere.
>
> I have found a bug, which should be addressed by the patch below.
>
> If it still doesn't reduce the discrepancy, we'll need to look further.
>
> ---
> drivers/cpuidle/governors/menu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Index: linux-pm/drivers/cpuidle/governors/menu.c
> ===================================================================
> --- linux-pm.orig/drivers/cpuidle/governors/menu.c
> +++ linux-pm/drivers/cpuidle/governors/menu.c
> @@ -516,8 +516,8 @@ static void menu_update(struct cpuidle_d
> new_factor -= new_factor / DECAY;
>
> if (data->next_timer_ns > 0 && measured_ns < MAX_INTERESTING)
> - new_factor += RESOLUTION * div64_u64(measured_ns,
> - data->next_timer_ns);
> + new_factor += div64_u64(RESOLUTION * measured_ns,
> + data->next_timer_ns);
> else
> /*
> * we were idle so long that we count it as a perfect

Yes, that was the exact bit of code I focused on yesterday.
However, my attempt to fix was different, and made no difference,
with the new graph being exactly on top of the old bad one.
I had defined new_factor as u64 and RESOLUTION as ULL.
Note: I didn't care about the most efficient code, in these attempts
to just get to the answer.

I'll try yours and report back.

... Doug