fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / include / asm-s390 / cputime.h
blob4b3ef7cad11583bf580a6539340e85c4f8e2c5d9
1 /*
2 * include/asm-s390/cputime.h
4 * (C) Copyright IBM Corp. 2004
6 * Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
7 */
9 #ifndef _S390_CPUTIME_H
10 #define _S390_CPUTIME_H
12 #include <asm/div64.h>
14 /* We want to use micro-second resolution. */
16 typedef unsigned long long cputime_t;
17 typedef unsigned long long cputime64_t;
19 #ifndef __s390x__
21 static inline unsigned int
22 __div(unsigned long long n, unsigned int base)
24 register_pair rp;
26 rp.pair = n >> 1;
27 asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
28 return rp.subreg.odd;
31 #else /* __s390x__ */
33 static inline unsigned int
34 __div(unsigned long long n, unsigned int base)
36 return n / base;
39 #endif /* __s390x__ */
41 #define cputime_zero (0ULL)
42 #define cputime_max ((~0UL >> 1) - 1)
43 #define cputime_add(__a, __b) ((__a) + (__b))
44 #define cputime_sub(__a, __b) ((__a) - (__b))
45 #define cputime_div(__a, __n) ({ \
46 unsigned long long __div = (__a); \
47 do_div(__div,__n); \
48 __div; \
50 #define cputime_halve(__a) ((__a) >> 1)
51 #define cputime_eq(__a, __b) ((__a) == (__b))
52 #define cputime_gt(__a, __b) ((__a) > (__b))
53 #define cputime_ge(__a, __b) ((__a) >= (__b))
54 #define cputime_lt(__a, __b) ((__a) < (__b))
55 #define cputime_le(__a, __b) ((__a) <= (__b))
56 #define cputime_to_jiffies(__ct) (__div((__ct), 1000000 / HZ))
57 #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ))
59 #define cputime64_zero (0ULL)
60 #define cputime64_add(__a, __b) ((__a) + (__b))
61 #define cputime_to_cputime64(__ct) (__ct)
63 static inline u64
64 cputime64_to_jiffies64(cputime64_t cputime)
66 do_div(cputime, 1000000 / HZ);
67 return cputime;
71 * Convert cputime to milliseconds and back.
73 static inline unsigned int
74 cputime_to_msecs(const cputime_t cputime)
76 return __div(cputime, 1000);
79 static inline cputime_t
80 msecs_to_cputime(const unsigned int m)
82 return (cputime_t) m * 1000;
86 * Convert cputime to milliseconds and back.
88 static inline unsigned int
89 cputime_to_secs(const cputime_t cputime)
91 return __div(cputime, 1000000);
94 static inline cputime_t
95 secs_to_cputime(const unsigned int s)
97 return (cputime_t) s * 1000000;
101 * Convert cputime to timespec and back.
103 static inline cputime_t
104 timespec_to_cputime(const struct timespec *value)
106 return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000;
109 static inline void
110 cputime_to_timespec(const cputime_t cputime, struct timespec *value)
112 #ifndef __s390x__
113 register_pair rp;
115 rp.pair = cputime >> 1;
116 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
117 value->tv_nsec = rp.subreg.even * 1000;
118 value->tv_sec = rp.subreg.odd;
119 #else
120 value->tv_nsec = (cputime % 1000000) * 1000;
121 value->tv_sec = cputime / 1000000;
122 #endif
126 * Convert cputime to timeval and back.
127 * Since cputime and timeval have the same resolution (microseconds)
128 * this is easy.
130 static inline cputime_t
131 timeval_to_cputime(const struct timeval *value)
133 return value->tv_usec + (u64) value->tv_sec * 1000000;
136 static inline void
137 cputime_to_timeval(const cputime_t cputime, struct timeval *value)
139 #ifndef __s390x__
140 register_pair rp;
142 rp.pair = cputime >> 1;
143 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
144 value->tv_usec = rp.subreg.even;
145 value->tv_sec = rp.subreg.odd;
146 #else
147 value->tv_usec = cputime % 1000000;
148 value->tv_sec = cputime / 1000000;
149 #endif
153 * Convert cputime to clock and back.
155 static inline clock_t
156 cputime_to_clock_t(cputime_t cputime)
158 return __div(cputime, 1000000 / USER_HZ);
161 static inline cputime_t
162 clock_t_to_cputime(unsigned long x)
164 return (cputime_t) x * (1000000 / USER_HZ);
168 * Convert cputime64 to clock.
170 static inline clock_t
171 cputime64_to_clock_t(cputime64_t cputime)
173 return __div(cputime, 1000000 / USER_HZ);
176 #endif /* _S390_CPUTIME_H */