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 #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
;
24 static inline unsigned int
25 __div(unsigned long long n
, unsigned int base
)
30 asm ("dr %0,%1" : "+d" (rp
) : "d" (base
>> 1));
36 static inline unsigned int
37 __div(unsigned long long n
, unsigned int base
)
42 #endif /* __s390x__ */
44 #define cputime_zero (0ULL)
45 #define cputime_max ((~0UL >> 1) - 1)
46 #define cputime_add(__a, __b) ((__a) + (__b))
47 #define cputime_sub(__a, __b) ((__a) - (__b))
48 #define cputime_div(__a, __n) ({ \
49 unsigned long long __div = (__a); \
53 #define cputime_halve(__a) ((__a) >> 1)
54 #define cputime_eq(__a, __b) ((__a) == (__b))
55 #define cputime_gt(__a, __b) ((__a) > (__b))
56 #define cputime_ge(__a, __b) ((__a) >= (__b))
57 #define cputime_lt(__a, __b) ((__a) < (__b))
58 #define cputime_le(__a, __b) ((__a) <= (__b))
59 #define cputime_to_jiffies(__ct) (__div((__ct), 4096000000ULL / HZ))
60 #define cputime_to_scaled(__ct) (__ct)
61 #define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (4096000000ULL / HZ))
63 #define cputime64_zero (0ULL)
64 #define cputime64_add(__a, __b) ((__a) + (__b))
65 #define cputime_to_cputime64(__ct) (__ct)
68 cputime64_to_jiffies64(cputime64_t cputime
)
70 do_div(cputime
, 4096000000ULL / HZ
);
75 * Convert cputime to milliseconds and back.
77 static inline unsigned int
78 cputime_to_msecs(const cputime_t cputime
)
80 return __div(cputime
, 4096000);
83 static inline cputime_t
84 msecs_to_cputime(const unsigned int m
)
86 return (cputime_t
) m
* 4096000;
90 * Convert cputime to milliseconds and back.
92 static inline unsigned int
93 cputime_to_secs(const cputime_t cputime
)
95 return __div(cputime
, 2048000000) >> 1;
98 static inline cputime_t
99 secs_to_cputime(const unsigned int s
)
101 return (cputime_t
) s
* 4096000000ULL;
105 * Convert cputime to timespec and back.
107 static inline cputime_t
108 timespec_to_cputime(const struct timespec
*value
)
110 return value
->tv_nsec
* 4096 / 1000 + (u64
) value
->tv_sec
* 4096000000ULL;
114 cputime_to_timespec(const cputime_t cputime
, struct timespec
*value
)
119 rp
.pair
= cputime
>> 1;
120 asm ("dr %0,%1" : "+d" (rp
) : "d" (2048000000UL));
121 value
->tv_nsec
= rp
.subreg
.even
* 1000 / 4096;
122 value
->tv_sec
= rp
.subreg
.odd
;
124 value
->tv_nsec
= (cputime
% 4096000000ULL) * 1000 / 4096;
125 value
->tv_sec
= cputime
/ 4096000000ULL;
130 * Convert cputime to timeval and back.
131 * Since cputime and timeval have the same resolution (microseconds)
134 static inline cputime_t
135 timeval_to_cputime(const struct timeval
*value
)
137 return value
->tv_usec
* 4096 + (u64
) value
->tv_sec
* 4096000000ULL;
141 cputime_to_timeval(const cputime_t cputime
, struct timeval
*value
)
146 rp
.pair
= cputime
>> 1;
147 asm ("dr %0,%1" : "+d" (rp
) : "d" (2048000000UL));
148 value
->tv_usec
= rp
.subreg
.even
/ 4096;
149 value
->tv_sec
= rp
.subreg
.odd
;
151 value
->tv_usec
= (cputime
% 4096000000ULL) / 4096;
152 value
->tv_sec
= cputime
/ 4096000000ULL;
157 * Convert cputime to clock and back.
159 static inline clock_t
160 cputime_to_clock_t(cputime_t cputime
)
162 return __div(cputime
, 4096000000ULL / USER_HZ
);
165 static inline cputime_t
166 clock_t_to_cputime(unsigned long x
)
168 return (cputime_t
) x
* (4096000000ULL / USER_HZ
);
172 * Convert cputime64 to clock.
174 static inline clock_t
175 cputime64_to_clock_t(cputime64_t cputime
)
177 return __div(cputime
, 4096000000ULL / USER_HZ
);
180 struct s390_idle_data
{
181 unsigned int sequence
;
182 unsigned long long idle_count
;
183 unsigned long long idle_enter
;
184 unsigned long long idle_time
;
187 DECLARE_PER_CPU(struct s390_idle_data
, s390_idle
);
189 void vtime_start_cpu(void);
190 cputime64_t
s390_get_idle_time(int cpu
);
192 #define arch_idle_time(cpu) s390_get_idle_time(cpu)
194 static inline void s390_idle_check(void)
196 if ((&__get_cpu_var(s390_idle
))->idle_enter
!= 0ULL)
200 #endif /* _S390_CPUTIME_H */