NTP: rtc: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization
Subsystems (2)
PATCH v3 1/3 NTP: rtc: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization
From: Xunlei Pang <[email protected]>
Currently, CONFIG_RTC_SYSTOHC uses CONFIG_RTC_HCTOSYS_DEVICE which is originally used by CONFIG_RTC_HCTOSYS, but this rtc device has some limiations, for example, it must be battery-backed, be able to work with irq off and through system suspension, etc.
So add CONFIG_RTC_SYSTOHC_DEVICE used exclusively for CONFIG_RTC_SYSTOHC, it is more lenient compared to CONFIG_RTC_HCTOSYS_DEVICE, and could be assigned any available RTC in the system.
Default value is CONFIG_RTC_HCTOSYS_DEVICE which is "rtc0" by default. After this patch, NTP will sync up "rtc0" by default.
--- drivers/rtc/Kconfig | 28 +++++++++++++++++++--------- drivers/rtc/systohc.c | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-)
drivers/rtc/Kconfig +19 -9
@@ -25,17 +25,9 @@ config RTC_HCTOSYS the value read from a specified RTC device. This is useful to avoid unnecessary fsck runs at boot time, and to network better. -config RTC_SYSTOHC - bool "Set the RTC time based on NTP synchronization" - default y - help - If you say yes here, the system time (wall clock) will be stored - in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11 - minutes if userspace reports synchronized NTP status. - config RTC_HCTOSYS_DEVICE string "RTC used to set the system time" - depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y + depends on RTC_HCTOSYS default "rtc0" help The RTC device that will be used to (re)initialize the system
@@ -56,6 +48,24 @@ config RTC_HCTOSYS_DEVICE sleep states. Do not specify an RTC here unless it stays powered during all this system's supported sleep states. +config RTC_SYSTOHC + bool "Set the RTC time based on NTP synchronization" + default y + help + If you say yes here, the system time (wall clock) will be stored + in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11 + minutes if userspace reports synchronized NTP status. + +config RTC_SYSTOHC_DEVICE + string "RTC used to synchronize NTP adjustment" + depends on RTC_SYSTOHC + default RTC_HCTOSYS_DEVICE + help + The RTC device used for NTP synchronization. The main difference + between RTC_HCTOSYS_DEVICE and RTC_SYSTOHC_DEVICE is that this + one can sleep when setting time, because it runs in the workqueue + context. + config RTC_DEBUG bool "RTC debug support" help
drivers/rtc/systohc.c +1 -1
@@ -31,7 +31,7 @@ int rtc_set_ntp_time(struct timespec64 now)else rtc_time64_to_tm (now.tv_sec +1 , &tm); - rtc =rtc_class_open (CONFIG_RTC_HCTOSYS_DEVICE ); + rtc =rtc_class_open (CONFIG_RTC_SYSTOHC_DEVICE );if (rtc) {/* rtc_hctosys exclusively uses UTC, so we call set_time here, * not set_mmss. */
Signature · 1 line
1.9.1
PATCH v3 2/3 sparc: time: Replace update_persistent_clock() with CONFIG_RTC_SYSTOHC
From: Xunlei Pang <[email protected]>
On Sparc systems, update_persistent_clock() uses RTC drivers to do the job, it makes more sense to hand it over to CONFIG_RTC_SYSTOHC.
In the long run, all the update_persistent_clock() should migrate to proper class RTC drivers if any and use CONFIG_RTC_SYSTOHC instead.
--- arch/sparc/Kconfig | 2 +- arch/sparc/kernel/time_32.c | 21 --------------------- arch/sparc/kernel/time_64.c | 14 -------------- 3 files changed, 1 insertion(+), 36 deletions(-)
arch/sparc/Kconfig +1 -1
@@ -25,6 +25,7 @@ config SPARC select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE select RTC_CLASS select RTC_DRV_M48T59 + select RTC_SYSTOHC select HAVE_DMA_ATTRS select HAVE_DMA_API_DEBUG select HAVE_ARCH_JUMP_LABEL if SPARC64
@@ -35,7 +36,6 @@ config SPARC select HAVE_BPF_JIT select HAVE_DEBUG_BUGVERBOSE select GENERIC_SMP_IDLE_THREAD - select GENERIC_CMOS_UPDATE select GENERIC_CLOCKEVENTS select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER
arch/sparc/kernel/time_32.c +0 -21
@@ -23,7 +23,6 @@#include <linux/mm.h> #include <linux/interrupt.h> #include <linux/time.h> -#include <linux/rtc.h> #include <linux/rtc/m48t59.h> #include <linux/timex.h> #include <linux/clocksource.h>
@@ -65,8 +64,6 @@ DEFINE_PER_CPU(struct clock_event_device, sparc32_clockevent);DEFINE_SPINLOCK (rtc_lock);EXPORT_SYMBOL (rtc_lock); -static int set_rtc_mmss (unsigned long ); -unsigned long profile_pc (struct pt_regs *regs) {extern char __copy_user_begin[], __copy_user_end[];
@@ -87,11 +84,6 @@ EXPORT_SYMBOL(profile_pc);volatile u32 __iomem *master_l10_counter; -int update_persistent_clock (struct timespec now) -{ -return set_rtc_mmss (now.tv_sec); -} - irqreturn_t notrace timer_interrupt(int dummy, void *dev_id) {if (timer_cs_enabled) {
@@ -362,16 +354,3 @@ void __init time_init(void)sbus_time_init (); } - -static int set_rtc_mmss (unsigned long secs) -{ -struct rtc_device *rtc =rtc_class_open ("rtc0" ); -int err =-1 ; - -if (rtc) { - err =rtc_set_mmss (rtc, secs); -rtc_class_close (rtc); - } - -return err; -}
arch/sparc/kernel/time_64.c +0 -14
@@ -28,7 +28,6 @@#include <linux/cpufreq.h> #include <linux/percpu.h> #include <linux/miscdevice.h> -#include <linux/rtc.h> #include <linux/rtc/m48t59.h> #include <linux/kernel_stat.h> #include <linux/clockchips.h>
@@ -394,19 +393,6 @@ static struct sparc64_tick_ops hbtick_operations __read_mostly = {static unsigned long timer_ticks_per_nsec_quotient__read_mostly ; -int update_persistent_clock (struct timespec now) -{ -struct rtc_device *rtc =rtc_class_open ("rtc0" ); -int err =-1 ; - -if (rtc) { - err =rtc_set_mmss (rtc, now.tv_sec); -rtc_class_close (rtc); - } - -return err; -} -unsigned long cmos_regs;EXPORT_SYMBOL (cmos_regs);
Signature · 1 line
1.9.1
Re: [PATCH v3 2/3] sparc: time: Replace update_persistent_clock() with CONFIG_RTC_SYSTOHC
Dave,
I would like to take that patch as part of the series once you have acked it.
Quoted 121 lines · Xunlei Pang
From: Xunlei Pang <[email protected]>
On Sparc systems,
update_persistent_clock()uses RTC drivers to do the job, it makes more sense to hand it over toCONFIG_RTC_SYSTOHC.In the long run, all the
update_persistent_clock()should migrate to proper class RTC drivers if any and useCONFIG_RTC_SYSTOHCinstead.Signed-off-by Xunlei Pang <[email protected]>--- arch/sparc/Kconfig | 2 +- arch/sparc/kernel/time_32.c | 21 --------------------- arch/sparc/kernel/time_64.c | 14 -------------- 3 files changed, 1 insertion(+), 36 deletions(-)arch/sparc/Kconfig +1
-1@@ -25,6 +25,7 @@ config SPARC select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE select RTC_CLASS select RTC_DRV_M48T59 + select RTC_SYSTOHC select HAVE_DMA_ATTRS select HAVE_DMA_API_DEBUG select HAVE_ARCH_JUMP_LABEL if SPARC64@@ -35,7 +36,6 @@ config SPARC select HAVE_BPF_JIT select HAVE_DEBUG_BUGVERBOSE select GENERIC_SMP_IDLE_THREAD - select GENERIC_CMOS_UPDATE select GENERIC_CLOCKEVENTS select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USERarch/sparc/kernel/time_32.c +0
-21@@ -23,7 +23,6 @@#include <linux/mm.h> #include <linux/interrupt.h> #include <linux/time.h> -#include <linux/rtc.h> #include <linux/rtc/m48t59.h> #include <linux/timex.h> #include <linux/clocksource.h> @@ -65,8 +64,6 @@ DEFINE_PER_CPU(struct clock_event_device, sparc32_clockevent);DEFINE_SPINLOCK (rtc_lock);EXPORT_SYMBOL (rtc_lock); -static int set_rtc_mmss (unsigned long ); -unsigned long profile_pc (struct pt_regs *regs) {extern char __copy_user_begin[], __copy_user_end[];@@ -87,11 +84,6 @@ EXPORT_SYMBOL(profile_pc);volatile u32 __iomem *master_l10_counter; -int update_persistent_clock (struct timespec now) -{ -return set_rtc_mmss (now.tv_sec); -} - irqreturn_t notrace timer_interrupt(int dummy, void *dev_id) {if (timer_cs_enabled) {@@ -362,16 +354,3 @@ void __init time_init(void)sbus_time_init (); } - -static int set_rtc_mmss (unsigned long secs) -{ -struct rtc_device *rtc =rtc_class_open ("rtc0" ); -int err =-1 ; - -if (rtc) { - err =rtc_set_mmss (rtc, secs); -rtc_class_close (rtc); - } - -return err; -}arch/sparc/kernel/time_64.c +0
-14@@ -28,7 +28,6 @@#include <linux/cpufreq.h> #include <linux/percpu.h> #include <linux/miscdevice.h> -#include <linux/rtc.h> #include <linux/rtc/m48t59.h> #include <linux/kernel_stat.h> #include <linux/clockchips.h> @@ -394,19 +393,6 @@ static struct sparc64_tick_ops hbtick_operations __read_mostly = {static unsigned long timer_ticks_per_nsec_quotient__read_mostly ; -int update_persistent_clock (struct timespec now) -{ -struct rtc_device *rtc =rtc_class_open ("rtc0" ); -int err =-1 ; - -if (rtc) { - err =rtc_set_mmss (rtc, now.tv_sec); -rtc_class_close (rtc); - } - -return err; -} -unsigned long cmos_regs;EXPORT_SYMBOL (cmos_regs);Signature · 1 line
1.9.1
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
Re: [PATCH v3 2/3] sparc: time: Replace update_persistent_clock() with CONFIG_RTC_SYSTOHC
From: Alexandre Belloni <[email protected]>
Date: Fri, 12 Jun 2015 10:42:38 +0200
Quoted 2 lines
I would like to take that patch as part of the series once you have acked it.
Sure:
PATCH v3 3/3 drivers/rtc/interface.c: Remove rtc_set_mmss()
In reply to Xunlei PangFrom: Xunlei Pang <[email protected]>
Now rtc_set_mmss() has no users, just remove it.
We still have rtc_set_time() doing similar things.
--- drivers/rtc/interface.c | 45 --------------------------------------------- include/linux/rtc.h | 1 - 2 files changed, 46 deletions(-)
drivers/rtc/interface.c +0 -45
@@ -91,51 +91,6 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) }EXPORT_SYMBOL_GPL (rtc_set_time); -int rtc_set_mmss (struct rtc_device *rtc,unsigned long secs) -{ -int err; - - err =mutex_lock_interruptible (&rtc->ops_lock); -if (err) -return err; - -if (!rtc->ops) - err = -ENODEV ; -else if (rtc->ops->set_mmss64) - err = rtc->ops->set_mmss64 (rtc->dev.parent, secs); -else if (rtc->ops->set_mmss) - err = rtc->ops->set_mmss (rtc->dev.parent, secs); -else if (rtc->ops->read_time && rtc->ops->set_time) { -struct rtc_time new, old; - - err = rtc->ops->read_time (rtc->dev.parent, &old); -if (err =0 ) { -rtc_time64_to_tm (secs, &new); - -/* -* avoid writing when we're going to change the day of -* the month. We will retry in the next minute. This -* basically means that if the RTC must not drift -* by more than 1 minute in 11 minutes. -*/ -if (!((old.tm_hour =23 && old.tm_min =59 ) || - (new.tm_hour =23 && new.tm_min =59 ))) - err = rtc->ops->set_time (rtc->dev.parent, - &new); - } - }else { - err = -EINVAL ; - } - -pm_stay_awake (rtc->dev.parent); -mutex_unlock (&rtc->ops_lock); -/* A timer might have just expired */ -schedule_work (&rtc->irqwork); - -return err; -} -EXPORT_SYMBOL_GPL (rtc_set_mmss); -static int rtc_read_alarm_internal (struct rtc_device *rtc,struct rtc_wkalrm *alarm) {int err;
include/linux/rtc.h +0 -1
@@ -169,7 +169,6 @@ extern void devm_rtc_device_unregister(struct device *dev,extern int rtc_read_time (struct rtc_device *rtc,struct rtc_time *tm);extern int rtc_set_time (struct rtc_device *rtc,struct rtc_time *tm); -extern int rtc_set_mmss (struct rtc_device *rtc,unsigned long secs);extern int rtc_set_ntp_time (struct timespec64 now);int __rtc_read_alarm (struct rtc_device *rtc,struct rtc_wkalrm *alarm); extern int rtc_read_alarm(struct rtc_device *rtc,
Signature · 1 line
1.9.1
Alexandre Belloni
AppliedHi,
drivers/rtc/Kconfig config RTC_HCTOSYS_DEVICE · line 62
Quoted 4 lines · Xunlei Pang
drivers/rtc/Kconfig +4
-0+config RTC_SYSTOHC_DEVICE + string "RTC used to synchronize NTP adjustment" + depends on RTC_SYSTOHC + default RTC_HCTOSYS_DEVICE
Actually, I forgot one case so I changed it to:
+ default RTC_HCTOSYS_DEVICE if RTC_HCTOSYS
+ default "rtc0"
I applied both series, thanks.
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com