Wrapper to use the lower level clock sources available on the systems. Fall-back on jiffies or'd with a logical clock for architectures lacking CPU timestamp counters. Fall-back on a mixed TSC-logical clock on architectures lacking synchronized TSC on SMP. A generic fallback based on a logical clock and the timer interrupt is available. generic - Uses jiffies or'd with a logical clock extended to 64 bits by ltt-timestamp.c. i386 - Uses TSC. If detects non synchronized TSC, uses mixed TSC-logical clock. mips - Uses TSC extended atomically from 32 to 64 bits by ltt-heartbeat.c. powerpc - Uses TSC or generic ltt clock. x86_64 - Uses TSC. If detects non synchronized TSC, uses mixed TSC-logical clock Signed-off-by: Mathieu Desnoyers CC: Ralf Baechle CC: benh@kernel.crashing.org CC: paulus@samba.org CC: David Miller CC: Linus Torvalds CC: Andrew Morton CC: Ingo Molnar CC: Peter Zijlstra CC: Thomas Gleixner CC: Steven Rostedt CC: linux-arch@vger.kernel.org --- include/asm-generic/trace-clock.h | 69 ++++++++++++++++++++++++++++++++++++++ include/linux/trace-clock.h | 17 +++++++++ kernel/timer.c | 2 + 3 files changed, 88 insertions(+) Index: linux.trees.git/kernel/timer.c =================================================================== --- linux.trees.git.orig/kernel/timer.c 2008-10-06 10:23:39.000000000 -0400 +++ linux.trees.git/kernel/timer.c 2008-11-07 00:10:13.000000000 -0500 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1067,6 +1068,7 @@ void do_timer(unsigned long ticks) { jiffies_64 += ticks; update_times(ticks); + trace_clock_add_timestamp(ticks); } #ifdef __ARCH_WANT_SYS_ALARM Index: linux.trees.git/include/asm-generic/trace-clock.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux.trees.git/include/asm-generic/trace-clock.h 2008-11-07 00:10:13.000000000 -0500 @@ -0,0 +1,69 @@ +#ifndef _ASM_GENERIC_TRACE_CLOCK_H +#define _ASM_GENERIC_TRACE_CLOCK_H + +/* + * include/asm-generic/trace-clock.h + * + * Copyright (C) 2007 - Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) + * + * Generic tracing clock for architectures without TSC. + */ + +#include /* For HZ */ +#include + +#define TRACE_CLOCK_SHIFT 13 + +u64 trace_clock_read_synthetic_tsc(void); + +extern atomic_t trace_clock; + +static inline u32 trace_clock_read32(void) +{ + return atomic_add_return(1, &trace_clock); +} + +static inline u64 trace_clock_read64(void) +{ + return trace_clock_read_synthetic_tsc(); +} + +static inline void trace_clock_add_timestamp(unsigned long ticks) +{ + int old_clock, new_clock; + + do { + old_clock = atomic_read(&trace_clock); + new_clock = (old_clock + (ticks << TRACE_CLOCK_SHIFT)) + & (~((1 << TRACE_CLOCK_SHIFT) - 1)); + } while (atomic_cmpxchg(&trace_clock, old_clock, new_clock) + != old_clock); +} + +static inline unsigned int trace_clock_frequency(void) +{ + return HZ << TRACE_CLOCK_SHIFT; +} + +static inline u32 trace_clock_freq_scale(void) +{ + return 1; +} + +extern void get_synthetic_tsc(void); +extern void put_synthetic_tsc(void); + +static inline void get_trace_clock(void) +{ + get_synthetic_tsc(); +} + +static inline void put_trace_clock(void) +{ + put_synthetic_tsc(); +} + +static inline void set_trace_clock_is_sync(int state) +{ +} +#endif /* _ASM_GENERIC_TRACE_CLOCK_H */ Index: linux.trees.git/include/linux/trace-clock.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ linux.trees.git/include/linux/trace-clock.h 2008-11-07 00:10:13.000000000 -0500 @@ -0,0 +1,17 @@ +#ifndef _LINUX_TRACE_CLOCK_H +#define _LINUX_TRACE_CLOCK_H + +/* + * Trace clock + * + * Chooses between an architecture specific clock or an atomic logical clock. + * + * Copyright (C) 2007,2008 Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) + */ + +#ifdef CONFIG_HAVE_TRACE_CLOCK +#include +#else +#include +#endif /* CONFIG_HAVE_TRACE_CLOCK */ +#endif /* _LINUX_TRACE_CLOCK_H */ -- Mathieu Desnoyers OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/