Loading drivers/rtc/class.c +2 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ static int rtc_suspend(struct device *dev) struct timespec delta, delta_delta; int err; if (has_persistent_clock()) if (timekeeping_rtc_skipsuspend()) return 0; if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) Loading Loading @@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev) struct timespec sleep_time; int err; if (has_persistent_clock()) if (timekeeping_rtc_skipresume()) return 0; rtc_hctosys_ret = -ENODEV; Loading include/linux/timekeeping.h +2 −6 Original line number Diff line number Diff line Loading @@ -183,6 +183,8 @@ static inline void timekeeping_clocktai(struct timespec *ts) * RTC specific */ extern void timekeeping_inject_sleeptime(struct timespec *delta); extern bool timekeeping_rtc_skipsuspend(void); extern bool timekeeping_rtc_skipresume(void); /* * PPS accessor Loading @@ -193,14 +195,8 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw, /* * Persistent clock related interfaces */ extern bool persistent_clock_exist; extern int persistent_clock_is_local; static inline bool has_persistent_clock(void) { return persistent_clock_exist; } extern void read_persistent_clock(struct timespec *ts); extern void read_boot_clock(struct timespec *ts); extern int update_persistent_clock(struct timespec now); Loading kernel/time/timekeeping.c +49 −17 Original line number Diff line number Diff line Loading @@ -63,9 +63,6 @@ static struct tk_fast tk_fast_mono ____cacheline_aligned; /* flag for if timekeeping is suspended */ int __read_mostly timekeeping_suspended; /* Flag for if there is a persistent clock on this platform */ bool __read_mostly persistent_clock_exist = false; static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->tkr_mono.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_mono.shift)) { Loading Loading @@ -977,6 +974,12 @@ void __weak read_boot_clock(struct timespec *ts) ts->tv_nsec = 0; } /* Flag for if timekeeping_resume() has injected sleeptime */ static bool sleeptime_injected; /* Flag for if there is a persistent clock on this platform */ static bool persistent_clock_exists; /* * timekeeping_init - Initializes the clocksource and common timekeeping values */ Loading @@ -996,7 +999,7 @@ void __init timekeeping_init(void) now.tv_sec = 0; now.tv_nsec = 0; } else if (now.tv_sec || now.tv_nsec) persistent_clock_exist = true; persistent_clock_exists = true; read_boot_clock(&ts); boot = timespec_to_timespec64(ts); Loading Loading @@ -1056,12 +1059,48 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, tk_debug_account_sleep_time(delta); } /** * We have three kinds of time sources to use for sleep time * injection, the preference order is: * 1) non-stop clocksource * 2) persistent clock (ie: RTC accessible when irqs are off) * 3) RTC * * 1) and 2) are used by timekeeping, 3) by RTC subsystem. * If system has neither 1) nor 2), 3) will be used finally. * * * If timekeeping has injected sleeptime via either 1) or 2), * 3) becomes needless, so in this case we don't need to call * rtc_resume(), and this is what timekeeping_rtc_skipresume() * means. */ bool timekeeping_rtc_skipresume(void) { return sleeptime_injected; } /** * 1) can be determined whether to use or not only when doing * timekeeping_resume() which is invoked after rtc_suspend(), * so we can't skip rtc_suspend() surely if system has 1). * * But if system has 2), 2) will definitely be used, so in this * case we don't need to call rtc_suspend(), and this is what * timekeeping_rtc_skipsuspend() means. */ bool timekeeping_rtc_skipsuspend(void) { return persistent_clock_exists; } /** * timekeeping_inject_sleeptime - Adds suspend interval to timeekeeping values * @delta: pointer to a timespec delta value * * This hook is for architectures that cannot support read_persistent_clock * because their RTC/persistent clock is only accessible when irqs are enabled. * and also don't have an effective nonstop clocksource. * * This function should only be called by rtc_resume(), and allows * a suspend offset to be injected into the timekeeping values. Loading @@ -1072,13 +1111,6 @@ void timekeeping_inject_sleeptime(struct timespec *delta) struct timespec64 tmp; unsigned long flags; /* * Make sure we don't set the clock twice, as timekeeping_resume() * already did it */ if (has_persistent_clock()) return; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); Loading Loading @@ -1111,8 +1143,8 @@ static void timekeeping_resume(void) struct timespec64 ts_new, ts_delta; struct timespec tmp; cycle_t cycle_now, cycle_delta; bool suspendtime_found = false; sleeptime_injected = false; read_persistent_clock(&tmp); ts_new = timespec_to_timespec64(tmp); Loading Loading @@ -1159,13 +1191,13 @@ static void timekeeping_resume(void) nsec += ((u64) cycle_delta * mult) >> shift; ts_delta = ns_to_timespec64(nsec); suspendtime_found = true; sleeptime_injected = true; } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time); suspendtime_found = true; sleeptime_injected = true; } if (suspendtime_found) if (sleeptime_injected) __timekeeping_inject_sleeptime(tk, &ts_delta); /* Re-base the last cycle value */ Loading Loading @@ -1203,14 +1235,14 @@ static int timekeeping_suspend(void) * value returned, update the persistent_clock_exists flag. */ if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec) persistent_clock_exist = true; persistent_clock_exists = true; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); timekeeping_suspended = 1; if (has_persistent_clock()) { if (persistent_clock_exists) { /* * To avoid drift caused by repeated suspend/resumes, * which each can add ~1 second drift error, Loading Loading
drivers/rtc/class.c +2 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ static int rtc_suspend(struct device *dev) struct timespec delta, delta_delta; int err; if (has_persistent_clock()) if (timekeeping_rtc_skipsuspend()) return 0; if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) Loading Loading @@ -102,7 +102,7 @@ static int rtc_resume(struct device *dev) struct timespec sleep_time; int err; if (has_persistent_clock()) if (timekeeping_rtc_skipresume()) return 0; rtc_hctosys_ret = -ENODEV; Loading
include/linux/timekeeping.h +2 −6 Original line number Diff line number Diff line Loading @@ -183,6 +183,8 @@ static inline void timekeeping_clocktai(struct timespec *ts) * RTC specific */ extern void timekeeping_inject_sleeptime(struct timespec *delta); extern bool timekeeping_rtc_skipsuspend(void); extern bool timekeeping_rtc_skipresume(void); /* * PPS accessor Loading @@ -193,14 +195,8 @@ extern void getnstime_raw_and_real(struct timespec *ts_raw, /* * Persistent clock related interfaces */ extern bool persistent_clock_exist; extern int persistent_clock_is_local; static inline bool has_persistent_clock(void) { return persistent_clock_exist; } extern void read_persistent_clock(struct timespec *ts); extern void read_boot_clock(struct timespec *ts); extern int update_persistent_clock(struct timespec now); Loading
kernel/time/timekeeping.c +49 −17 Original line number Diff line number Diff line Loading @@ -63,9 +63,6 @@ static struct tk_fast tk_fast_mono ____cacheline_aligned; /* flag for if timekeeping is suspended */ int __read_mostly timekeeping_suspended; /* Flag for if there is a persistent clock on this platform */ bool __read_mostly persistent_clock_exist = false; static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->tkr_mono.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_mono.shift)) { Loading Loading @@ -977,6 +974,12 @@ void __weak read_boot_clock(struct timespec *ts) ts->tv_nsec = 0; } /* Flag for if timekeeping_resume() has injected sleeptime */ static bool sleeptime_injected; /* Flag for if there is a persistent clock on this platform */ static bool persistent_clock_exists; /* * timekeeping_init - Initializes the clocksource and common timekeeping values */ Loading @@ -996,7 +999,7 @@ void __init timekeeping_init(void) now.tv_sec = 0; now.tv_nsec = 0; } else if (now.tv_sec || now.tv_nsec) persistent_clock_exist = true; persistent_clock_exists = true; read_boot_clock(&ts); boot = timespec_to_timespec64(ts); Loading Loading @@ -1056,12 +1059,48 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, tk_debug_account_sleep_time(delta); } /** * We have three kinds of time sources to use for sleep time * injection, the preference order is: * 1) non-stop clocksource * 2) persistent clock (ie: RTC accessible when irqs are off) * 3) RTC * * 1) and 2) are used by timekeeping, 3) by RTC subsystem. * If system has neither 1) nor 2), 3) will be used finally. * * * If timekeeping has injected sleeptime via either 1) or 2), * 3) becomes needless, so in this case we don't need to call * rtc_resume(), and this is what timekeeping_rtc_skipresume() * means. */ bool timekeeping_rtc_skipresume(void) { return sleeptime_injected; } /** * 1) can be determined whether to use or not only when doing * timekeeping_resume() which is invoked after rtc_suspend(), * so we can't skip rtc_suspend() surely if system has 1). * * But if system has 2), 2) will definitely be used, so in this * case we don't need to call rtc_suspend(), and this is what * timekeeping_rtc_skipsuspend() means. */ bool timekeeping_rtc_skipsuspend(void) { return persistent_clock_exists; } /** * timekeeping_inject_sleeptime - Adds suspend interval to timeekeeping values * @delta: pointer to a timespec delta value * * This hook is for architectures that cannot support read_persistent_clock * because their RTC/persistent clock is only accessible when irqs are enabled. * and also don't have an effective nonstop clocksource. * * This function should only be called by rtc_resume(), and allows * a suspend offset to be injected into the timekeeping values. Loading @@ -1072,13 +1111,6 @@ void timekeeping_inject_sleeptime(struct timespec *delta) struct timespec64 tmp; unsigned long flags; /* * Make sure we don't set the clock twice, as timekeeping_resume() * already did it */ if (has_persistent_clock()) return; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); Loading Loading @@ -1111,8 +1143,8 @@ static void timekeeping_resume(void) struct timespec64 ts_new, ts_delta; struct timespec tmp; cycle_t cycle_now, cycle_delta; bool suspendtime_found = false; sleeptime_injected = false; read_persistent_clock(&tmp); ts_new = timespec_to_timespec64(tmp); Loading Loading @@ -1159,13 +1191,13 @@ static void timekeeping_resume(void) nsec += ((u64) cycle_delta * mult) >> shift; ts_delta = ns_to_timespec64(nsec); suspendtime_found = true; sleeptime_injected = true; } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { ts_delta = timespec64_sub(ts_new, timekeeping_suspend_time); suspendtime_found = true; sleeptime_injected = true; } if (suspendtime_found) if (sleeptime_injected) __timekeeping_inject_sleeptime(tk, &ts_delta); /* Re-base the last cycle value */ Loading Loading @@ -1203,14 +1235,14 @@ static int timekeeping_suspend(void) * value returned, update the persistent_clock_exists flag. */ if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec) persistent_clock_exist = true; persistent_clock_exists = true; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); timekeeping_suspended = 1; if (has_persistent_clock()) { if (persistent_clock_exists) { /* * To avoid drift caused by repeated suspend/resumes, * which each can add ~1 second drift error, Loading