Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a53c8fab | 2 | * Copyright IBM Corp. 2004 |
1da177e4 LT |
3 | * |
4 | * Author: Martin Schwidefsky <schwidefsky@de.ibm.com> | |
5 | */ | |
6 | ||
7 | #ifndef _S390_CPUTIME_H | |
8 | #define _S390_CPUTIME_H | |
9 | ||
76d4e00a MS |
10 | #include <linux/types.h> |
11 | #include <linux/percpu.h> | |
12 | #include <linux/spinlock.h> | |
1da177e4 LT |
13 | #include <asm/div64.h> |
14 | ||
a7e1a9e3 | 15 | |
aa5e97ce | 16 | /* We want to use full resolution of the CPU timer: 2**-12 micro-seconds. */ |
1da177e4 | 17 | |
64861634 MS |
18 | typedef unsigned long long __nocast cputime_t; |
19 | typedef unsigned long long __nocast cputime64_t; | |
1da177e4 | 20 | |
64861634 | 21 | static inline unsigned long __div(unsigned long long n, unsigned long base) |
1da177e4 | 22 | { |
f4815ac6 | 23 | #ifndef CONFIG_64BIT |
1da177e4 LT |
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; | |
f4815ac6 | 29 | #else /* CONFIG_64BIT */ |
64861634 | 30 | return n / base; |
f4815ac6 | 31 | #endif /* CONFIG_64BIT */ |
1da177e4 LT |
32 | } |
33 | ||
64861634 | 34 | #define cputime_one_jiffy jiffies_to_cputime(1) |
1da177e4 | 35 | |
64861634 MS |
36 | /* |
37 | * Convert cputime to jiffies and back. | |
38 | */ | |
39 | static inline unsigned long cputime_to_jiffies(const cputime_t cputime) | |
1da177e4 | 40 | { |
64861634 | 41 | return __div((__force unsigned long long) cputime, 4096000000ULL / HZ); |
1da177e4 LT |
42 | } |
43 | ||
64861634 MS |
44 | static inline cputime_t jiffies_to_cputime(const unsigned int jif) |
45 | { | |
46 | return (__force cputime_t)(jif * (4096000000ULL / HZ)); | |
47 | } | |
1da177e4 | 48 | |
64861634 MS |
49 | static inline u64 cputime64_to_jiffies64(cputime64_t cputime) |
50 | { | |
51 | unsigned long long jif = (__force unsigned long long) cputime; | |
52 | do_div(jif, 4096000000ULL / HZ); | |
53 | return jif; | |
54 | } | |
55 | ||
56 | static inline cputime64_t jiffies64_to_cputime64(const u64 jif) | |
57 | { | |
58 | return (__force cputime64_t)(jif * (4096000000ULL / HZ)); | |
1da177e4 LT |
59 | } |
60 | ||
61 | /* | |
d57af9b2 | 62 | * Convert cputime to microseconds and back. |
1da177e4 | 63 | */ |
64861634 | 64 | static inline unsigned int cputime_to_usecs(const cputime_t cputime) |
1da177e4 | 65 | { |
64861634 | 66 | return (__force unsigned long long) cputime >> 12; |
1da177e4 LT |
67 | } |
68 | ||
64861634 | 69 | static inline cputime_t usecs_to_cputime(const unsigned int m) |
1da177e4 | 70 | { |
64861634 | 71 | return (__force cputime_t)(m * 4096ULL); |
1da177e4 LT |
72 | } |
73 | ||
34845636 AS |
74 | #define usecs_to_cputime64(m) usecs_to_cputime(m) |
75 | ||
1da177e4 LT |
76 | /* |
77 | * Convert cputime to milliseconds and back. | |
78 | */ | |
64861634 | 79 | static inline unsigned int cputime_to_secs(const cputime_t cputime) |
1da177e4 | 80 | { |
64861634 | 81 | return __div((__force unsigned long long) cputime, 2048000000) >> 1; |
1da177e4 LT |
82 | } |
83 | ||
64861634 | 84 | static inline cputime_t secs_to_cputime(const unsigned int s) |
1da177e4 | 85 | { |
64861634 | 86 | return (__force cputime_t)(s * 4096000000ULL); |
1da177e4 LT |
87 | } |
88 | ||
89 | /* | |
90 | * Convert cputime to timespec and back. | |
91 | */ | |
64861634 | 92 | static inline cputime_t timespec_to_cputime(const struct timespec *value) |
1da177e4 | 93 | { |
64861634 MS |
94 | unsigned long long ret = value->tv_sec * 4096000000ULL; |
95 | return (__force cputime_t)(ret + value->tv_nsec * 4096 / 1000); | |
1da177e4 LT |
96 | } |
97 | ||
64861634 MS |
98 | static inline void cputime_to_timespec(const cputime_t cputime, |
99 | struct timespec *value) | |
1da177e4 | 100 | { |
64861634 | 101 | unsigned long long __cputime = (__force unsigned long long) cputime; |
f4815ac6 | 102 | #ifndef CONFIG_64BIT |
1da177e4 LT |
103 | register_pair rp; |
104 | ||
64861634 | 105 | rp.pair = __cputime >> 1; |
aa5e97ce MS |
106 | asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL)); |
107 | value->tv_nsec = rp.subreg.even * 1000 / 4096; | |
1da177e4 LT |
108 | value->tv_sec = rp.subreg.odd; |
109 | #else | |
64861634 MS |
110 | value->tv_nsec = (__cputime % 4096000000ULL) * 1000 / 4096; |
111 | value->tv_sec = __cputime / 4096000000ULL; | |
1da177e4 LT |
112 | #endif |
113 | } | |
114 | ||
115 | /* | |
116 | * Convert cputime to timeval and back. | |
117 | * Since cputime and timeval have the same resolution (microseconds) | |
118 | * this is easy. | |
119 | */ | |
64861634 | 120 | static inline cputime_t timeval_to_cputime(const struct timeval *value) |
1da177e4 | 121 | { |
64861634 MS |
122 | unsigned long long ret = value->tv_sec * 4096000000ULL; |
123 | return (__force cputime_t)(ret + value->tv_usec * 4096ULL); | |
1da177e4 LT |
124 | } |
125 | ||
64861634 MS |
126 | static inline void cputime_to_timeval(const cputime_t cputime, |
127 | struct timeval *value) | |
1da177e4 | 128 | { |
64861634 | 129 | unsigned long long __cputime = (__force unsigned long long) cputime; |
f4815ac6 | 130 | #ifndef CONFIG_64BIT |
1da177e4 LT |
131 | register_pair rp; |
132 | ||
64861634 | 133 | rp.pair = __cputime >> 1; |
aa5e97ce MS |
134 | asm ("dr %0,%1" : "+d" (rp) : "d" (2048000000UL)); |
135 | value->tv_usec = rp.subreg.even / 4096; | |
1da177e4 LT |
136 | value->tv_sec = rp.subreg.odd; |
137 | #else | |
64861634 MS |
138 | value->tv_usec = (__cputime % 4096000000ULL) / 4096; |
139 | value->tv_sec = __cputime / 4096000000ULL; | |
1da177e4 LT |
140 | #endif |
141 | } | |
142 | ||
143 | /* | |
144 | * Convert cputime to clock and back. | |
145 | */ | |
64861634 | 146 | static inline clock_t cputime_to_clock_t(cputime_t cputime) |
1da177e4 | 147 | { |
64861634 MS |
148 | unsigned long long clock = (__force unsigned long long) cputime; |
149 | do_div(clock, 4096000000ULL / USER_HZ); | |
150 | return clock; | |
1da177e4 LT |
151 | } |
152 | ||
64861634 | 153 | static inline cputime_t clock_t_to_cputime(unsigned long x) |
1da177e4 | 154 | { |
64861634 | 155 | return (__force cputime_t)(x * (4096000000ULL / USER_HZ)); |
1da177e4 LT |
156 | } |
157 | ||
158 | /* | |
159 | * Convert cputime64 to clock. | |
160 | */ | |
64861634 | 161 | static inline clock_t cputime64_to_clock_t(cputime64_t cputime) |
1da177e4 | 162 | { |
64861634 MS |
163 | unsigned long long clock = (__force unsigned long long) cputime; |
164 | do_div(clock, 4096000000ULL / USER_HZ); | |
165 | return clock; | |
1da177e4 LT |
166 | } |
167 | ||
76d4e00a | 168 | struct s390_idle_data { |
711d2731 | 169 | int nohz_delay; |
e98bbaaf | 170 | unsigned int sequence; |
76d4e00a | 171 | unsigned long long idle_count; |
76d4e00a | 172 | unsigned long long idle_time; |
27f6b416 MS |
173 | unsigned long long clock_idle_enter; |
174 | unsigned long long clock_idle_exit; | |
175 | unsigned long long timer_idle_enter; | |
176 | unsigned long long timer_idle_exit; | |
76d4e00a MS |
177 | }; |
178 | ||
179 | DECLARE_PER_CPU(struct s390_idle_data, s390_idle); | |
180 | ||
e1c80530 MS |
181 | cputime64_t s390_get_idle_time(int cpu); |
182 | ||
183 | #define arch_idle_time(cpu) s390_get_idle_time(cpu) | |
184 | ||
3c5d92a0 MS |
185 | static inline int s390_nohz_delay(int cpu) |
186 | { | |
eb7e7d76 | 187 | return __this_cpu_read(s390_idle.nohz_delay) != 0; |
3c5d92a0 MS |
188 | } |
189 | ||
190 | #define arch_needs_cpu(cpu) s390_nohz_delay(cpu) | |
191 | ||
1da177e4 | 192 | #endif /* _S390_CPUTIME_H */ |