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

From: John Stultz
Date: Fri Apr 29 2011 - 21:57:49 EST


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.


> @@ -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)?

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?

thanks
-john




--
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/