diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-12 09:17:48 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-12 09:17:48 -0400 |
commit | 03d3602a833715f83ea53b9feb078b9c4c5f6c1a (patch) | |
tree | 7b63ec6753dd65e61392017e1aba2ee1e6b4bcd1 /kernel | |
parent | 0588f1f934791b79d0a1e9b327be9b6eb361d2b8 (diff) | |
parent | 5b3900cd409466c0070b234d941650685ad0c791 (diff) |
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer core update from Thomas Gleixner:
- Bug fixes (one for a longstanding dead loop issue)
- Rework of time related vsyscalls
- Alarm timer updates
- Jiffies updates to remove compile time dependencies
* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
timekeeping: Cast raw_interval to u64 to avoid shift overflow
timers: Fix endless looping between cascade() and internal_add_timer()
time/jiffies: bring back unconditional LATCH definition
time: Convert x86_64 to using new update_vsyscall
time: Only do nanosecond rounding on GENERIC_TIME_VSYSCALL_OLD systems
time: Introduce new GENERIC_TIME_VSYSCALL
time: Convert CONFIG_GENERIC_TIME_VSYSCALL to CONFIG_GENERIC_TIME_VSYSCALL_OLD
time: Move update_vsyscall definitions to timekeeper_internal.h
time: Move timekeeper structure to timekeeper_internal.h for vsyscall changes
jiffies: Remove compile time assumptions about CLOCK_TICK_RATE
jiffies: Kill unused TICK_USEC_TO_NSEC
alarmtimer: Rename alarmtimer_remove to alarmtimer_dequeue
alarmtimer: Remove unused helpers & defines
alarmtimer: Use hrtimer per-alarm instead of per-base
alarmtimer: Implement minimum alarm interval for allowing suspend
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/time.c | 2 | ||||
-rw-r--r-- | kernel/time/Kconfig | 4 | ||||
-rw-r--r-- | kernel/time/alarmtimer.c | 118 | ||||
-rw-r--r-- | kernel/time/jiffies.c | 32 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 117 | ||||
-rw-r--r-- | kernel/timer.c | 10 |
6 files changed, 119 insertions, 164 deletions
diff --git a/kernel/time.c b/kernel/time.c index ba744cf8069..d226c6a3fd2 100644 --- a/kernel/time.c +++ b/kernel/time.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <linux/export.h> | 30 | #include <linux/export.h> |
31 | #include <linux/timex.h> | 31 | #include <linux/timex.h> |
32 | #include <linux/capability.h> | 32 | #include <linux/capability.h> |
33 | #include <linux/clocksource.h> | 33 | #include <linux/timekeeper_internal.h> |
34 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
35 | #include <linux/syscalls.h> | 35 | #include <linux/syscalls.h> |
36 | #include <linux/security.h> | 36 | #include <linux/security.h> |
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index fd42bd452b7..8601f0db126 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig | |||
@@ -16,6 +16,10 @@ config ARCH_CLOCKSOURCE_DATA | |||
16 | config GENERIC_TIME_VSYSCALL | 16 | config GENERIC_TIME_VSYSCALL |
17 | bool | 17 | bool |
18 | 18 | ||
19 | # Timekeeping vsyscall support | ||
20 | config GENERIC_TIME_VSYSCALL_OLD | ||
21 | bool | ||
22 | |||
19 | # ktime_t scalar 64bit nsec representation | 23 | # ktime_t scalar 64bit nsec representation |
20 | config KTIME_SCALAR | 24 | config KTIME_SCALAR |
21 | bool | 25 | bool |
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index aa27d391bfc..f11d83b1294 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c | |||
@@ -37,7 +37,6 @@ | |||
37 | static struct alarm_base { | 37 | static struct alarm_base { |
38 | spinlock_t lock; | 38 | spinlock_t lock; |
39 | struct timerqueue_head timerqueue; | 39 | struct timerqueue_head timerqueue; |
40 | struct hrtimer timer; | ||
41 | ktime_t (*gettime)(void); | 40 | ktime_t (*gettime)(void); |
42 | clockid_t base_clockid; | 41 | clockid_t base_clockid; |
43 | } alarm_bases[ALARM_NUMTYPE]; | 42 | } alarm_bases[ALARM_NUMTYPE]; |
@@ -46,6 +45,8 @@ static struct alarm_base { | |||
46 | static ktime_t freezer_delta; | 45 | static ktime_t freezer_delta; |
47 | static DEFINE_SPINLOCK(freezer_delta_lock); | 46 | static DEFINE_SPINLOCK(freezer_delta_lock); |
48 | 47 | ||
48 | static struct wakeup_source *ws; | ||
49 | |||
49 | #ifdef CONFIG_RTC_CLASS | 50 | #ifdef CONFIG_RTC_CLASS |
50 | /* rtc timer and device for setting alarm wakeups at suspend */ | 51 | /* rtc timer and device for setting alarm wakeups at suspend */ |
51 | static struct rtc_timer rtctimer; | 52 | static struct rtc_timer rtctimer; |
@@ -130,50 +131,35 @@ static inline void alarmtimer_rtc_timer_init(void) { } | |||
130 | * @base: pointer to the base where the timer is being run | 131 | * @base: pointer to the base where the timer is being run |
131 | * @alarm: pointer to alarm being enqueued. | 132 | * @alarm: pointer to alarm being enqueued. |
132 | * | 133 | * |
133 | * Adds alarm to a alarm_base timerqueue and if necessary sets | 134 | * Adds alarm to a alarm_base timerqueue |
134 | * an hrtimer to run. | ||
135 | * | 135 | * |
136 | * Must hold base->lock when calling. | 136 | * Must hold base->lock when calling. |
137 | */ | 137 | */ |
138 | static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm) | 138 | static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm) |
139 | { | 139 | { |
140 | if (alarm->state & ALARMTIMER_STATE_ENQUEUED) | ||
141 | timerqueue_del(&base->timerqueue, &alarm->node); | ||
142 | |||
140 | timerqueue_add(&base->timerqueue, &alarm->node); | 143 | timerqueue_add(&base->timerqueue, &alarm->node); |
141 | alarm->state |= ALARMTIMER_STATE_ENQUEUED; | 144 | alarm->state |= ALARMTIMER_STATE_ENQUEUED; |
142 | |||
143 | if (&alarm->node == timerqueue_getnext(&base->timerqueue)) { | ||
144 | hrtimer_try_to_cancel(&base->timer); | ||
145 | hrtimer_start(&base->timer, alarm->node.expires, | ||
146 | HRTIMER_MODE_ABS); | ||
147 | } | ||
148 | } | 145 | } |
149 | 146 | ||
150 | /** | 147 | /** |
151 | * alarmtimer_remove - Removes an alarm timer from an alarm_base timerqueue | 148 | * alarmtimer_dequeue - Removes an alarm timer from an alarm_base timerqueue |
152 | * @base: pointer to the base where the timer is running | 149 | * @base: pointer to the base where the timer is running |
153 | * @alarm: pointer to alarm being removed | 150 | * @alarm: pointer to alarm being removed |
154 | * | 151 | * |
155 | * Removes alarm to a alarm_base timerqueue and if necessary sets | 152 | * Removes alarm to a alarm_base timerqueue |
156 | * a new timer to run. | ||
157 | * | 153 | * |
158 | * Must hold base->lock when calling. | 154 | * Must hold base->lock when calling. |
159 | */ | 155 | */ |
160 | static void alarmtimer_remove(struct alarm_base *base, struct alarm *alarm) | 156 | static void alarmtimer_dequeue(struct alarm_base *base, struct alarm *alarm) |
161 | { | 157 | { |
162 | struct timerqueue_node *next = timerqueue_getnext(&base->timerqueue); | ||
163 | |||
164 | if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED)) | 158 | if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED)) |
165 | return; | 159 | return; |
166 | 160 | ||
167 | timerqueue_del(&base->timerqueue, &alarm->node); | 161 | timerqueue_del(&base->timerqueue, &alarm->node); |
168 | alarm->state &= ~ALARMTIMER_STATE_ENQUEUED; | 162 | alarm->state &= ~ALARMTIMER_STATE_ENQUEUED; |
169 | |||
170 | if (next == &alarm->node) { | ||
171 | hrtimer_try_to_cancel(&base->timer); | ||
172 | next = timerqueue_getnext(&base->timerqueue); | ||
173 | if (!next) | ||
174 | return; | ||
175 | hrtimer_start(&base->timer, next->expires, HRTIMER_MODE_ABS); | ||
176 | } | ||
177 | } | 163 | } |
178 | 164 | ||
179 | 165 | ||
@@ -188,42 +174,23 @@ static void alarmtimer_remove(struct alarm_base *base, struct alarm *alarm) | |||
188 | */ | 174 | */ |
189 | static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) | 175 | static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) |
190 | { | 176 | { |
191 | struct alarm_base *base = container_of(timer, struct alarm_base, timer); | 177 | struct alarm *alarm = container_of(timer, struct alarm, timer); |
192 | struct timerqueue_node *next; | 178 | struct alarm_base *base = &alarm_bases[alarm->type]; |
193 | unsigned long flags; | 179 | unsigned long flags; |
194 | ktime_t now; | ||
195 | int ret = HRTIMER_NORESTART; | 180 | int ret = HRTIMER_NORESTART; |
196 | int restart = ALARMTIMER_NORESTART; | 181 | int restart = ALARMTIMER_NORESTART; |
197 | 182 | ||
198 | spin_lock_irqsave(&base->lock, flags); | 183 | spin_lock_irqsave(&base->lock, flags); |
199 | now = base->gettime(); | 184 | alarmtimer_dequeue(base, alarm); |
200 | while ((next = timerqueue_getnext(&base->timerqueue))) { | 185 | spin_unlock_irqrestore(&base->lock, flags); |
201 | struct alarm *alarm; | ||
202 | ktime_t expired = next->expires; | ||
203 | |||
204 | if (expired.tv64 > now.tv64) | ||
205 | break; | ||
206 | |||
207 | alarm = container_of(next, struct alarm, node); | ||
208 | |||
209 | timerqueue_del(&base->timerqueue, &alarm->node); | ||
210 | alarm->state &= ~ALARMTIMER_STATE_ENQUEUED; | ||
211 | |||
212 | alarm->state |= ALARMTIMER_STATE_CALLBACK; | ||
213 | spin_unlock_irqrestore(&base->lock, flags); | ||
214 | if (alarm->function) | ||
215 | restart = alarm->function(alarm, now); | ||
216 | spin_lock_irqsave(&base->lock, flags); | ||
217 | alarm->state &= ~ALARMTIMER_STATE_CALLBACK; | ||
218 | 186 | ||
219 | if (restart != ALARMTIMER_NORESTART) { | 187 | if (alarm->function) |
220 | timerqueue_add(&base->timerqueue, &alarm->node); | 188 | restart = alarm->function(alarm, base->gettime()); |
221 | alarm->state |= ALARMTIMER_STATE_ENQUEUED; | ||
222 | } | ||
223 | } | ||
224 | 189 | ||
225 | if (next) { | 190 | spin_lock_irqsave(&base->lock, flags); |
226 | hrtimer_set_expires(&base->timer, next->expires); | 191 | if (restart != ALARMTIMER_NORESTART) { |
192 | hrtimer_set_expires(&alarm->timer, alarm->node.expires); | ||
193 | alarmtimer_enqueue(base, alarm); | ||
227 | ret = HRTIMER_RESTART; | 194 | ret = HRTIMER_RESTART; |
228 | } | 195 | } |
229 | spin_unlock_irqrestore(&base->lock, flags); | 196 | spin_unlock_irqrestore(&base->lock, flags); |
@@ -250,6 +217,7 @@ static int alarmtimer_suspend(struct device *dev) | |||
250 | unsigned long flags; | 217 | unsigned long flags; |
251 | struct rtc_device *rtc; | 218 | struct rtc_device *rtc; |
252 | int i; | 219 | int i; |
220 | int ret; | ||
253 | 221 | ||
254 | spin_lock_irqsave(&freezer_delta_lock, flags); | 222 | spin_lock_irqsave(&freezer_delta_lock, flags); |
255 | min = freezer_delta; | 223 | min = freezer_delta; |
@@ -279,8 +247,10 @@ static int alarmtimer_suspend(struct device *dev) | |||
279 | if (min.tv64 == 0) | 247 | if (min.tv64 == 0) |
280 | return 0; | 248 | return 0; |
281 | 249 | ||
282 | /* XXX - Should we enforce a minimum sleep time? */ | 250 | if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) { |
283 | WARN_ON(min.tv64 < NSEC_PER_SEC); | 251 | __pm_wakeup_event(ws, 2 * MSEC_PER_SEC); |
252 | return -EBUSY; | ||
253 | } | ||
284 | 254 | ||
285 | /* Setup an rtc timer to fire that far in the future */ | 255 | /* Setup an rtc timer to fire that far in the future */ |
286 | rtc_timer_cancel(rtc, &rtctimer); | 256 | rtc_timer_cancel(rtc, &rtctimer); |
@@ -288,9 +258,11 @@ static int alarmtimer_suspend(struct device *dev) | |||
288 | now = rtc_tm_to_ktime(tm); | 258 | now = rtc_tm_to_ktime(tm); |
289 | now = ktime_add(now, min); | 259 | now = ktime_add(now, min); |
290 | 260 | ||
291 | rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0)); | 261 | /* Set alarm, if in the past reject suspend briefly to handle */ |
292 | 262 | ret = rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0)); | |
293 | return 0; | 263 | if (ret < 0) |
264 | __pm_wakeup_event(ws, MSEC_PER_SEC); | ||
265 | return ret; | ||
294 | } | 266 | } |
295 | #else | 267 | #else |
296 | static int alarmtimer_suspend(struct device *dev) | 268 | static int alarmtimer_suspend(struct device *dev) |
@@ -324,6 +296,9 @@ void alarm_init(struct alarm *alarm, enum alarmtimer_type type, | |||
324 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) | 296 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) |
325 | { | 297 | { |
326 | timerqueue_init(&alarm->node); | 298 | timerqueue_init(&alarm->node); |
299 | hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid, | ||
300 | HRTIMER_MODE_ABS); | ||
301 | alarm->timer.function = alarmtimer_fired; | ||
327 | alarm->function = function; | 302 | alarm->function = function; |
328 | alarm->type = type; | 303 | alarm->type = type; |
329 | alarm->state = ALARMTIMER_STATE_INACTIVE; | 304 | alarm->state = ALARMTIMER_STATE_INACTIVE; |
@@ -334,17 +309,19 @@ void alarm_init(struct alarm *alarm, enum alarmtimer_type type, | |||
334 | * @alarm: ptr to alarm to set | 309 | * @alarm: ptr to alarm to set |
335 | * @start: time to run the alarm | 310 | * @start: time to run the alarm |
336 | */ | 311 | */ |
337 | void alarm_start(struct alarm *alarm, ktime_t start) | 312 | int alarm_start(struct alarm *alarm, ktime_t start) |
338 | { | 313 | { |
339 | struct alarm_base *base = &alarm_bases[alarm->type]; | 314 | struct alarm_base *base = &alarm_bases[alarm->type]; |
340 | unsigned long flags; | 315 | unsigned long flags; |
316 | int ret; | ||
341 | 317 | ||
342 | spin_lock_irqsave(&base->lock, flags); | 318 | spin_lock_irqsave(&base->lock, flags); |
343 | if (alarmtimer_active(alarm)) | ||
344 | alarmtimer_remove(base, alarm); | ||
345 | alarm->node.expires = start; | 319 | alarm->node.expires = start; |
346 | alarmtimer_enqueue(base, alarm); | 320 | alarmtimer_enqueue(base, alarm); |
321 | ret = hrtimer_start(&alarm->timer, alarm->node.expires, | ||
322 | HRTIMER_MODE_ABS); | ||
347 | spin_unlock_irqrestore(&base->lock, flags); | 323 | spin_unlock_irqrestore(&base->lock, flags); |
324 | return ret; | ||
348 | } | 325 | } |
349 | 326 | ||
350 | /** | 327 | /** |
@@ -358,18 +335,12 @@ int alarm_try_to_cancel(struct alarm *alarm) | |||
358 | { | 335 | { |
359 | struct alarm_base *base = &alarm_bases[alarm->type]; | 336 | struct alarm_base *base = &alarm_bases[alarm->type]; |
360 | unsigned long flags; | 337 | unsigned long flags; |
361 | int ret = -1; | 338 | int ret; |
362 | spin_lock_irqsave(&base->lock, flags); | ||
363 | |||
364 | if (alarmtimer_callback_running(alarm)) | ||
365 | goto out; | ||
366 | 339 | ||
367 | if (alarmtimer_is_queued(alarm)) { | 340 | spin_lock_irqsave(&base->lock, flags); |
368 | alarmtimer_remove(base, alarm); | 341 | ret = hrtimer_try_to_cancel(&alarm->timer); |
369 | ret = 1; | 342 | if (ret >= 0) |
370 | } else | 343 | alarmtimer_dequeue(base, alarm); |
371 | ret = 0; | ||
372 | out: | ||
373 | spin_unlock_irqrestore(&base->lock, flags); | 344 | spin_unlock_irqrestore(&base->lock, flags); |
374 | return ret; | 345 | return ret; |
375 | } | 346 | } |
@@ -802,10 +773,6 @@ static int __init alarmtimer_init(void) | |||
802 | for (i = 0; i < ALARM_NUMTYPE; i++) { | 773 | for (i = 0; i < ALARM_NUMTYPE; i++) { |
803 | timerqueue_init_head(&alarm_bases[i].timerqueue); | 774 | timerqueue_init_head(&alarm_bases[i].timerqueue); |
804 | spin_lock_init(&alarm_bases[i].lock); | 775 | spin_lock_init(&alarm_bases[i].lock); |
805 | hrtimer_init(&alarm_bases[i].timer, | ||
806 | alarm_bases[i].base_clockid, | ||
807 | HRTIMER_MODE_ABS); | ||
808 | alarm_bases[i].timer.function = alarmtimer_fired; | ||
809 | } | 776 | } |
810 | 777 | ||
811 | error = alarmtimer_rtc_interface_setup(); | 778 | error = alarmtimer_rtc_interface_setup(); |
@@ -821,6 +788,7 @@ static int __init alarmtimer_init(void) | |||
821 | error = PTR_ERR(pdev); | 788 | error = PTR_ERR(pdev); |
822 | goto out_drv; | 789 | goto out_drv; |
823 | } | 790 | } |
791 | ws = wakeup_source_register("alarmtimer"); | ||
824 | return 0; | 792 | return 0; |
825 | 793 | ||
826 | out_drv: | 794 | out_drv: |
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index 46da0537c10..6629bf7b528 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c | |||
@@ -37,7 +37,7 @@ | |||
37 | * requested HZ value. It is also not recommended | 37 | * requested HZ value. It is also not recommended |
38 | * for "tick-less" systems. | 38 | * for "tick-less" systems. |
39 | */ | 39 | */ |
40 | #define NSEC_PER_JIFFY ((u32)((((u64)NSEC_PER_SEC)<<8)/SHIFTED_HZ)) | 40 | #define NSEC_PER_JIFFY ((NSEC_PER_SEC+HZ/2)/HZ) |
41 | 41 | ||
42 | /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier | 42 | /* Since jiffies uses a simple NSEC_PER_JIFFY multiplier |
43 | * conversion, the .shift value could be zero. However | 43 | * conversion, the .shift value could be zero. However |
@@ -95,3 +95,33 @@ struct clocksource * __init __weak clocksource_default_clock(void) | |||
95 | { | 95 | { |
96 | return &clocksource_jiffies; | 96 | return &clocksource_jiffies; |
97 | } | 97 | } |
98 | |||
99 | struct clocksource refined_jiffies; | ||
100 | |||
101 | int register_refined_jiffies(long cycles_per_second) | ||
102 | { | ||
103 | u64 nsec_per_tick, shift_hz; | ||
104 | long cycles_per_tick; | ||
105 | |||
106 | |||
107 | |||
108 | refined_jiffies = clocksource_jiffies; | ||
109 | refined_jiffies.name = "refined-jiffies"; | ||
110 | refined_jiffies.rating++; | ||
111 | |||
112 | /* Calc cycles per tick */ | ||
113 | cycles_per_tick = (cycles_per_second + HZ/2)/HZ; | ||
114 | /* shift_hz stores hz<<8 for extra accuracy */ | ||
115 | shift_hz = (u64)cycles_per_second << 8; | ||
116 | shift_hz += cycles_per_tick/2; | ||
117 | do_div(shift_hz, cycles_per_tick); | ||
118 | /* Calculate nsec_per_tick using shift_hz */ | ||
119 | nsec_per_tick = (u64)NSEC_PER_SEC << 8; | ||
120 | nsec_per_tick += (u32)shift_hz/2; | ||
121 | do_div(nsec_per_tick, (u32)shift_hz); | ||
122 | |||
123 | refined_jiffies.mult = ((u32)nsec_per_tick) << JIFFIES_SHIFT; | ||
124 | |||
125 | clocksource_register(&refined_jiffies); | ||
126 | return 0; | ||
127 | } | ||
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5ce06a3fa91..e424970bb56 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/timekeeper_internal.h> | ||
11 | #include <linux/module.h> | 12 | #include <linux/module.h> |
12 | #include <linux/interrupt.h> | 13 | #include <linux/interrupt.h> |
13 | #include <linux/percpu.h> | 14 | #include <linux/percpu.h> |
@@ -21,61 +22,6 @@ | |||
21 | #include <linux/tick.h> | 22 | #include <linux/tick.h> |
22 | #include <linux/stop_machine.h> | 23 | #include <linux/stop_machine.h> |
23 | 24 | ||
24 | /* Structure holding internal timekeeping values. */ | ||
25 | struct timekeeper { | ||
26 | /* Current clocksource used for timekeeping. */ | ||
27 | struct clocksource *clock; | ||
28 | /* NTP adjusted clock multiplier */ | ||
29 | u32 mult; | ||
30 | /* The shift value of the current clocksource. */ | ||
31 | u32 shift; | ||
32 | /* Number of clock cycles in one NTP interval. */ | ||
33 | cycle_t cycle_interval; | ||
34 | /* Number of clock shifted nano seconds in one NTP interval. */ | ||
35 | u64 xtime_interval; | ||
36 | /* shifted nano seconds left over when rounding cycle_interval */ | ||
37 | s64 xtime_remainder; | ||
38 | /* Raw nano seconds accumulated per NTP interval. */ | ||
39 | u32 raw_interval; | ||
40 | |||
41 | /* Current CLOCK_REALTIME time in seconds */ | ||
42 | u64 xtime_sec; | ||
43 | /* Clock shifted nano seconds */ | ||
44 | u64 xtime_nsec; | ||
45 | |||
46 | /* Difference between accumulated time and NTP time in ntp | ||
47 | * shifted nano seconds. */ | ||
48 | s64 ntp_error; | ||
49 | /* Shift conversion between clock shifted nano seconds and | ||
50 | * ntp shifted nano seconds. */ | ||
51 | u32 ntp_error_shift; | ||
52 | |||
53 | /* | ||
54 | * wall_to_monotonic is what we need to add to xtime (or xtime corrected | ||
55 | * for sub jiffie times) to get to monotonic time. Monotonic is pegged | ||
56 | * at zero at system boot time, so wall_to_monotonic will be negative, | ||
57 | * however, we will ALWAYS keep the tv_nsec part positive so we can use | ||
58 | * the usual normalization. | ||
59 | * | ||
60 | * wall_to_monotonic is moved after resume from suspend for the | ||
61 | * monotonic time not to jump. We need to add total_sleep_time to | ||
62 | * wall_to_monotonic to get the real boot based time offset. | ||
63 | * | ||
64 | * - wall_to_monotonic is no longer the boot time, getboottime must be | ||
65 | * used instead. | ||
66 | */ | ||
67 | struct timespec wall_to_monotonic; | ||
68 | /* Offset clock monotonic -> clock realtime */ | ||
69 | ktime_t offs_real; | ||
70 | /* time spent in suspend */ | ||
71 | struct timespec total_sleep_time; | ||
72 | /* Offset clock monotonic -> clock boottime */ | ||
73 | ktime_t offs_boot; | ||
74 | /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ | ||
75 | struct timespec raw_time; | ||
76 | /* Seqlock for all timekeeper values */ | ||
77 | seqlock_t lock; | ||
78 | }; | ||
79 | 25 | ||
80 | static struct timekeeper timekeeper; | 26 | static struct timekeeper timekeeper; |
81 | 27 | ||
@@ -96,15 +42,6 @@ static inline void tk_normalize_xtime(struct timekeeper *tk) | |||
96 | } | 42 | } |
97 | } | 43 | } |
98 | 44 | ||
99 | static struct timespec tk_xtime(struct timekeeper *tk) | ||
100 | { | ||
101 | struct timespec ts; | ||
102 | |||
103 | ts.tv_sec = tk->xtime_sec; | ||
104 | ts.tv_nsec = (long)(tk->xtime_nsec >> tk->shift); | ||
105 | return ts; | ||
106 | } | ||
107 | |||
108 | static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts) | 45 | static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts) |
109 | { | 46 | { |
110 | tk->xtime_sec = ts->tv_sec; | 47 | tk->xtime_sec = ts->tv_sec; |
@@ -246,14 +183,11 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) | |||
246 | /* must hold write on timekeeper.lock */ | 183 | /* must hold write on timekeeper.lock */ |
247 | static void timekeeping_update(struct timekeeper *tk, bool clearntp) | 184 | static void timekeeping_update(struct timekeeper *tk, bool clearntp) |
248 | { | 185 | { |
249 | struct timespec xt; | ||
250 | |||
251 | if (clearntp) { | 186 | if (clearntp) { |
252 | tk->ntp_error = 0; | 187 | tk->ntp_error = 0; |
253 | ntp_clear(); | 188 | ntp_clear(); |
254 | } | 189 | } |
255 | xt = tk_xtime(tk); | 190 | update_vsyscall(tk); |
256 | update_vsyscall(&xt, &tk->wall_to_monotonic, tk->clock, tk->mult); | ||
257 | } | 191 | } |
258 | 192 | ||
259 | /** | 193 | /** |
@@ -1113,7 +1047,7 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset, | |||
1113 | accumulate_nsecs_to_secs(tk); | 1047 | accumulate_nsecs_to_secs(tk); |
1114 | 1048 | ||
1115 | /* Accumulate raw time */ | 1049 | /* Accumulate raw time */ |
1116 | raw_nsecs = tk->raw_interval << shift; | 1050 | raw_nsecs = (u64)tk->raw_interval << shift; |
1117 | raw_nsecs += tk->raw_time.tv_nsec; | 1051 | raw_nsecs += tk->raw_time.tv_nsec; |
1118 | if (raw_nsecs >= NSEC_PER_SEC) { | 1052 | if (raw_nsecs >= NSEC_PER_SEC) { |
1119 | u64 raw_secs = raw_nsecs; | 1053 | u64 raw_secs = raw_nsecs; |
@@ -1130,6 +1064,33 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset, | |||
1130 | return offset; | 1064 | return offset; |
1131 | } | 1065 | } |
1132 | 1066 | ||
1067 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD | ||
1068 | static inline void old_vsyscall_fixup(struct timekeeper *tk) | ||
1069 | { | ||
1070 | s64 remainder; | ||
1071 | |||
1072 | /* | ||
1073 | * Store only full nanoseconds into xtime_nsec after rounding | ||
1074 | * it up and add the remainder to the error difference. | ||
1075 | * XXX - This is necessary to avoid small 1ns inconsistnecies caused | ||
1076 | * by truncating the remainder in vsyscalls. However, it causes | ||
1077 | * additional work to be done in timekeeping_adjust(). Once | ||
1078 | * the vsyscall implementations are converted to use xtime_nsec | ||
1079 | * (shifted nanoseconds), and CONFIG_GENERIC_TIME_VSYSCALL_OLD | ||
1080 | * users are removed, this can be killed. | ||
1081 | */ | ||
1082 | remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1); | ||
1083 | tk->xtime_nsec -= remainder; | ||
1084 | tk->xtime_nsec += 1ULL << tk->shift; | ||
1085 | tk->ntp_error += remainder << tk->ntp_error_shift; | ||
1086 | |||
1087 | } | ||
1088 | #else | ||
1089 | #define old_vsyscall_fixup(tk) | ||
1090 | #endif | ||
1091 | |||
1092 | |||
1093 | |||
1133 | /** | 1094 | /** |
1134 | * update_wall_time - Uses the current clocksource to increment the wall time | 1095 | * update_wall_time - Uses the current clocksource to increment the wall time |
1135 | * | 1096 | * |
@@ -1141,7 +1102,6 @@ static void update_wall_time(void) | |||
1141 | cycle_t offset; | 1102 | cycle_t offset; |
1142 | int shift = 0, maxshift; | 1103 | int shift = 0, maxshift; |
1143 | unsigned long flags; | 1104 | unsigned long flags; |
1144 | s64 remainder; | ||
1145 | 1105 | ||
1146 | write_seqlock_irqsave(&tk->lock, flags); | 1106 | write_seqlock_irqsave(&tk->lock, flags); |
1147 | 1107 | ||
@@ -1183,20 +1143,11 @@ static void update_wall_time(void) | |||
1183 | /* correct the clock when NTP error is too big */ | 1143 | /* correct the clock when NTP error is too big */ |
1184 | timekeeping_adjust(tk, offset); | 1144 | timekeeping_adjust(tk, offset); |
1185 | 1145 | ||
1186 | |||
1187 | /* | 1146 | /* |
1188 | * Store only full nanoseconds into xtime_nsec after rounding | 1147 | * XXX This can be killed once everyone converts |
1189 | * it up and add the remainder to the error difference. | 1148 | * to the new update_vsyscall. |
1190 | * XXX - This is necessary to avoid small 1ns inconsistnecies caused | 1149 | */ |
1191 | * by truncating the remainder in vsyscalls. However, it causes | 1150 | old_vsyscall_fixup(tk); |
1192 | * additional work to be done in timekeeping_adjust(). Once | ||
1193 | * the vsyscall implementations are converted to use xtime_nsec | ||
1194 | * (shifted nanoseconds), this can be killed. | ||
1195 | */ | ||
1196 | remainder = tk->xtime_nsec & ((1ULL << tk->shift) - 1); | ||
1197 | tk->xtime_nsec -= remainder; | ||
1198 | tk->xtime_nsec += 1ULL << tk->shift; | ||
1199 | tk->ntp_error += remainder << tk->ntp_error_shift; | ||
1200 | 1151 | ||
1201 | /* | 1152 | /* |
1202 | * Finally, make sure that after the rounding | 1153 | * Finally, make sure that after the rounding |
diff --git a/kernel/timer.c b/kernel/timer.c index d5de1b2292a..367d0085848 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -63,6 +63,7 @@ EXPORT_SYMBOL(jiffies_64); | |||
63 | #define TVR_SIZE (1 << TVR_BITS) | 63 | #define TVR_SIZE (1 << TVR_BITS) |
64 | #define TVN_MASK (TVN_SIZE - 1) | 64 | #define TVN_MASK (TVN_SIZE - 1) |
65 | #define TVR_MASK (TVR_SIZE - 1) | 65 | #define TVR_MASK (TVR_SIZE - 1) |
66 | #define MAX_TVAL ((unsigned long)((1ULL << (TVR_BITS + 4*TVN_BITS)) - 1)) | ||
66 | 67 | ||
67 | struct tvec { | 68 | struct tvec { |
68 | struct list_head vec[TVN_SIZE]; | 69 | struct list_head vec[TVN_SIZE]; |
@@ -359,11 +360,12 @@ __internal_add_timer(struct tvec_base *base, struct timer_list *timer) | |||
359 | vec = base->tv1.vec + (base->timer_jiffies & TVR_MASK); | 360 | vec = base->tv1.vec + (base->timer_jiffies & TVR_MASK); |
360 | } else { | 361 | } else { |
361 | int i; | 362 | int i; |
362 | /* If the timeout is larger than 0xffffffff on 64-bit | 363 | /* If the timeout is larger than MAX_TVAL (on 64-bit |
363 | * architectures then we use the maximum timeout: | 364 | * architectures or with CONFIG_BASE_SMALL=1) then we |
365 | * use the maximum timeout. | ||
364 | */ | 366 | */ |
365 | if (idx > 0xffffffffUL) { | 367 | if (idx > MAX_TVAL) { |
366 | idx = 0xffffffffUL; | 368 | idx = MAX_TVAL; |
367 | expires = idx + base->timer_jiffies; | 369 | expires = idx + base->timer_jiffies; |
368 | } | 370 | } |
369 | i = (expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK; | 371 | i = (expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK; |