x86/amd-iommu: Add function to complete a tlb flush
[linux/fpc-iii.git] / arch / s390 / include / asm / cputime.h
blobf23961ada7fb2ce8c99e3b240627d8e1016e1ba2
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 <linux/types.h>
13 #include <linux/percpu.h>
14 #include <linux/spinlock.h>
15 #include <asm/div64.h>
17 /* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */
19 typedef unsigned long long cputime_t;
20 typedef unsigned long long cputime64_t;
22 #ifndef __s390x__
24 static inline unsigned int
25 __div(unsigned long long n, unsigned int base)
27 register_pair rp;
29 rp.pair = n >> 1;
30 asm ("dr %0,%1" : "+d" (rp) : "d" (base >> 1));
31 return rp.subreg.odd;
34 #else /* __s390x__ */
36 static inline unsigned int
37 __div(unsigned long long n, unsigned int base)
39 return n / base;
42 #endif /* __s390x__ */
44 #define cputime_zero (0ULL)
45 #define cputime_one_jiffy jiffies_to_cputime(1)
46 #define cputime_max ((~0UL >> 1) - 1)
47 #define cputime_add(__a, __b) ((__a) + (__b))
48 #define cputime_sub(__a, __b) ((__a) - (__b))
49 #define cputime_div(__a, __n) ({ \
50 unsigned long long __div = (__a); \
51 do_div(__div,__n); \
52 __div; \
54 #define cputime_halve(__a) ((__a) >> 1)
55 #define cputime_eq(__a, __b) ((__a) == (__b))
56 #define cputime_gt(__a, __b) ((__a) > (__b))
57 #define cputime_ge(__a, __b) ((__a) >= (__b))
58 #define cputime_lt(__a, __b) ((__a) < (__b))
59 #define cputime_le(__a, __b) ((__a) <= (__b))
60 #define cputime_to_jiffies(__ct) (__div((__ct), 4096000000ULL / HZ))
61 #define cputime_to_scaled(__ct) (__ct)
62 #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (4096000000ULL / HZ))
64 #define cputime64_zero (0ULL)
65 #define cputime64_add(__a, __b) ((__a) + (__b))
66 #define cputime_to_cputime64(__ct) (__ct)
68 static inline u64
69 cputime64_to_jiffies64(cputime64_t cputime)
71 do_div(cputime, 4096000000ULL / HZ);
72 return cputime;
76 * Convert cputime to milliseconds and back.
78 static inline unsigned int
79 cputime_to_msecs(const cputime_t cputime)
81 return cputime_div(cputime, 4096000);
84 static inline cputime_t
85 msecs_to_cputime(const unsigned int m)
87 return (cputime_t) m * 4096000;
91 * Convert cputime to milliseconds and back.
93 static inline unsigned int
94 cputime_to_secs(const cputime_t cputime)
96 return __div(cputime, 2048000000) >> 1;
99 static inline cputime_t
100 secs_to_cputime(const unsigned int s)
102 return (cputime_t) s * 4096000000ULL;
106 * Convert cputime to timespec and back.
108 static inline cputime_t
109 timespec_to_cputime(const struct timespec *value)
111 return value->tv_nsec * 4096 / 1000 + (u64) value->tv_sec * 4096000000ULL;
114 static inline void
115 cputime_to_timespec(const cputime_t cputime, struct timespec *value)
117 #ifndef __s390x__
118 register_pair rp;
120 rp.pair = cputime >> 1;
121 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
122 value->tv_nsec = rp.subreg.even * 1000 / 4096;
123 value->tv_sec = rp.subreg.odd;
124 #else
125 value->tv_nsec = (cputime % 4096000000ULL) * 1000 / 4096;
126 value->tv_sec = cputime / 4096000000ULL;
127 #endif
131 * Convert cputime to timeval and back.
132 * Since cputime and timeval have the same resolution (microseconds)
133 * this is easy.
135 static inline cputime_t
136 timeval_to_cputime(const struct timeval *value)
138 return value->tv_usec * 4096 + (u64) value->tv_sec * 4096000000ULL;
141 static inline void
142 cputime_to_timeval(const cputime_t cputime, struct timeval *value)
144 #ifndef __s390x__
145 register_pair rp;
147 rp.pair = cputime >> 1;
148 asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL));
149 value->tv_usec = rp.subreg.even / 4096;
150 value->tv_sec = rp.subreg.odd;
151 #else
152 value->tv_usec = (cputime % 4096000000ULL) / 4096;
153 value->tv_sec = cputime / 4096000000ULL;
154 #endif
158 * Convert cputime to clock and back.
160 static inline clock_t
161 cputime_to_clock_t(cputime_t cputime)
163 return cputime_div(cputime, 4096000000ULL / USER_HZ);
166 static inline cputime_t
167 clock_t_to_cputime(unsigned long x)
169 return (cputime_t) x * (4096000000ULL / USER_HZ);
173 * Convert cputime64 to clock.
175 static inline clock_t
176 cputime64_to_clock_t(cputime64_t cputime)
178 return cputime_div(cputime, 4096000000ULL / USER_HZ);
181 struct s390_idle_data {
182 unsigned int sequence;
183 unsigned long long idle_count;
184 unsigned long long idle_enter;
185 unsigned long long idle_time;
188 DECLARE_PER_CPU(struct s390_idle_data, s390_idle);
190 void vtime_start_cpu(void);
191 cputime64_t s390_get_idle_time(int cpu);
193 #define arch_idle_time(cpu) s390_get_idle_time(cpu)
195 static inline void s390_idle_check(void)
197 if ((&__get_cpu_var(s390_idle))->idle_enter != 0ULL)
198 vtime_start_cpu();
201 #endif /* _S390_CPUTIME_H */