diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-19 22:05:45 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-19 22:05:45 -0500 |
commit | 266d7ad7f4fe2f44b91561f5b812115c1b3018ab (patch) | |
tree | 45acf12d5cb170205ccffe24b9f24672ff8bff2e /kernel/time | |
parent | bcbd818c069b9e1bf82517401225b152a33968e2 (diff) | |
parent | 36dfbbf136db0d645bacfd42ce7d9d6928ea532d (diff) |
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer changes from Ingo Molnar:
"Main changes:
- ntp: Add CONFIG_RTC_SYSTOHC: a generic RTC driver facility
complementing the existing CONFIG_RTC_HCTOSYS, which uses NTP to
keep the hardware clock updated.
- posix-timers: Fix clock_adjtime to always return timex data on
success. This is changing the ABI, but no breakage was expected
and found - caution is warranted nevertheless.
- platform persistent clock improvements/cleanups.
- clockevents: refactor timer broadcast handling to be more generic
and less duplicated with matching architecture code (mostly ARM
motivated.)
- various fixes and cleanups"
* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
timers/x86/hpet: Use HPET_COUNTER to specify the hpet counter in vread_hpet()
posix-cpu-timers: Fix nanosleep task_struct leak
clockevents: Fix generic broadcast for FEAT_C3STOP
time, Fix setting of hardware clock in NTP code
hrtimer: Prevent hrtimer_enqueue_reprogram race
clockevents: Add generic timer broadcast function
clockevents: Add generic timer broadcast receiver
timekeeping: Switch HAS_PERSISTENT_CLOCK to ALWAYS_USE_PERSISTENT_CLOCK
x86/time/rtc: Don't print extended CMOS year when reading RTC
x86: Select HAS_PERSISTENT_CLOCK on x86
timekeeping: Add CONFIG_HAS_PERSISTENT_CLOCK option
rtc: Skip the suspend/resume handling if persistent clock exist
timekeeping: Add persistent_clock_exist flag
posix-timers: Fix clock_adjtime to always return timex data on success
Round the calculated scale factor in set_cyc2ns_scale()
NTP: Add a CONFIG_RTC_SYSTOHC configuration
MAINTAINERS: Update John Stultz's email
time: create __getnstimeofday for WARNless calls
Diffstat (limited to 'kernel/time')
-rw-r--r-- | kernel/time/Kconfig | 9 | ||||
-rw-r--r-- | kernel/time/ntp.c | 22 | ||||
-rw-r--r-- | kernel/time/tick-broadcast.c | 38 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 45 |
4 files changed, 98 insertions, 16 deletions
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index 8601f0db1261..24510d84efd7 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig | |||
@@ -12,6 +12,11 @@ config CLOCKSOURCE_WATCHDOG | |||
12 | config ARCH_CLOCKSOURCE_DATA | 12 | config ARCH_CLOCKSOURCE_DATA |
13 | bool | 13 | bool |
14 | 14 | ||
15 | # Platforms has a persistent clock | ||
16 | config ALWAYS_USE_PERSISTENT_CLOCK | ||
17 | bool | ||
18 | default n | ||
19 | |||
15 | # Timekeeping vsyscall support | 20 | # Timekeeping vsyscall support |
16 | config GENERIC_TIME_VSYSCALL | 21 | config GENERIC_TIME_VSYSCALL |
17 | bool | 22 | bool |
@@ -38,6 +43,10 @@ config GENERIC_CLOCKEVENTS_BUILD | |||
38 | default y | 43 | default y |
39 | depends on GENERIC_CLOCKEVENTS | 44 | depends on GENERIC_CLOCKEVENTS |
40 | 45 | ||
46 | # Architecture can handle broadcast in a driver-agnostic way | ||
47 | config ARCH_HAS_TICK_BROADCAST | ||
48 | bool | ||
49 | |||
41 | # Clockevents broadcasting infrastructure | 50 | # Clockevents broadcasting infrastructure |
42 | config GENERIC_CLOCKEVENTS_BROADCAST | 51 | config GENERIC_CLOCKEVENTS_BROADCAST |
43 | bool | 52 | bool |
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 24174b4d669b..b10a42bb0165 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/time.h> | 15 | #include <linux/time.h> |
16 | #include <linux/mm.h> | 16 | #include <linux/mm.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/rtc.h> | ||
18 | 19 | ||
19 | #include "tick-internal.h" | 20 | #include "tick-internal.h" |
20 | 21 | ||
@@ -483,8 +484,7 @@ out: | |||
483 | return leap; | 484 | return leap; |
484 | } | 485 | } |
485 | 486 | ||
486 | #ifdef CONFIG_GENERIC_CMOS_UPDATE | 487 | #if defined(CONFIG_GENERIC_CMOS_UPDATE) || defined(CONFIG_RTC_SYSTOHC) |
487 | |||
488 | static void sync_cmos_clock(struct work_struct *work); | 488 | static void sync_cmos_clock(struct work_struct *work); |
489 | 489 | ||
490 | static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock); | 490 | static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock); |
@@ -510,14 +510,26 @@ static void sync_cmos_clock(struct work_struct *work) | |||
510 | } | 510 | } |
511 | 511 | ||
512 | getnstimeofday(&now); | 512 | getnstimeofday(&now); |
513 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) | 513 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) { |
514 | fail = update_persistent_clock(now); | 514 | struct timespec adjust = now; |
515 | |||
516 | fail = -ENODEV; | ||
517 | if (persistent_clock_is_local) | ||
518 | adjust.tv_sec -= (sys_tz.tz_minuteswest * 60); | ||
519 | #ifdef CONFIG_GENERIC_CMOS_UPDATE | ||
520 | fail = update_persistent_clock(adjust); | ||
521 | #endif | ||
522 | #ifdef CONFIG_RTC_SYSTOHC | ||
523 | if (fail == -ENODEV) | ||
524 | fail = rtc_set_ntp_time(adjust); | ||
525 | #endif | ||
526 | } | ||
515 | 527 | ||
516 | next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2); | 528 | next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2); |
517 | if (next.tv_nsec <= 0) | 529 | if (next.tv_nsec <= 0) |
518 | next.tv_nsec += NSEC_PER_SEC; | 530 | next.tv_nsec += NSEC_PER_SEC; |
519 | 531 | ||
520 | if (!fail) | 532 | if (!fail || fail == -ENODEV) |
521 | next.tv_sec = 659; | 533 | next.tv_sec = 659; |
522 | else | 534 | else |
523 | next.tv_sec = 0; | 535 | next.tv_sec = 0; |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index f113755695e2..2fb8cb88df8d 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/profile.h> | 19 | #include <linux/profile.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/smp.h> | ||
21 | 22 | ||
22 | #include "tick-internal.h" | 23 | #include "tick-internal.h" |
23 | 24 | ||
@@ -86,6 +87,22 @@ int tick_is_broadcast_device(struct clock_event_device *dev) | |||
86 | return (dev && tick_broadcast_device.evtdev == dev); | 87 | return (dev && tick_broadcast_device.evtdev == dev); |
87 | } | 88 | } |
88 | 89 | ||
90 | static void err_broadcast(const struct cpumask *mask) | ||
91 | { | ||
92 | pr_crit_once("Failed to broadcast timer tick. Some CPUs may be unresponsive.\n"); | ||
93 | } | ||
94 | |||
95 | static void tick_device_setup_broadcast_func(struct clock_event_device *dev) | ||
96 | { | ||
97 | if (!dev->broadcast) | ||
98 | dev->broadcast = tick_broadcast; | ||
99 | if (!dev->broadcast) { | ||
100 | pr_warn_once("%s depends on broadcast, but no broadcast function available\n", | ||
101 | dev->name); | ||
102 | dev->broadcast = err_broadcast; | ||
103 | } | ||
104 | } | ||
105 | |||
89 | /* | 106 | /* |
90 | * Check, if the device is disfunctional and a place holder, which | 107 | * Check, if the device is disfunctional and a place holder, which |
91 | * needs to be handled by the broadcast device. | 108 | * needs to be handled by the broadcast device. |
@@ -105,6 +122,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) | |||
105 | */ | 122 | */ |
106 | if (!tick_device_is_functional(dev)) { | 123 | if (!tick_device_is_functional(dev)) { |
107 | dev->event_handler = tick_handle_periodic; | 124 | dev->event_handler = tick_handle_periodic; |
125 | tick_device_setup_broadcast_func(dev); | ||
108 | cpumask_set_cpu(cpu, tick_get_broadcast_mask()); | 126 | cpumask_set_cpu(cpu, tick_get_broadcast_mask()); |
109 | tick_broadcast_start_periodic(tick_broadcast_device.evtdev); | 127 | tick_broadcast_start_periodic(tick_broadcast_device.evtdev); |
110 | ret = 1; | 128 | ret = 1; |
@@ -116,15 +134,33 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) | |||
116 | */ | 134 | */ |
117 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) { | 135 | if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) { |
118 | int cpu = smp_processor_id(); | 136 | int cpu = smp_processor_id(); |
119 | |||
120 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); | 137 | cpumask_clear_cpu(cpu, tick_get_broadcast_mask()); |
121 | tick_broadcast_clear_oneshot(cpu); | 138 | tick_broadcast_clear_oneshot(cpu); |
139 | } else { | ||
140 | tick_device_setup_broadcast_func(dev); | ||
122 | } | 141 | } |
123 | } | 142 | } |
124 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); | 143 | raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
125 | return ret; | 144 | return ret; |
126 | } | 145 | } |
127 | 146 | ||
147 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST | ||
148 | int tick_receive_broadcast(void) | ||
149 | { | ||
150 | struct tick_device *td = this_cpu_ptr(&tick_cpu_device); | ||
151 | struct clock_event_device *evt = td->evtdev; | ||
152 | |||
153 | if (!evt) | ||
154 | return -ENODEV; | ||
155 | |||
156 | if (!evt->event_handler) | ||
157 | return -EINVAL; | ||
158 | |||
159 | evt->event_handler(evt); | ||
160 | return 0; | ||
161 | } | ||
162 | #endif | ||
163 | |||
128 | /* | 164 | /* |
129 | * Broadcast the event to the cpus, which are set in the mask (mangled). | 165 | * Broadcast the event to the cpus, which are set in the mask (mangled). |
130 | */ | 166 | */ |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index cbc6acb0db3f..1e35515a875e 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -29,6 +29,9 @@ static struct timekeeper timekeeper; | |||
29 | /* flag for if timekeeping is suspended */ | 29 | /* flag for if timekeeping is suspended */ |
30 | int __read_mostly timekeeping_suspended; | 30 | int __read_mostly timekeeping_suspended; |
31 | 31 | ||
32 | /* Flag for if there is a persistent clock on this platform */ | ||
33 | bool __read_mostly persistent_clock_exist = false; | ||
34 | |||
32 | static inline void tk_normalize_xtime(struct timekeeper *tk) | 35 | static inline void tk_normalize_xtime(struct timekeeper *tk) |
33 | { | 36 | { |
34 | while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) { | 37 | while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) { |
@@ -264,19 +267,18 @@ static void timekeeping_forward_now(struct timekeeper *tk) | |||
264 | } | 267 | } |
265 | 268 | ||
266 | /** | 269 | /** |
267 | * getnstimeofday - Returns the time of day in a timespec | 270 | * __getnstimeofday - Returns the time of day in a timespec. |
268 | * @ts: pointer to the timespec to be set | 271 | * @ts: pointer to the timespec to be set |
269 | * | 272 | * |
270 | * Returns the time of day in a timespec. | 273 | * Updates the time of day in the timespec. |
274 | * Returns 0 on success, or -ve when suspended (timespec will be undefined). | ||
271 | */ | 275 | */ |
272 | void getnstimeofday(struct timespec *ts) | 276 | int __getnstimeofday(struct timespec *ts) |
273 | { | 277 | { |
274 | struct timekeeper *tk = &timekeeper; | 278 | struct timekeeper *tk = &timekeeper; |
275 | unsigned long seq; | 279 | unsigned long seq; |
276 | s64 nsecs = 0; | 280 | s64 nsecs = 0; |
277 | 281 | ||
278 | WARN_ON(timekeeping_suspended); | ||
279 | |||
280 | do { | 282 | do { |
281 | seq = read_seqbegin(&tk->lock); | 283 | seq = read_seqbegin(&tk->lock); |
282 | 284 | ||
@@ -287,6 +289,26 @@ void getnstimeofday(struct timespec *ts) | |||
287 | 289 | ||
288 | ts->tv_nsec = 0; | 290 | ts->tv_nsec = 0; |
289 | timespec_add_ns(ts, nsecs); | 291 | timespec_add_ns(ts, nsecs); |
292 | |||
293 | /* | ||
294 | * Do not bail out early, in case there were callers still using | ||
295 | * the value, even in the face of the WARN_ON. | ||
296 | */ | ||
297 | if (unlikely(timekeeping_suspended)) | ||
298 | return -EAGAIN; | ||
299 | return 0; | ||
300 | } | ||
301 | EXPORT_SYMBOL(__getnstimeofday); | ||
302 | |||
303 | /** | ||
304 | * getnstimeofday - Returns the time of day in a timespec. | ||
305 | * @ts: pointer to the timespec to be set | ||
306 | * | ||
307 | * Returns the time of day in a timespec (WARN if suspended). | ||
308 | */ | ||
309 | void getnstimeofday(struct timespec *ts) | ||
310 | { | ||
311 | WARN_ON(__getnstimeofday(ts)); | ||
290 | } | 312 | } |
291 | EXPORT_SYMBOL(getnstimeofday); | 313 | EXPORT_SYMBOL(getnstimeofday); |
292 | 314 | ||
@@ -640,12 +662,14 @@ void __init timekeeping_init(void) | |||
640 | struct timespec now, boot, tmp; | 662 | struct timespec now, boot, tmp; |
641 | 663 | ||
642 | read_persistent_clock(&now); | 664 | read_persistent_clock(&now); |
665 | |||
643 | if (!timespec_valid_strict(&now)) { | 666 | if (!timespec_valid_strict(&now)) { |
644 | pr_warn("WARNING: Persistent clock returned invalid value!\n" | 667 | pr_warn("WARNING: Persistent clock returned invalid value!\n" |
645 | " Check your CMOS/BIOS settings.\n"); | 668 | " Check your CMOS/BIOS settings.\n"); |
646 | now.tv_sec = 0; | 669 | now.tv_sec = 0; |
647 | now.tv_nsec = 0; | 670 | now.tv_nsec = 0; |
648 | } | 671 | } else if (now.tv_sec || now.tv_nsec) |
672 | persistent_clock_exist = true; | ||
649 | 673 | ||
650 | read_boot_clock(&boot); | 674 | read_boot_clock(&boot); |
651 | if (!timespec_valid_strict(&boot)) { | 675 | if (!timespec_valid_strict(&boot)) { |
@@ -718,11 +742,12 @@ void timekeeping_inject_sleeptime(struct timespec *delta) | |||
718 | { | 742 | { |
719 | struct timekeeper *tk = &timekeeper; | 743 | struct timekeeper *tk = &timekeeper; |
720 | unsigned long flags; | 744 | unsigned long flags; |
721 | struct timespec ts; | ||
722 | 745 | ||
723 | /* Make sure we don't set the clock twice */ | 746 | /* |
724 | read_persistent_clock(&ts); | 747 | * Make sure we don't set the clock twice, as timekeeping_resume() |
725 | if (!(ts.tv_sec == 0 && ts.tv_nsec == 0)) | 748 | * already did it |
749 | */ | ||
750 | if (has_persistent_clock()) | ||
726 | return; | 751 | return; |
727 | 752 | ||
728 | write_seqlock_irqsave(&tk->lock, flags); | 753 | write_seqlock_irqsave(&tk->lock, flags); |