diff options
author | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2011-12-15 08:56:09 -0500 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2011-12-15 08:56:19 -0500 |
commit | 648616343cdbe904c585a6c12e323d3b3c72e46f (patch) | |
tree | 514bce1b52663db4ab5662b637c764cf3c2ed1eb /arch/s390/include | |
parent | 55b02d2f4445ad625213817a1736bf2884d32547 (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/s390/include')
-rw-r--r-- | arch/s390/include/asm/cputime.h | 140 |
1 files changed, 63 insertions, 77 deletions
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 | ||
19 | typedef unsigned long long cputime_t; | 19 | typedef unsigned long long __nocast cputime_t; |
20 | typedef unsigned long long cputime64_t; | 20 | typedef unsigned long long __nocast cputime64_t; |
21 | 21 | ||
22 | #ifndef __s390x__ | 22 | static inline unsigned long __div(unsigned long long n, unsigned long base) |
23 | |||
24 | static 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 | ||
36 | static inline unsigned int | 37 | /* |
37 | __div(unsigned long long n, unsigned int base) | 38 | * Convert cputime to jiffies and back. |
39 | */ | ||
40 | static 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__ */ | 45 | static 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) | 50 | static 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); \ | 57 | static 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 | |||
68 | static inline u64 | ||
69 | cputime64_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 | */ |
78 | static inline unsigned int | 65 | static inline unsigned int cputime_to_usecs(const cputime_t cputime) |
79 | cputime_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 | ||
84 | static inline cputime_t | 70 | static inline cputime_t usecs_to_cputime(const unsigned int m) |
85 | usecs_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 | */ |
93 | static inline unsigned int | 78 | static inline unsigned int cputime_to_secs(const cputime_t cputime) |
94 | cputime_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 | ||
99 | static inline cputime_t | 83 | static inline cputime_t secs_to_cputime(const unsigned int s) |
100 | secs_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 | */ |
108 | static inline cputime_t | 91 | static inline cputime_t timespec_to_cputime(const struct timespec *value) |
109 | timespec_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 | ||
114 | static inline void | 97 | static inline void cputime_to_timespec(const cputime_t cputime, |
115 | cputime_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 | */ |
135 | static inline cputime_t | 119 | static inline cputime_t timeval_to_cputime(const struct timeval *value) |
136 | timeval_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 | ||
141 | static inline void | 125 | static inline void cputime_to_timeval(const cputime_t cputime, |
142 | cputime_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 | */ |
160 | static inline clock_t | 145 | static inline clock_t cputime_to_clock_t(cputime_t cputime) |
161 | cputime_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 | ||
166 | static inline cputime_t | 152 | static inline cputime_t clock_t_to_cputime(unsigned long x) |
167 | clock_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 | */ |
175 | static inline clock_t | 160 | static inline clock_t cputime64_to_clock_t(cputime64_t cputime) |
176 | cputime64_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 | ||
181 | struct s390_idle_data { | 167 | struct s390_idle_data { |