lkml.org 
[lkml]   [2013]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 5/5] timekeeping: Add support for clocksource which doesn't stop during suspend
    Date
    There are some new processors whose TSC clocksource won't stop during
    suspend. Currently, after system resumes from sleep state, kernel will
    use persistent clock or RTC to compensate the sleep time, but for those
    new types of clocksources, we could skip the special compensation from
    external sources, and just use current clocksource for recounting.

    This can solve some time drift bugs caused by the not-so-accurate RTC
    devices.

    Signed-off-by: Feng Tang <feng.tang@intel.com>
    ---
    kernel/time/timekeeping.c | 23 ++++++++++++++++++-----
    1 file changed, 18 insertions(+), 5 deletions(-)

    diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
    index cbc6acb..628c9ba 100644
    --- a/kernel/time/timekeeping.c
    +++ b/kernel/time/timekeeping.c
    @@ -749,22 +749,36 @@ void timekeeping_inject_sleeptime(struct timespec *delta)
    static void timekeeping_resume(void)
    {
    struct timekeeper *tk = &timekeeper;
    + struct clocksource *clock = tk->clock;
    unsigned long flags;
    struct timespec ts;
    + cycle_t cycle_now, cycle_delta;
    + s64 nsec;

    read_persistent_clock(&ts);
    -
    clockevents_resume();
    clocksource_resume();

    write_seqlock_irqsave(&tk->lock, flags);

    - if (timespec_compare(&ts, &timekeeping_suspend_time) > 0) {
    + if (clock->flags & CLOCK_SOURCE_SUSPEND_NOTSTOP) {
    + cycle_now = clock->read(clock);
    + cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
    + clock->cycle_last = cycle_now;
    +
    + nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift);
    + ts = ns_to_timespec(nsec);
    + } else if (timespec_compare(&ts, &timekeeping_suspend_time) > 0)
    ts = timespec_sub(ts, timekeeping_suspend_time);
    - __timekeeping_inject_sleeptime(tk, &ts);
    + else {
    + ts.tv_sec = 0;
    + ts.tv_nsec = 0;
    }
    +
    + __timekeeping_inject_sleeptime(tk, &ts);
    +
    /* re-base the last cycle value */
    - tk->clock->cycle_last = tk->clock->read(tk->clock);
    + clock->cycle_last = clock->read(clock);
    tk->ntp_error = 0;
    timekeeping_suspended = 0;
    timekeeping_update(tk, false);
    @@ -1134,7 +1148,6 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk)
    #endif


    -
    /**
    * update_wall_time - Uses the current clocksource to increment the wall time
    *
    --
    1.7.9.5


    \
     
     \ /
      Last update: 2013-01-21 08:21    [W:4.156 / U:0.092 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site