Skip to contentSkip to conversation

NTP: rtc: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization

PATCH Superseded Xunlei Pang 3 participants 6 messages May 29, 2015 – Jun 2, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 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 "rtc0".

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
index 0fe4ad8..f429e9a 100644
@@ -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 = y
 	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 = y
+	default "rtc0"
+	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
index 7728d5e..b4a68ff 100644
@@ -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
#1 lore raw

PATCH v2 2/4 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
index e49502a..56442d2 100644
@@ -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
index 8caf45e..c9692f3 100644
@@ -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
index edbbeb1..2e6035c 100644
@@ -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
#2 lore raw

PATCH v2 3/4 drivers/rtc/interface.c: Remove rtc_set_mmss()

In reply to Xunlei Pang

From: 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
index 166fc60..b511aa1 100644
@@ -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
index 8dcf682..e8f2c3c 100644
@@ -161,7 +161,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
#3 lore raw

PATCH v2 4/4 cris: time: Cleanup of persistent clock stuff

In reply to Xunlei Pang

From: Xunlei Pang <[email protected]>

- Remove update_persistent_clock(), as it does nothing now.
- Remove read_persistent_clock(), let it fall back to the weak version.

---
 arch/cris/Kconfig       |  1 -
 arch/cris/kernel/time.c | 25 -------------------------
 2 files changed, 26 deletions(-)
arch/cris/Kconfig +0 -1
index 0314e32..982d562 100644
@@ -46,7 +46,6 @@ config CRIS
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select GENERIC_IRQ_SHOW
 	select GENERIC_IOMAP
-	select GENERIC_CMOS_UPDATE
 	select MODULES_USE_ELF_RELA
 	select CLONE_BACKWARDS2
 	select OLD_SIGSUSPEND
arch/cris/kernel/time.c +0 -25
index 7780d37..2dda6da 100644
@@ -39,31 +39,6 @@
 extern unsigned long loops_per_jiffy; /* init/main.c */
 unsigned long loops_per_usec;
 
-int set_rtc_mmss(unsigned long nowtime)
-{
-	D(printk(KERN_DEBUG "set_rtc_mmss(%lu)\n", nowtime));
-	return 0;
-}
-
-/* grab the time from the RTC chip */
-unsigned long get_cmos_time(void)
-{
-	return 0;
-}
-
-
-int update_persistent_clock(struct timespec now)
-{
-	return set_rtc_mmss(now.tv_sec);
-}
-
-void read_persistent_clock(struct timespec *ts)
-{
-	ts->tv_sec = 0;
-	ts->tv_nsec = 0;
-}
-
-
 extern void cris_profile_sample(struct pt_regs* regs);
 
 void
Signature · 1 line
1.9.1
#4 lore raw
In reply to Xunlei Pang

drivers/rtc/Kconfig config RTC_HCTOSYS · line 30

Quoted 7 lines · Xunlei Pang
drivers/rtc/Kconfig +1 -1
 
 config RTC_HCTOSYS_DEVICE
 	string "RTC used to set the system time"
-	depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y
+	depends on RTC_HCTOSYS = y

RTC_HCTOSYS and RTC_SYSTOHC are bool symbols. The "= y" test is not needed and the common idiom is to use only
depends on RTC_HCTOSYS

Since you're touching this you might as well switch to that idiom.

drivers/rtc/Kconfig config RTC_HCTOSYS_DEVICE · line 61

Quoted 8 lines
drivers/rtc/Kconfig +0 -0
 	default "rtc0"
 	help
 	  The RTC device that will be used to (re)initialize the system

minutes if userspace reports synchronized NTP status.

drivers/rtc/Kconfig +3 -0
+config RTC_SYSTOHC_DEVICE
+	string "RTC used to synchronize NTP adjustment"
+	depends on RTC_SYSTOHC = y

Likewise.

drivers/rtc/Kconfig config RTC_HCTOSYS_DEVICE · line 67

Quoted 6 lines
drivers/rtc/Kconfig +6 -0
+	default "rtc0"
+	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.

Paul Bolle

#5 lore raw

Hi Paul,

Paul Bolle <[email protected]> wrote 2015-06-01 PM 04:27:40:

Quoted 24 lines

Re: [PATCH v2 1/4] NTP: rtc: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization

drivers/rtc/Kconfig config RTC_HCTOSYS · line 30

Quoted 7 lines · Xunlei Pang
drivers/rtc/Kconfig +1 -1
 
 config RTC_HCTOSYS_DEVICE
    string "RTC used to set the system time"
-   depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y
+   depends on RTC_HCTOSYS = y

RTC_HCTOSYS and RTC_SYSTOHC are bool symbols. The "= y" test is not needed and the common idiom is to use only
depends on RTC_HCTOSYS

Since you're touching this you might as well switch to that idiom.

Quoted 4 lines

default "rtc0"
help
The RTC device that will be used to (re)initialize the system
minutes if userspace reports synchronized NTP status.

Quoted 5 lines

drivers/rtc/Kconfig config RTC_HCTOSYS_DEVICE · line 61

Quoted 3 lines
drivers/rtc/Kconfig +3 -0
+config RTC_SYSTOHC_DEVICE
+   string "RTC used to synchronize NTP adjustment"
+   depends on RTC_SYSTOHC = y

Likewise.

Yea, thanks for pointing this out.

-Xunlei

Quoted 6 lines

drivers/rtc/Kconfig config RTC_HCTOSYS_DEVICE

Quoted 6 lines
drivers/rtc/Kconfig +5 -0
+   default "rtc0"
+   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

Quoted 5 lines
Quoted 1 line

+ context.

Paul Bolle

--------------------------------------------------------
ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s). If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited. If you have received this mail in error, please delete it and notify us immediately.