diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-s390/cputime.h |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'include/asm-s390/cputime.h')
-rw-r--r-- | include/asm-s390/cputime.h | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/include/asm-s390/cputime.h b/include/asm-s390/cputime.h new file mode 100644 index 000000000000..4b3ef7cad115 --- /dev/null +++ b/include/asm-s390/cputime.h | |||
@@ -0,0 +1,176 @@ | |||
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 | #include <asm/div64.h> | ||
13 | |||
14 | /* We want to use micro-second resolution. */ | ||
15 | |||
16 | typedef unsigned long long cputime_t; | ||
17 | typedef unsigned long long cputime64_t; | ||
18 | |||
19 | #ifndef __s390x__ | ||
20 | |||
21 | static inline unsigned int | ||
22 | __div(unsigned long long n, unsigned int base) | ||
23 | { | ||
24 | register_pair rp; | ||
25 | |||
26 | rp.pair = n >> 1; | ||
27 | asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1)); | ||
28 | return rp.subreg.odd; | ||
29 | } | ||
30 | |||
31 | #else /* __s390x__ */ | ||
32 | |||
33 | static inline unsigned int | ||
34 | __div(unsigned long long n, unsigned int base) | ||
35 | { | ||
36 | return n / base; | ||
37 | } | ||
38 | |||
39 | #endif /* __s390x__ */ | ||
40 | |||
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; \ | ||
49 | }) | ||
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)) | ||
58 | |||
59 | #define cputime64_zero (0ULL) | ||
60 | #define cputime64_add(__a, __b) ((__a) + (__b)) | ||
61 | #define cputime_to_cputime64(__ct) (__ct) | ||
62 | |||
63 | static inline u64 | ||
64 | cputime64_to_jiffies64(cputime64_t cputime) | ||
65 | { | ||
66 | do_div(cputime, 1000000 / HZ); | ||
67 | return cputime; | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * Convert cputime to milliseconds and back. | ||
72 | */ | ||
73 | static inline unsigned int | ||
74 | cputime_to_msecs(const cputime_t cputime) | ||
75 | { | ||
76 | return __div(cputime, 1000); | ||
77 | } | ||
78 | |||
79 | static inline cputime_t | ||
80 | msecs_to_cputime(const unsigned int m) | ||
81 | { | ||
82 | return (cputime_t) m * 1000; | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | * Convert cputime to milliseconds and back. | ||
87 | */ | ||
88 | static inline unsigned int | ||
89 | cputime_to_secs(const cputime_t cputime) | ||
90 | { | ||
91 | return __div(cputime, 1000000); | ||
92 | } | ||
93 | |||
94 | static inline cputime_t | ||
95 | secs_to_cputime(const unsigned int s) | ||
96 | { | ||
97 | return (cputime_t) s * 1000000; | ||
98 | } | ||
99 | |||
100 | /* | ||
101 | * Convert cputime to timespec and back. | ||
102 | */ | ||
103 | static inline cputime_t | ||
104 | timespec_to_cputime(const struct timespec *value) | ||
105 | { | ||
106 | return value->tv_nsec / 1000 + (u64) value->tv_sec * 1000000; | ||
107 | } | ||
108 | |||
109 | static inline void | ||
110 | cputime_to_timespec(const cputime_t cputime, struct timespec *value) | ||
111 | { | ||
112 | #ifndef __s390x__ | ||
113 | register_pair rp; | ||
114 | |||
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 | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * Convert cputime to timeval and back. | ||
127 | * Since cputime and timeval have the same resolution (microseconds) | ||
128 | * this is easy. | ||
129 | */ | ||
130 | static inline cputime_t | ||
131 | timeval_to_cputime(const struct timeval *value) | ||
132 | { | ||
133 | return value->tv_usec + (u64) value->tv_sec * 1000000; | ||
134 | } | ||
135 | |||
136 | static inline void | ||
137 | cputime_to_timeval(const cputime_t cputime, struct timeval *value) | ||
138 | { | ||
139 | #ifndef __s390x__ | ||
140 | register_pair rp; | ||
141 | |||
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 | ||
150 | } | ||
151 | |||
152 | /* | ||
153 | * Convert cputime to clock and back. | ||
154 | */ | ||
155 | static inline clock_t | ||
156 | cputime_to_clock_t(cputime_t cputime) | ||
157 | { | ||
158 | return __div(cputime, 1000000 / USER_HZ); | ||
159 | } | ||
160 | |||
161 | static inline cputime_t | ||
162 | clock_t_to_cputime(unsigned long x) | ||
163 | { | ||
164 | return (cputime_t) x * (1000000 / USER_HZ); | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * Convert cputime64 to clock. | ||
169 | */ | ||
170 | static inline clock_t | ||
171 | cputime64_to_clock_t(cputime64_t cputime) | ||
172 | { | ||
173 | return __div(cputime, 1000000 / USER_HZ); | ||
174 | } | ||
175 | |||
176 | #endif /* _S390_CPUTIME_H */ | ||