Re: [tip:timers/core] time: Add timekeeping_inject_sleeptime

From: Arve Hjønnevåg
Date: Fri Apr 29 2011 - 23:30:11 EST


2011/4/29 John Stultz <john.stultz@xxxxxxxxxx>:
> On Fri, 2011-04-29 at 18:12 -0700, Arve Hjønnevåg wrote:
>>         /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */
>> -       set_normalized_timespec(&delta,
>> +       set_normalized_timespec(&new_delta,
>>                                 ts.tv_sec - oldtime,
>>                                 ts.tv_nsec - (NSEC_PER_SEC >> 1));
>>
>> +       /* prevent 1/2 sec errors from accumulating */
>> +       delta_delta = timespec_sub(new_delta, delta);
>> +       if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2)
>> +               delta = new_delta;
>>         return 0;
>
> So, the basic idea is to keep the RTC vs CLOCK_REALTIME delta constant
> (by using the same value as the last time) for each resume cycle
> assuming it stays within +/-2 seconds.
>
> If it changes more then that since the last suspend (due to user running
> hwclock or the periodic NTP sync or drift of the uncorrected RTC) then
> throw away the old value and use the new delta.
>

Yes.

>
>> @@ -80,6 +87,8 @@ static int rtc_resume(struct device *dev)
>>                 return 0;
>>         }
>>         rtc_tm_to_time(&tm, &newtime);
>> +       if (delta_delta.tv_sec < -1)
>> +               newtime++;
>
>
> So this part isn't quite clicking at the moment (forgive my brain, its a
> sunny friday!). Wouldn't this trigger even if we threw away the old
> delta (since nothing clears delta_delta)?
>
Probably.

> I'll spend some more time looking at it, but if you can clarify why we
> want to inject a second here (and why there's not a corresponding dec
> for delta_delta being > 1 sec to make it symmetric) it would help?
>

I don't remember exactly why I did it this way, but the goal is to
make sure time does not jump backwards. If the rtc runs slower than
the clock we are using when awake, then time could jump backwards
after suspend since we re-sync with the rtc. With your new code, it is
probably better to just clip the resulting sleep-time to not allow
negative values.

--
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/