new timeofday core subsystem (v. B0)
Subsystems (3)
PATCH 1/1 new timeofday core subsystem (v. B0)
Ugh. I forgot to CC lkml.
Andrew, All,
With the goal to simplify, streamline and consolidate the time-of-day
infrastructure, I propose the following common implementation across all arches. This will allow generic bugs to be fixed once, reduce code duplication, and with many architectures sharing the same time source, this allows drivers to be written once for multiple architectures. Additionally it will better delineate the lines between the soft-timer subsystem and the time-of-day subsystem, opening the door for more flexible and better soft-timer management.
Features of this design:
========================
o Splits time of day management from timer interrupts
o Consolidates a large amount of code
o Generic algorithms which use time-source drivers chosen at runtime
o More consistent and readable code
o Uses nanoseconds as the kernel's base time unit
o Clearly separates the NTP code from the time code
For another description on the rework, see here:
http://lwn.net/Articles/120850/ (Many thanks to the LWN team for that easy to understand writeup!)
This patch implements the architecture independent portion of the new time of day subsystem. Included below is timeofday.c (which includes all the time of day management and accessor functions), ntp.c (which includes the ntp adjustment code, leapsecond processing, and ntp kernel state machine code), timesource.c (for timesource specific management functions), interface definition .h files, the example jiffies timesource (lowest common denominator time source, mainly for use as example code) and minimal hooks into arch independent code.
The patch does nothing without at least minimal architecture specific hooks (i386, x86-64 to follow), and it should be able to be applied to a tree without affecting the existing code.
Finally I'd like to thank the following people who have contributed ideas, criticism, testing and code that has helped shape this work:
George Anzinger, Nish Aravamudan, Max Asbock, Dominik Brodowski, Darren Hart, Christoph Lameter, Matt Mackal, Keith Mannthey, Martin Schwidefsky, Frank Sorenson, Ulrich Windl, Darrick Wong, and any others whom I've accidentally forgotten.
Andrew, please consider for inclusion for testing into your tree (I'd like to target around end of July for possible inclusion into mainline).
thanks
-john
linux-2.6.12-rc5_timeofday-core_B0.patch
========================================
drivers/Makefile (mode:100644) +1 -0
@@ -64,3 +64,4 @@ obj-$(CONFIG_BLK_DEV_SGIIOC4) += sn/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ +obj-$(CONFIG_NEWTOD) += timesource/
drivers/char/hangcheck-timer.c (mode:100644) +5 -0
@@ -49,6 +49,7 @@ #include <linux/delay.h> #include <asm/uaccess.h> #include <linux/sysrq.h> +#include <linux/timeofday.h> #define VERSION_STR "0.9.0"
@@ -130,8 +131,12 @@ #endif #ifdef HAVE_MONOTONIC +#ifndef CONFIG_NEWTOD extern unsigned long long monotonic_clock(void); #else +#define monotonic_clock() do_monotonic_clock() +#endif +#else static inline unsigned long long monotonic_clock(void) { # ifdef __s390__
drivers/timesource/Makefile (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +1 -0
@@ -0,0 +1 @@ +obj-y += jiffies.o
drivers/timesource/jiffies.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +69 -0
69 lines not on this page · raw message
include/asm-generic/timeofday.h (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +26 -0
@@ -0,0 +1,26 @@ +/* linux/include/asm-generic/timeofday.h + * + * This file contains the asm-generic interface + * to the arch specific calls used by the time of day subsystem + */ +#ifndef _ASM_GENERIC_TIMEOFDAY_H +#define _ASM_GENERIC_TIMEOFDAY_H +#include <linux/types.h> +#include <linux/time.h> +#include <linux/timex.h> +#include <asm/div64.h> +#ifdef CONFIG_NEWTOD + +/* Required externs */ +extern nsec_t read_persistent_clock(void); +extern void sync_persistent_clock(struct timespec ts); + +#ifdef CONFIG_NEWTOD_VSYSCALL +extern void arch_update_vsyscall_gtod(nsec_t wall_time, cycle_t offset_base, + struct timesource_t* timesource, int ntp_adj); +#else +#define arch_update_vsyscall_gtod(x,y,z,w) {} +#endif + +#endif /* CONFIG_NEWTOD */ +#endif
include/linux/ntp.h (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +19 -0
@@ -0,0 +1,19 @@ +/* linux/include/linux/ntp.h + * + * This file NTP state machine accessor functions. + */ + +#ifndef _LINUX_NTP_H +#define _LINUX_NTP_H +#include <linux/types.h> +#include <linux/time.h> +#include <linux/timex.h> + +/* NTP state machine interfaces */ +int ntp_advance(nsec_t value); +int ntp_adjtimex(struct timex*); +int ntp_leapsecond(struct timespec now); +void ntp_clear(void); +int get_ntp_status(void); + +#endif
include/linux/time.h (mode:100644) +4 -0
@@ -27,6 +27,10 @@ #ifdef __KERNEL__ +/* timeofday base types */ +typedef u64 nsec_t; +typedef u64 cycle_t; + /* Parameters used to convert the timespec values */ #ifndef USEC_PER_SEC #define USEC_PER_SEC (1000000L)
include/linux/timeofday.h (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +59 -0
59 lines not on this page · raw message
include/linux/timesource.h (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +158 -0
158 lines not on this page · raw message
include/linux/timex.h (mode:100644) +2 -0
@@ -228,6 +228,7 @@ extern unsigned long tick_nsec; /* ACTHZ period (nsec) */ extern int tickadj; /* amount of adjustment per tick */ +#ifndef CONFIG_NEWTOD /* * phase-lock loop variables */
@@ -314,6 +315,7 @@ } #endif /* !CONFIG_TIME_INTERPOLATION */ +#endif /* !CONFIG_NEWTOD */ #endif /* KERNEL */
init/main.c (mode:100644) +2 -0
@@ -47,6 +47,7 @@ #include <linux/rmap.h> #include <linux/mempolicy.h> #include <linux/key.h> +#include <linux/timeofday.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -467,6 +468,7 @@ pidhash_init(); init_timers(); softirq_init(); + timeofday_init(); time_init(); /*
kernel/Makefile (mode:100644) +1 -0
@@ -9,6 +9,7 @@ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o +obj-$(CONFIG_NEWTOD) += timeofday.o timesource.o ntp.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += cpu.o spinlock.o
kernel/ntp.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +519 -0
519 lines not on this page · raw message
kernel/time.c (mode:100644) +18 -0
@@ -38,6 +38,7 @@ #include <asm/uaccess.h> #include <asm/unistd.h> +#include <linux/timeofday.h> /* * The timezone where the local system is located. Used as a default by some
@@ -128,6 +129,7 @@ * as real UNIX machines always do it. This avoids all headaches about * daylight saving times and warping kernel clocks. */ +#ifndef CONFIG_NEWTOD inline static void warp_clock(void) { write_seqlock_irq(&xtime_lock);
@@ -137,6 +139,18 @@ write_sequnlock_irq(&xtime_lock); clock_was_set(); } +#else /* !CONFIG_NEWTOD */ +/* XXX - this is somewhat cracked out and should + be checked [email protected] +*/ +inline static void warp_clock(void) +{ + struct timespec ts; + getnstimeofday(&ts); + ts.tv_sec += sys_tz.tz_minuteswest * 60; + do_settimeofday(&ts); +} +#endif /* !CONFIG_NEWTOD */ /* * In case for some reason the CMOS clock has not already been running
@@ -227,6 +241,7 @@ /* adjtimex mainly allows reading (and writing, if superuser) of * kernel time-keeping variables. used by xntpd. */ +#ifndef CONFIG_NEWTOD int do_adjtimex(struct timex *txc) { long ltemp, mtemp, save_adjust;
@@ -410,6 +425,7 @@ notify_arch_cmos_timer(); return(result); } +#endif /* !CONFIG_NEWTOD */ asmlinkage long sys_adjtimex(struct timex __user *txc_p) {
@@ -558,6 +574,7 @@ #else +#ifndef CONFIG_NEWTOD /* * Simulate gettimeofday using do_gettimeofday which only allows a timeval * and therefore only yields usec accuracy
@@ -570,6 +587,7 @@ tv->tv_sec = x.tv_sec; tv->tv_nsec = x.tv_usec * NSEC_PER_USEC; } +#endif /* !CONFIG_NEWTOD */ #endif #if (BITS_PER_LONG < 64)
kernel/timeofday.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +607 -0
607 lines not on this page · raw message
kernel/timer.c (mode:100644) +4 -0
@@ -577,6 +577,7 @@ int tickadj = 500/HZ ? : 1; /* microsecs */ +#ifndef CONFIG_NEWTOD /* * phase-lock loop variables */
@@ -807,6 +808,9 @@ } } while (ticks); } +#else /* !CONFIG_NEWTOD */ +#define update_wall_time(x) +#endif /* !CONFIG_NEWTOD */ /* * Called from the timer interrupt handler to charge one tick to the current
kernel/timesource.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +237 -0
237 lines not on this page · raw message