aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include/asm/cputime.h
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/powerpc/include/asm/cputime.h
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/powerpc/include/asm/cputime.h')
-rw-r--r--arch/powerpc/include/asm/cputime.h70
1 files changed, 27 insertions, 43 deletions
diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 1cf20bdfbec..e94935c5201 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))