aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/mips/kernel/binfmt_elfn32.c5
-rw-r--r--arch/mips/kernel/binfmt_elfo32.c5
-rw-r--r--drivers/char/mmtimer.c24
-rw-r--r--include/asm-x86/div64.h18
-rw-r--r--include/linux/calc64.h49
-rw-r--r--include/linux/jiffies.h2
-rw-r--r--kernel/posix-cpu-timers.c11
-rw-r--r--kernel/time.c25
-rw-r--r--kernel/time/ntp.c6
-rw-r--r--mm/slub.c9
10 files changed, 44 insertions, 110 deletions
diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
index 77db3473deab..9fdd8bcdd21e 100644
--- a/arch/mips/kernel/binfmt_elfn32.c
+++ b/arch/mips/kernel/binfmt_elfn32.c
@@ -54,6 +54,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/elfcore.h> 55#include <linux/elfcore.h>
56#include <linux/compat.h> 56#include <linux/compat.h>
57#include <linux/math64.h>
57 58
58#define elf_prstatus elf_prstatus32 59#define elf_prstatus elf_prstatus32
59struct elf_prstatus32 60struct elf_prstatus32
@@ -102,8 +103,8 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
102 * one divide. 103 * one divide.
103 */ 104 */
104 u64 nsec = (u64)jiffies * TICK_NSEC; 105 u64 nsec = (u64)jiffies * TICK_NSEC;
105 long rem; 106 u32 rem;
106 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 107 value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
107 value->tv_usec = rem / NSEC_PER_USEC; 108 value->tv_usec = rem / NSEC_PER_USEC;
108} 109}
109 110
diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
index 08f4cd781ee3..e1333d7319e2 100644
--- a/arch/mips/kernel/binfmt_elfo32.c
+++ b/arch/mips/kernel/binfmt_elfo32.c
@@ -56,6 +56,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/elfcore.h> 57#include <linux/elfcore.h>
58#include <linux/compat.h> 58#include <linux/compat.h>
59#include <linux/math64.h>
59 60
60#define elf_prstatus elf_prstatus32 61#define elf_prstatus elf_prstatus32
61struct elf_prstatus32 62struct elf_prstatus32
@@ -104,8 +105,8 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
104 * one divide. 105 * one divide.
105 */ 106 */
106 u64 nsec = (u64)jiffies * TICK_NSEC; 107 u64 nsec = (u64)jiffies * TICK_NSEC;
107 long rem; 108 u32 rem;
108 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 109 value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
109 value->tv_usec = rem / NSEC_PER_USEC; 110 value->tv_usec = rem / NSEC_PER_USEC;
110} 111}
111 112
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index d83db5d880e0..192961fd7173 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -30,6 +30,8 @@
30#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
31#include <linux/posix-timers.h> 31#include <linux/posix-timers.h>
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/time.h>
34#include <linux/math64.h>
33 35
34#include <asm/uaccess.h> 36#include <asm/uaccess.h>
35#include <asm/sn/addrs.h> 37#include <asm/sn/addrs.h>
@@ -472,8 +474,8 @@ static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
472 474
473 nsec = rtc_time() * sgi_clock_period 475 nsec = rtc_time() * sgi_clock_period
474 + sgi_clock_offset.tv_nsec; 476 + sgi_clock_offset.tv_nsec;
475 tp->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tp->tv_nsec) 477 *tp = ns_to_timespec(nsec);
476 + sgi_clock_offset.tv_sec; 478 tp->tv_sec += sgi_clock_offset.tv_sec;
477 return 0; 479 return 0;
478}; 480};
479 481
@@ -481,11 +483,11 @@ static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
481{ 483{
482 484
483 u64 nsec; 485 u64 nsec;
484 u64 rem; 486 u32 rem;
485 487
486 nsec = rtc_time() * sgi_clock_period; 488 nsec = rtc_time() * sgi_clock_period;
487 489
488 sgi_clock_offset.tv_sec = tp->tv_sec - div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 490 sgi_clock_offset.tv_sec = tp->tv_sec - div_u64_rem(nsec, NSEC_PER_SEC, &rem);
489 491
490 if (rem <= tp->tv_nsec) 492 if (rem <= tp->tv_nsec)
491 sgi_clock_offset.tv_nsec = tp->tv_sec - rem; 493 sgi_clock_offset.tv_nsec = tp->tv_sec - rem;
@@ -644,9 +646,6 @@ static int sgi_timer_del(struct k_itimer *timr)
644 return 0; 646 return 0;
645} 647}
646 648
647#define timespec_to_ns(x) ((x).tv_nsec + (x).tv_sec * NSEC_PER_SEC)
648#define ns_to_timespec(ts, nsec) (ts).tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &(ts).tv_nsec)
649
650/* Assumption: it_lock is already held with irq's disabled */ 649/* Assumption: it_lock is already held with irq's disabled */
651static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) 650static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
652{ 651{
@@ -659,9 +658,8 @@ static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
659 return; 658 return;
660 } 659 }
661 660
662 ns_to_timespec(cur_setting->it_interval, timr->it.mmtimer.incr * sgi_clock_period); 661 cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * sgi_clock_period);
663 ns_to_timespec(cur_setting->it_value, (timr->it.mmtimer.expires - rtc_time())* sgi_clock_period); 662 cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - rtc_time()) * sgi_clock_period);
664 return;
665} 663}
666 664
667 665
@@ -679,8 +677,8 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
679 sgi_timer_get(timr, old_setting); 677 sgi_timer_get(timr, old_setting);
680 678
681 sgi_timer_del(timr); 679 sgi_timer_del(timr);
682 when = timespec_to_ns(new_setting->it_value); 680 when = timespec_to_ns(&new_setting->it_value);
683 period = timespec_to_ns(new_setting->it_interval); 681 period = timespec_to_ns(&new_setting->it_interval);
684 682
685 if (when == 0) 683 if (when == 0)
686 /* Clear timer */ 684 /* Clear timer */
@@ -695,7 +693,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
695 unsigned long now; 693 unsigned long now;
696 694
697 getnstimeofday(&n); 695 getnstimeofday(&n);
698 now = timespec_to_ns(n); 696 now = timespec_to_ns(&n);
699 if (when > now) 697 if (when > now)
700 when -= now; 698 when -= now;
701 else 699 else
diff --git a/include/asm-x86/div64.h b/include/asm-x86/div64.h
index 32fdbddaae55..9a2d644c08ef 100644
--- a/include/asm-x86/div64.h
+++ b/include/asm-x86/div64.h
@@ -33,24 +33,6 @@
33 __mod; \ 33 __mod; \
34}) 34})
35 35
36/*
37 * (long)X = ((long long)divs) / (long)div
38 * (long)rem = ((long long)divs) % (long)div
39 *
40 * Warning, this will do an exception if X overflows.
41 */
42#define div_long_long_rem(a, b, c) div_ll_X_l_rem(a, b, c)
43
44static inline long div_ll_X_l_rem(long long divs, long div, long *rem)
45{
46 long dum2;
47 asm("divl %2":"=a"(dum2), "=d"(*rem)
48 : "rm"(div), "A"(divs));
49
50 return dum2;
51
52}
53
54static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) 36static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
55{ 37{
56 union { 38 union {
diff --git a/include/linux/calc64.h b/include/linux/calc64.h
deleted file mode 100644
index ebf4b8f38d88..000000000000
--- a/include/linux/calc64.h
+++ /dev/null
@@ -1,49 +0,0 @@
1#ifndef _LINUX_CALC64_H
2#define _LINUX_CALC64_H
3
4#include <linux/types.h>
5#include <asm/div64.h>
6
7/*
8 * This is a generic macro which is used when the architecture
9 * specific div64.h does not provide a optimized one.
10 *
11 * The 64bit dividend is divided by the divisor (data type long), the
12 * result is returned and the remainder stored in the variable
13 * referenced by remainder (data type long *). In contrast to the
14 * do_div macro the dividend is kept intact.
15 */
16#ifndef div_long_long_rem
17#define div_long_long_rem(dividend, divisor, remainder) \
18 do_div_llr((dividend), divisor, remainder)
19
20static inline unsigned long do_div_llr(const long long dividend,
21 const long divisor, long *remainder)
22{
23 u64 result = dividend;
24
25 *(remainder) = do_div(result, divisor);
26 return (unsigned long) result;
27}
28#endif
29
30/*
31 * Sign aware variation of the above. On some architectures a
32 * negative dividend leads to an divide overflow exception, which
33 * is avoided by the sign check.
34 */
35static inline long div_long_long_rem_signed(const long long dividend,
36 const long divisor, long *remainder)
37{
38 long res;
39
40 if (unlikely(dividend < 0)) {
41 res = -div_long_long_rem(-dividend, divisor, remainder);
42 *remainder = -(*remainder);
43 } else
44 res = div_long_long_rem(dividend, divisor, remainder);
45
46 return res;
47}
48
49#endif
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 33ef710dac24..abb6ac639e8e 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -1,7 +1,7 @@
1#ifndef _LINUX_JIFFIES_H 1#ifndef _LINUX_JIFFIES_H
2#define _LINUX_JIFFIES_H 2#define _LINUX_JIFFIES_H
3 3
4#include <linux/calc64.h> 4#include <linux/math64.h>
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/time.h> 7#include <linux/time.h>
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 */
diff --git a/mm/slub.c b/mm/slub.c
index 70db2897c1ea..32b62623846a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -22,6 +22,7 @@
22#include <linux/debugobjects.h> 22#include <linux/debugobjects.h>
23#include <linux/kallsyms.h> 23#include <linux/kallsyms.h>
24#include <linux/memory.h> 24#include <linux/memory.h>
25#include <linux/math64.h>
25 26
26/* 27/*
27 * Lock order: 28 * Lock order:
@@ -3621,12 +3622,10 @@ static int list_locations(struct kmem_cache *s, char *buf,
3621 len += sprintf(buf + len, "<not-available>"); 3622 len += sprintf(buf + len, "<not-available>");
3622 3623
3623 if (l->sum_time != l->min_time) { 3624 if (l->sum_time != l->min_time) {
3624 unsigned long remainder;
3625
3626 len += sprintf(buf + len, " age=%ld/%ld/%ld", 3625 len += sprintf(buf + len, " age=%ld/%ld/%ld",
3627 l->min_time, 3626 l->min_time,
3628 div_long_long_rem(l->sum_time, l->count, &remainder), 3627 (long)div_u64(l->sum_time, l->count),
3629 l->max_time); 3628 l->max_time);
3630 } else 3629 } else
3631 len += sprintf(buf + len, " age=%ld", 3630 len += sprintf(buf + len, " age=%ld",
3632 l->min_time); 3631 l->min_time);