aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/include/asm/cputime.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390/include/asm/cputime.h')
-rw-r--r--arch/s390/include/asm/cputime.h140
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
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 {