aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time.c29
-rw-r--r--kernel/time/ntp.c25
2 files changed, 15 insertions, 39 deletions
diff --git a/kernel/time.c b/kernel/time.c
index 86729042e4cd..343e2515375a 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -36,6 +36,7 @@
36#include <linux/security.h> 36#include <linux/security.h>
37#include <linux/fs.h> 37#include <linux/fs.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/math64.h>
39 40
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41#include <asm/unistd.h> 42#include <asm/unistd.h>
@@ -587,9 +588,7 @@ clock_t jiffies_to_clock_t(long x)
587 return x / (HZ / USER_HZ); 588 return x / (HZ / USER_HZ);
588# endif 589# endif
589#else 590#else
590 u64 tmp = (u64)x * TICK_NSEC; 591 return div_u64((u64)x * TICK_NSEC, NSEC_PER_SEC / USER_HZ);
591 do_div(tmp, (NSEC_PER_SEC / USER_HZ));
592 return (long)tmp;
593#endif 592#endif
594} 593}
595EXPORT_SYMBOL(jiffies_to_clock_t); 594EXPORT_SYMBOL(jiffies_to_clock_t);
@@ -601,16 +600,12 @@ unsigned long clock_t_to_jiffies(unsigned long x)
601 return ~0UL; 600 return ~0UL;
602 return x * (HZ / USER_HZ); 601 return x * (HZ / USER_HZ);
603#else 602#else
604 u64 jif;
605
606 /* Don't worry about loss of precision here .. */ 603 /* Don't worry about loss of precision here .. */
607 if (x >= ~0UL / HZ * USER_HZ) 604 if (x >= ~0UL / HZ * USER_HZ)
608 return ~0UL; 605 return ~0UL;
609 606
610 /* .. but do try to contain it here */ 607 /* .. but do try to contain it here */
611 jif = x * (u64) HZ; 608 return div_u64((u64)x * HZ, USER_HZ);
612 do_div(jif, USER_HZ);
613 return jif;
614#endif 609#endif
615} 610}
616EXPORT_SYMBOL(clock_t_to_jiffies); 611EXPORT_SYMBOL(clock_t_to_jiffies);
@@ -619,10 +614,9 @@ u64 jiffies_64_to_clock_t(u64 x)
619{ 614{
620#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0 615#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
621# if HZ < USER_HZ 616# if HZ < USER_HZ
622 x *= USER_HZ; 617 x = div_u64(x * USER_HZ, HZ);
623 do_div(x, HZ);
624# elif HZ > USER_HZ 618# elif HZ > USER_HZ
625 do_div(x, HZ / USER_HZ); 619 x = div_u64(x, HZ / USER_HZ);
626# else 620# else
627 /* Nothing to do */ 621 /* Nothing to do */
628# endif 622# endif
@@ -632,8 +626,7 @@ u64 jiffies_64_to_clock_t(u64 x)
632 * but even this doesn't overflow in hundreds of years 626 * but even this doesn't overflow in hundreds of years
633 * in 64 bits, so.. 627 * in 64 bits, so..
634 */ 628 */
635 x *= TICK_NSEC; 629 x = div_u64(x * TICK_NSEC, (NSEC_PER_SEC / USER_HZ));
636 do_div(x, (NSEC_PER_SEC / USER_HZ));
637#endif 630#endif
638 return x; 631 return x;
639} 632}
@@ -642,21 +635,17 @@ EXPORT_SYMBOL(jiffies_64_to_clock_t);
642u64 nsec_to_clock_t(u64 x) 635u64 nsec_to_clock_t(u64 x)
643{ 636{
644#if (NSEC_PER_SEC % USER_HZ) == 0 637#if (NSEC_PER_SEC % USER_HZ) == 0
645 do_div(x, (NSEC_PER_SEC / USER_HZ)); 638 return div_u64(x, NSEC_PER_SEC / USER_HZ);
646#elif (USER_HZ % 512) == 0 639#elif (USER_HZ % 512) == 0
647 x *= USER_HZ/512; 640 return div_u64(x * USER_HZ / 512, NSEC_PER_SEC / 512);
648 do_div(x, (NSEC_PER_SEC / 512));
649#else 641#else
650 /* 642 /*
651 * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024, 643 * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,
652 * overflow after 64.99 years. 644 * overflow after 64.99 years.
653 * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ... 645 * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
654 */ 646 */
655 x *= 9; 647 return div_u64(x * 9, (9ull * NSEC_PER_SEC + (USER_HZ / 2)) / USER_HZ);
656 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (USER_HZ/2)) /
657 USER_HZ));
658#endif 648#endif
659 return x;
660} 649}
661 650
662#if (BITS_PER_LONG < 64) 651#if (BITS_PER_LONG < 64)
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 5fd9b9469770..a4492f3d64db 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -15,7 +15,7 @@
15#include <linux/jiffies.h> 15#include <linux/jiffies.h>
16#include <linux/hrtimer.h> 16#include <linux/hrtimer.h>
17#include <linux/capability.h> 17#include <linux/capability.h>
18#include <asm/div64.h> 18#include <linux/math64.h>
19#include <asm/timex.h> 19#include <asm/timex.h>
20 20
21/* 21/*
@@ -53,10 +53,8 @@ static void ntp_update_frequency(void)
53 53
54 tick_length_base = second_length; 54 tick_length_base = second_length;
55 55
56 do_div(second_length, HZ); 56 tick_nsec = div_u64(second_length, HZ) >> TICK_LENGTH_SHIFT;
57 tick_nsec = second_length >> TICK_LENGTH_SHIFT; 57 tick_length_base = div_u64(tick_length_base, NTP_INTERVAL_FREQ);
58
59 do_div(tick_length_base, NTP_INTERVAL_FREQ);
60} 58}
61 59
62/** 60/**
@@ -237,7 +235,7 @@ static inline void notify_cmos_timer(void) { }
237int do_adjtimex(struct timex *txc) 235int do_adjtimex(struct timex *txc)
238{ 236{
239 long mtemp, save_adjust, rem; 237 long mtemp, save_adjust, rem;
240 s64 freq_adj, temp64; 238 s64 freq_adj;
241 int result; 239 int result;
242 240
243 /* In order to modify anything, you gotta be super-user! */ 241 /* In order to modify anything, you gotta be super-user! */
@@ -342,19 +340,8 @@ int do_adjtimex(struct timex *txc)
342 freq_adj = time_offset * mtemp; 340 freq_adj = time_offset * mtemp;
343 freq_adj = shift_right(freq_adj, time_constant * 2 + 341 freq_adj = shift_right(freq_adj, time_constant * 2 +
344 (SHIFT_PLL + 2) * 2 - SHIFT_NSEC); 342 (SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
345 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) { 343 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC))
346 u64 utemp64; 344 freq_adj += div_s64(time_offset << (SHIFT_NSEC - SHIFT_FLL), mtemp);
347 temp64 = time_offset << (SHIFT_NSEC - SHIFT_FLL);
348 if (time_offset < 0) {
349 utemp64 = -temp64;
350 do_div(utemp64, mtemp);
351 freq_adj -= utemp64;
352 } else {
353 utemp64 = temp64;
354 do_div(utemp64, mtemp);
355 freq_adj += utemp64;
356 }
357 }
358 freq_adj += time_freq; 345 freq_adj += time_freq;
359 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC); 346 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
360 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC); 347 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC);