diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2014-07-16 17:05:10 -0400 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2014-07-23 18:01:51 -0400 |
commit | 3a97837784acbf9fed699fc04d1799b0eb742fdf (patch) | |
tree | 12297634077b24bcc6a01b779205043fc2a2a1f1 /kernel/time/timekeeping.c | |
parent | 6438e0ddc870f282f7ad46c050c211063a574687 (diff) |
clocksource: Make delta calculation a function
We want to move the TSC sanity check into core code to make NMI safe
accessors to clock monotonic[_raw] possible. For this we need to
sanity check the delta calculation. Create a helper function and
convert all sites to use it.
[ Build fix from jstultz ]
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'kernel/time/timekeeping.c')
-rw-r--r-- | kernel/time/timekeeping.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index af8051f4420d..531805013786 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -173,7 +173,7 @@ static inline u32 arch_gettimeoffset(void) { return 0; } | |||
173 | 173 | ||
174 | static inline s64 timekeeping_get_ns(struct timekeeper *tk) | 174 | static inline s64 timekeeping_get_ns(struct timekeeper *tk) |
175 | { | 175 | { |
176 | cycle_t cycle_now, cycle_delta; | 176 | cycle_t cycle_now, delta; |
177 | struct clocksource *clock; | 177 | struct clocksource *clock; |
178 | s64 nsec; | 178 | s64 nsec; |
179 | 179 | ||
@@ -182,9 +182,9 @@ static inline s64 timekeeping_get_ns(struct timekeeper *tk) | |||
182 | cycle_now = clock->read(clock); | 182 | cycle_now = clock->read(clock); |
183 | 183 | ||
184 | /* calculate the delta since the last update_wall_time: */ | 184 | /* calculate the delta since the last update_wall_time: */ |
185 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | 185 | delta = clocksource_delta(cycle_now, clock->cycle_last, clock->mask); |
186 | 186 | ||
187 | nsec = cycle_delta * tk->mult + tk->xtime_nsec; | 187 | nsec = delta * tk->mult + tk->xtime_nsec; |
188 | nsec >>= tk->shift; | 188 | nsec >>= tk->shift; |
189 | 189 | ||
190 | /* If arch requires, add in get_arch_timeoffset() */ | 190 | /* If arch requires, add in get_arch_timeoffset() */ |
@@ -193,7 +193,7 @@ static inline s64 timekeeping_get_ns(struct timekeeper *tk) | |||
193 | 193 | ||
194 | static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) | 194 | static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) |
195 | { | 195 | { |
196 | cycle_t cycle_now, cycle_delta; | 196 | cycle_t cycle_now, delta; |
197 | struct clocksource *clock; | 197 | struct clocksource *clock; |
198 | s64 nsec; | 198 | s64 nsec; |
199 | 199 | ||
@@ -202,10 +202,10 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk) | |||
202 | cycle_now = clock->read(clock); | 202 | cycle_now = clock->read(clock); |
203 | 203 | ||
204 | /* calculate the delta since the last update_wall_time: */ | 204 | /* calculate the delta since the last update_wall_time: */ |
205 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | 205 | delta = clocksource_delta(cycle_now, clock->cycle_last, clock->mask); |
206 | 206 | ||
207 | /* convert delta to nanoseconds. */ | 207 | /* convert delta to nanoseconds. */ |
208 | nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); | 208 | nsec = clocksource_cyc2ns(delta, clock->mult, clock->shift); |
209 | 209 | ||
210 | /* If arch requires, add in get_arch_timeoffset() */ | 210 | /* If arch requires, add in get_arch_timeoffset() */ |
211 | return nsec + arch_gettimeoffset(); | 211 | return nsec + arch_gettimeoffset(); |
@@ -336,23 +336,23 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action) | |||
336 | */ | 336 | */ |
337 | static void timekeeping_forward_now(struct timekeeper *tk) | 337 | static void timekeeping_forward_now(struct timekeeper *tk) |
338 | { | 338 | { |
339 | cycle_t cycle_now, cycle_delta; | 339 | cycle_t cycle_now, delta; |
340 | struct clocksource *clock; | 340 | struct clocksource *clock; |
341 | s64 nsec; | 341 | s64 nsec; |
342 | 342 | ||
343 | clock = tk->clock; | 343 | clock = tk->clock; |
344 | cycle_now = clock->read(clock); | 344 | cycle_now = clock->read(clock); |
345 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | 345 | delta = clocksource_delta(cycle_now, clock->cycle_last, clock->mask); |
346 | tk->cycle_last = clock->cycle_last = cycle_now; | 346 | tk->cycle_last = clock->cycle_last = cycle_now; |
347 | 347 | ||
348 | tk->xtime_nsec += cycle_delta * tk->mult; | 348 | tk->xtime_nsec += delta * tk->mult; |
349 | 349 | ||
350 | /* If arch requires, add in get_arch_timeoffset() */ | 350 | /* If arch requires, add in get_arch_timeoffset() */ |
351 | tk->xtime_nsec += (u64)arch_gettimeoffset() << tk->shift; | 351 | tk->xtime_nsec += (u64)arch_gettimeoffset() << tk->shift; |
352 | 352 | ||
353 | tk_normalize_xtime(tk); | 353 | tk_normalize_xtime(tk); |
354 | 354 | ||
355 | nsec = clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); | 355 | nsec = clocksource_cyc2ns(delta, clock->mult, clock->shift); |
356 | timespec64_add_ns(&tk->raw_time, nsec); | 356 | timespec64_add_ns(&tk->raw_time, nsec); |
357 | } | 357 | } |
358 | 358 | ||
@@ -1026,7 +1026,8 @@ static void timekeeping_resume(void) | |||
1026 | u32 shift = clock->shift; | 1026 | u32 shift = clock->shift; |
1027 | s64 nsec = 0; | 1027 | s64 nsec = 0; |
1028 | 1028 | ||
1029 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | 1029 | cycle_delta = clocksource_delta(cycle_now, clock->cycle_last, |
1030 | clock->mask); | ||
1030 | 1031 | ||
1031 | /* | 1032 | /* |
1032 | * "cycle_delta * mutl" may cause 64 bits overflow, if the | 1033 | * "cycle_delta * mutl" may cause 64 bits overflow, if the |
@@ -1432,7 +1433,8 @@ void update_wall_time(void) | |||
1432 | #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET | 1433 | #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET |
1433 | offset = real_tk->cycle_interval; | 1434 | offset = real_tk->cycle_interval; |
1434 | #else | 1435 | #else |
1435 | offset = (clock->read(clock) - clock->cycle_last) & clock->mask; | 1436 | offset = clocksource_delta(clock->read(clock), clock->cycle_last, |
1437 | clock->mask); | ||
1436 | #endif | 1438 | #endif |
1437 | 1439 | ||
1438 | /* Check if there's really nothing to do */ | 1440 | /* Check if there's really nothing to do */ |