aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2011-12-15 08:56:09 -0500
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2011-12-15 08:56:19 -0500
commit648616343cdbe904c585a6c12e323d3b3c72e46f (patch)
tree514bce1b52663db4ab5662b637c764cf3c2ed1eb /arch
parent55b02d2f4445ad625213817a1736bf2884d32547 (diff)
[S390] cputime: add sparse checking and cleanup
Make cputime_t and cputime64_t nocast to enable sparse checking to detect incorrect use of cputime. Drop the cputime macros for simple scalar operations. The conversion macros are still needed. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/ia64/include/asm/cputime.h69
-rw-r--r--arch/powerpc/include/asm/cputime.h70
-rw-r--r--arch/s390/include/asm/cputime.h140
3 files changed, 122 insertions, 157 deletions
diff --git a/arch/ia64/include/asm/cputime.h b/arch/ia64/include/asm/cputime.h
index 6073b187528a..461e52f0277f 100644
--- a/arch/ia64/include/asm/cputime.h
+++ b/arch/ia64/include/asm/cputime.h
@@ -26,59 +26,51 @@
26#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <asm/processor.h> 27#include <asm/processor.h>
28 28
29typedef u64 cputime_t; 29typedef u64 __nocast cputime_t;
30typedef u64 cputime64_t; 30typedef u64 __nocast cputime64_t;
31 31
32#define cputime_zero ((cputime_t)0)
33#define cputime_one_jiffy jiffies_to_cputime(1) 32#define cputime_one_jiffy jiffies_to_cputime(1)
34#define cputime_max ((~((cputime_t)0) >> 1) - 1)
35#define cputime_add(__a, __b) ((__a) + (__b))
36#define cputime_sub(__a, __b) ((__a) - (__b))
37#define cputime_div(__a, __n) ((__a) / (__n))
38#define cputime_halve(__a) ((__a) >> 1)
39#define cputime_eq(__a, __b) ((__a) == (__b))
40#define cputime_gt(__a, __b) ((__a) > (__b))
41#define cputime_ge(__a, __b) ((__a) >= (__b))
42#define cputime_lt(__a, __b) ((__a) < (__b))
43#define cputime_le(__a, __b) ((__a) <= (__b))
44
45#define cputime64_zero ((cputime64_t)0)
46#define cputime64_add(__a, __b) ((__a) + (__b))
47#define cputime64_sub(__a, __b) ((__a) - (__b))
48#define cputime_to_cputime64(__ct) (__ct)
49 33
50/* 34/*
51 * Convert cputime <-> jiffies (HZ) 35 * Convert cputime <-> jiffies (HZ)
52 */ 36 */
53#define cputime_to_jiffies(__ct) ((__ct) / (NSEC_PER_SEC / HZ)) 37#define cputime_to_jiffies(__ct) \
54#define jiffies_to_cputime(__jif) ((__jif) * (NSEC_PER_SEC / HZ)) 38 ((__force u64)(__ct) / (NSEC_PER_SEC / HZ))
55#define cputime64_to_jiffies64(__ct) ((__ct) / (NSEC_PER_SEC / HZ)) 39#define jiffies_to_cputime(__jif) \
56#define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ)) 40 (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ))
41#define cputime64_to_jiffies64(__ct) \
42 ((__force u64)(__ct) / (NSEC_PER_SEC / HZ))
43#define jiffies64_to_cputime64(__jif) \
44 (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ))
57 45
58/* 46/*
59 * Convert cputime <-> microseconds 47 * Convert cputime <-> microseconds
60 */ 48 */
61#define cputime_to_usecs(__ct) ((__ct) / NSEC_PER_USEC) 49#define cputime_to_usecs(__ct) \
62#define usecs_to_cputime(__usecs) ((__usecs) * NSEC_PER_USEC) 50 ((__force u64)(__ct) / NSEC_PER_USEC)
51#define usecs_to_cputime(__usecs) \
52 (__force cputime_t)((__usecs) * NSEC_PER_USEC)
63 53
64/* 54/*
65 * Convert cputime <-> seconds 55 * Convert cputime <-> seconds
66 */ 56 */
67#define cputime_to_secs(__ct) ((__ct) / NSEC_PER_SEC) 57#define cputime_to_secs(__ct) \
68#define secs_to_cputime(__secs) ((__secs) * NSEC_PER_SEC) 58 ((__force u64)(__ct) / NSEC_PER_SEC)
59#define secs_to_cputime(__secs) \
60 (__force cputime_t)((__secs) * NSEC_PER_SEC)
69 61
70/* 62/*
71 * Convert cputime <-> timespec (nsec) 63 * Convert cputime <-> timespec (nsec)
72 */ 64 */
73static inline cputime_t timespec_to_cputime(const struct timespec *val) 65static inline cputime_t timespec_to_cputime(const struct timespec *val)
74{ 66{
75 cputime_t ret = val->tv_sec * NSEC_PER_SEC; 67 u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_nsec;
76 return (ret + val->tv_nsec); 68 return (__force cputime_t) ret;
77} 69}
78static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) 70static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
79{ 71{
80 val->tv_sec = ct / NSEC_PER_SEC; 72 val->tv_sec = (__force u64) ct / NSEC_PER_SEC;
81 val->tv_nsec = ct % NSEC_PER_SEC; 73 val->tv_nsec = (__force u64) ct % NSEC_PER_SEC;
82} 74}
83 75
84/* 76/*
@@ -86,25 +78,28 @@ static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
86 */ 78 */
87static inline cputime_t timeval_to_cputime(struct timeval *val) 79static inline cputime_t timeval_to_cputime(struct timeval *val)
88{ 80{
89 cputime_t ret = val->tv_sec * NSEC_PER_SEC; 81 u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_usec * NSEC_PER_USEC;
90 return (ret + val->tv_usec * NSEC_PER_USEC); 82 return (__force cputime_t) ret;
91} 83}
92static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val) 84static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val)
93{ 85{
94 val->tv_sec = ct / NSEC_PER_SEC; 86 val->tv_sec = (__force u64) ct / NSEC_PER_SEC;
95 val->tv_usec = (ct % NSEC_PER_SEC) / NSEC_PER_USEC; 87 val->tv_usec = ((__force u64) ct % NSEC_PER_SEC) / NSEC_PER_USEC;
96} 88}
97 89
98/* 90/*
99 * Convert cputime <-> clock (USER_HZ) 91 * Convert cputime <-> clock (USER_HZ)
100 */ 92 */
101#define cputime_to_clock_t(__ct) ((__ct) / (NSEC_PER_SEC / USER_HZ)) 93#define cputime_to_clock_t(__ct) \
102#define clock_t_to_cputime(__x) ((__x) * (NSEC_PER_SEC / USER_HZ)) 94 ((__force u64)(__ct) / (NSEC_PER_SEC / USER_HZ))
95#define clock_t_to_cputime(__x) \
96 (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ))
103 97
104/* 98/*
105 * Convert cputime64 to clock. 99 * Convert cputime64 to clock.
106 */ 100 */
107#define cputime64_to_clock_t(__ct) cputime_to_clock_t((cputime_t)__ct) 101#define cputime64_to_clock_t(__ct) \
102 cputime_to_clock_t((__force cputime_t)__ct)
108 103
109#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ 104#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
110#endif /* __IA64_CPUTIME_H */ 105#endif /* __IA64_CPUTIME_H */
diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 1cf20bdfbeca..e94935c52019 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -29,25 +29,8 @@ static inline void setup_cputime_one_jiffy(void) { }
29#include <asm/time.h> 29#include <asm/time.h>
30#include <asm/param.h> 30#include <asm/param.h>
31 31
32typedef u64 cputime_t; 32typedef u64 __nocast cputime_t;
33typedef u64 cputime64_t; 33typedef u64 __nocast cputime64_t;
34
35#define cputime_zero ((cputime_t)0)
36#define cputime_max ((~((cputime_t)0) >> 1) - 1)
37#define cputime_add(__a, __b) ((__a) + (__b))
38#define cputime_sub(__a, __b) ((__a) - (__b))
39#define cputime_div(__a, __n) ((__a) / (__n))
40#define cputime_halve(__a) ((__a) >> 1)
41#define cputime_eq(__a, __b) ((__a) == (__b))
42#define cputime_gt(__a, __b) ((__a) > (__b))
43#define cputime_ge(__a, __b) ((__a) >= (__b))
44#define cputime_lt(__a, __b) ((__a) < (__b))
45#define cputime_le(__a, __b) ((__a) <= (__b))
46
47#define cputime64_zero ((cputime64_t)0)
48#define cputime64_add(__a, __b) ((__a) + (__b))
49#define cputime64_sub(__a, __b) ((__a) - (__b))
50#define cputime_to_cputime64(__ct) (__ct)
51 34
52#ifdef __KERNEL__ 35#ifdef __KERNEL__
53 36
@@ -65,7 +48,7 @@ DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);
65 48
66static inline unsigned long cputime_to_jiffies(const cputime_t ct) 49static inline unsigned long cputime_to_jiffies(const cputime_t ct)
67{ 50{
68 return mulhdu(ct, __cputime_jiffies_factor); 51 return mulhdu((__force u64) ct, __cputime_jiffies_factor);
69} 52}
70 53
71/* Estimate the scaled cputime by scaling the real cputime based on 54/* Estimate the scaled cputime by scaling the real cputime based on
@@ -74,14 +57,15 @@ static inline cputime_t cputime_to_scaled(const cputime_t ct)
74{ 57{
75 if (cpu_has_feature(CPU_FTR_SPURR) && 58 if (cpu_has_feature(CPU_FTR_SPURR) &&
76 __get_cpu_var(cputime_last_delta)) 59 __get_cpu_var(cputime_last_delta))
77 return ct * __get_cpu_var(cputime_scaled_last_delta) / 60 return (__force u64) ct *
78 __get_cpu_var(cputime_last_delta); 61 __get_cpu_var(cputime_scaled_last_delta) /
62 __get_cpu_var(cputime_last_delta);
79 return ct; 63 return ct;
80} 64}
81 65
82static inline cputime_t jiffies_to_cputime(const unsigned long jif) 66static inline cputime_t jiffies_to_cputime(const unsigned long jif)
83{ 67{
84 cputime_t ct; 68 u64 ct;
85 unsigned long sec; 69 unsigned long sec;
86 70
87 /* have to be a little careful about overflow */ 71 /* have to be a little careful about overflow */
@@ -93,7 +77,7 @@ static inline cputime_t jiffies_to_cputime(const unsigned long jif)
93 } 77 }
94 if (sec) 78 if (sec)
95 ct += (cputime_t) sec * tb_ticks_per_sec; 79 ct += (cputime_t) sec * tb_ticks_per_sec;
96 return ct; 80 return (__force cputime_t) ct;
97} 81}
98 82
99static inline void setup_cputime_one_jiffy(void) 83static inline void setup_cputime_one_jiffy(void)
@@ -103,7 +87,7 @@ static inline void setup_cputime_one_jiffy(void)
103 87
104static inline cputime64_t jiffies64_to_cputime64(const u64 jif) 88static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
105{ 89{
106 cputime_t ct; 90 u64 ct;
107 u64 sec; 91 u64 sec;
108 92
109 /* have to be a little careful about overflow */ 93 /* have to be a little careful about overflow */
@@ -114,13 +98,13 @@ static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
114 do_div(ct, HZ); 98 do_div(ct, HZ);
115 } 99 }
116 if (sec) 100 if (sec)
117 ct += (cputime_t) sec * tb_ticks_per_sec; 101 ct += (u64) sec * tb_ticks_per_sec;
118 return ct; 102 return (__force cputime64_t) ct;
119} 103}
120 104
121static inline u64 cputime64_to_jiffies64(const cputime_t ct) 105static inline u64 cputime64_to_jiffies64(const cputime_t ct)
122{ 106{
123 return mulhdu(ct, __cputime_jiffies_factor); 107 return mulhdu((__force u64) ct, __cputime_jiffies_factor);
124} 108}
125 109
126/* 110/*
@@ -130,12 +114,12 @@ extern u64 __cputime_msec_factor;
130 114
131static inline unsigned long cputime_to_usecs(const cputime_t ct) 115static inline unsigned long cputime_to_usecs(const cputime_t ct)
132{ 116{
133 return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC; 117 return mulhdu((__force u64) ct, __cputime_msec_factor) * USEC_PER_MSEC;
134} 118}
135 119
136static inline cputime_t usecs_to_cputime(const unsigned long us) 120static inline cputime_t usecs_to_cputime(const unsigned long us)
137{ 121{
138 cputime_t ct; 122 u64 ct;
139 unsigned long sec; 123 unsigned long sec;
140 124
141 /* have to be a little careful about overflow */ 125 /* have to be a little careful about overflow */
@@ -147,7 +131,7 @@ static inline cputime_t usecs_to_cputime(const unsigned long us)
147 } 131 }
148 if (sec) 132 if (sec)
149 ct += (cputime_t) sec * tb_ticks_per_sec; 133 ct += (cputime_t) sec * tb_ticks_per_sec;
150 return ct; 134 return (__force cputime_t) ct;
151} 135}
152 136
153/* 137/*
@@ -157,12 +141,12 @@ extern u64 __cputime_sec_factor;
157 141
158static inline unsigned long cputime_to_secs(const cputime_t ct) 142static inline unsigned long cputime_to_secs(const cputime_t ct)
159{ 143{
160 return mulhdu(ct, __cputime_sec_factor); 144 return mulhdu((__force u64) ct, __cputime_sec_factor);
161} 145}
162 146
163static inline cputime_t secs_to_cputime(const unsigned long sec) 147static inline cputime_t secs_to_cputime(const unsigned long sec)
164{ 148{
165 return (cputime_t) sec * tb_ticks_per_sec; 149 return (__force cputime_t)((u64) sec * tb_ticks_per_sec);
166} 150}
167 151
168/* 152/*
@@ -170,7 +154,7 @@ static inline cputime_t secs_to_cputime(const unsigned long sec)
170 */ 154 */
171static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p) 155static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
172{ 156{
173 u64 x = ct; 157 u64 x = (__force u64) ct;
174 unsigned int frac; 158 unsigned int frac;
175 159
176 frac = do_div(x, tb_ticks_per_sec); 160 frac = do_div(x, tb_ticks_per_sec);
@@ -182,11 +166,11 @@ static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
182 166
183static inline cputime_t timespec_to_cputime(const struct timespec *p) 167static inline cputime_t timespec_to_cputime(const struct timespec *p)
184{ 168{
185 cputime_t ct; 169 u64 ct;
186 170
187 ct = (u64) p->tv_nsec * tb_ticks_per_sec; 171 ct = (u64) p->tv_nsec * tb_ticks_per_sec;
188 do_div(ct, 1000000000); 172 do_div(ct, 1000000000);
189 return ct + (u64) p->tv_sec * tb_ticks_per_sec; 173 return (__force cputime_t)(ct + (u64) p->tv_sec * tb_ticks_per_sec);
190} 174}
191 175
192/* 176/*
@@ -194,7 +178,7 @@ static inline cputime_t timespec_to_cputime(const struct timespec *p)
194 */ 178 */
195static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p) 179static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p)
196{ 180{
197 u64 x = ct; 181 u64 x = (__force u64) ct;
198 unsigned int frac; 182 unsigned int frac;
199 183
200 frac = do_div(x, tb_ticks_per_sec); 184 frac = do_div(x, tb_ticks_per_sec);
@@ -206,11 +190,11 @@ static inline void cputime_to_timeval(const cputime_t ct, struct timeval *p)
206 190
207static inline cputime_t timeval_to_cputime(const struct timeval *p) 191static inline cputime_t timeval_to_cputime(const struct timeval *p)
208{ 192{
209 cputime_t ct; 193 u64 ct;
210 194
211 ct = (u64) p->tv_usec * tb_ticks_per_sec; 195 ct = (u64) p->tv_usec * tb_ticks_per_sec;
212 do_div(ct, 1000000); 196 do_div(ct, 1000000);
213 return ct + (u64) p->tv_sec * tb_ticks_per_sec; 197 return (__force cputime_t)(ct + (u64) p->tv_sec * tb_ticks_per_sec);
214} 198}
215 199
216/* 200/*
@@ -220,12 +204,12 @@ extern u64 __cputime_clockt_factor;
220 204
221static inline unsigned long cputime_to_clock_t(const cputime_t ct) 205static inline unsigned long cputime_to_clock_t(const cputime_t ct)
222{ 206{
223 return mulhdu(ct, __cputime_clockt_factor); 207 return mulhdu((__force u64) ct, __cputime_clockt_factor);
224} 208}
225 209
226static inline cputime_t clock_t_to_cputime(const unsigned long clk) 210static inline cputime_t clock_t_to_cputime(const unsigned long clk)
227{ 211{
228 cputime_t ct; 212 u64 ct;
229 unsigned long sec; 213 unsigned long sec;
230 214
231 /* have to be a little careful about overflow */ 215 /* have to be a little careful about overflow */
@@ -236,8 +220,8 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)
236 do_div(ct, USER_HZ); 220 do_div(ct, USER_HZ);
237 } 221 }
238 if (sec) 222 if (sec)
239 ct += (cputime_t) sec * tb_ticks_per_sec; 223 ct += (u64) sec * tb_ticks_per_sec;
240 return ct; 224 return (__force cputime_t) ct;
241} 225}
242 226
243#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct)) 227#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h
index 081434878296..0887a0463e33 100644
--- a/arch/s390/include/asm/cputime.h
+++ b/arch/s390/include/asm/cputime.h
@@ -16,114 +16,98 @@
16 16
17/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */ 17/* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
18 18
19typedef unsigned long long cputime_t; 19typedef unsigned long long __nocast cputime_t;
20typedef unsigned long long cputime64_t; 20typedef unsigned long long __nocast cputime64_t;
21 21
22#ifndef __s390x__ 22static inline unsigned long __div(unsigned long long n, unsigned long base)
23
24static inline unsigned int
25__div(unsigned long long n, unsigned int base)
26{ 23{
24#ifndef __s390x__
27 register_pair rp; 25 register_pair rp;
28 26
29 rp.pair = n >> 1; 27 rp.pair = n >> 1;
30 asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1)); 28 asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
31 return rp.subreg.odd; 29 return rp.subreg.odd;
30#else /* __s390x__ */
31 return n / base;
32#endif /* __s390x__ */
32} 33}
33 34
34#else /* __s390x__ */ 35#define cputime_one_jiffy jiffies_to_cputime(1)
35 36
36static inline unsigned int 37/*
37__div(unsigned long long n, unsigned int base) 38 * Convert cputime to jiffies and back.
39 */
40static inline unsigned long cputime_to_jiffies(const cputime_t cputime)
38{ 41{
39 return n / base; 42 return __div((__force unsigned long long) cputime, 4096000000ULL / HZ);
40} 43}
41 44
42#endif /* __s390x__ */ 45static inline cputime_t jiffies_to_cputime(const unsigned int jif)
46{
47 return (__force cputime_t)(jif * (4096000000ULL / HZ));
48}
43 49
44#define cputime_zero (0ULL) 50static inline u64 cputime64_to_jiffies64(cputime64_t cputime)
45#define cputime_one_jiffy jiffies_to_cputime(1) 51{
46#define cputime_max ((~0UL >> 1) - 1) 52 unsigned long long jif = (__force unsigned long long) cputime;
47#define cputime_add(__a, __b) ((__a) + (__b)) 53 do_div(jif, 4096000000ULL / HZ);
48#define cputime_sub(__a, __b) ((__a) - (__b)) 54 return jif;
49#define cputime_div(__a, __n) ({ \ 55}
50 unsigned long long __div = (__a); \ 56
51 do_div(__div,__n); \ 57static inline cputime64_t jiffies64_to_cputime64(const u64 jif)
52 __div; \ 58{
53}) 59 return (__force cputime64_t)(jif * (4096000000ULL / HZ));
54#define cputime_halve(__a) ((__a) >> 1)
55#define cputime_eq(__a, __b) ((__a) == (__b))
56#define cputime_gt(__a, __b) ((__a) > (__b))
57#define cputime_ge(__a, __b) ((__a) >= (__b))
58#define cputime_lt(__a, __b) ((__a) < (__b))
59#define cputime_le(__a, __b) ((__a) <= (__b))
60#define cputime_to_jiffies(__ct) (__div((__ct), 4096000000ULL / HZ))
61#define cputime_to_scaled(__ct) (__ct)
62#define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (4096000000ULL / HZ))
63
64#define cputime64_zero (0ULL)
65#define cputime64_add(__a, __b) ((__a) + (__b))
66#define cputime_to_cputime64(__ct) (__ct)
67
68static inline u64
69cputime64_to_jiffies64(cputime64_t cputime)
70{
71 do_div(cputime, 4096000000ULL / HZ);
72 return cputime;
73} 60}
74 61
75/* 62/*
76 * Convert cputime to microseconds and back. 63 * Convert cputime to microseconds and back.
77 */ 64 */
78static inline unsigned int 65static inline unsigned int cputime_to_usecs(const cputime_t cputime)
79cputime_to_usecs(const cputime_t cputime)
80{ 66{
81 return cputime_div(cputime, 4096); 67 return (__force unsigned long long) cputime >> 12;
82} 68}
83 69
84static inline cputime_t 70static inline cputime_t usecs_to_cputime(const unsigned int m)
85usecs_to_cputime(const unsigned int m)
86{ 71{
87 return (cputime_t) m * 4096; 72 return (__force cputime_t)(m * 4096ULL);
88} 73}
89 74
90/* 75/*
91 * Convert cputime to milliseconds and back. 76 * Convert cputime to milliseconds and back.
92 */ 77 */
93static inline unsigned int 78static inline unsigned int cputime_to_secs(const cputime_t cputime)
94cputime_to_secs(const cputime_t cputime)
95{ 79{
96 return __div(cputime, 2048000000) >> 1; 80 return __div((__force unsigned long long) cputime, 2048000000) >> 1;
97} 81}
98 82
99static inline cputime_t 83static inline cputime_t secs_to_cputime(const unsigned int s)
100secs_to_cputime(const unsigned int s)
101{ 84{
102 return (cputime_t) s * 4096000000ULL; 85 return (__force cputime_t)(s * 4096000000ULL);
103} 86}
104 87
105/* 88/*
106 * Convert cputime to timespec and back. 89 * Convert cputime to timespec and back.
107 */ 90 */
108static inline cputime_t 91static inline cputime_t timespec_to_cputime(const struct timespec *value)
109timespec_to_cputime(const struct timespec *value)
110{ 92{
111 return value->tv_nsec * 4096 / 1000 + (u64) value->tv_sec * 4096000000ULL; 93 unsigned long long ret = value->tv_sec * 4096000000ULL;
94 return (__force cputime_t)(ret + value->tv_nsec * 4096 / 1000);
112} 95}
113 96
114static inline void 97static inline void cputime_to_timespec(const cputime_t cputime,
115cputime_to_timespec(const cputime_t cputime, struct timespec *value) 98 struct timespec *value)
116{ 99{
100 unsigned long long __cputime = (__force unsigned long long) cputime;
117#ifndef __s390x__ 101#ifndef __s390x__
118 register_pair rp; 102 register_pair rp;
119 103
120 rp.pair = cputime >> 1; 104 rp.pair = __cputime >> 1;
121 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL)); 105 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
122 value->tv_nsec = rp.subreg.even * 1000 / 4096; 106 value->tv_nsec = rp.subreg.even * 1000 / 4096;
123 value->tv_sec = rp.subreg.odd; 107 value->tv_sec = rp.subreg.odd;
124#else 108#else
125 value->tv_nsec = (cputime % 4096000000ULL) * 1000 / 4096; 109 value->tv_nsec = (__cputime % 4096000000ULL) * 1000 / 4096;
126 value->tv_sec = cputime / 4096000000ULL; 110 value->tv_sec = __cputime / 4096000000ULL;
127#endif 111#endif
128} 112}
129 113
@@ -132,50 +116,52 @@ cputime_to_timespec(const cputime_t cputime, struct timespec *value)
132 * Since cputime and timeval have the same resolution (microseconds) 116 * Since cputime and timeval have the same resolution (microseconds)
133 * this is easy. 117 * this is easy.
134 */ 118 */
135static inline cputime_t 119static inline cputime_t timeval_to_cputime(const struct timeval *value)
136timeval_to_cputime(const struct timeval *value)
137{ 120{
138 return value->tv_usec * 4096 + (u64) value->tv_sec * 4096000000ULL; 121 unsigned long long ret = value->tv_sec * 4096000000ULL;
122 return (__force cputime_t)(ret + value->tv_usec * 4096ULL);
139} 123}
140 124
141static inline void 125static inline void cputime_to_timeval(const cputime_t cputime,
142cputime_to_timeval(const cputime_t cputime, struct timeval *value) 126 struct timeval *value)
143{ 127{
128 unsigned long long __cputime = (__force unsigned long long) cputime;
144#ifndef __s390x__ 129#ifndef __s390x__
145 register_pair rp; 130 register_pair rp;
146 131
147 rp.pair = cputime >> 1; 132 rp.pair = __cputime >> 1;
148 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL)); 133 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
149 value->tv_usec = rp.subreg.even / 4096; 134 value->tv_usec = rp.subreg.even / 4096;
150 value->tv_sec = rp.subreg.odd; 135 value->tv_sec = rp.subreg.odd;
151#else 136#else
152 value->tv_usec = (cputime % 4096000000ULL) / 4096; 137 value->tv_usec = (__cputime % 4096000000ULL) / 4096;
153 value->tv_sec = cputime / 4096000000ULL; 138 value->tv_sec = __cputime / 4096000000ULL;
154#endif 139#endif
155} 140}
156 141
157/* 142/*
158 * Convert cputime to clock and back. 143 * Convert cputime to clock and back.
159 */ 144 */
160static inline clock_t 145static inline clock_t cputime_to_clock_t(cputime_t cputime)
161cputime_to_clock_t(cputime_t cputime)
162{ 146{
163 return cputime_div(cputime, 4096000000ULL / USER_HZ); 147 unsigned long long clock = (__force unsigned long long) cputime;
148 do_div(clock, 4096000000ULL / USER_HZ);
149 return clock;
164} 150}
165 151
166static inline cputime_t 152static inline cputime_t clock_t_to_cputime(unsigned long x)
167clock_t_to_cputime(unsigned long x)
168{ 153{
169 return (cputime_t) x * (4096000000ULL / USER_HZ); 154 return (__force cputime_t)(x * (4096000000ULL / USER_HZ));
170} 155}
171 156
172/* 157/*
173 * Convert cputime64 to clock. 158 * Convert cputime64 to clock.
174 */ 159 */
175static inline clock_t 160static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
176cputime64_to_clock_t(cputime64_t cputime)
177{ 161{
178 return cputime_div(cputime, 4096000000ULL / USER_HZ); 162 unsigned long long clock = (__force unsigned long long) cputime;
163 do_div(clock, 4096000000ULL / USER_HZ);
164 return clock;
179} 165}
180 166
181struct s390_idle_data { 167struct s390_idle_data {