[PATCH 01/12] timekeeping: create kernel/time/timekeeping.c
Move the generic timekeeping code from kernel/timer.c to kernel/time/timekeeping.c . This requires some glue code which is added to the include/linux/timekeeping.h header. Signed-Off-By: Daniel Walker <[EMAIL PROTECTED]> --- include/linux/clocksource.h |3 include/linux/timekeeping.h | 19 + kernel/time/Makefile|2 kernel/time/clocksource.c |3 kernel/time/timekeeping.c | 639 kernel/timer.c | 630 --- 6 files changed, 663 insertions(+), 633 deletions(-) Index: linux-2.6.19/include/linux/clocksource.h === --- linux-2.6.19.orig/include/linux/clocksource.h +++ linux-2.6.19/include/linux/clocksource.h @@ -18,6 +18,9 @@ /* clocksource cycle base type */ typedef u64 cycle_t; +/* XXX - Would like a better way for initializing curr_clocksource */ +extern struct clocksource clocksource_jiffies; + /** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. Index: linux-2.6.19/include/linux/timekeeping.h === --- /dev/null +++ linux-2.6.19/include/linux/timekeeping.h @@ -0,0 +1,19 @@ +#ifndef _LINUX_TIMEKEEPING_H +#define _LINUX_TIMEKEEPING_H + +#include + +extern void update_wall_time(void); + +#ifdef CONFIG_GENERIC_TIME + +extern struct clocksource *clock; + +#else /* CONFIG_GENERIC_TIME */ +static inline int change_clocksource(void) +{ + return 0; +} +#endif /* !CONFIG_GENERIC_TIME */ + +#endif /* _LINUX_TIMEKEEPING_H */ Index: linux-2.6.19/kernel/time/Makefile === --- linux-2.6.19.orig/kernel/time/Makefile +++ linux-2.6.19/kernel/time/Makefile @@ -1,4 +1,4 @@ -obj-y += ntp.o clocksource.o jiffies.o timer_list.o +obj-y += ntp.o clocksource.o jiffies.o timer_list.o timekeeping.o obj-$(CONFIG_GENERIC_CLOCKEVENTS) += clockevents.o obj-$(CONFIG_TIMER_STATS) += timer_stats.o Index: linux-2.6.19/kernel/time/clocksource.c === --- linux-2.6.19.orig/kernel/time/clocksource.c +++ linux-2.6.19/kernel/time/clocksource.c @@ -29,9 +29,6 @@ #include #include -/* XXX - Would like a better way for initializing curr_clocksource */ -extern struct clocksource clocksource_jiffies; - /*[Clocksource internal variables]- * curr_clocksource: * currently selected clocksource. Initialized to clocksource_jiffies. Index: linux-2.6.19/kernel/time/timekeeping.c === --- /dev/null +++ linux-2.6.19/kernel/time/timekeeping.c @@ -0,0 +1,639 @@ + + +#include +#include +#include +#include + +/* + * flag for if timekeeping is suspended + */ +static int timekeeping_suspended; + +/* + * time in seconds when suspend began + */ +static unsigned long timekeeping_suspend_time; + +/* + * Clock used for timekeeping + */ +struct clocksource *clock = _jiffies; + +/* + * The current time + * wall_to_monotonic is what we need to add to xtime (or xtime corrected + * for sub jiffie times) to get to monotonic time. Monotonic is pegged + * at zero at system boot time, so wall_to_monotonic will be negative, + * however, we will ALWAYS keep the tv_nsec part positive so we can use + * the usual normalization. + */ +struct timespec xtime __attribute__ ((aligned (16))); +struct timespec wall_to_monotonic __attribute__ ((aligned (16))); + +EXPORT_SYMBOL(xtime); + +#ifdef CONFIG_GENERIC_TIME +/** + * __get_nsec_offset - Returns nanoseconds since last call to periodic_hook + * + * private function, must hold xtime_lock lock when being + * called. Returns the number of nanoseconds since the + * last call to update_wall_time() (adjusted by NTP scaling) + */ +static inline s64 __get_nsec_offset(void) +{ + cycle_t cycle_now, cycle_delta; + s64 ns_offset; + + /* read clocksource: */ + cycle_now = clocksource_read(clock); + + /* calculate the delta since the last update_wall_time: */ + cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; + + /* convert to nanoseconds: */ + ns_offset = cyc2ns(clock, cycle_delta); + + return ns_offset; +} + +/** + * __get_realtime_clock_ts - Returns the time of day in a timespec + * @ts:pointer to the timespec to be set + * + * Returns the time of day in a timespec. Used by + * do_gettimeofday() and get_realtime_clock_ts(). + */ +static inline void __get_realtime_clock_ts(struct timespec *ts) +{ + unsigned long seq; + s64 nsecs; + + do { + seq = read_seqbegin(_lock); + + *ts = xtime; + nsecs = __get_nsec_offset(); + + } while (read_seqretry(_lock, seq)); + + timespec_add_ns(ts, nsecs); +} + +/** + *
[PATCH 01/12] timekeeping: create kernel/time/timekeeping.c
Move the generic timekeeping code from kernel/timer.c to kernel/time/timekeeping.c . This requires some glue code which is added to the include/linux/timekeeping.h header. Signed-Off-By: Daniel Walker [EMAIL PROTECTED] --- include/linux/clocksource.h |3 include/linux/timekeeping.h | 19 + kernel/time/Makefile|2 kernel/time/clocksource.c |3 kernel/time/timekeeping.c | 639 kernel/timer.c | 630 --- 6 files changed, 663 insertions(+), 633 deletions(-) Index: linux-2.6.19/include/linux/clocksource.h === --- linux-2.6.19.orig/include/linux/clocksource.h +++ linux-2.6.19/include/linux/clocksource.h @@ -18,6 +18,9 @@ /* clocksource cycle base type */ typedef u64 cycle_t; +/* XXX - Would like a better way for initializing curr_clocksource */ +extern struct clocksource clocksource_jiffies; + /** * struct clocksource - hardware abstraction for a free running counter * Provides mostly state-free accessors to the underlying hardware. Index: linux-2.6.19/include/linux/timekeeping.h === --- /dev/null +++ linux-2.6.19/include/linux/timekeeping.h @@ -0,0 +1,19 @@ +#ifndef _LINUX_TIMEKEEPING_H +#define _LINUX_TIMEKEEPING_H + +#include linux/clocksource.h + +extern void update_wall_time(void); + +#ifdef CONFIG_GENERIC_TIME + +extern struct clocksource *clock; + +#else /* CONFIG_GENERIC_TIME */ +static inline int change_clocksource(void) +{ + return 0; +} +#endif /* !CONFIG_GENERIC_TIME */ + +#endif /* _LINUX_TIMEKEEPING_H */ Index: linux-2.6.19/kernel/time/Makefile === --- linux-2.6.19.orig/kernel/time/Makefile +++ linux-2.6.19/kernel/time/Makefile @@ -1,4 +1,4 @@ -obj-y += ntp.o clocksource.o jiffies.o timer_list.o +obj-y += ntp.o clocksource.o jiffies.o timer_list.o timekeeping.o obj-$(CONFIG_GENERIC_CLOCKEVENTS) += clockevents.o obj-$(CONFIG_TIMER_STATS) += timer_stats.o Index: linux-2.6.19/kernel/time/clocksource.c === --- linux-2.6.19.orig/kernel/time/clocksource.c +++ linux-2.6.19/kernel/time/clocksource.c @@ -29,9 +29,6 @@ #include linux/init.h #include linux/module.h -/* XXX - Would like a better way for initializing curr_clocksource */ -extern struct clocksource clocksource_jiffies; - /*[Clocksource internal variables]- * curr_clocksource: * currently selected clocksource. Initialized to clocksource_jiffies. Index: linux-2.6.19/kernel/time/timekeeping.c === --- /dev/null +++ linux-2.6.19/kernel/time/timekeeping.c @@ -0,0 +1,639 @@ + + +#include linux/module.h +#include linux/timekeeping.h +#include linux/time.h +#include linux/hrtimer.h + +/* + * flag for if timekeeping is suspended + */ +static int timekeeping_suspended; + +/* + * time in seconds when suspend began + */ +static unsigned long timekeeping_suspend_time; + +/* + * Clock used for timekeeping + */ +struct clocksource *clock = clocksource_jiffies; + +/* + * The current time + * wall_to_monotonic is what we need to add to xtime (or xtime corrected + * for sub jiffie times) to get to monotonic time. Monotonic is pegged + * at zero at system boot time, so wall_to_monotonic will be negative, + * however, we will ALWAYS keep the tv_nsec part positive so we can use + * the usual normalization. + */ +struct timespec xtime __attribute__ ((aligned (16))); +struct timespec wall_to_monotonic __attribute__ ((aligned (16))); + +EXPORT_SYMBOL(xtime); + +#ifdef CONFIG_GENERIC_TIME +/** + * __get_nsec_offset - Returns nanoseconds since last call to periodic_hook + * + * private function, must hold xtime_lock lock when being + * called. Returns the number of nanoseconds since the + * last call to update_wall_time() (adjusted by NTP scaling) + */ +static inline s64 __get_nsec_offset(void) +{ + cycle_t cycle_now, cycle_delta; + s64 ns_offset; + + /* read clocksource: */ + cycle_now = clocksource_read(clock); + + /* calculate the delta since the last update_wall_time: */ + cycle_delta = (cycle_now - clock-cycle_last) clock-mask; + + /* convert to nanoseconds: */ + ns_offset = cyc2ns(clock, cycle_delta); + + return ns_offset; +} + +/** + * __get_realtime_clock_ts - Returns the time of day in a timespec + * @ts:pointer to the timespec to be set + * + * Returns the time of day in a timespec. Used by + * do_gettimeofday() and get_realtime_clock_ts(). + */ +static inline void __get_realtime_clock_ts(struct timespec *ts) +{ + unsigned long seq; + s64 nsecs; + + do { + seq = read_seqbegin(xtime_lock); + + *ts = xtime; + nsecs =