aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/clocksource.h
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2009-08-14 09:47:26 -0400
committerThomas Gleixner <tglx@linutronix.de>2009-08-15 04:55:46 -0400
commit155ec60226ae0ae2aadaa57c951a58a359331030 (patch)
treefdee05f7b587f8d49cdd277abdbe44212279a4ba /include/linux/clocksource.h
parentc55c87c892c1875deace0c8fc28787335277fdf2 (diff)
timekeeping: Introduce struct timekeeper
Add struct timekeeper to keep the internal values timekeeping.c needs in regard to the currently selected clock source. This moves the timekeeping intervals, xtime_nsec and the ntp error value from struct clocksource to struct timekeeper. The raw_time is removed from the clocksource as well. It gets treated like xtime as a global variable. Eventually xtime raw_time should be moved to struct timekeeper. [ tglx: minor cleanup ] Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Ingo Molnar <mingo@elte.hu> Acked-by: John Stultz <johnstul@us.ibm.com> Cc: Daniel Walker <dwalker@fifo99.com> LKML-Reference: <20090814134809.613209842@de.ibm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/clocksource.h')
-rw-r--r--include/linux/clocksource.h54
1 files changed, 4 insertions, 50 deletions
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 19ad43af62d..e12e3095e2f 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -155,8 +155,6 @@ extern u64 timecounter_cyc2time(struct timecounter *tc,
155 * @flags: flags describing special properties 155 * @flags: flags describing special properties
156 * @vread: vsyscall based read 156 * @vread: vsyscall based read
157 * @resume: resume function for the clocksource, if necessary 157 * @resume: resume function for the clocksource, if necessary
158 * @cycle_interval: Used internally by timekeeping core, please ignore.
159 * @xtime_interval: Used internally by timekeeping core, please ignore.
160 */ 158 */
161struct clocksource { 159struct clocksource {
162 /* 160 /*
@@ -182,19 +180,12 @@ struct clocksource {
182#define CLKSRC_FSYS_MMIO_SET(mmio, addr) do { } while (0) 180#define CLKSRC_FSYS_MMIO_SET(mmio, addr) do { } while (0)
183#endif 181#endif
184 182
185 /* timekeeping specific data, ignore */
186 cycle_t cycle_interval;
187 u64 xtime_interval;
188 u32 raw_interval;
189 /* 183 /*
190 * Second part is written at each timer interrupt 184 * Second part is written at each timer interrupt
191 * Keep it in a different cache line to dirty no 185 * Keep it in a different cache line to dirty no
192 * more than one cache line. 186 * more than one cache line.
193 */ 187 */
194 cycle_t cycle_last ____cacheline_aligned_in_smp; 188 cycle_t cycle_last ____cacheline_aligned_in_smp;
195 u64 xtime_nsec;
196 s64 error;
197 struct timespec raw_time;
198 189
199#ifdef CONFIG_CLOCKSOURCE_WATCHDOG 190#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
200 /* Watchdog related data, used by the framework */ 191 /* Watchdog related data, used by the framework */
@@ -203,8 +194,6 @@ struct clocksource {
203#endif 194#endif
204}; 195};
205 196
206extern struct clocksource *clock; /* current clocksource */
207
208/* 197/*
209 * Clock source flags bits:: 198 * Clock source flags bits::
210 */ 199 */
@@ -270,50 +259,15 @@ static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
270} 259}
271 260
272/** 261/**
273 * cyc2ns - converts clocksource cycles to nanoseconds 262 * clocksource_cyc2ns - converts clocksource cycles to nanoseconds
274 * @cs: Pointer to clocksource
275 * @cycles: Cycles
276 * 263 *
277 * Uses the clocksource and ntp ajdustment to convert cycle_ts to nanoseconds. 264 * Converts cycles to nanoseconds, using the given mult and shift.
278 * 265 *
279 * XXX - This could use some mult_lxl_ll() asm optimization 266 * XXX - This could use some mult_lxl_ll() asm optimization
280 */ 267 */
281static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles) 268static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
282{ 269{
283 u64 ret = (u64)cycles; 270 return ((u64) cycles * mult) >> shift;
284 ret = (ret * cs->mult) >> cs->shift;
285 return ret;
286}
287
288/**
289 * clocksource_calculate_interval - Calculates a clocksource interval struct
290 *
291 * @c: Pointer to clocksource.
292 * @length_nsec: Desired interval length in nanoseconds.
293 *
294 * Calculates a fixed cycle/nsec interval for a given clocksource/adjustment
295 * pair and interval request.
296 *
297 * Unless you're the timekeeping code, you should not be using this!
298 */
299static inline void clocksource_calculate_interval(struct clocksource *c,
300 unsigned long length_nsec)
301{
302 u64 tmp;
303
304 /* Do the ns -> cycle conversion first, using original mult */
305 tmp = length_nsec;
306 tmp <<= c->shift;
307 tmp += c->mult_orig/2;
308 do_div(tmp, c->mult_orig);
309
310 c->cycle_interval = (cycle_t)tmp;
311 if (c->cycle_interval == 0)
312 c->cycle_interval = 1;
313
314 /* Go back from cycles -> shifted ns, this time use ntp adjused mult */
315 c->xtime_interval = (u64)c->cycle_interval * c->mult;
316 c->raw_interval = ((u64)c->cycle_interval * c->mult_orig) >> c->shift;
317} 271}
318 272
319 273