Reduced NTP rework (part 1)
Subsystems (5)
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH 1/11 Reduced NTP rework (part 1)
All,
With Roman's suggestions, I've been working on reducing the footprint
of my timeofday patches. This is the first of two patches that reworks some of the interrupt time NTP adjustments so that it could be re-used with the timeofday patches. The motivation of the change is to logically separate the code which adjusts xtime and the code that decides, based on the NTP state variables, how much per tick to adjust xtime.
Thus this patch should not affect the existing behavior, but just separate the logical functionality so it can be re-used.
This patch applies on top of my ntp-shift-right patch I posted awhile back.
thanks
-john
timer.c | 88 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 55 insertions(+), 33 deletions(-)
linux-2.6.14-rc2_timeofday-ntp-part1_B6.patch
============================================
kernel/timer.c +55 -33
@@ -620,6 +620,7 @@ static long time_adj; /* tick adjust (long time_reftime;/* time at last adjustment (s) */ long time_adjust;long time_next_adjust; +long time_adjust_step;/* per tick time_adjust step */ /* * this routine handles the overflow of the microsecond field
@@ -742,46 +743,46 @@ static void second_overflow(void)#endif } -/* in the NTP reference this is called "hardclock()" */ -static void update_wall_time_one_tick (void ) + +static void ntp_advance (unsigned long interval_ns) { -long time_adjust_step, delta_nsec; +static unsigned long interval_sum; -if ( (time_adjust_step = time_adjust) !=0 ) { -/* We are doing an adjtime thing. -* -* Prepare time_adjust_step to be within bounds. -* Note that a positive time_adjust means we want the clock -* to run faster. -* -* Limit the amount of the step to be in the range -* -tickadj .. +tickadj -*/ - time_adjust_step =min (time_adjust_step, (long )tickadj); - time_adjust_step =max (time_adjust_step, (long )-tickadj); +/* increment the interval sum */ + interval_sum += interval_ns; -/* Reduce by this step the amount of time left */ - time_adjust -= time_adjust_step; - } - delta_nsec = tick_nsec + time_adjust_step *1000 ; -/* -* Advance the phase, once it gets to one microsecond, then -* advance the tick more. -*/ - time_phase += time_adj; -if ((time_phase >=FINENSEC ) || (time_phase <= -FINENSEC )) { -long ltemp =shift_right (time_phase, (SHIFT_SCALE -10 )); - time_phase -= ltemp << (SHIFT_SCALE -10 ); - delta_nsec += ltemp; +/* calculate the per tick singleshot adjtime adjustment step */ +while (interval_ns >= tick_nsec) { + time_adjust_step = time_adjust; +if (time_adjust_step) { +/* We are doing an adjtime thing. +* +* Prepare time_adjust_step to be within bounds. +* Note that a positive time_adjust means we want the clock +* to run faster. +* +* Limit the amount of the step to be in the range +* -tickadj .. +tickadj +*/ + time_adjust_step =min (time_adjust_step, (long )tickadj); + time_adjust_step =max (time_adjust_step, (long )-tickadj); + +/* Reduce by this step the amount of time left */ + time_adjust -= time_adjust_step; + } + interval_ns -= tick_nsec; } - xtime.tv_nsec += delta_nsec; -time_interpolator_update (delta_nsec);/* Changes by adjtime() do not take effect till next tick. */ -if (time_next_adjust !=0 ) { +if (time_next_adjust) { time_adjust = time_next_adjust; time_next_adjust =0 ; } + +while (interval_sum >NSEC_PER_SEC ) { + interval_sum -=NSEC_PER_SEC ; +second_overflow (); + } }/*
@@ -793,14 +794,35 @@ static void update_wall_time_one_tick(vo*/ static void update_wall_time (unsigned long ticks) { +long delta_nsec; +do { ticks--; -update_wall_time_one_tick (); + +/* Calculate the nsec delta using the +* precomputed NTP adjustments: +* tick_nsec, time_adjust_step, time_adj +*/ + delta_nsec = tick_nsec + time_adjust_step *1000 ; +/* +* Advance the phase, once it gets to one microsecond, then +* advance the tick more. +*/ + time_phase += time_adj; +if ((time_phase >=FINENSEC ) || (time_phase <= -FINENSEC )) { +long ltemp =shift_right (time_phase, (SHIFT_SCALE -10 )); + time_phase -= ltemp << (SHIFT_SCALE -10 ); + delta_nsec += ltemp; + } + + xtime.tv_nsec += delta_nsec;if (xtime.tv_nsec >=1000000000 ) { xtime.tv_nsec -=1000000000 ; xtime.tv_sec++; -second_overflow (); } +ntp_advance (tick_nsec); +time_interpolator_update (delta_nsec); + }while (ticks); }
RFC PATCH 2/11 Reduced NTP rework (part 2)
All,
Here is the second of two patches which try to minimize my ntp rework
patches.
This patch further changes the interrupt time NTP code, breaking out the leapsecond processing and introduces an accessor to a shifted ppm adjustment value. For correctness, I've also introduced a new lock, the ntp_lock, which protects the NTP state machine when accessing it from my timekeeping code (which does not use the xtime_lock).
Again, this patch should not affect the existing behavior, but just separate the logical functionality so it can be re-used by my timeofday patches.
thanks
-john
include/linux/timex.h | 24 ++++++ kernel/time.c | 25 ++++--- kernel/timer.c | 175 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 159 insertions(+), 65 deletions(-)
linux-2.6.14-rc2_timeofday-ntp-part2_B6.patch
============================================
include/linux/timex.h +24 -0
@@ -260,6 +260,7 @@ extern long pps_calcnt; /* calibrationextern long pps_errcnt;/* calibration errors */ extern long pps_stbcnt;/* stability limit exceeded */ +extern seqlock_t ntp_lock;/** * ntp_clear - Clears the NTP state variables *
@@ -267,10 +268,14 @@ extern long pps_stbcnt; /* stability li*/ static inline void ntp_clear (void ) { +unsigned long flags; +write_seqlock_irqsave (&ntp_lock, flags); time_adjust =0 ;/* stop active adjtime() */ time_status |=STA_UNSYNC ; time_maxerror =NTP_PHASE_LIMIT ; time_esterror =NTP_PHASE_LIMIT ; +write_sequnlock_irqrestore (&ntp_lock, flags); + }/**
@@ -282,6 +287,25 @@ static inline int ntp_synced(void)return !(time_status &STA_UNSYNC ); } +/** +* ntp_get_ppm_adjustment - Returns Shifted PPM adjustment +* +*/ +long ntp_get_ppm_adjustment (void ); + +/** +* ntp_advance - Advances the NTP state machine by interval_ns +* +*/ +void ntp_advance (unsigned long interval_ns); + +/** +* ntp_leapsecond - NTP leapsecond processing code. +* +*/ +int ntp_leapsecond (struct timespec now); + +/* Required to safely shift negative values */ #define shift_right (x, s) ({ \ __typeof__(x) __x = (x); \
kernel/time.c +15 -10
@@ -231,7 +231,9 @@ int do_adjtimex(struct timex *txc) {long ltemp, mtemp, save_adjust;int result; - +unsigned long flags; +struct timespec now_ts; +unsigned long seq;/* In order to modify anything, you gotta be super-user! */ if (txc->modes && !capable (CAP_SYS_TIME ))return -EPERM ;
@@ -254,7 +256,13 @@ int do_adjtimex(struct timex *txc) txc->tick > 1100000/USER_HZ)return -EINVAL ; -write_seqlock_irq (&xtime_lock); +do {/* save off current xtime */ + seq =read_seqbegin (&xtime_lock); + now_ts = xtime; + }while (read_seqretry (&xtime_lock, seq)); + +write_seqlock_irqsave (&ntp_lock, flags); + result = time_state;/* mostly `TIME_OK' */ /* Save for later - semantics of adjtime is to return old value */
@@ -331,9 +339,9 @@ int do_adjtimex(struct timex *txc)*/ if (time_status &STA_FREQHOLD || time_reftime ==0 ) - time_reftime = xtime.tv_sec; - mtemp = xtime.tv_sec - time_reftime; - time_reftime = xtime.tv_sec; + time_reftime = now_ts.tv_sec; + mtemp = now_ts.tv_sec - time_reftime; + time_reftime = now_ts.tv_sec;if (time_status &STA_FLL ) {if (mtemp >=MINSEC ) { ltemp = (time_offset / mtemp) << (SHIFT_USEC -
@@ -392,7 +400,7 @@ leave: if ((time_status & (STA_UNSYNC|ST txc->calcnt = pps_calcnt; txc->errcnt = pps_errcnt; txc->stbcnt = pps_stbcnt; -write_sequnlock_irq (&xtime_lock); +write_sequnlock_irqrestore (&ntp_lock, flags);do_gettimeofday (&txc->time);notify_arch_cmos_timer ();return (result);
@@ -509,10 +517,7 @@ int do_settimeofday (struct timespec *tvset_normalized_timespec (&xtime, sec, nsec);set_normalized_timespec (&wall_to_monotonic, wtm_sec, wtm_nsec); - time_adjust =0 ;/* stop active adjtime() */ - time_status |=STA_UNSYNC ; - time_maxerror =NTP_PHASE_LIMIT ; - time_esterror =NTP_PHASE_LIMIT ; +ntp_clear ();time_interpolator_reset (); }write_sequnlock_irq (&xtime_lock);
kernel/timer.c +120 -55
233 lines not on this page · raw message
RFC PATCH 3/11 timesource management code
All,
This patch introduces the timesource management infrastructure. A
timesource is a driver-like architecture generic abstraction of a free running counter. This patch defines the timesource structure, and provides management code for registering, selecting, accessing and scaling timesources. The timesource structure is influenced by the time_interpolator code, although I feel it has a cleaner interface and avoids preserving system state in the timesource structure.
Additionally, this patch includes the trivial jiffies timesource, a lowest common denominator timesource, provided mainly for use as an example.
This patch applies ontop of my ntp cleanup patchset.
Since this patch provides the groundwork for the generic timeofday core, it will not function without the generic timeofday patches to follow.
thanks
-john
Documentation/kernel-parameters.txt | 7 drivers/Makefile | 1 drivers/timesource/Makefile | 1 drivers/timesource/jiffies.c | 74 ++++++++++ include/linux/timesource.h | 172 +++++++++++++++++++++++ kernel/timesource.c | 259 ++++++++++++++++++++++++++++++++++++ 6 files changed, 513 insertions(+), 1 deletion(-)
linux-2.6.14-rc2_timeofday-timesource-core_B6.patch
============================================
Documentation/kernel-parameters.txt +6 -1
@@ -52,6 +52,7 @@ restrictions referred to are that the re MTD MTD support is enabled. NET Appropriate network support is enabled. NUMA NUMA support is enabled. + GENERIC_TOD The generic timeofday code is enabled. NFS Appropriate NFS support is enabled. OSS OSS sound support is enabled. PARIDE The ParIDE subsystem is enabled.
@@ -323,7 +324,7 @@ running once the system is up. Default value is set via a kernel config option. Value can be changed at runtime via /selinux/checkreqprot. - clock= [BUGS=IA-32, HW] gettimeofday timesource override. + clock= [BUGS=IA-32, HW] gettimeofday timesource override. [Deprecated] Forces specified timesource (if avaliable) to be used when calculating gettimeofday(). If specicified timesource is not avalible, it defaults to PIT.
@@ -1462,6 +1463,10 @@ running once the system is up. time Show timing data prefixed to each printk message line + timesource= [GENERIC_TOD] Override the default timesource + Override the default timesource and use the timesource + with the name specified. + tipar.timeout= [HW,PPT] Set communications timeout in tenths of a second (default 15).
drivers/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_INFINIBAND) += infiniband/ obj-$(CONFIG_SGI_IOC4) += sn/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ +obj-$(CONFIG_GENERICTOD) += timesource/
drivers/timesource/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += jiffies.o
drivers/timesource/jiffies.c new file +74 -0
74 lines not on this page · raw message
include/linux/timesource.h new file +172 -0
172 lines not on this page · raw message
kernel/timesource.c new file +259 -0
259 lines not on this page · raw message
PATCH 4/11 generic timeofday core subsystem
All,
This patch implements my generic timeofday framework. This common
infrastructure is intended to be used by any arch to reduce code duplication. Hopefully it will allow generic bugs to be fixed once. And with many architectures sharing the same time source, this allows drivers to be written once for multiple architectures.
One major change with this code is that it delineate the lines between the soft-timer subsystem and the time-of-day subsystem, allowing for a more direct mapping between a hardware timesource counter and the time of day. This allows for lost ticks or other software delays to not affect timekeeping.
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
For an older 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 generic time of day subsystem. Included below is timeofday.c (which includes all the time of day management and accessor functions), and minimal hooks into arch independent code. This patch does not remove the current timekeeping code, allowing architectures to move over when they are ready.
This patch applies on top of my timesource management patch.
The patch does nothing without at least minimal architecture specific hooks (i386, x86-64 and other architecture examples 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, Thomas
Gleixner Darren Hart, Christoph Lameter, Matt Mackal, Keith Mannthey, Martin Schwidefsky, Frank Sorenson, Ulrich Windl, Darrick Wong, Roman Zippel and any others whom I've accidentally forgotten.
thanks
-john
drivers/char/hangcheck-timer.c | 5 include/asm-generic/timeofday.h | 26 + include/linux/time.h | 4 include/linux/timeofday.h | 83 +++++ include/linux/timex.h | 2 init/main.c | 2 kernel/Makefile | 1 kernel/time.c | 40 ++ kernel/timeofday.c | 575 ++++++++++++++++++++++++++++++++++++++++ kernel/timer.c | 4 10 files changed, 742 insertions(+)
linux-2.6.14-rc2_timeofday-core_B6.patch
============================================
drivers/char/hangcheck-timer.c +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 @@ __setup("hcheck_dump_tasks", hangcheck_p#endif #ifdef HAVE_MONOTONIC +#ifndef CONFIG_GENERICTOD 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__
include/asm-generic/timeofday.h new file +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_GENERICTOD + +/* Required externs */ +extern nsec_t read_persistent_clock (void ); +extern void sync_persistent_clock (struct timespec ts); + +#ifdef CONFIG_GENERICTOD_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 /* CONFIG_GENERICTOD_VSYSCALL */ + +#endif /* CONFIG_GENERICTOD */ +#endif
include/linux/time.h +4 -0
@@ -27,6 +27,10 @@ struct timezone {#ifdef __KERNEL__ +/* timeofday base types */ +typedef s64 nsec_t ; +typedef unsigned long cycle_t ; +/* Parameters used to convert the timespec values */ #define MSEC_PER_SEC (1000L)#define USEC_PER_SEC (1000000L)
include/linux/timeofday.h new file +83 -0
83 lines not on this page · raw message
include/linux/timex.h +2 -0
@@ -313,6 +313,7 @@ int ntp_leapsecond(struct timespec now); __x <0 ? -(-__x >> __s) : __x >> __s; \ }) +#ifndef CONFIG_GENERICTOD #ifdef CONFIG_TIME_INTERPOLATION
@@ -368,6 +369,7 @@ time_interpolator_reset(void) }#endif /* !CONFIG_TIME_INTERPOLATION */ +#endif /* !CONFIG_GENERICTOD */ #endif /* KERNEL */
init/main.c +2 -0
@@ -47,6 +47,7 @@#include <linux/rmap.h> #include <linux/mempolicy.h> #include <linux/key.h> +#include <linux/timeofday.h> #include <net/sock.h> #include <asm/io.h>
@@ -486,6 +487,7 @@ asmlinkage void __init start_kernel(voidpidhash_init ();init_timers ();softirq_init (); +timeofday_init ();time_init ();/*
kernel/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-y = sched.o fork.o exec_domain.o 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_GENERICTOD) += timeofday.o timesource.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += cpu.o spinlock.o
kernel/time.c +40 -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 @@ asmlinkage long sys_gettimeofday(struct* as real UNIX machines always do it. This avoids all headaches about * daylight saving times and warping kernel clocks. */ +#ifndef CONFIG_GENERICTOD static inline void warp_clock (void ) {write_seqlock_irq (&xtime_lock);
@@ -137,6 +139,18 @@ static inline void warp_clock(void)write_sequnlock_irq (&xtime_lock); clock_was_set(); } +#else /* !CONFIG_GENERICTOD */ +/* XXX - this is somewhat cracked out and should +be checked [email protected] +*/ +static inline void warp_clock (void ) +{ +struct timespec ts; +getnstimeofday (&ts); + ts.tv_sec += sys_tz.tz_minuteswest *60 ; +do_settimeofday (&ts); +} +#endif /* !CONFIG_GENERICTOD */ /* * In case for some reason the CMOS clock has not already been running
@@ -481,6 +495,7 @@ struct timespec timespec_trunc(struct ti }EXPORT_SYMBOL (timespec_trunc); +#ifndef CONFIG_GENERICTOD #ifdef CONFIG_TIME_INTERPOLATION void getnstimeofday (struct timespec *tv) {
@@ -564,6 +579,31 @@ void getnstimeofday(struct timespec *tv) }#endif +/** +* do_monotonic_clock - Returns monotonically increasing nanoseconds +* +* Returns the monotonically increasing number of nanoseconds +* since the system booted. +*/ +nsec_t do_monotonic_clock (void ) +{ +struct timespec ts, mo; +unsigned int seq; + +do { + seq =read_seqbegin (&xtime_lock); +getnstimeofday (&ts); + mo = wall_to_monotonic; + }while (read_seqretry (&xtime_lock, seq)); + + ts.tv_sec += mo.tv_sec; + ts.tv_nsec += mo.tv_nsec; + +return ((u64 )ts.tv_sec *NSEC_PER_SEC ) + ts.tv_nsec; +} + +#endif /* !CONFIG_GENERICTOD */ +#if (BITS_PER_LONG <64 )u64 get_jiffies_64 (void ) {
kernel/timeofday.c new file +575 -0
575 lines not on this page · raw message
kernel/timer.c +4 -0
@@ -839,6 +839,7 @@ void ntp_advance(unsigned long interval_ } +#ifndef CONFIG_GENERICTOD /* * Using a loop looks inefficient, but "ticks" is * usually just one (we shouldn't be losing ticks,
@@ -890,6 +891,9 @@ static void update_wall_time(unsigned lo } while (ticks); } +#else /* !CONFIG_GENERICTOD */ +#define update_wall_time (x) +#endif /* !CONFIG_GENERICTOD */ /* * Called from the timer interrupt handler to charge one tick to the current
RFC PATCH 5/11 generic timeofday i386 arch specific changes, part 1
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the first of six, is just a simple cleanup for the i386 arch in preparation of moving the the generic timeofday infrastructure. It simply moves some code from timer_pit.c to i8259.c.
It applies on top of my timeofday-core patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile (although just this one should).
thanks
-john
i8259.c | 40 ++++++++++++++++++++++++++++++++++++++++ time.c | 1 - timers/timer_pit.c | 13 ------------- 3 files changed, 40 insertions(+), 14 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part1_B6.patch
============================================
arch/i386/kernel/i8259.c +40 -0
@@ -23,6 +23,7 @@#include <asm/apic.h> #include <asm/arch_hooks.h> #include <asm/i8259.h> +#include <asm/i8253.h> #include <io_ports.h>
@@ -396,6 +397,45 @@ void __init init_ISA_irqs (void) } } +void setup_pit_timer (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&i8253_lock, flags); +outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ +udelay (10 ); +outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */ +udelay (10 ); +outb (LATCH >>8 ,PIT_CH0 );/* MSB */ +spin_unlock_irqrestore (&i8253_lock, flags); +} + +static int timer_resume (struct sys_device *dev) +{ +setup_pit_timer (); +return 0 ; +} + +static struct sysdev_class timer_sysclass = { +set_kset_name ("timer_pit" ), + .resume = timer_resume, +}; + +static struct sys_device device_timer = { + .id =0 , + .cls = &timer_sysclass, +}; + +static int __init init_timer_sysfs (void ) +{ +int error =sysdev_class_register (&timer_sysclass); +if (!error) + error =sysdev_register (&device_timer); +return error; +} + +device_initcall (init_timer_sysfs); +void __init init_IRQ (void ) {int i;
arch/i386/kernel/time.c +0 -1
@@ -404,7 +404,6 @@ static int timer_resume(struct sys_devicif (is_hpet_enabled ())hpet_reenable ();#endif -setup_pit_timer (); sec =get_cmos_time () + clock_cmos_diff; sleep_length = (get_cmos_time () - sleep_start) *HZ ;write_seqlock_irqsave (&xtime_lock, flags);
arch/i386/kernel/timers/timer_pit.c +0 -13
@@ -161,16 +161,3 @@ struct init_timer_opts __initdata timer_ .init = init_pit, .opts = &timer_pit, }; - -void setup_pit_timer (void ) -{ -unsigned long flags; - -spin_lock_irqsave (&i8253_lock, flags); -outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ -udelay (10 ); -outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */ -udelay (10 ); -outb (LATCH >>8 ,PIT_CH0 );/* MSB */ -spin_unlock_irqrestore (&i8253_lock, flags); -}
RFC PATCH 6/11 generic timeofday i386 arch specific changes, part 2
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the second of six, is a cleanup patch for the i386 arch in preparation of moving the the generic timeofday infrastructure. It moves some code from timer_tsc.c to a new tsc.c file.
It applies on top of my timeofday-arch-i386-part1 patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile.
thanks
-john
arch/i386/kernel/Makefile | 2 arch/i386/kernel/timers/common.c | 84 ---------- arch/i386/kernel/timers/timer_tsc.c | 207 ------------------------- arch/i386/kernel/tsc.c | 298 ++++++++++++++++++++++++++++++++++++ include/asm-i386/timex.h | 34 ---- include/asm-i386/tsc.h | 44 +++++ 6 files changed, 344 insertions(+), 325 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part2_B6.patch
============================================
arch/i386/kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ extra-y := head.o init_task.o vmlinux.ld obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \ ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \ pci-dma.o i386_ksyms.o i387.o dmi_scan.o bootflag.o \ - doublefault.o quirks.o i8237.o + doublefault.o quirks.o i8237.o tsc.o obj-y += cpu/ obj-y += timers/
arch/i386/kernel/timers/common.c +0 -84
93 lines not on this page · raw message
arch/i386/kernel/timers/timer_tsc.c +0 -207
237 lines not on this page · raw message
arch/i386/kernel/tsc.c new file +298 -0
298 lines not on this page · raw message
include/asm-i386/timex.h +1 -33
@@ -8,6 +8,7 @@#include <linux/config.h> #include <asm/processor.h> +#include <asm/tsc.h> #ifdef CONFIG_X86_ELAN # define CLOCK_TICK_RATE 1189200/* AMD Elan has different frequency! */
@@ -16,39 +17,6 @@#endif -/* -* Standard way to access the cycle counter on i586+ CPUs. -* Currently only used on SMP. -* -* If you really have a SMP machine with i486 chips or older, -* compile for that, and this will just always return zero. -* That's ok, it just means that the nicer scheduling heuristics -* won't work for you. -* -* We only use the low 32 bits, and we'd simply better make sure -* that we reschedule before that wraps. Scheduling at least every -* four billion cycles just basically sounds like a good idea, -* regardless of how fast the machine is. -*/ -typedef unsigned long long cycles_t ; - -static inline cycles_t get_cycles (void ) -{ -unsigned long long ret=0 ; - -#ifndef CONFIG_X86_TSC -if (!cpu_has_tsc) -return 0 ; -#endif - -#if defined(CONFIG_X86_GENERIC ) || defined(CONFIG_X86_TSC ) -rdtscll (ret); -#endif -return ret; -} - -extern unsigned int cpu_khz; -extern int read_current_timer (unsigned long *timer_value);#define ARCH_HAS_READ_CURRENT_TIMER 1
include/asm-i386/tsc.h new file +44 -0
44 lines not on this page · raw message
RFC PATCH 7/11 generic timeofday i386 arch specific changes, part 3
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the third of six, reworks some of the code in the new tsc.c file, adding some new interfaces and hooks to use these new interfaces appropriately.
It applies on top of my timeofday-arch-i386-part2 patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile.
thanks
-john
arch/i386/kernel/setup.c | 1 arch/i386/kernel/tsc.c | 192 ++++++++++++++-------------- drivers/acpi/processor_idle.c | 6 include/asm-i386/mach-default/mach_timer.h | 4 include/asm-i386/mach-summit/mach_mpparse.h | 2 include/asm-i386/tsc.h | 6 6 files changed, 118 insertions(+), 93 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part3_B6.patch
============================================
arch/i386/kernel/setup.c +1 -0
@@ -1612,6 +1612,7 @@ void __init setup_arch(char **cmdline_p) conswitchp = &dummy_con;#endif #endif +tsc_init (); }#include "setup_arch_post.h"
arch/i386/kernel/tsc.c +100 -92
299 lines not on this page · raw message
drivers/acpi/processor_idle.c +6 -0
@@ -166,6 +166,7 @@ acpi_processor_power_activate(struct acpreturn ; } +extern void tsc_c3_compensate (unsigned long usecs);static atomic_t c3_cpu_count;static void acpi_processor_idle (void )
@@ -334,6 +335,11 @@ static void acpi_processor_idle(void) ACPI_MTX_DO_NOT_LOCK); } +#ifdef CONFIG_GENERICTOD +/* compensate for TSC pause */ +tsc_c3_compensate ((((t2-t1)&0xFFFFFF )*286 )>>10 ); +#endif +/* Re-enable interrupts */ local_irq_enable ();/* Compute time (ticks) that we were actually asleep */
include/asm-i386/mach-default/mach_timer.h +3 -1
@@ -15,7 +15,9 @@#ifndef _MACH_TIMER_H#define _MACH_TIMER_H -#define CALIBRATE_LATCH (5 * LATCH) +#define CALIBRATE_TIME_MSEC 30/* 30 msecs */ +#define CALIBRATE_LATCH \ + ((CLOCK_TICK_RATE * CALIBRATE_TIME_MSEC + 1000/2)/1000)static inline void mach_prepare_counter (void ) {
include/asm-i386/mach-summit/mach_mpparse.h +2 -0
@@ -30,6 +30,7 @@ static inline int mps_oem_check(struct m (!strncmp(productid, "VIGIL SMP", 9) || !strncmp(productid, "EXA", 3) || !strncmp(productid, "RUTHLESS SMP", 12))){ +mark_tsc_unstable (); use_cyclone =1 ;/*enable cyclone-timer*/ setup_summit (); usb_early_handoff =1 ;
@@ -44,6 +45,7 @@ static inline int acpi_madt_oem_check(chif (!strncmp (oem_id,"IBM" ,3 ) && (!strncmp (oem_table_id,"SERVIGIL" ,8 ) || !strncmp (oem_table_id,"EXA" ,3 ))){ +mark_tsc_unstable (); use_cyclone =1 ;/*enable cyclone-timer*/ setup_summit (); usb_early_handoff =1 ;
include/asm-i386/tsc.h +6 -0
@@ -41,4 +41,10 @@ static inline cycles_t get_cycles (void) }extern unsigned int cpu_khz; +extern unsigned int tsc_khz; +extern void tsc_init (void ); +void tsc_c3_compensate (unsigned long usecs); +u64 tsc_read_c3_time (void ); +extern int check_tsc_unstable (void ); +extern void mark_tsc_unstable (void );#endif
RFC PATCH 8/11 generic timeofday i386 arch specific changes, part 4
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the fourth of six, renames some ACPI PM variables.
It applies on top of my timeofday-arch-i386-part3 patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile.
thanks
-john
boot.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part4_B6.patch
============================================
arch/i386/kernel/acpi/boot.c +8 -6
@@ -612,7 +612,8 @@ static int __init acpi_parse_hpet(unsign#endif #ifdef CONFIG_X86_PM_TIMER -extern u32 pmtmr_ioport; +u32 acpi_pmtmr_ioport; +int acpi_pmtmr_buggy;#endif static int __init acpi_parse_fadt (unsigned long phys,unsigned long size)
@@ -640,14 +641,15 @@ static int __init acpi_parse_fadt(unsign ACPI_ADR_SPACE_SYSTEM_IO)return 0 ; - pmtmr_ioport = fadt->xpm_tmr_blk.address; + acpi_pmtmr_ioport = fadt->xpm_tmr_blk.address; }else {/* FADT rev. 1 */ - pmtmr_ioport = fadt->V1_pm_tmr_blk; + acpi_pmtmr_ioport = fadt->V1_pm_tmr_blk; } -if (pmtmr_ioport) - printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", - pmtmr_ioport); + +if (acpi_pmtmr_ioport) + printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n", acpi_pmtmr_ioport); +#endif return 0 ; }
RFC PATCH 9/11 generic timeofday i386 arch specific changes, part 5
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the fifth of six, converts the i386 arch to use the generic timeofday subsystem.
It applies on top of my timeofday-arch-i386-part4 patch. This patch is the last in the the timeofday-arch-i386 patchset, so you should be able to build and boot a kernel after it has been applied.
Note that this patch does not provide any i386 timesources, so you will only have the jiffies timesource. To get full replacements for the code being removed here, the following timeofday-timesources-i386 patch will need to be applied.
thanks
-john
arch/i386/Kconfig | 4 arch/i386/kernel/Makefile | 1 arch/i386/kernel/time.c | 219 ++++++------------------------------------- arch/i386/lib/delay.c | 16 ++- include/asm-i386/timeofday.h | 4 include/asm-i386/timer.h | 57 ----------- 6 files changed, 55 insertions(+), 246 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part5_B6.patch
============================================
arch/i386/Kconfig +4 -0
@@ -14,6 +14,10 @@ config X86 486, 586, Pentiums, and various instruction-set-compatible chips by AMD, Cyrix, and others. +config GENERICTOD + bool + default y + config SEMAPHORE_SLEEPERS bool default y
arch/i386/kernel/Makefile +0 -1
@@ -10,7 +10,6 @@ obj-y := process.o semaphore.o signal.o doublefault.o quirks.o i8237.o tsc.o obj-y += cpu/ -obj-y += timers/ obj-$(CONFIG_ACPI) += acpi/ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o obj-$(CONFIG_MCA) += mca.o
arch/i386/kernel/time.c +34 -185
321 lines not on this page · raw message
arch/i386/lib/delay.c +13 -3
@@ -13,6 +13,7 @@#include <linux/config.h> #include <linux/sched.h> #include <linux/delay.h> +#include <linux/timeofday.h> #include <linux/module.h> #include <asm/processor.h> #include <asm/delay.h>
@@ -22,11 +23,20 @@#include <asm/smp.h> #endif -extern struct timer_opts * timer; - +/* XXX - For now just use a simple loop delay +* This has cpufreq issues, but so did the old method. +*/ void __delay (unsigned long loops) { - cur_timer->delay (loops); +int d0; + __asm__ __volatile__( +"\tjmp 1f\n" +".align 16\n" +"1:\tjmp 2f\n" +".align 16\n" +"2:\tdecl %0\n\tjns 2b" + :"=&a" (d0) + :"0" (loops)); }inline void __const_udelay (unsigned long xloops)
include/asm-i386/timeofday.h new file +4 -0
@@ -0,0 +1,4 @@ +#ifndef _ASM_I386_TIMEOFDAY_H +#define _ASM_I386_TIMEOFDAY_H +#include <asm-generic/timeofday.h> +#endif
include/asm-i386/timer.h +0 -57
68 lines not on this page · raw message
RFC PATCH 10/11 generic timeofday i386 arch specific changes, part 6
All,
The conversion of i386 to use the generic timeofday subsystem has been
split into 6 parts. This patch, the final of four, removes the old timers/timer_opts infrastructure.
It applies on top of my timeofday-arch-i386-part5 patch. This patch is the last in the the timeofday-arch-i386 patchset, so you should be able to build and boot a kernel after it has been applied.
Note that this patch does not provide any i386 timesources, so you will only have the jiffies timesource. To get full replacements for the code being removed here, the following timeofday-timesources-i386 patch will need to be applied.
thanks
-john
Makefile | 9 - common.c | 88 ------------ timer.c | 75 ---------- timer_cyclone.c | 259 ------------------------------------- timer_hpet.c | 212 ------------------------------ timer_none.c | 39 ----- timer_pit.c | 163 ----------------------- timer_pm.c | 268 -------------------------------------- timer_tsc.c | 388 -------------------------------------------------------- 9 files changed, 1501 deletions(-)
linux-2.6.14-rc2_timeofday-arch-i386-part6_B6.patch
============================================
arch/i386/kernel/timers/Makefile deleted +0 -9
@@ -1,9 +0,0 @@ -# -# Makefile for x86 timers -# - -obj-y := timer.o timer_none.o timer_tsc.o timer_pit.o common.o - -obj-$(CONFIG_X86_CYCLONE_TIMER) += timer_cyclone.o -obj-$(CONFIG_HPET_TIMER) += timer_hpet.o -obj-$(CONFIG_X86_PM_TIMER) += timer_pm.o
arch/i386/kernel/timers/common.c deleted +0 -88
88 lines not on this page · raw message
arch/i386/kernel/timers/timer.c deleted +0 -75
75 lines not on this page · raw message
arch/i386/kernel/timers/timer_cyclone.c deleted +0 -259
259 lines not on this page · raw message
arch/i386/kernel/timers/timer_hpet.c deleted +0 -212
212 lines not on this page · raw message
arch/i386/kernel/timers/timer_none.c deleted +0 -39
@@ -1,39 +0,0 @@ -#include <linux/init.h> -#include <asm/timer.h> - -static void mark_offset_none (void ) -{ -/* nothing needed */ -} - -static unsigned long get_offset_none (void ) -{ -return 0 ; -} - -static unsigned long long monotonic_clock_none (void ) -{ -return 0 ; -} - -static void delay_none (unsigned long loops) -{ -int d0; - __asm__ __volatile__( -"\tjmp 1f\n" -".align 16\n" -"1:\tjmp 2f\n" -".align 16\n" -"2:\tdecl %0\n\tjns 2b" - :"=&a" (d0) - :"0" (loops)); -} - -/* none timer_opts struct */ -struct timer_opts timer_none = { - .name ="none" , - .mark_offset = mark_offset_none, - .get_offset = get_offset_none, - .monotonic_clock = monotonic_clock_none, - .delay = delay_none, -};
arch/i386/kernel/timers/timer_pit.c deleted +0 -163
163 lines not on this page · raw message
arch/i386/kernel/timers/timer_pm.c deleted +0 -268
268 lines not on this page · raw message
arch/i386/kernel/timers/timer_tsc.c deleted +0 -388
388 lines not on this page · raw message
RFC PATCH 11/11 generic timeofday i386 specific timesources
All,
This patch implements the time sources shared between i386 and x86-64
(acpi_pm, cyclone, hpet, pit, tsc and tsc-interp). The patch should apply on top of the timeofday-arch-i386-part6 patch.
The patch should be fairly straight forward, only adding the new
timesources.
thanks
-john
Makefile | 7 ++ acpi_pm.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cyclone.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hpet.c | 59 ++++++++++++++++++++++ i386_pit.c | 63 ++++++++++++++++++++++++ tsc-interp.c | 112 +++++++++++++++++++++++++++++++++++++++++++ tsc.c | 92 +++++++++++++++++++++++++++++++++++ 7 files changed, 623 insertions(+)
linux-2.6.14-rc2_timeofday-timesources-i386_B6.patch
============================================
drivers/timesource/Makefile +7 -0
@@ -1 +1,8 @@ obj-y += jiffies.o + +obj-$(CONFIG_X86) += tsc.o +obj-$(CONFIG_X86) += i386_pit.o +#XXX doesn't boot! obj-$(CONFIG_X86) += tsc-interp.o +obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o +obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o +obj-$(CONFIG_HPET_TIMER) += hpet.o
drivers/timesource/acpi_pm.c new file +152 -0
152 lines not on this page · raw message
drivers/timesource/cyclone.c new file +138 -0
138 lines not on this page · raw message
drivers/timesource/hpet.c new file +59 -0
59 lines not on this page · raw message
drivers/timesource/i386_pit.c new file +63 -0
63 lines not on this page · raw message
drivers/timesource/tsc-interp.c new file +112 -0
112 lines not on this page · raw message
drivers/timesource/tsc.c new file +92 -0
92 lines not on this page · raw message
RFC PATCH 1/1 Generic Timekeeping Rework (cumulative - bz'ed) (v. B6)
In reply to a message not in the archiveQuoted 73 lines · john stultz
All,
Here is the cumulative patch for my generic timekeeping rework (v. B6).
Individual broken out patches to follow. This patch provides the NTP changes, the timesource abstraction, the core timekeeping code as well as the code to convert the i386 arch.New in this release:
o Minimized the NTP changes needed to better facilitate discussion
o Maintains both timespec andnsec_ttimekeeping values to improve performance.
o Implemented a first pass at Roman's idea for fixed interval time accounting in the interrupt hot-path. More optimizations are likely to follow, but this hopefully illustrates some improvement and forward progress.
o Added hooks to allow unified code between systems with continuous hardware timesource and those that require tick/offset time accounting without the performance penalty the old method would cause.Notes:
Some of these changes have affected the codes readability, but hopefully this will be resolved in future versions.Since its been awhile since the last release, I'd not be surprised if a few regressions have shown up. I've tested this on my laptop, but not very widely. Any problem reports would be greatly appreciated.
This patch should apply against Linus' git tree from today.
Please let me know if you have any comments or feedback.
thanks
-johnarch/i386/kernel/timers/Makefile | 9 arch/i386/kernel/timers/common.c | 172 ------- arch/i386/kernel/timers/timer.c | 75 --- arch/i386/kernel/timers/timer_cyclone.c | 259 ----------- arch/i386/kernel/timers/timer_hpet.c | 212 --------- arch/i386/kernel/timers/timer_none.c | 39 - arch/i386/kernel/timers/timer_pit.c | 176 ------- arch/i386/kernel/timers/timer_pm.c | 268 ----------- arch/i386/kernel/timers/timer_tsc.c | 595 -------------------------- b/Documentation/kernel-parameters.txt | 7 b/arch/i386/Kconfig | 4 b/arch/i386/kernel/Makefile | 3 b/arch/i386/kernel/acpi/boot.c | 14 b/arch/i386/kernel/i8259.c | 40 + b/arch/i386/kernel/setup.c | 1 b/arch/i386/kernel/time.c | 220 +-------- b/arch/i386/kernel/tsc.c | 306 +++++++++++++ b/arch/i386/lib/delay.c | 16 b/drivers/Makefile | 1 b/drivers/acpi/processor_idle.c | 6 b/drivers/char/hangcheck-timer.c | 5 b/drivers/timesource/Makefile | 8 b/drivers/timesource/acpi_pm.c | 152 ++++++ b/drivers/timesource/cyclone.c | 138 ++++++ b/drivers/timesource/hpet.c | 59 ++ b/drivers/timesource/i386_pit.c | 63 ++ b/drivers/timesource/jiffies.c | 74 +++ b/drivers/timesource/tsc-interp.c | 112 ++++ b/drivers/timesource/tsc.c | 92 ++++ b/include/asm-generic/timeofday.h | 26 + b/include/asm-i386/mach-default/mach_timer.h | 4 b/include/asm-i386/mach-summit/mach_mpparse.h | 2 b/include/asm-i386/timeofday.h | 4 b/include/asm-i386/timer.h | 57 -- b/include/asm-i386/timex.h | 34 - b/include/asm-i386/tsc.h | 50 ++ b/include/linux/time.h | 4 b/include/linux/timeofday.h | 83 +++ b/include/linux/timesource.h | 172 +++++++
Quoted 8 lines
b/include/linux/timex.h | 33 + b/init/main.c | 2 b/kernel/Makefile | 1 b/kernel/time.c | 90 ++- b/kernel/timeofday.c | 575 +++++++++++++++++++++++++ b/kernel/timer.c | 305 ++++++++----- b/kernel/timesource.c | 259 +++++++++++ 46 files changed, 2583 insertions(+), 2244 deletions(-)
Ack. I just realized I might hit size restrictions on lkml.
bz'ed patch attached.
Sorry,
-john