This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-s390 / cputime.h
1 /*
2  *  include/asm-s390/cputime.h
3  *
4  *  (C) Copyright IBM Corp. 2004
5  *
6  *  Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
7  */
8
9 #ifndef _S390_CPUTIME_H
10 #define _S390_CPUTIME_H
11
12 /* We want to use micro-second resolution. */
13
14 typedef unsigned long long cputime_t;
15 typedef unsigned long long cputime64_t;
16
17 #ifndef __s390x__
18
19 static inline unsigned int
20 __div(unsigned long long n, unsigned int base)
21 {
22         register_pair rp;
23
24         rp.pair = n >> 1;
25         asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
26         return rp.subreg.odd;
27 }
28
29 #else /* __s390x__ */
30
31 static inline unsigned int
32 __div(unsigned long long n, unsigned int base)
33 {
34         return n / base;
35 }
36
37 #endif /* __s390x__ */
38
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))
50
51 #define cputime64_zero                  (0ULL)
52 #define cputime64_add(__a, __b)         ((__a) + (__b))
53 #define cputime_to_cputime64(__ct)      (__ct)
54
55 static inline u64
56 cputime64_to_jiffies64(cputime64_t cputime)
57 {
58         do_div(cputime, 1000000 / HZ);
59         return cputime;
60 }
61
62 /*
63  * Convert cputime to milliseconds and back.
64  */
65 static inline unsigned int
66 cputime_to_msecs(const cputime_t cputime)
67 {
68         return __div(cputime, 1000);
69 }
70
71 static inline cputime_t
72 msecs_to_cputime(const unsigned int m)
73 {
74         return (cputime_t) m * 1000;
75 }
76
77 /*
78  * Convert cputime to milliseconds and back.
79  */
80 static inline unsigned int
81 cputime_to_secs(const cputime_t cputime)
82 {
83         return __div(cputime, 1000000);
84 }
85
86 static inline cputime_t
87 secs_to_cputime(const unsigned int s)
88 {
89         return (cputime_t) s * 1000000;
90 }
91
92 /*
93  * Convert cputime to timespec and back.
94  */
95 static inline cputime_t
96 timespec_to_cputime(const struct timespec *value)
97 {
98         return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000;
99 }
100
101 static inline void
102 cputime_to_timespec(const cputime_t cputime, struct timespec *value)
103 {
104 #ifndef __s390x__
105         register_pair rp;
106
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;
111 #else
112         value->tv_nsec = (cputime % 1000000) * 1000;
113         value->tv_sec = cputime / 1000000;
114 #endif
115 }
116
117 /*
118  * Convert cputime to timeval and back.
119  * Since cputime and timeval have the same resolution (microseconds)
120  * this is easy.
121  */
122 static inline cputime_t
123 timeval_to_cputime(const struct timeval *value)
124 {
125         return value->tv_usec + (u64) value->tv_sec * 1000000;
126 }
127
128 static inline void
129 cputime_to_timeval(const cputime_t cputime, struct timeval *value)
130 {
131 #ifndef __s390x__
132         register_pair rp;
133
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;
138 #else
139         value->tv_usec = cputime % 1000000;
140         value->tv_sec = cputime / 1000000;
141 #endif
142 }
143
144 /*
145  * Convert cputime to clock and back.
146  */
147 static inline clock_t
148 cputime_to_clock_t(cputime_t cputime)
149 {
150         return __div(cputime, 1000000 / USER_HZ);
151 }
152
153 static inline cputime_t
154 clock_t_to_cputime(unsigned long x)
155 {
156         return (cputime_t) x * (1000000 / USER_HZ);
157 }
158
159 /*
160  * Convert cputime64 to clock.
161  */
162 static inline clock_t
163 cputime64_to_clock_t(cputime64_t cputime)
164 {
165        return __div(cputime, 1000000 / USER_HZ);
166 }
167
168 #endif /* _S390_CPUTIME_H */