diff options
Diffstat (limited to 'kernel/time.c')
-rw-r--r-- | kernel/time.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/kernel/time.c b/kernel/time.c index 33af3e55570d..a5ec013b6c80 100644 --- a/kernel/time.c +++ b/kernel/time.c | |||
@@ -39,6 +39,8 @@ | |||
39 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
40 | #include <asm/unistd.h> | 40 | #include <asm/unistd.h> |
41 | 41 | ||
42 | #include "timeconst.h" | ||
43 | |||
42 | /* | 44 | /* |
43 | * The timezone where the local system is located. Used as a default by some | 45 | * The timezone where the local system is located. Used as a default by some |
44 | * programs who obtain this value by using gettimeofday. | 46 | * programs who obtain this value by using gettimeofday. |
@@ -93,7 +95,8 @@ asmlinkage long sys_stime(time_t __user *tptr) | |||
93 | 95 | ||
94 | #endif /* __ARCH_WANT_SYS_TIME */ | 96 | #endif /* __ARCH_WANT_SYS_TIME */ |
95 | 97 | ||
96 | asmlinkage long sys_gettimeofday(struct timeval __user *tv, struct timezone __user *tz) | 98 | asmlinkage long sys_gettimeofday(struct timeval __user *tv, |
99 | struct timezone __user *tz) | ||
97 | { | 100 | { |
98 | if (likely(tv != NULL)) { | 101 | if (likely(tv != NULL)) { |
99 | struct timeval ktv; | 102 | struct timeval ktv; |
@@ -118,7 +121,7 @@ asmlinkage long sys_gettimeofday(struct timeval __user *tv, struct timezone __us | |||
118 | * hard to make the program warp the clock precisely n hours) or | 121 | * hard to make the program warp the clock precisely n hours) or |
119 | * compile in the timezone information into the kernel. Bad, bad.... | 122 | * compile in the timezone information into the kernel. Bad, bad.... |
120 | * | 123 | * |
121 | * - TYT, 1992-01-01 | 124 | * - TYT, 1992-01-01 |
122 | * | 125 | * |
123 | * The best thing to do is to keep the CMOS clock in universal time (UTC) | 126 | * The best thing to do is to keep the CMOS clock in universal time (UTC) |
124 | * as real UNIX machines always do it. This avoids all headaches about | 127 | * as real UNIX machines always do it. This avoids all headaches about |
@@ -240,7 +243,11 @@ unsigned int inline jiffies_to_msecs(const unsigned long j) | |||
240 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) | 243 | #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) |
241 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); | 244 | return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); |
242 | #else | 245 | #else |
243 | return (j * MSEC_PER_SEC) / HZ; | 246 | # if BITS_PER_LONG == 32 |
247 | return ((u64)HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32; | ||
248 | # else | ||
249 | return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN; | ||
250 | # endif | ||
244 | #endif | 251 | #endif |
245 | } | 252 | } |
246 | EXPORT_SYMBOL(jiffies_to_msecs); | 253 | EXPORT_SYMBOL(jiffies_to_msecs); |
@@ -252,7 +259,11 @@ unsigned int inline jiffies_to_usecs(const unsigned long j) | |||
252 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) | 259 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) |
253 | return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC); | 260 | return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC); |
254 | #else | 261 | #else |
255 | return (j * USEC_PER_SEC) / HZ; | 262 | # if BITS_PER_LONG == 32 |
263 | return ((u64)HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32; | ||
264 | # else | ||
265 | return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN; | ||
266 | # endif | ||
256 | #endif | 267 | #endif |
257 | } | 268 | } |
258 | EXPORT_SYMBOL(jiffies_to_usecs); | 269 | EXPORT_SYMBOL(jiffies_to_usecs); |
@@ -267,7 +278,7 @@ EXPORT_SYMBOL(jiffies_to_usecs); | |||
267 | * | 278 | * |
268 | * This function should be only used for timestamps returned by | 279 | * This function should be only used for timestamps returned by |
269 | * current_kernel_time() or CURRENT_TIME, not with do_gettimeofday() because | 280 | * current_kernel_time() or CURRENT_TIME, not with do_gettimeofday() because |
270 | * it doesn't handle the better resolution of the later. | 281 | * it doesn't handle the better resolution of the latter. |
271 | */ | 282 | */ |
272 | struct timespec timespec_trunc(struct timespec t, unsigned gran) | 283 | struct timespec timespec_trunc(struct timespec t, unsigned gran) |
273 | { | 284 | { |
@@ -315,7 +326,7 @@ EXPORT_SYMBOL_GPL(getnstimeofday); | |||
315 | * This algorithm was first published by Gauss (I think). | 326 | * This algorithm was first published by Gauss (I think). |
316 | * | 327 | * |
317 | * WARNING: this function will overflow on 2106-02-07 06:28:16 on | 328 | * WARNING: this function will overflow on 2106-02-07 06:28:16 on |
318 | * machines were long is 32-bit! (However, as time_t is signed, we | 329 | * machines where long is 32-bit! (However, as time_t is signed, we |
319 | * will already get problems at other places on 2038-01-19 03:14:08) | 330 | * will already get problems at other places on 2038-01-19 03:14:08) |
320 | */ | 331 | */ |
321 | unsigned long | 332 | unsigned long |
@@ -352,7 +363,7 @@ EXPORT_SYMBOL(mktime); | |||
352 | * normalize to the timespec storage format | 363 | * normalize to the timespec storage format |
353 | * | 364 | * |
354 | * Note: The tv_nsec part is always in the range of | 365 | * Note: The tv_nsec part is always in the range of |
355 | * 0 <= tv_nsec < NSEC_PER_SEC | 366 | * 0 <= tv_nsec < NSEC_PER_SEC |
356 | * For negative values only the tv_sec field is negative ! | 367 | * For negative values only the tv_sec field is negative ! |
357 | */ | 368 | */ |
358 | void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec) | 369 | void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec) |
@@ -453,12 +464,13 @@ unsigned long msecs_to_jiffies(const unsigned int m) | |||
453 | /* | 464 | /* |
454 | * Generic case - multiply, round and divide. But first | 465 | * Generic case - multiply, round and divide. But first |
455 | * check that if we are doing a net multiplication, that | 466 | * check that if we are doing a net multiplication, that |
456 | * we wouldnt overflow: | 467 | * we wouldn't overflow: |
457 | */ | 468 | */ |
458 | if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) | 469 | if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) |
459 | return MAX_JIFFY_OFFSET; | 470 | return MAX_JIFFY_OFFSET; |
460 | 471 | ||
461 | return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC; | 472 | return ((u64)MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) |
473 | >> MSEC_TO_HZ_SHR32; | ||
462 | #endif | 474 | #endif |
463 | } | 475 | } |
464 | EXPORT_SYMBOL(msecs_to_jiffies); | 476 | EXPORT_SYMBOL(msecs_to_jiffies); |
@@ -472,7 +484,8 @@ unsigned long usecs_to_jiffies(const unsigned int u) | |||
472 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) | 484 | #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) |
473 | return u * (HZ / USEC_PER_SEC); | 485 | return u * (HZ / USEC_PER_SEC); |
474 | #else | 486 | #else |
475 | return (u * HZ + USEC_PER_SEC - 1) / USEC_PER_SEC; | 487 | return ((u64)USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32) |
488 | >> USEC_TO_HZ_SHR32; | ||
476 | #endif | 489 | #endif |
477 | } | 490 | } |
478 | EXPORT_SYMBOL(usecs_to_jiffies); | 491 | EXPORT_SYMBOL(usecs_to_jiffies); |