diff options
-rw-r--r-- | include/linux/calc64.h | 49 | ||||
-rw-r--r-- | include/linux/jiffies.h | 18 |
2 files changed, 55 insertions, 12 deletions
diff --git a/include/linux/calc64.h b/include/linux/calc64.h new file mode 100644 index 000000000000..ebf4b8f38d88 --- /dev/null +++ b/include/linux/calc64.h | |||
@@ -0,0 +1,49 @@ | |||
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 | |||
20 | static 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 | */ | ||
35 | static 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 6acfdbba734b..99905e180532 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h | |||
@@ -1,21 +1,12 @@ | |||
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/kernel.h> | 5 | #include <linux/kernel.h> |
5 | #include <linux/types.h> | 6 | #include <linux/types.h> |
6 | #include <linux/time.h> | 7 | #include <linux/time.h> |
7 | #include <linux/timex.h> | 8 | #include <linux/timex.h> |
8 | #include <asm/param.h> /* for HZ */ | 9 | #include <asm/param.h> /* for HZ */ |
9 | #include <asm/div64.h> | ||
10 | |||
11 | #ifndef div_long_long_rem | ||
12 | #define div_long_long_rem(dividend,divisor,remainder) \ | ||
13 | ({ \ | ||
14 | u64 result = dividend; \ | ||
15 | *remainder = do_div(result,divisor); \ | ||
16 | result; \ | ||
17 | }) | ||
18 | #endif | ||
19 | 10 | ||
20 | /* | 11 | /* |
21 | * The following defines establish the engineering parameters of the PLL | 12 | * The following defines establish the engineering parameters of the PLL |
@@ -373,8 +364,11 @@ jiffies_to_timeval(const unsigned long jiffies, struct timeval *value) | |||
373 | * one divide. | 364 | * one divide. |
374 | */ | 365 | */ |
375 | u64 nsec = (u64)jiffies * TICK_NSEC; | 366 | u64 nsec = (u64)jiffies * TICK_NSEC; |
376 | value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_usec); | 367 | long tv_usec; |
377 | value->tv_usec /= NSEC_PER_USEC; | 368 | |
369 | value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec); | ||
370 | tv_usec /= NSEC_PER_USEC; | ||
371 | value->tv_usec = tv_usec; | ||
378 | } | 372 | } |
379 | 373 | ||
380 | /* | 374 | /* |