2 * include/asm-s390/cputime.h
4 * (C) Copyright IBM Corp. 2004
6 * Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
9 #ifndef _S390_CPUTIME_H
10 #define _S390_CPUTIME_H
12 /* We want to use micro-second resolution. */
14 typedef unsigned long long cputime_t;
15 typedef unsigned long long cputime64_t;
19 static inline unsigned int
20 __div(unsigned long long n, unsigned int base)
25 asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
31 static inline unsigned int
32 __div(unsigned long long n, unsigned int base)
37 #endif /* __s390x__ */
39 #define cputime_zero (0ULL)
40 #define cputime_max ((~0UL >> 1) - 1)
41 #define cputime_add(__a, __b) ((__a) + (__b))
42 #define cputime_sub(__a, __b) ((__a) - (__b))
43 #define cputime_eq(__a, __b) ((__a) == (__b))
44 #define cputime_gt(__a, __b) ((__a) > (__b))
45 #define cputime_ge(__a, __b) ((__a) >= (__b))
46 #define cputime_lt(__a, __b) ((__a) < (__b))
47 #define cputime_le(__a, __b) ((__a) <= (__b))
48 #define cputime_to_jiffies(__ct) (__div((__ct), 1000000 / HZ))
49 #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ))
51 #define cputime64_zero (0ULL)
52 #define cputime64_add(__a, __b) ((__a) + (__b))
53 #define cputime_to_cputime64(__ct) (__ct)
56 cputime64_to_jiffies64(cputime64_t cputime)
58 do_div(cputime, 1000000 / HZ);
63 * Convert cputime to milliseconds and back.
65 static inline unsigned int
66 cputime_to_msecs(const cputime_t cputime)
68 return __div(cputime, 1000);
71 static inline cputime_t
72 msecs_to_cputime(const unsigned int m)
74 return (cputime_t) m * 1000;
78 * Convert cputime to milliseconds and back.
80 static inline unsigned int
81 cputime_to_secs(const cputime_t cputime)
83 return __div(cputime, 1000000);
86 static inline cputime_t
87 secs_to_cputime(const unsigned int s)
89 return (cputime_t) s * 1000000;
93 * Convert cputime to timespec and back.
95 static inline cputime_t
96 timespec_to_cputime(const struct timespec *value)
98 return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000;
102 cputime_to_timespec(const cputime_t cputime, struct timespec *value)
107 rp.pair = cputime >> 1;
108 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
109 value->tv_nsec = rp.subreg.even * 1000;
110 value->tv_sec = rp.subreg.odd;
112 value->tv_nsec = (cputime % 1000000) * 1000;
113 value->tv_sec = cputime / 1000000;
118 * Convert cputime to timeval and back.
119 * Since cputime and timeval have the same resolution (microseconds)
122 static inline cputime_t
123 timeval_to_cputime(const struct timeval *value)
125 return value->tv_usec + (u64) value->tv_sec * 1000000;
129 cputime_to_timeval(const cputime_t cputime, struct timeval *value)
134 rp.pair = cputime >> 1;
135 asm ("dr %0,%1" : "+d" (rp) : "d" (1000000 >> 1));
136 value->tv_usec = rp.subreg.even;
137 value->tv_sec = rp.subreg.odd;
139 value->tv_usec = cputime % 1000000;
140 value->tv_sec = cputime / 1000000;
145 * Convert cputime to clock and back.
147 static inline clock_t
148 cputime_to_clock_t(cputime_t cputime)
150 return __div(cputime, 1000000 / USER_HZ);
153 static inline cputime_t
154 clock_t_to_cputime(unsigned long x)
156 return (cputime_t) x * (1000000 / USER_HZ);
160 * Convert cputime64 to clock.
162 static inline clock_t
163 cputime64_to_clock_t(cputime64_t cputime)
165 return __div(cputime, 1000000 / USER_HZ);
168 #endif /* _S390_CPUTIME_H */