diff options
Diffstat (limited to 'include/linux/clocksource.h')
-rw-r--r-- | include/linux/clocksource.h | 122 |
1 files changed, 11 insertions, 111 deletions
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 1219be4fb42e..83d2fbd81b93 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/list.h> | 14 | #include <linux/list.h> |
15 | #include <linux/cache.h> | 15 | #include <linux/cache.h> |
16 | #include <linux/timer.h> | 16 | #include <linux/timer.h> |
17 | #include <linux/init.h> | ||
17 | #include <asm/div64.h> | 18 | #include <asm/div64.h> |
18 | #include <asm/io.h> | 19 | #include <asm/io.h> |
19 | 20 | ||
@@ -148,14 +149,11 @@ extern u64 timecounter_cyc2time(struct timecounter *tc, | |||
148 | * @disable: optional function to disable the clocksource | 149 | * @disable: optional function to disable the clocksource |
149 | * @mask: bitmask for two's complement | 150 | * @mask: bitmask for two's complement |
150 | * subtraction of non 64 bit counters | 151 | * subtraction of non 64 bit counters |
151 | * @mult: cycle to nanosecond multiplier (adjusted by NTP) | 152 | * @mult: cycle to nanosecond multiplier |
152 | * @mult_orig: cycle to nanosecond multiplier (unadjusted by NTP) | ||
153 | * @shift: cycle to nanosecond divisor (power of two) | 153 | * @shift: cycle to nanosecond divisor (power of two) |
154 | * @flags: flags describing special properties | 154 | * @flags: flags describing special properties |
155 | * @vread: vsyscall based read | 155 | * @vread: vsyscall based read |
156 | * @resume: resume function for the clocksource, if necessary | 156 | * @resume: resume function for the clocksource, if necessary |
157 | * @cycle_interval: Used internally by timekeeping core, please ignore. | ||
158 | * @xtime_interval: Used internally by timekeeping core, please ignore. | ||
159 | */ | 157 | */ |
160 | struct clocksource { | 158 | struct clocksource { |
161 | /* | 159 | /* |
@@ -169,7 +167,6 @@ struct clocksource { | |||
169 | void (*disable)(struct clocksource *cs); | 167 | void (*disable)(struct clocksource *cs); |
170 | cycle_t mask; | 168 | cycle_t mask; |
171 | u32 mult; | 169 | u32 mult; |
172 | u32 mult_orig; | ||
173 | u32 shift; | 170 | u32 shift; |
174 | unsigned long flags; | 171 | unsigned long flags; |
175 | cycle_t (*vread)(void); | 172 | cycle_t (*vread)(void); |
@@ -181,19 +178,12 @@ struct clocksource { | |||
181 | #define CLKSRC_FSYS_MMIO_SET(mmio, addr) do { } while (0) | 178 | #define CLKSRC_FSYS_MMIO_SET(mmio, addr) do { } while (0) |
182 | #endif | 179 | #endif |
183 | 180 | ||
184 | /* timekeeping specific data, ignore */ | ||
185 | cycle_t cycle_interval; | ||
186 | u64 xtime_interval; | ||
187 | u32 raw_interval; | ||
188 | /* | 181 | /* |
189 | * Second part is written at each timer interrupt | 182 | * Second part is written at each timer interrupt |
190 | * Keep it in a different cache line to dirty no | 183 | * Keep it in a different cache line to dirty no |
191 | * more than one cache line. | 184 | * more than one cache line. |
192 | */ | 185 | */ |
193 | cycle_t cycle_last ____cacheline_aligned_in_smp; | 186 | cycle_t cycle_last ____cacheline_aligned_in_smp; |
194 | u64 xtime_nsec; | ||
195 | s64 error; | ||
196 | struct timespec raw_time; | ||
197 | 187 | ||
198 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG | 188 | #ifdef CONFIG_CLOCKSOURCE_WATCHDOG |
199 | /* Watchdog related data, used by the framework */ | 189 | /* Watchdog related data, used by the framework */ |
@@ -202,8 +192,6 @@ struct clocksource { | |||
202 | #endif | 192 | #endif |
203 | }; | 193 | }; |
204 | 194 | ||
205 | extern struct clocksource *clock; /* current clocksource */ | ||
206 | |||
207 | /* | 195 | /* |
208 | * Clock source flags bits:: | 196 | * Clock source flags bits:: |
209 | */ | 197 | */ |
@@ -212,6 +200,7 @@ extern struct clocksource *clock; /* current clocksource */ | |||
212 | 200 | ||
213 | #define CLOCK_SOURCE_WATCHDOG 0x10 | 201 | #define CLOCK_SOURCE_WATCHDOG 0x10 |
214 | #define CLOCK_SOURCE_VALID_FOR_HRES 0x20 | 202 | #define CLOCK_SOURCE_VALID_FOR_HRES 0x20 |
203 | #define CLOCK_SOURCE_UNSTABLE 0x40 | ||
215 | 204 | ||
216 | /* simplify initialization of mask field */ | 205 | /* simplify initialization of mask field */ |
217 | #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) | 206 | #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) |
@@ -268,108 +257,15 @@ static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant) | |||
268 | } | 257 | } |
269 | 258 | ||
270 | /** | 259 | /** |
271 | * clocksource_read: - Access the clocksource's current cycle value | 260 | * clocksource_cyc2ns - converts clocksource cycles to nanoseconds |
272 | * @cs: pointer to clocksource being read | ||
273 | * | ||
274 | * Uses the clocksource to return the current cycle_t value | ||
275 | */ | ||
276 | static inline cycle_t clocksource_read(struct clocksource *cs) | ||
277 | { | ||
278 | return cs->read(cs); | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * clocksource_enable: - enable clocksource | ||
283 | * @cs: pointer to clocksource | ||
284 | * | ||
285 | * Enables the specified clocksource. The clocksource callback | ||
286 | * function should start up the hardware and setup mult and field | ||
287 | * members of struct clocksource to reflect hardware capabilities. | ||
288 | */ | ||
289 | static inline int clocksource_enable(struct clocksource *cs) | ||
290 | { | ||
291 | int ret = 0; | ||
292 | |||
293 | if (cs->enable) | ||
294 | ret = cs->enable(cs); | ||
295 | |||
296 | /* | ||
297 | * The frequency may have changed while the clocksource | ||
298 | * was disabled. If so the code in ->enable() must update | ||
299 | * the mult value to reflect the new frequency. Make sure | ||
300 | * mult_orig follows this change. | ||
301 | */ | ||
302 | cs->mult_orig = cs->mult; | ||
303 | |||
304 | return ret; | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * clocksource_disable: - disable clocksource | ||
309 | * @cs: pointer to clocksource | ||
310 | * | ||
311 | * Disables the specified clocksource. The clocksource callback | ||
312 | * function should power down the now unused hardware block to | ||
313 | * save power. | ||
314 | */ | ||
315 | static inline void clocksource_disable(struct clocksource *cs) | ||
316 | { | ||
317 | /* | ||
318 | * Save mult_orig in mult so clocksource_enable() can | ||
319 | * restore the value regardless if ->enable() updates | ||
320 | * the value of mult or not. | ||
321 | */ | ||
322 | cs->mult = cs->mult_orig; | ||
323 | |||
324 | if (cs->disable) | ||
325 | cs->disable(cs); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * cyc2ns - converts clocksource cycles to nanoseconds | ||
330 | * @cs: Pointer to clocksource | ||
331 | * @cycles: Cycles | ||
332 | * | 261 | * |
333 | * Uses the clocksource and ntp ajdustment to convert cycle_ts to nanoseconds. | 262 | * Converts cycles to nanoseconds, using the given mult and shift. |
334 | * | 263 | * |
335 | * XXX - This could use some mult_lxl_ll() asm optimization | 264 | * XXX - This could use some mult_lxl_ll() asm optimization |
336 | */ | 265 | */ |
337 | static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles) | 266 | static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift) |
338 | { | ||
339 | u64 ret = (u64)cycles; | ||
340 | ret = (ret * cs->mult) >> cs->shift; | ||
341 | return ret; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * clocksource_calculate_interval - Calculates a clocksource interval struct | ||
346 | * | ||
347 | * @c: Pointer to clocksource. | ||
348 | * @length_nsec: Desired interval length in nanoseconds. | ||
349 | * | ||
350 | * Calculates a fixed cycle/nsec interval for a given clocksource/adjustment | ||
351 | * pair and interval request. | ||
352 | * | ||
353 | * Unless you're the timekeeping code, you should not be using this! | ||
354 | */ | ||
355 | static inline void clocksource_calculate_interval(struct clocksource *c, | ||
356 | unsigned long length_nsec) | ||
357 | { | 267 | { |
358 | u64 tmp; | 268 | return ((u64) cycles * mult) >> shift; |
359 | |||
360 | /* Do the ns -> cycle conversion first, using original mult */ | ||
361 | tmp = length_nsec; | ||
362 | tmp <<= c->shift; | ||
363 | tmp += c->mult_orig/2; | ||
364 | do_div(tmp, c->mult_orig); | ||
365 | |||
366 | c->cycle_interval = (cycle_t)tmp; | ||
367 | if (c->cycle_interval == 0) | ||
368 | c->cycle_interval = 1; | ||
369 | |||
370 | /* Go back from cycles -> shifted ns, this time use ntp adjused mult */ | ||
371 | c->xtime_interval = (u64)c->cycle_interval * c->mult; | ||
372 | c->raw_interval = ((u64)c->cycle_interval * c->mult_orig) >> c->shift; | ||
373 | } | 269 | } |
374 | 270 | ||
375 | 271 | ||
@@ -380,6 +276,8 @@ extern void clocksource_touch_watchdog(void); | |||
380 | extern struct clocksource* clocksource_get_next(void); | 276 | extern struct clocksource* clocksource_get_next(void); |
381 | extern void clocksource_change_rating(struct clocksource *cs, int rating); | 277 | extern void clocksource_change_rating(struct clocksource *cs, int rating); |
382 | extern void clocksource_resume(void); | 278 | extern void clocksource_resume(void); |
279 | extern struct clocksource * __init __weak clocksource_default_clock(void); | ||
280 | extern void clocksource_mark_unstable(struct clocksource *cs); | ||
383 | 281 | ||
384 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL | 282 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL |
385 | extern void update_vsyscall(struct timespec *ts, struct clocksource *c); | 283 | extern void update_vsyscall(struct timespec *ts, struct clocksource *c); |
@@ -394,4 +292,6 @@ static inline void update_vsyscall_tz(void) | |||
394 | } | 292 | } |
395 | #endif | 293 | #endif |
396 | 294 | ||
295 | extern void timekeeping_notify(struct clocksource *clock); | ||
296 | |||
397 | #endif /* _LINUX_CLOCKSOURCE_H */ | 297 | #endif /* _LINUX_CLOCKSOURCE_H */ |