aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/cputime_nsecs.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-generic/cputime_nsecs.h')
-rw-r--r--include/asm-generic/cputime_nsecs.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index a8ece9a33aef..2c9e62c2bfd0 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -16,21 +16,27 @@
16#ifndef _ASM_GENERIC_CPUTIME_NSECS_H 16#ifndef _ASM_GENERIC_CPUTIME_NSECS_H
17#define _ASM_GENERIC_CPUTIME_NSECS_H 17#define _ASM_GENERIC_CPUTIME_NSECS_H
18 18
19#include <linux/math64.h>
20
19typedef u64 __nocast cputime_t; 21typedef u64 __nocast cputime_t;
20typedef u64 __nocast cputime64_t; 22typedef u64 __nocast cputime64_t;
21 23
22#define cputime_one_jiffy jiffies_to_cputime(1) 24#define cputime_one_jiffy jiffies_to_cputime(1)
23 25
26#define cputime_div(__ct, divisor) div_u64((__force u64)__ct, divisor)
27#define cputime_div_rem(__ct, divisor, remainder) \
28 div_u64_rem((__force u64)__ct, divisor, remainder);
29
24/* 30/*
25 * Convert cputime <-> jiffies (HZ) 31 * Convert cputime <-> jiffies (HZ)
26 */ 32 */
27#define cputime_to_jiffies(__ct) \ 33#define cputime_to_jiffies(__ct) \
28 ((__force u64)(__ct) / (NSEC_PER_SEC / HZ)) 34 cputime_div(__ct, NSEC_PER_SEC / HZ)
29#define cputime_to_scaled(__ct) (__ct) 35#define cputime_to_scaled(__ct) (__ct)
30#define jiffies_to_cputime(__jif) \ 36#define jiffies_to_cputime(__jif) \
31 (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ)) 37 (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ))
32#define cputime64_to_jiffies64(__ct) \ 38#define cputime64_to_jiffies64(__ct) \
33 ((__force u64)(__ct) / (NSEC_PER_SEC / HZ)) 39 cputime_div(__ct, NSEC_PER_SEC / HZ)
34#define jiffies64_to_cputime64(__jif) \ 40#define jiffies64_to_cputime64(__jif) \
35 (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ)) 41 (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ))
36 42
@@ -45,7 +51,7 @@ typedef u64 __nocast cputime64_t;
45 * Convert cputime <-> microseconds 51 * Convert cputime <-> microseconds
46 */ 52 */
47#define cputime_to_usecs(__ct) \ 53#define cputime_to_usecs(__ct) \
48 ((__force u64)(__ct) / NSEC_PER_USEC) 54 cputime_div(__ct, NSEC_PER_USEC)
49#define usecs_to_cputime(__usecs) \ 55#define usecs_to_cputime(__usecs) \
50 (__force cputime_t)((__usecs) * NSEC_PER_USEC) 56 (__force cputime_t)((__usecs) * NSEC_PER_USEC)
51#define usecs_to_cputime64(__usecs) \ 57#define usecs_to_cputime64(__usecs) \
@@ -55,7 +61,7 @@ typedef u64 __nocast cputime64_t;
55 * Convert cputime <-> seconds 61 * Convert cputime <-> seconds
56 */ 62 */
57#define cputime_to_secs(__ct) \ 63#define cputime_to_secs(__ct) \
58 ((__force u64)(__ct) / NSEC_PER_SEC) 64 cputime_div(__ct, NSEC_PER_SEC)
59#define secs_to_cputime(__secs) \ 65#define secs_to_cputime(__secs) \
60 (__force cputime_t)((__secs) * NSEC_PER_SEC) 66 (__force cputime_t)((__secs) * NSEC_PER_SEC)
61 67
@@ -69,8 +75,10 @@ static inline cputime_t timespec_to_cputime(const struct timespec *val)
69} 75}
70static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) 76static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
71{ 77{
72 val->tv_sec = (__force u64) ct / NSEC_PER_SEC; 78 u32 rem;
73 val->tv_nsec = (__force u64) ct % NSEC_PER_SEC; 79
80 val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem);
81 val->tv_nsec = rem;
74} 82}
75 83
76/* 84/*
@@ -83,15 +91,17 @@ static inline cputime_t timeval_to_cputime(const struct timeval *val)
83} 91}
84static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val) 92static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)
85{ 93{
86 val->tv_sec = (__force u64) ct / NSEC_PER_SEC; 94 u32 rem;
87 val->tv_usec = ((__force u64) ct % NSEC_PER_SEC) / NSEC_PER_USEC; 95
96 val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem);
97 val->tv_usec = rem / NSEC_PER_USEC;
88} 98}
89 99
90/* 100/*
91 * Convert cputime <-> clock (USER_HZ) 101 * Convert cputime <-> clock (USER_HZ)
92 */ 102 */
93#define cputime_to_clock_t(__ct) \ 103#define cputime_to_clock_t(__ct) \
94 ((__force u64)(__ct) / (NSEC_PER_SEC / USER_HZ)) 104 cputime_div(__ct, (NSEC_PER_SEC / USER_HZ))
95#define clock_t_to_cputime(__x) \ 105#define clock_t_to_cputime(__x) \
96 (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ)) 106 (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ))
97 107