diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-09 19:33:07 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-09 19:33:07 -0500 |
commit | 0ba97bc4b4b054b71cd348dab838a7545a27b893 (patch) | |
tree | 6ceac2634bbf46410ddc015c98689c150e1e8571 | |
parent | 5b9b28a63f2e47dac5ff3a2503bfe3ade8796aa0 (diff) | |
parent | 4ebbda5251374d532ba8939de4241d769d1420b6 (diff) |
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Ingo Molnar:
"The main changes in this cycle were:
- rework hrtimer expiry calculation in hrtimer_interrupt(): the
previous code had a subtle bug where expiry caching would miss an
expiry, resulting in occasional bogus (late) expiry of hrtimers.
- continuing Y2038 fixes
- ktime division optimization
- misc smaller fixes and cleanups"
* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
hrtimer: Make __hrtimer_get_next_event() static
rtc: Convert rtc_set_ntp_time() to use timespec64
rtc: Remove redundant rtc_valid_tm() from rtc_hctosys()
rtc: Modify rtc_hctosys() to address y2038 issues
rtc: Update rtc-dev to use y2038-safe time interfaces
rtc: Update interface.c to use y2038-safe time interfaces
time: Expose get_monotonic_boottime64 for in-kernel use
time: Expose getboottime64 for in-kernel uses
ktime: Optimize ktime_divns for constant divisors
hrtimer: Prevent stale expiry time in hrtimer_interrupt()
ktime.h: Introduce ktime_ms_delta
-rw-r--r-- | drivers/rtc/hctosys.c | 18 | ||||
-rw-r--r-- | drivers/rtc/interface.c | 22 | ||||
-rw-r--r-- | drivers/rtc/rtc-dev.c | 8 | ||||
-rw-r--r-- | drivers/rtc/systohc.c | 6 | ||||
-rw-r--r-- | include/linux/hrtimer.h | 2 | ||||
-rw-r--r-- | include/linux/ktime.h | 17 | ||||
-rw-r--r-- | include/linux/rtc.h | 2 | ||||
-rw-r--r-- | include/linux/timekeeping.h | 21 | ||||
-rw-r--r-- | kernel/time/hrtimer.c | 112 | ||||
-rw-r--r-- | kernel/time/ntp.c | 4 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 12 |
11 files changed, 120 insertions, 104 deletions
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index 4aa60d74004e..6c719f23520a 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c | |||
@@ -26,7 +26,7 @@ static int __init rtc_hctosys(void) | |||
26 | { | 26 | { |
27 | int err = -ENODEV; | 27 | int err = -ENODEV; |
28 | struct rtc_time tm; | 28 | struct rtc_time tm; |
29 | struct timespec tv = { | 29 | struct timespec64 tv64 = { |
30 | .tv_nsec = NSEC_PER_SEC >> 1, | 30 | .tv_nsec = NSEC_PER_SEC >> 1, |
31 | }; | 31 | }; |
32 | struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); | 32 | struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); |
@@ -45,25 +45,17 @@ static int __init rtc_hctosys(void) | |||
45 | 45 | ||
46 | } | 46 | } |
47 | 47 | ||
48 | err = rtc_valid_tm(&tm); | 48 | tv64.tv_sec = rtc_tm_to_time64(&tm); |
49 | if (err) { | ||
50 | dev_err(rtc->dev.parent, | ||
51 | "hctosys: invalid date/time\n"); | ||
52 | goto err_invalid; | ||
53 | } | ||
54 | |||
55 | rtc_tm_to_time(&tm, &tv.tv_sec); | ||
56 | 49 | ||
57 | err = do_settimeofday(&tv); | 50 | err = do_settimeofday64(&tv64); |
58 | 51 | ||
59 | dev_info(rtc->dev.parent, | 52 | dev_info(rtc->dev.parent, |
60 | "setting system clock to " | 53 | "setting system clock to " |
61 | "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", | 54 | "%d-%02d-%02d %02d:%02d:%02d UTC (%lld)\n", |
62 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | 55 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, |
63 | tm.tm_hour, tm.tm_min, tm.tm_sec, | 56 | tm.tm_hour, tm.tm_min, tm.tm_sec, |
64 | (unsigned int) tv.tv_sec); | 57 | (long long) tv64.tv_sec); |
65 | 58 | ||
66 | err_invalid: | ||
67 | err_read: | 59 | err_read: |
68 | rtc_class_close(rtc); | 60 | rtc_class_close(rtc); |
69 | 61 | ||
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 45bfc28ee3aa..37215cf983e9 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
@@ -73,10 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) | |||
73 | else if (rtc->ops->set_time) | 73 | else if (rtc->ops->set_time) |
74 | err = rtc->ops->set_time(rtc->dev.parent, tm); | 74 | err = rtc->ops->set_time(rtc->dev.parent, tm); |
75 | else if (rtc->ops->set_mmss) { | 75 | else if (rtc->ops->set_mmss) { |
76 | unsigned long secs; | 76 | time64_t secs64 = rtc_tm_to_time64(tm); |
77 | err = rtc_tm_to_time(tm, &secs); | 77 | err = rtc->ops->set_mmss(rtc->dev.parent, secs64); |
78 | if (err == 0) | ||
79 | err = rtc->ops->set_mmss(rtc->dev.parent, secs); | ||
80 | } else | 78 | } else |
81 | err = -EINVAL; | 79 | err = -EINVAL; |
82 | 80 | ||
@@ -105,7 +103,7 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) | |||
105 | 103 | ||
106 | err = rtc->ops->read_time(rtc->dev.parent, &old); | 104 | err = rtc->ops->read_time(rtc->dev.parent, &old); |
107 | if (err == 0) { | 105 | if (err == 0) { |
108 | rtc_time_to_tm(secs, &new); | 106 | rtc_time64_to_tm(secs, &new); |
109 | 107 | ||
110 | /* | 108 | /* |
111 | * avoid writing when we're going to change the day of | 109 | * avoid writing when we're going to change the day of |
@@ -157,7 +155,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
157 | int err; | 155 | int err; |
158 | struct rtc_time before, now; | 156 | struct rtc_time before, now; |
159 | int first_time = 1; | 157 | int first_time = 1; |
160 | unsigned long t_now, t_alm; | 158 | time64_t t_now, t_alm; |
161 | enum { none, day, month, year } missing = none; | 159 | enum { none, day, month, year } missing = none; |
162 | unsigned days; | 160 | unsigned days; |
163 | 161 | ||
@@ -258,8 +256,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
258 | } | 256 | } |
259 | 257 | ||
260 | /* with luck, no rollover is needed */ | 258 | /* with luck, no rollover is needed */ |
261 | rtc_tm_to_time(&now, &t_now); | 259 | t_now = rtc_tm_to_time64(&now); |
262 | rtc_tm_to_time(&alarm->time, &t_alm); | 260 | t_alm = rtc_tm_to_time64(&alarm->time); |
263 | if (t_now < t_alm) | 261 | if (t_now < t_alm) |
264 | goto done; | 262 | goto done; |
265 | 263 | ||
@@ -273,7 +271,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
273 | case day: | 271 | case day: |
274 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day"); | 272 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day"); |
275 | t_alm += 24 * 60 * 60; | 273 | t_alm += 24 * 60 * 60; |
276 | rtc_time_to_tm(t_alm, &alarm->time); | 274 | rtc_time64_to_tm(t_alm, &alarm->time); |
277 | break; | 275 | break; |
278 | 276 | ||
279 | /* Month rollover ... if it's the 31th, an alarm on the 3rd will | 277 | /* Month rollover ... if it's the 31th, an alarm on the 3rd will |
@@ -346,19 +344,19 @@ EXPORT_SYMBOL_GPL(rtc_read_alarm); | |||
346 | static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | 344 | static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
347 | { | 345 | { |
348 | struct rtc_time tm; | 346 | struct rtc_time tm; |
349 | long now, scheduled; | 347 | time64_t now, scheduled; |
350 | int err; | 348 | int err; |
351 | 349 | ||
352 | err = rtc_valid_tm(&alarm->time); | 350 | err = rtc_valid_tm(&alarm->time); |
353 | if (err) | 351 | if (err) |
354 | return err; | 352 | return err; |
355 | rtc_tm_to_time(&alarm->time, &scheduled); | 353 | scheduled = rtc_tm_to_time64(&alarm->time); |
356 | 354 | ||
357 | /* Make sure we're not setting alarms in the past */ | 355 | /* Make sure we're not setting alarms in the past */ |
358 | err = __rtc_read_time(rtc, &tm); | 356 | err = __rtc_read_time(rtc, &tm); |
359 | if (err) | 357 | if (err) |
360 | return err; | 358 | return err; |
361 | rtc_tm_to_time(&tm, &now); | 359 | now = rtc_tm_to_time64(&tm); |
362 | if (scheduled <= now) | 360 | if (scheduled <= now) |
363 | return -ETIME; | 361 | return -ETIME; |
364 | /* | 362 | /* |
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index d04939369251..799c34bcb26f 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c | |||
@@ -304,12 +304,12 @@ static long rtc_dev_ioctl(struct file *file, | |||
304 | * Not supported here. | 304 | * Not supported here. |
305 | */ | 305 | */ |
306 | { | 306 | { |
307 | unsigned long now, then; | 307 | time64_t now, then; |
308 | 308 | ||
309 | err = rtc_read_time(rtc, &tm); | 309 | err = rtc_read_time(rtc, &tm); |
310 | if (err < 0) | 310 | if (err < 0) |
311 | return err; | 311 | return err; |
312 | rtc_tm_to_time(&tm, &now); | 312 | now = rtc_tm_to_time64(&tm); |
313 | 313 | ||
314 | alarm.time.tm_mday = tm.tm_mday; | 314 | alarm.time.tm_mday = tm.tm_mday; |
315 | alarm.time.tm_mon = tm.tm_mon; | 315 | alarm.time.tm_mon = tm.tm_mon; |
@@ -317,11 +317,11 @@ static long rtc_dev_ioctl(struct file *file, | |||
317 | err = rtc_valid_tm(&alarm.time); | 317 | err = rtc_valid_tm(&alarm.time); |
318 | if (err < 0) | 318 | if (err < 0) |
319 | return err; | 319 | return err; |
320 | rtc_tm_to_time(&alarm.time, &then); | 320 | then = rtc_tm_to_time64(&alarm.time); |
321 | 321 | ||
322 | /* alarm may need to wrap into tomorrow */ | 322 | /* alarm may need to wrap into tomorrow */ |
323 | if (then < now) { | 323 | if (then < now) { |
324 | rtc_time_to_tm(now + 24 * 60 * 60, &tm); | 324 | rtc_time64_to_tm(now + 24 * 60 * 60, &tm); |
325 | alarm.time.tm_mday = tm.tm_mday; | 325 | alarm.time.tm_mday = tm.tm_mday; |
326 | alarm.time.tm_mon = tm.tm_mon; | 326 | alarm.time.tm_mon = tm.tm_mon; |
327 | alarm.time.tm_year = tm.tm_year; | 327 | alarm.time.tm_year = tm.tm_year; |
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c index bf3e242ccc5c..eb71872d0361 100644 --- a/drivers/rtc/systohc.c +++ b/drivers/rtc/systohc.c | |||
@@ -20,16 +20,16 @@ | |||
20 | * | 20 | * |
21 | * If temporary failure is indicated the caller should try again 'soon' | 21 | * If temporary failure is indicated the caller should try again 'soon' |
22 | */ | 22 | */ |
23 | int rtc_set_ntp_time(struct timespec now) | 23 | int rtc_set_ntp_time(struct timespec64 now) |
24 | { | 24 | { |
25 | struct rtc_device *rtc; | 25 | struct rtc_device *rtc; |
26 | struct rtc_time tm; | 26 | struct rtc_time tm; |
27 | int err = -ENODEV; | 27 | int err = -ENODEV; |
28 | 28 | ||
29 | if (now.tv_nsec < (NSEC_PER_SEC >> 1)) | 29 | if (now.tv_nsec < (NSEC_PER_SEC >> 1)) |
30 | rtc_time_to_tm(now.tv_sec, &tm); | 30 | rtc_time64_to_tm(now.tv_sec, &tm); |
31 | else | 31 | else |
32 | rtc_time_to_tm(now.tv_sec + 1, &tm); | 32 | rtc_time64_to_tm(now.tv_sec + 1, &tm); |
33 | 33 | ||
34 | rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); | 34 | rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); |
35 | if (rtc) { | 35 | if (rtc) { |
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index a036d058a249..05f6df1fdf5b 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h | |||
@@ -170,6 +170,7 @@ enum hrtimer_base_type { | |||
170 | * @clock_was_set: Indicates that clock was set from irq context. | 170 | * @clock_was_set: Indicates that clock was set from irq context. |
171 | * @expires_next: absolute time of the next event which was scheduled | 171 | * @expires_next: absolute time of the next event which was scheduled |
172 | * via clock_set_next_event() | 172 | * via clock_set_next_event() |
173 | * @in_hrtirq: hrtimer_interrupt() is currently executing | ||
173 | * @hres_active: State of high resolution mode | 174 | * @hres_active: State of high resolution mode |
174 | * @hang_detected: The last hrtimer interrupt detected a hang | 175 | * @hang_detected: The last hrtimer interrupt detected a hang |
175 | * @nr_events: Total number of hrtimer interrupt events | 176 | * @nr_events: Total number of hrtimer interrupt events |
@@ -185,6 +186,7 @@ struct hrtimer_cpu_base { | |||
185 | unsigned int clock_was_set; | 186 | unsigned int clock_was_set; |
186 | #ifdef CONFIG_HIGH_RES_TIMERS | 187 | #ifdef CONFIG_HIGH_RES_TIMERS |
187 | ktime_t expires_next; | 188 | ktime_t expires_next; |
189 | int in_hrtirq; | ||
188 | int hres_active; | 190 | int hres_active; |
189 | int hang_detected; | 191 | int hang_detected; |
190 | unsigned long nr_events; | 192 | unsigned long nr_events; |
diff --git a/include/linux/ktime.h b/include/linux/ktime.h index c9d645ad98ff..5fc3d1083071 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h | |||
@@ -166,7 +166,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | #if BITS_PER_LONG < 64 | 168 | #if BITS_PER_LONG < 64 |
169 | extern u64 ktime_divns(const ktime_t kt, s64 div); | 169 | extern u64 __ktime_divns(const ktime_t kt, s64 div); |
170 | static inline u64 ktime_divns(const ktime_t kt, s64 div) | ||
171 | { | ||
172 | if (__builtin_constant_p(div) && !(div >> 32)) { | ||
173 | u64 ns = kt.tv64; | ||
174 | do_div(ns, div); | ||
175 | return ns; | ||
176 | } else { | ||
177 | return __ktime_divns(kt, div); | ||
178 | } | ||
179 | } | ||
170 | #else /* BITS_PER_LONG < 64 */ | 180 | #else /* BITS_PER_LONG < 64 */ |
171 | # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) | 181 | # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) |
172 | #endif | 182 | #endif |
@@ -186,6 +196,11 @@ static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier) | |||
186 | return ktime_to_us(ktime_sub(later, earlier)); | 196 | return ktime_to_us(ktime_sub(later, earlier)); |
187 | } | 197 | } |
188 | 198 | ||
199 | static inline s64 ktime_ms_delta(const ktime_t later, const ktime_t earlier) | ||
200 | { | ||
201 | return ktime_to_ms(ktime_sub(later, earlier)); | ||
202 | } | ||
203 | |||
189 | static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec) | 204 | static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec) |
190 | { | 205 | { |
191 | return ktime_add_ns(kt, usec * NSEC_PER_USEC); | 206 | return ktime_add_ns(kt, usec * NSEC_PER_USEC); |
diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 6d6be09a2fe5..dcad7ee0d746 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h | |||
@@ -161,7 +161,7 @@ extern void devm_rtc_device_unregister(struct device *dev, | |||
161 | extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm); | 161 | extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm); |
162 | extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm); | 162 | extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm); |
163 | extern int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs); | 163 | extern int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs); |
164 | extern int rtc_set_ntp_time(struct timespec now); | 164 | extern int rtc_set_ntp_time(struct timespec64 now); |
165 | int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm); | 165 | int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm); |
166 | extern int rtc_read_alarm(struct rtc_device *rtc, | 166 | extern int rtc_read_alarm(struct rtc_device *rtc, |
167 | struct rtc_wkalrm *alrm); | 167 | struct rtc_wkalrm *alrm); |
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 9b63d13ba82b..3eaae4754275 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h | |||
@@ -33,6 +33,7 @@ extern time64_t ktime_get_real_seconds(void); | |||
33 | 33 | ||
34 | extern int __getnstimeofday64(struct timespec64 *tv); | 34 | extern int __getnstimeofday64(struct timespec64 *tv); |
35 | extern void getnstimeofday64(struct timespec64 *tv); | 35 | extern void getnstimeofday64(struct timespec64 *tv); |
36 | extern void getboottime64(struct timespec64 *ts); | ||
36 | 37 | ||
37 | #if BITS_PER_LONG == 64 | 38 | #if BITS_PER_LONG == 64 |
38 | /** | 39 | /** |
@@ -72,6 +73,11 @@ static inline struct timespec get_monotonic_coarse(void) | |||
72 | { | 73 | { |
73 | return get_monotonic_coarse64(); | 74 | return get_monotonic_coarse64(); |
74 | } | 75 | } |
76 | |||
77 | static inline void getboottime(struct timespec *ts) | ||
78 | { | ||
79 | return getboottime64(ts); | ||
80 | } | ||
75 | #else | 81 | #else |
76 | /** | 82 | /** |
77 | * Deprecated. Use do_settimeofday64(). | 83 | * Deprecated. Use do_settimeofday64(). |
@@ -129,9 +135,15 @@ static inline struct timespec get_monotonic_coarse(void) | |||
129 | { | 135 | { |
130 | return timespec64_to_timespec(get_monotonic_coarse64()); | 136 | return timespec64_to_timespec(get_monotonic_coarse64()); |
131 | } | 137 | } |
132 | #endif | ||
133 | 138 | ||
134 | extern void getboottime(struct timespec *ts); | 139 | static inline void getboottime(struct timespec *ts) |
140 | { | ||
141 | struct timespec64 ts64; | ||
142 | |||
143 | getboottime64(&ts64); | ||
144 | *ts = timespec64_to_timespec(ts64); | ||
145 | } | ||
146 | #endif | ||
135 | 147 | ||
136 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) | 148 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) |
137 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) | 149 | #define ktime_get_real_ts64(ts) getnstimeofday64(ts) |
@@ -217,6 +229,11 @@ static inline void get_monotonic_boottime(struct timespec *ts) | |||
217 | *ts = ktime_to_timespec(ktime_get_boottime()); | 229 | *ts = ktime_to_timespec(ktime_get_boottime()); |
218 | } | 230 | } |
219 | 231 | ||
232 | static inline void get_monotonic_boottime64(struct timespec64 *ts) | ||
233 | { | ||
234 | *ts = ktime_to_timespec64(ktime_get_boottime()); | ||
235 | } | ||
236 | |||
220 | static inline void timekeeping_clocktai(struct timespec *ts) | 237 | static inline void timekeeping_clocktai(struct timespec *ts) |
221 | { | 238 | { |
222 | *ts = ktime_to_timespec(ktime_get_clocktai()); | 239 | *ts = ktime_to_timespec(ktime_get_clocktai()); |
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index d8c724cda37b..3f5e183c3d97 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c | |||
@@ -266,7 +266,7 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags) | |||
266 | /* | 266 | /* |
267 | * Divide a ktime value by a nanosecond value | 267 | * Divide a ktime value by a nanosecond value |
268 | */ | 268 | */ |
269 | u64 ktime_divns(const ktime_t kt, s64 div) | 269 | u64 __ktime_divns(const ktime_t kt, s64 div) |
270 | { | 270 | { |
271 | u64 dclc; | 271 | u64 dclc; |
272 | int sft = 0; | 272 | int sft = 0; |
@@ -282,7 +282,7 @@ u64 ktime_divns(const ktime_t kt, s64 div) | |||
282 | 282 | ||
283 | return dclc; | 283 | return dclc; |
284 | } | 284 | } |
285 | EXPORT_SYMBOL_GPL(ktime_divns); | 285 | EXPORT_SYMBOL_GPL(__ktime_divns); |
286 | #endif /* BITS_PER_LONG >= 64 */ | 286 | #endif /* BITS_PER_LONG >= 64 */ |
287 | 287 | ||
288 | /* | 288 | /* |
@@ -440,6 +440,37 @@ static inline void debug_deactivate(struct hrtimer *timer) | |||
440 | trace_hrtimer_cancel(timer); | 440 | trace_hrtimer_cancel(timer); |
441 | } | 441 | } |
442 | 442 | ||
443 | #if defined(CONFIG_NO_HZ_COMMON) || defined(CONFIG_HIGH_RES_TIMERS) | ||
444 | static ktime_t __hrtimer_get_next_event(struct hrtimer_cpu_base *cpu_base) | ||
445 | { | ||
446 | struct hrtimer_clock_base *base = cpu_base->clock_base; | ||
447 | ktime_t expires, expires_next = { .tv64 = KTIME_MAX }; | ||
448 | int i; | ||
449 | |||
450 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { | ||
451 | struct timerqueue_node *next; | ||
452 | struct hrtimer *timer; | ||
453 | |||
454 | next = timerqueue_getnext(&base->active); | ||
455 | if (!next) | ||
456 | continue; | ||
457 | |||
458 | timer = container_of(next, struct hrtimer, node); | ||
459 | expires = ktime_sub(hrtimer_get_expires(timer), base->offset); | ||
460 | if (expires.tv64 < expires_next.tv64) | ||
461 | expires_next = expires; | ||
462 | } | ||
463 | /* | ||
464 | * clock_was_set() might have changed base->offset of any of | ||
465 | * the clock bases so the result might be negative. Fix it up | ||
466 | * to prevent a false positive in clockevents_program_event(). | ||
467 | */ | ||
468 | if (expires_next.tv64 < 0) | ||
469 | expires_next.tv64 = 0; | ||
470 | return expires_next; | ||
471 | } | ||
472 | #endif | ||
473 | |||
443 | /* High resolution timer related functions */ | 474 | /* High resolution timer related functions */ |
444 | #ifdef CONFIG_HIGH_RES_TIMERS | 475 | #ifdef CONFIG_HIGH_RES_TIMERS |
445 | 476 | ||
@@ -488,32 +519,7 @@ static inline int hrtimer_hres_active(void) | |||
488 | static void | 519 | static void |
489 | hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) | 520 | hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) |
490 | { | 521 | { |
491 | int i; | 522 | ktime_t expires_next = __hrtimer_get_next_event(cpu_base); |
492 | struct hrtimer_clock_base *base = cpu_base->clock_base; | ||
493 | ktime_t expires, expires_next; | ||
494 | |||
495 | expires_next.tv64 = KTIME_MAX; | ||
496 | |||
497 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { | ||
498 | struct hrtimer *timer; | ||
499 | struct timerqueue_node *next; | ||
500 | |||
501 | next = timerqueue_getnext(&base->active); | ||
502 | if (!next) | ||
503 | continue; | ||
504 | timer = container_of(next, struct hrtimer, node); | ||
505 | |||
506 | expires = ktime_sub(hrtimer_get_expires(timer), base->offset); | ||
507 | /* | ||
508 | * clock_was_set() has changed base->offset so the | ||
509 | * result might be negative. Fix it up to prevent a | ||
510 | * false positive in clockevents_program_event() | ||
511 | */ | ||
512 | if (expires.tv64 < 0) | ||
513 | expires.tv64 = 0; | ||
514 | if (expires.tv64 < expires_next.tv64) | ||
515 | expires_next = expires; | ||
516 | } | ||
517 | 523 | ||
518 | if (skip_equal && expires_next.tv64 == cpu_base->expires_next.tv64) | 524 | if (skip_equal && expires_next.tv64 == cpu_base->expires_next.tv64) |
519 | return; | 525 | return; |
@@ -587,6 +593,15 @@ static int hrtimer_reprogram(struct hrtimer *timer, | |||
587 | return 0; | 593 | return 0; |
588 | 594 | ||
589 | /* | 595 | /* |
596 | * When the target cpu of the timer is currently executing | ||
597 | * hrtimer_interrupt(), then we do not touch the clock event | ||
598 | * device. hrtimer_interrupt() will reevaluate all clock bases | ||
599 | * before reprogramming the device. | ||
600 | */ | ||
601 | if (cpu_base->in_hrtirq) | ||
602 | return 0; | ||
603 | |||
604 | /* | ||
590 | * If a hang was detected in the last timer interrupt then we | 605 | * If a hang was detected in the last timer interrupt then we |
591 | * do not schedule a timer which is earlier than the expiry | 606 | * do not schedule a timer which is earlier than the expiry |
592 | * which we enforced in the hang detection. We want the system | 607 | * which we enforced in the hang detection. We want the system |
@@ -1104,29 +1119,14 @@ EXPORT_SYMBOL_GPL(hrtimer_get_remaining); | |||
1104 | ktime_t hrtimer_get_next_event(void) | 1119 | ktime_t hrtimer_get_next_event(void) |
1105 | { | 1120 | { |
1106 | struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); | 1121 | struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); |
1107 | struct hrtimer_clock_base *base = cpu_base->clock_base; | 1122 | ktime_t mindelta = { .tv64 = KTIME_MAX }; |
1108 | ktime_t delta, mindelta = { .tv64 = KTIME_MAX }; | ||
1109 | unsigned long flags; | 1123 | unsigned long flags; |
1110 | int i; | ||
1111 | 1124 | ||
1112 | raw_spin_lock_irqsave(&cpu_base->lock, flags); | 1125 | raw_spin_lock_irqsave(&cpu_base->lock, flags); |
1113 | 1126 | ||
1114 | if (!hrtimer_hres_active()) { | 1127 | if (!hrtimer_hres_active()) |
1115 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { | 1128 | mindelta = ktime_sub(__hrtimer_get_next_event(cpu_base), |
1116 | struct hrtimer *timer; | 1129 | ktime_get()); |
1117 | struct timerqueue_node *next; | ||
1118 | |||
1119 | next = timerqueue_getnext(&base->active); | ||
1120 | if (!next) | ||
1121 | continue; | ||
1122 | |||
1123 | timer = container_of(next, struct hrtimer, node); | ||
1124 | delta.tv64 = hrtimer_get_expires_tv64(timer); | ||
1125 | delta = ktime_sub(delta, base->get_time()); | ||
1126 | if (delta.tv64 < mindelta.tv64) | ||
1127 | mindelta.tv64 = delta.tv64; | ||
1128 | } | ||
1129 | } | ||
1130 | 1130 | ||
1131 | raw_spin_unlock_irqrestore(&cpu_base->lock, flags); | 1131 | raw_spin_unlock_irqrestore(&cpu_base->lock, flags); |
1132 | 1132 | ||
@@ -1253,7 +1253,7 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1253 | raw_spin_lock(&cpu_base->lock); | 1253 | raw_spin_lock(&cpu_base->lock); |
1254 | entry_time = now = hrtimer_update_base(cpu_base); | 1254 | entry_time = now = hrtimer_update_base(cpu_base); |
1255 | retry: | 1255 | retry: |
1256 | expires_next.tv64 = KTIME_MAX; | 1256 | cpu_base->in_hrtirq = 1; |
1257 | /* | 1257 | /* |
1258 | * We set expires_next to KTIME_MAX here with cpu_base->lock | 1258 | * We set expires_next to KTIME_MAX here with cpu_base->lock |
1259 | * held to prevent that a timer is enqueued in our queue via | 1259 | * held to prevent that a timer is enqueued in our queue via |
@@ -1291,28 +1291,20 @@ retry: | |||
1291 | * are right-of a not yet expired timer, because that | 1291 | * are right-of a not yet expired timer, because that |
1292 | * timer will have to trigger a wakeup anyway. | 1292 | * timer will have to trigger a wakeup anyway. |
1293 | */ | 1293 | */ |
1294 | 1294 | if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer)) | |
1295 | if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer)) { | ||
1296 | ktime_t expires; | ||
1297 | |||
1298 | expires = ktime_sub(hrtimer_get_expires(timer), | ||
1299 | base->offset); | ||
1300 | if (expires.tv64 < 0) | ||
1301 | expires.tv64 = KTIME_MAX; | ||
1302 | if (expires.tv64 < expires_next.tv64) | ||
1303 | expires_next = expires; | ||
1304 | break; | 1295 | break; |
1305 | } | ||
1306 | 1296 | ||
1307 | __run_hrtimer(timer, &basenow); | 1297 | __run_hrtimer(timer, &basenow); |
1308 | } | 1298 | } |
1309 | } | 1299 | } |
1310 | 1300 | /* Reevaluate the clock bases for the next expiry */ | |
1301 | expires_next = __hrtimer_get_next_event(cpu_base); | ||
1311 | /* | 1302 | /* |
1312 | * Store the new expiry value so the migration code can verify | 1303 | * Store the new expiry value so the migration code can verify |
1313 | * against it. | 1304 | * against it. |
1314 | */ | 1305 | */ |
1315 | cpu_base->expires_next = expires_next; | 1306 | cpu_base->expires_next = expires_next; |
1307 | cpu_base->in_hrtirq = 0; | ||
1316 | raw_spin_unlock(&cpu_base->lock); | 1308 | raw_spin_unlock(&cpu_base->lock); |
1317 | 1309 | ||
1318 | /* Reprogramming necessary ? */ | 1310 | /* Reprogramming necessary ? */ |
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 28bf91c60a0b..4b585e0fdd22 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -488,13 +488,13 @@ static void sync_cmos_clock(struct work_struct *work) | |||
488 | 488 | ||
489 | getnstimeofday64(&now); | 489 | getnstimeofday64(&now); |
490 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) { | 490 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec * 5) { |
491 | struct timespec adjust = timespec64_to_timespec(now); | 491 | struct timespec64 adjust = now; |
492 | 492 | ||
493 | fail = -ENODEV; | 493 | fail = -ENODEV; |
494 | if (persistent_clock_is_local) | 494 | if (persistent_clock_is_local) |
495 | adjust.tv_sec -= (sys_tz.tz_minuteswest * 60); | 495 | adjust.tv_sec -= (sys_tz.tz_minuteswest * 60); |
496 | #ifdef CONFIG_GENERIC_CMOS_UPDATE | 496 | #ifdef CONFIG_GENERIC_CMOS_UPDATE |
497 | fail = update_persistent_clock(adjust); | 497 | fail = update_persistent_clock(timespec64_to_timespec(adjust)); |
498 | #endif | 498 | #endif |
499 | #ifdef CONFIG_RTC_SYSTOHC | 499 | #ifdef CONFIG_RTC_SYSTOHC |
500 | if (fail == -ENODEV) | 500 | if (fail == -ENODEV) |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 6a931852082f..b124af259800 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -1659,24 +1659,24 @@ out: | |||
1659 | } | 1659 | } |
1660 | 1660 | ||
1661 | /** | 1661 | /** |
1662 | * getboottime - Return the real time of system boot. | 1662 | * getboottime64 - Return the real time of system boot. |
1663 | * @ts: pointer to the timespec to be set | 1663 | * @ts: pointer to the timespec64 to be set |
1664 | * | 1664 | * |
1665 | * Returns the wall-time of boot in a timespec. | 1665 | * Returns the wall-time of boot in a timespec64. |
1666 | * | 1666 | * |
1667 | * This is based on the wall_to_monotonic offset and the total suspend | 1667 | * This is based on the wall_to_monotonic offset and the total suspend |
1668 | * time. Calls to settimeofday will affect the value returned (which | 1668 | * time. Calls to settimeofday will affect the value returned (which |
1669 | * basically means that however wrong your real time clock is at boot time, | 1669 | * basically means that however wrong your real time clock is at boot time, |
1670 | * you get the right time here). | 1670 | * you get the right time here). |
1671 | */ | 1671 | */ |
1672 | void getboottime(struct timespec *ts) | 1672 | void getboottime64(struct timespec64 *ts) |
1673 | { | 1673 | { |
1674 | struct timekeeper *tk = &tk_core.timekeeper; | 1674 | struct timekeeper *tk = &tk_core.timekeeper; |
1675 | ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot); | 1675 | ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot); |
1676 | 1676 | ||
1677 | *ts = ktime_to_timespec(t); | 1677 | *ts = ktime_to_timespec64(t); |
1678 | } | 1678 | } |
1679 | EXPORT_SYMBOL_GPL(getboottime); | 1679 | EXPORT_SYMBOL_GPL(getboottime64); |
1680 | 1680 | ||
1681 | unsigned long get_seconds(void) | 1681 | unsigned long get_seconds(void) |
1682 | { | 1682 | { |