hw_random doc updates
[pv_ops_mirror.git] / include / asm-s390 / cputime.h
blob133ce054fc8945dbe4d18a7fe8fd031908410c3b
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 cputime_to_scaled(__ct) (__ct)
58 #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ))
60 #define cputime64_zero (0ULL)
61 #define cputime64_add(__a, __b) ((__a) + (__b))
62 #define cputime_to_cputime64(__ct) (__ct)
64 static inline u64
65 cputime64_to_jiffies64(cputime64_t cputime)
67 do_div(cputime, 1000000 / HZ);
68 return cputime;
72 * Convert cputime to milliseconds and back.
74 static inline unsigned int
75 cputime_to_msecs(const cputime_t cputime)
77 return __div(cputime, 1000);
80 static inline cputime_t
81 msecs_to_cputime(const unsigned int m)
83 return (cputime_t) m * 1000;
87 * Convert cputime to milliseconds and back.
89 static inline unsigned int
90 cputime_to_secs(const cputime_t cputime)
92 return __div(cputime, 1000000);
95 static inline cputime_t
96 secs_to_cputime(const unsigned int s)
98 return (cputime_t) s * 1000000;
102 * Convert cputime to timespec and back.
104 static inline cputime_t
105 timespec_to_cputime(const struct timespec *value)
107 return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000;
110 static inline void
111 cputime_to_timespec(const cputime_t cputime, struct timespec *value)
113 #ifndef __s390x__
114 register_pair rp;
116 rp.pair = cputime >> 1;
117 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
118 value->tv_nsec = rp.subreg.even * 1000;
119 value->tv_sec = rp.subreg.odd;
120 #else
121 value->tv_nsec = (cputime % 1000000) * 1000;
122 value->tv_sec = cputime / 1000000;
123 #endif
127 * Convert cputime to timeval and back.
128 * Since cputime and timeval have the same resolution (microseconds)
129 * this is easy.
131 static inline cputime_t
132 timeval_to_cputime(const struct timeval *value)
134 return value->tv_usec + (u64) value->tv_sec * 1000000;
137 static inline void
138 cputime_to_timeval(const cputime_t cputime, struct timeval *value)
140 #ifndef __s390x__
141 register_pair rp;
143 rp.pair = cputime >> 1;
144 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
145 value->tv_usec = rp.subreg.even;
146 value->tv_sec = rp.subreg.odd;
147 #else
148 value->tv_usec = cputime % 1000000;
149 value->tv_sec = cputime / 1000000;
150 #endif
154 * Convert cputime to clock and back.
156 static inline clock_t
157 cputime_to_clock_t(cputime_t cputime)
159 return __div(cputime, 1000000 / USER_HZ);
162 static inline cputime_t
163 clock_t_to_cputime(unsigned long x)
165 return (cputime_t) x * (1000000 / USER_HZ);
169 * Convert cputime64 to clock.
171 static inline clock_t
172 cputime64_to_clock_t(cputime64_t cputime)
174 return __div(cputime, 1000000 / USER_HZ);
177 #endif /* _S390_CPUTIME_H */