Skip to content

Commit 90889a6

Browse files
committed
Merge branch 'fortglx/3.9/time' of git://git.linaro.org/people/jstultz/linux into timers/core
Trivial conflict in arch/x86/Kconfig Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2 parents a903743 + 6f16eeb commit 90889a6

15 files changed

Lines changed: 141 additions & 22 deletions

File tree

‎MAINTAINERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6598,7 +6598,7 @@ F: drivers/dma/dw_dmac_regs.h
65986598
F: drivers/dma/dw_dmac.c
65996599

66006600
TIMEKEEPING, NTP
6601-
M: John Stultz <johnstul@us.ibm.com>
6601+
M: John Stultz <john.stultz@linaro.org>
66026602
M: Thomas Gleixner <tglx@linutronix.de>
66036603
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/core
66046604
S: Supported

‎arch/powerpc/kernel/time.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ int update_persistent_clock(struct timespec now)
668668
struct rtc_time tm;
669669

670670
if (!ppc_md.set_rtc_time)
671-
return 0;
671+
return -ENODEV;
672672

673673
to_tm(now.tv_sec + 1 + timezone_offset, &tm);
674674
tm.tm_year -= 1900;

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ config X86
106106
select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC)
107107
select GENERIC_TIME_VSYSCALL if X86_64
108108
select KTIME_SCALAR if X86_32
109+
select ALWAYS_USE_PERSISTENT_CLOCK
109110
select GENERIC_STRNCPY_FROM_USER
110111
select GENERIC_STRNLEN_USER
111112
select HAVE_CONTEXT_TRACKING if X86_64

‎arch/x86/kernel/tsc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
623623
ns_now = __cycles_2_ns(tsc_now);
624624

625625
if (cpu_khz) {
626-
*scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz;
626+
*scale = ((NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR) +
627+
cpu_khz / 2) / cpu_khz;
627628
*offset = ns_now - mult_frac(tsc_now, *scale,
628629
(1UL << CYC2NS_SCALE_FACTOR));
629630
}

‎drivers/rtc/Kconfig‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ if RTC_CLASS
2020
config RTC_HCTOSYS
2121
bool "Set system time from RTC on startup and resume"
2222
default y
23+
depends on !ALWAYS_USE_PERSISTENT_CLOCK
2324
help
2425
If you say yes here, the system time (wall clock) will be set using
2526
the value read from a specified RTC device. This is useful to avoid
2627
unnecessary fsck runs at boot time, and to network better.
2728

29+
config RTC_SYSTOHC
30+
bool "Set the RTC time based on NTP synchronization"
31+
default y
32+
depends on !ALWAYS_USE_PERSISTENT_CLOCK
33+
help
34+
If you say yes here, the system time (wall clock) will be stored
35+
in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11
36+
minutes if userspace reports synchronized NTP status.
37+
2838
config RTC_HCTOSYS_DEVICE
2939
string "RTC used to set the system time"
30-
depends on RTC_HCTOSYS = y
40+
depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y
3141
default "rtc0"
3242
help
3343
The RTC device that will be used to (re)initialize the system

‎drivers/rtc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG
66

77
obj-$(CONFIG_RTC_LIB) += rtc-lib.o
88
obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
9+
obj-$(CONFIG_RTC_SYSTOHC) += systohc.o
910
obj-$(CONFIG_RTC_CLASS) += rtc-core.o
1011
rtc-core-y := class.o interface.o
1112

‎drivers/rtc/class.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ static int rtc_suspend(struct device *dev, pm_message_t mesg)
5050
struct rtc_device *rtc = to_rtc_device(dev);
5151
struct rtc_time tm;
5252
struct timespec delta, delta_delta;
53+
54+
if (has_persistent_clock())
55+
return 0;
56+
5357
if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
5458
return 0;
5559

@@ -88,6 +92,9 @@ static int rtc_resume(struct device *dev)
8892
struct timespec new_system, new_rtc;
8993
struct timespec sleep_time;
9094

95+
if (has_persistent_clock())
96+
return 0;
97+
9198
rtc_hctosys_ret = -ENODEV;
9299
if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
93100
return 0;

‎drivers/rtc/systohc.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify it
3+
* under the terms of the GNU General Public License version 2 as published by
4+
* the Free Software Foundation.
5+
*
6+
*/
7+
#include <linux/rtc.h>
8+
#include <linux/time.h>
9+
10+
/**
11+
* rtc_set_ntp_time - Save NTP synchronized time to the RTC
12+
* @now: Current time of day
13+
*
14+
* Replacement for the NTP platform function update_persistent_clock
15+
* that stores time for later retrieval by rtc_hctosys.
16+
*
17+
* Returns 0 on successful RTC update, -ENODEV if a RTC update is not
18+
* possible at all, and various other -errno for specific temporary failure
19+
* cases.
20+
*
21+
* If temporary failure is indicated the caller should try again 'soon'
22+
*/
23+
int rtc_set_ntp_time(struct timespec now)
24+
{
25+
struct rtc_device *rtc;
26+
struct rtc_time tm;
27+
int err = -ENODEV;
28+
29+
if (now.tv_nsec < (NSEC_PER_SEC >> 1))
30+
rtc_time_to_tm(now.tv_sec, &tm);
31+
else
32+
rtc_time_to_tm(now.tv_sec + 1, &tm);
33+
34+
rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
35+
if (rtc) {
36+
/* rtc_hctosys exclusively uses UTC, so we call set_time here,
37+
* not set_mmss. */
38+
if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss))
39+
err = rtc_set_time(rtc, &tm);
40+
rtc_class_close(rtc);
41+
}
42+
43+
return err;
44+
}

‎fs/pstore/ram.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
167167
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz)
168168
{
169169
char *hdr;
170-
struct timeval timestamp;
170+
struct timespec timestamp;
171171
size_t len;
172172

173-
do_gettimeofday(&timestamp);
173+
/* Report zeroed timestamp if called before timekeeping has resumed. */
174+
if (__getnstimeofday(&timestamp)) {
175+
timestamp.tv_sec = 0;
176+
timestamp.tv_nsec = 0;
177+
}
174178
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu\n",
175-
(long)timestamp.tv_sec, (long)timestamp.tv_usec);
179+
(long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000));
176180
WARN_ON_ONCE(!hdr);
177181
len = hdr ? strlen(hdr) : 0;
178182
persistent_ram_write(prz, hdr, len);

‎include/linux/rtc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ extern void rtc_device_unregister(struct rtc_device *rtc);
138138
extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
139139
extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
140140
extern int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs);
141+
extern int rtc_set_ntp_time(struct timespec now);
141142
int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm);
142143
extern int rtc_read_alarm(struct rtc_device *rtc,
143144
struct rtc_wkalrm *alrm);

0 commit comments

Comments
 (0)