aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2008-05-01 07:34:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-05-01 11:03:58 -0400
commitf8bd2258e2d520dff28c855658bd24bdafb5102d (patch)
treed76db1dc858cb316bc7d5b8473f690a753fd2c93 /kernel
parent6f6d6a1a6a1336431a6cba60ace9e97c3a496a19 (diff)
remove div_long_long_rem
x86 is the only arch right now, which provides an optimized for div_long_long_rem and it has the downside that one has to be very careful that the divide doesn't overflow. The API is a little akward, as the arguments for the unsigned divide are signed. The signed version also doesn't handle a negative divisor and produces worse code on 64bit archs. There is little incentive to keep this API alive, so this converts the few users to the new API. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: john stultz <johnstul@us.ibm.com> Cc: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/posix-cpu-timers.c11
-rw-r--r--kernel/time.c25
-rw-r--r--kernel/time/ntp.c6
3 files changed, 22 insertions, 20 deletions
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index ae5c6c147c4b..f1525ad06cb3 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -4,8 +4,9 @@
4 4
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/posix-timers.h> 6#include <linux/posix-timers.h>
7#include <asm/uaccess.h>
8#include <linux/errno.h> 7#include <linux/errno.h>
8#include <linux/math64.h>
9#include <asm/uaccess.h>
9 10
10static int check_clock(const clockid_t which_clock) 11static int check_clock(const clockid_t which_clock)
11{ 12{
@@ -47,12 +48,10 @@ static void sample_to_timespec(const clockid_t which_clock,
47 union cpu_time_count cpu, 48 union cpu_time_count cpu,
48 struct timespec *tp) 49 struct timespec *tp)
49{ 50{
50 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) { 51 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED)
51 tp->tv_sec = div_long_long_rem(cpu.sched, 52 *tp = ns_to_timespec(cpu.sched);
52 NSEC_PER_SEC, &tp->tv_nsec); 53 else
53 } else {
54 cputime_to_timespec(cpu.cpu, tp); 54 cputime_to_timespec(cpu.cpu, tp);
55 }
56} 55}
57 56
58static inline int cpu_time_before(const clockid_t which_clock, 57static inline int cpu_time_before(const clockid_t which_clock,
diff --git a/kernel/time.c b/kernel/time.c
index 343e2515375a..cbe0d5a222ff 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -392,13 +392,17 @@ EXPORT_SYMBOL(set_normalized_timespec);
392struct timespec ns_to_timespec(const s64 nsec) 392struct timespec ns_to_timespec(const s64 nsec)
393{ 393{
394 struct timespec ts; 394 struct timespec ts;
395 s32 rem;
395 396
396 if (!nsec) 397 if (!nsec)
397 return (struct timespec) {0, 0}; 398 return (struct timespec) {0, 0};
398 399
399 ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec); 400 ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem);
400 if (unlikely(nsec < 0)) 401 if (unlikely(rem < 0)) {
401 set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec); 402 ts.tv_sec--;
403 rem += NSEC_PER_SEC;
404 }
405 ts.tv_nsec = rem;
402 406
403 return ts; 407 return ts;
404} 408}
@@ -528,8 +532,10 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
528 * Convert jiffies to nanoseconds and separate with 532 * Convert jiffies to nanoseconds and separate with
529 * one divide. 533 * one divide.
530 */ 534 */
531 u64 nsec = (u64)jiffies * TICK_NSEC; 535 u32 rem;
532 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_nsec); 536 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
537 NSEC_PER_SEC, &rem);
538 value->tv_nsec = rem;
533} 539}
534EXPORT_SYMBOL(jiffies_to_timespec); 540EXPORT_SYMBOL(jiffies_to_timespec);
535 541
@@ -567,12 +573,11 @@ void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value)
567 * Convert jiffies to nanoseconds and separate with 573 * Convert jiffies to nanoseconds and separate with
568 * one divide. 574 * one divide.
569 */ 575 */
570 u64 nsec = (u64)jiffies * TICK_NSEC; 576 u32 rem;
571 long tv_usec;
572 577
573 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec); 578 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
574 tv_usec /= NSEC_PER_USEC; 579 NSEC_PER_SEC, &rem);
575 value->tv_usec = tv_usec; 580 value->tv_usec = rem / NSEC_PER_USEC;
576} 581}
577EXPORT_SYMBOL(jiffies_to_timeval); 582EXPORT_SYMBOL(jiffies_to_timeval);
578 583
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index a4492f3d64db..dbd6f8905614 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -234,7 +234,7 @@ static inline void notify_cmos_timer(void) { }
234 */ 234 */
235int do_adjtimex(struct timex *txc) 235int do_adjtimex(struct timex *txc)
236{ 236{
237 long mtemp, save_adjust, rem; 237 long mtemp, save_adjust;
238 s64 freq_adj; 238 s64 freq_adj;
239 int result; 239 int result;
240 240
@@ -345,9 +345,7 @@ int do_adjtimex(struct timex *txc)
345 freq_adj += time_freq; 345 freq_adj += time_freq;
346 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC); 346 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
347 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC); 347 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC);
348 time_offset = div_long_long_rem_signed(time_offset, 348 time_offset = div_s64(time_offset, NTP_INTERVAL_FREQ);
349 NTP_INTERVAL_FREQ,
350 &rem);
351 time_offset <<= SHIFT_UPDATE; 349 time_offset <<= SHIFT_UPDATE;
352 } /* STA_PLL */ 350 } /* STA_PLL */
353 } /* txc->modes & ADJ_OFFSET */ 351 } /* txc->modes & ADJ_OFFSET */