Re: [PATCH] update clocksource raw_time in timekeeping_suspend

From: Yong Zhang
Date: Wed Sep 09 2009 - 10:25:58 EST


On Wed, Sep 9, 2009 at 3:35 PM, ye janboe<janboe.ye@xxxxxxxxx> wrote:
> after resume from suspend, raw_time is not updated in
> timekeeping_suspend. CLOCK_MONOTONIC_RAW could not get the real hw
> time.

It seems that this is not a bug. The design of CLOCK_MONOTONIC_RAW doesn't
say it will reflect the real hw time. It's just monotonic time which
is unpoisoned by
ntp.

Cheers,
Yong

> This patch fix this issue.
>
> Signed-off-by: janboe <janboe.ye@xxxxxxxxx>
> ---
> Âkernel/time/timekeeping.c | Â Â6 ++++++
> Â1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index e8c77d9..8420b85 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -331,6 +331,8 @@ static unsigned long timekeeping_suspend_time;
> Âstatic int timekeeping_resume(struct sys_device *dev)
> Â{
> Â Â Â Âunsigned long flags;
> + Â Â Â s64 nsec;
> + Â Â Â cycle_t last_cycle, cycle_delta;
> Â Â Â Âunsigned long now = read_persistent_clock();
>
> Â Â Â Âclocksource_resume();
> @@ -346,8 +348,12 @@ static int timekeeping_resume(struct sys_device *dev)
> Â Â Â Â}
> Â Â Â Âupdate_xtime_cache(0);
> Â Â Â Â/* re-base the last cycle value */
> + Â Â Â last_cycle = clock->cycle_last;
> Â Â Â Âclock->cycle_last = 0;
> Â Â Â Âclock->cycle_last = clocksource_read(clock);
> + Â Â Â cycle_delta = clock->cycle_last - last_cycle;
> + Â Â Â nsec = cyc2ns(clock, cycle_delta);
> + Â Â Â timespec_add_ns(&clock->raw_time, nsec);
> Â Â Â Âclock->error = 0;
> Â Â Â Âtimekeeping_suspended = 0;
> Â Â Â Âwrite_sequnlock_irqrestore(&xtime_lock, flags);
> --
> 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/
>
--
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/