Time: Generic Timekeeping (v.C1)
Subsystems (5)
cover Time: Generic Timekeeping (v.C1)
Andrew, All,
Here is an updated version of the smaller, reworked and
improved patchset I mailed out monday. Please consider for inclusion into your tree.
Again, the majority of this new incremental design should be credited to Roman Zippel, but it is my implementation, so he gets the credit and I get the blame. :)
Summary:
This patchset provides a generic timekeeping infrastructure
that are independent of the timer interrupt. This allows for robust and correct behavior in cases of late or lost ticks, avoids interpolation errors, reduces duplication in arch specific code, and allows or assists future changes such as high-res timers, dynamic ticks, or realtime preemption. Additionally, it provides finer nanosecond resolution values to the clock_gettime functions. The patchset also converts the i386 arch to use this new infrastructure.
Changes since the C0 release:
o Cut out functions that are no longer used
o Re-arranged patch chunks so each patch makes more sense.
o Few small fixes.
o Improved comments.
On my TODO list:
o More attention on x86-64 and powerpc
o Re-add bits needed for inclusion into HRT and RT
o Try to restore cleanups via small patches
The patchset applies against the current 2.6.16-git.
The complete patchset can be found here:
http://sr71.net/~jstultz/tod/
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, Serge Belyshev,
Dominik Brodowski, Adrian Bunk, Thomas Gleixner, Darren Hart, Christoph Lameter, Matt Mackal, Keith Mannthey, Ingo Molnar, Andrew Morton, Paul Munt, Martin Schwidefsky, Frank Sorenson, Ulrich Windl, Jonathan Woithe, Darrick Wong, Roman Zippel and any others whom I've accidentally left off this list.
thanks
-john
PATCH 1/10 Time: Clocksource Infrastructure
This introduces the clocksource management infrastructure. A
clocksource is a driver-like architecture generic abstraction of a free-running counter. This code defines the clocksource structure, and provides management code for registering, selecting, accessing and scaling clocksources.
Additionally, this includes the trivial jiffies clocksource, a lowest common denominator clocksource, provided mainly for use as an example.
Documentation/kernel-parameters.txt | 14 + include/linux/clocksource.h | 181 ++++++++++++++++++ kernel/time/Makefile | 1 kernel/time/clocksource.c | 343 ++++++++++++++++++++++++++++++++++++ kernel/time/jiffies.c | 73 +++++++ 5 files changed, 608 insertions(+), 4 deletions(-)
linux-2.6.16_timeofday-clocksource-core_C1.patch
============================================
Documentation/kernel-parameters.txt +10 -4
@@ -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_TIME The generic timeofday code is enabled. NFS Appropriate NFS support is enabled. OSS OSS sound support is enabled. PARIDE The ParIDE subsystem is enabled.
@@ -329,10 +330,11 @@ running once the system is up. Value can be changed at runtime via /selinux/checkreqprot. - clock= [BUGS=IA-32,HW] gettimeofday timesource override. - Forces specified timesource (if avaliable) to be used - when calculating gettimeofday(). If specicified - timesource is not avalible, it defaults to PIT. + clock= [BUGS=IA-32, HW] gettimeofday clocksource override. + [Deprecated] + Forces specified clocksource (if avaliable) to be used + when calculating gettimeofday(). If specified + clocksource is not avalible, it defaults to PIT. Format: { pit | tsc | cyclone | pmtmr } disable_8254_timer
@@ -1579,6 +1581,10 @@ running once the system is up. time Show timing data prefixed to each printk message line + clocksource= [GENERIC_TIME] Override the default clocksource + Override the default clocksource and use the clocksource + with the name specified. + tipar.timeout= [HW,PPT] Set communications timeout in tenths of a second (default 15).
include/linux/clocksource.h new file +181 -0
181 lines not on this page · raw message
kernel/time/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += clocksource.o jiffies.o
kernel/time/clocksource.c new file +343 -0
343 lines not on this page · raw message
kernel/time/jiffies.c new file +73 -0
73 lines not on this page · raw message
PATCH 2/10 Time: Use clocksource infrastructure for update_wall_time
In reply to john stultz This patch modifies the update_wall_time function so it
increments time using the clocksource abstraction instead of jiffies. Since the only clocksource driver currently provided is the jiffies clocksource, this should result in no functional change. Additionally, a timekeeping_init and timekeeping_resume function has been added to initialize and maintain some of the new timekeping state.
Signed-off-by John Stultz <[email protected]>
include/linux/time.h | 2 + init/main.c | 1 kernel/Makefile | 1 kernel/timer.c | 93 +++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 84 insertions(+), 13 deletions(-)
linux-2.6.16_timeofday-core1_C1.patch
============================================
include/linux/time.h +2 -0
@@ -83,6 +83,8 @@ extern struct timespec xtime;extern struct timespec wall_to_monotonic;extern seqlock_t xtime_lock; +void timekeeping_init (void ); +static inline unsigned long get_seconds (void ) {return xtime.tv_sec;
init/main.c +1 -0
@@ -486,6 +486,7 @@ asmlinkage void __init start_kernel(voidhrtimers_init ();softirq_init ();time_init (); +timekeeping_init ();/* * HACK ALERT! This is early. We're enabling the console before
kernel/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-y = sched.o fork.o exec_domain.o kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ hrtimer.o +obj-y += time/ obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/timer.c +80 -13
114 lines not on this page · raw message
PATCH 3/10 Time: Let user request precision from current_tick_length()
In reply to john stultz Change the current_tick_length() function so it takes an
argument which specifies how much precision to return in shifted nanoseconds. This provides a simple way to convert between NTPs internal nanoseconds shifted by (SHIFT_SCALE - 10) to other shifted nanosecond units that are used by the clocksource abstraction.
Signed-off-by John Stultz <[email protected]>
arch/powerpc/kernel/time.c | 2 +- include/linux/timex.h | 2 +- kernel/timer.c | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-)
linux-2.6.16_timeofday-core2_C1.patch
============================================
arch/powerpc/kernel/time.c +1 -1
@@ -315,7 +315,7 @@ static __inline__ void timer_recalc_offsif (__USE_RTC ())return ; - tlen =current_tick_length (); + tlen =current_tick_length (SHIFT_SCALE -10 ); offset = cur_tb - do_gtod.varp->tb_orig_stamp;if (tlen == last_tick_len && offset <0x80000000u )return ;
include/linux/timex.h +1 -1
@@ -346,7 +346,7 @@ time_interpolator_reset(void)#endif /* !CONFIG_TIME_INTERPOLATION */ /* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ -extern u64 current_tick_length (void ); +extern u64 current_tick_length (long );#endif /* KERNEL */
kernel/timer.c +17 -4
@@ -791,16 +791,29 @@ static void update_wall_time_one_tick(vo* Return how long ticks are at the moment, that is, how much time * update_wall_time_one_tick will add to xtime next time we call it * (assuming no calls to do_adjtimex in the meantime). -* The return value is in fixed-point nanoseconds with SHIFT_SCALE-10 -* bits to the right of the binary point. +* The return value is in fixed-point nanoseconds shifted by the +* specified number of bits to the right of the binary point. * This function has no side-effects. */ -u64 current_tick_length (void ) +u64 current_tick_length (long shift) {long delta_nsec; +u64 ret; +/* calculate the finest interval NTP will allow. +* ie: nanosecond value shifted by (SHIFT_SCALE - 10) +*/ delta_nsec = tick_nsec +adjtime_adjustment () *1000 ; -return ((u64 ) delta_nsec << (SHIFT_SCALE -10 )) + time_adj; + ret = ((u64 ) delta_nsec << (SHIFT_SCALE -10 )) + time_adj; + +/* convert from (SHIFT_SCALE - 10) to specified shift scale: */ + shift = shift - (SHIFT_SCALE -10 ); +if (shift <0 ) + ret >>= -shift; +else + ret <<= shift; + +return ret; }/* XXX - all of this timekeeping code should be later moved to time.c */
PATCH 4/10 Time: Use clocksource abstraction for NTP adjustments
In reply to john stultz Instead of incrementing xtime by tick_nsec + ntp adjustments,
use the clocksource abstraction to increment and scale time. Using the clocksource abstraction allows other clocksources to be used consistently in the face of late or lost ticks, while preserving the existing behavior via the jiffies clocksource.
This removes the need to keep time_phase adjustments as we just use the current_tick_length() function as the NTP interface and accumulate time using shifted nanoseconds.
The basics of this design was by Roman Zippel, however it is my own interpretation and implementation, so the credit should go to him and the blame to me.
include/linux/clocksource.h | 98 ++++++++++++++++++++++++++++++++++++++++++++ kernel/timer.c | 47 ++++++++++++--------- 2 files changed, 126 insertions(+), 19 deletions(-)
linux-2.6.16_timeofday-core3_C1.patch
============================================
include/linux/clocksource.h +98 -0
@@ -173,6 +173,104 @@ static inline void calculate_clocksource c->interval_snsecs = (u64 )c->interval_cycles * c->mult; } + +/** +* error_aproximation - calculates an error adjustment for a given error +* +* @error: Error value (unsigned) +* @unit: Adjustment unit +* +* For a given error value, this function takes the adjustment unit +* and uses binary approximation to return a power of two adjustment value. +* +* This function is only for use by the the make_ntp_adj() function +* and you must hold a write on the xtime_lock when calling. +*/ +static inline int error_aproximation (u64 error,u64 unit) +{ +static int saved_adj =0 ; +u64 adjusted_unit = unit << saved_adj; + +if (error > (adjusted_unit *2 )) { +/* large error, so increment the adjustment factor */ + saved_adj++; + }else if (error > adjusted_unit) { +/* just right, don't touch it */ + }else if (saved_adj) { +/* small error, so drop the adjustment factor */ + saved_adj--; +return 0 ; + } + +return saved_adj; +} + + +/** +* make_ntp_adj - Adjusts the specified clocksource for a given error +* +* @clock: Pointer to clock to be adjusted +* @cycles_delta: Current unacounted cycle delta +* @error: Pointer to current error value +* +* Returns clock shifted nanosecond adjustment to be applied against +* the accumulated time value (ie: xtime). +* +* If the error value is large enough, this function calulates the +* (power of two) adjustment value, and adjusts the clock's mult and +* interval_snsecs values accordingly. +* +* However, since there may be some unaccumulated cycles, to avoid +* time inconsistencies we must adjust the accumulation value +* accordingly. +* +* This is not very intuitive, so the following proof should help: +* The basic timeofday algorithm: base + cycle * mult +* Thus: +* new_base + cycle * new_mult = old_base + cycle * old_mult +* new_base = old_base + cycle * old_mult - cycle * new_mult +* new_base = old_base + cycle * (old_mult - new_mult) +* new_base - old_base = cycle * (old_mult - new_mult) +* base_delta = cycle * (old_mult - new_mult) +* base_delta = cycle * (mult_delta) +* +* Where mult_delta is the adjustment value made to mult +* +* XXX - Hopefully gcc is smart enough to avoid the multiplies. +*/ +static inline s64 make_ntp_adj (struct clocksource *clock, +cycles_t cycles_delta,s64 * error) +{ +s64 ret =0 ; +if (*error > ((s64 )clock->interval_cycles+1 )/2 ) { +/* calculate adjustment value */ +int adjustment =1 <<error_aproximation (*error, + clock->interval_cycles); +/* adjust clock */ + clock->mult += adjustment; + clock->interval_snsecs += clock->interval_cycles * adjustment; + +/* adjust the base and error for the adjustment */ + ret = -(cycles_delta * adjustment); + *error -= clock->interval_cycles * adjustment; +/* XXX adj error for cycle_delta offset? */ + }else if ((-(*error)) > ((s64 )clock->interval_cycles+1 )/2 ) { +/* calculate adjustment value */ +int adjustment =1 <<error_aproximation (-(*error), + clock->interval_cycles); +/* adjust clock */ + clock->mult -= adjustment; + clock->interval_snsecs -= clock->interval_cycles * adjustment; + +/* adjust the base and error for the adjustment */ + ret = cycles_delta * adjustment; + *error += clock->interval_cycles * adjustment; +/* XXX adj error for cycle_delta offset? */ + } +return ret; +} + +/* used to install a new clocksource */ int register_clocksource (struct clocksource *);void reselect_clocksource (void );
kernel/timer.c +28 -19
87 lines not on this page · raw message
PATCH 5/10 Time: Introduce arch generic time accessors
In reply to john stultz Introduces clocksource switching code and the arch generic time
accessor functions that use the clocksource infrastructure.
include/linux/time.h | 15 ++++ kernel/time.c | 2 kernel/timer.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+)
linux-2.6.16_timeofday-core4_C1.patch
============================================
include/linux/time.h +15 -0
@@ -107,6 +107,7 @@ extern int do_getitimer(int which, strucextern void getnstimeofday (struct timespec *tv);extern struct timespec timespec_trunc (struct timespec t,unsigned gran); +extern int timekeeping_is_continuous (void );/** * timespec_to_ns - Convert timespec to nanoseconds
@@ -149,6 +150,20 @@ extern struct timespec ns_to_timespec(co*/ extern struct timeval ns_to_timeval (const nsec_t nsec); +/** +* timespec_add_ns - Adds nanoseconds to a timespec +* @a: pointer to timespec to be incremented +* @ns: unsigned nanoseconds value to be added +*/ +static inline void timespec_add_ns (struct timespec *a,u64 ns) +{ + ns += a->tv_nsec; +while (unlikely (ns >=NSEC_PER_SEC )) { + ns -=NSEC_PER_SEC ; + a->tv_sec++; + } + a->tv_nsec = ns; +}#endif /* __KERNEL__ */ #define NFDBITS __NFDBITS
kernel/time.c +2 -0
@@ -550,6 +550,7 @@ EXPORT_SYMBOL(do_gettimeofday);#else +#ifndef CONFIG_GENERIC_TIME /* * Simulate gettimeofday using do_gettimeofday which only allows a timeval * and therefore only yields usec accuracy
@@ -564,6 +565,7 @@ void getnstimeofday(struct timespec *tv) }EXPORT_SYMBOL_GPL (getnstimeofday);#endif +#endif /* Converts Gregorian date to seconds since 1970-01-01 00:00:00. * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
kernel/timer.c +170 -0
182 lines not on this page · raw message
PATCH 6/10 Time: i386 Conversion - part 1: Move timer_pit.c to i8253.c
In reply to john stultz This patch is just a simple cleanup for the i386 arch in
preparation of moving to the generic timeofday infrastructure. It simply moves the PIT initialization code, locks, and other code we want to keep from some code from timer_pit.c (which will be removed) to i8253.c.
thanks
-john
Makefile | 2 +- i8253.c | 32 ++++++++++++++++++++++++++++++++ time.c | 5 ----- timers/timer_pit.c | 13 ------------- 4 files changed, 33 insertions(+), 19 deletions(-)
linux-2.6.16_timeofday-arch-i386-part1_C1.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 \ 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 \ - quirks.o i8237.o topology.o + quirks.o i8237.o i8253.o topology.o obj-y += cpu/ obj-y += timers/
arch/i386/kernel/i8253.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* i8253.c 8253/PIT functions +* +*/ +#include <linux/spinlock.h> +#include <linux/jiffies.h> +#include <linux/sysdev.h> +#include <linux/module.h> +#include <linux/init.h> + +#include <asm/smp.h> +#include <asm/delay.h> +#include <asm/i8253.h> +#include <asm/io.h> + +#include "io_ports.h" + +DEFINE_SPINLOCK (i8253_lock); +EXPORT_SYMBOL (i8253_lock); + +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); +}
arch/i386/kernel/time.c +0 -5
@@ -82,11 +82,6 @@ extern unsigned long wall_jiffies;DEFINE_SPINLOCK (rtc_lock);EXPORT_SYMBOL (rtc_lock); -#include <asm/i8253.h> - -DEFINE_SPINLOCK (i8253_lock); -EXPORT_SYMBOL (i8253_lock); -struct timer_opts *cur_timer__read_mostly = &timer_none;/*
arch/i386/kernel/timers/timer_pit.c +0 -13
@@ -162,16 +162,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); -}
PATCH 7/10 Time: i386 Conversion - part 2: Rework TSC Support
In reply to john stultz As part of the i386 conversion to the generic timekeeping
infrastructure, this introduces a new tsc.c file. The code in this file replaces the TSC initialization, management and access code currently in timer_tsc.c (which will be removed) that we want to preserve.
The code also introduces the following functionality:
o tsc_khz: like cpu_khz but stores the TSC frequency on systems that do not change TSC frequency w/ CPU frequency
o check/mark_tsc_unstable: accessor/modifier flag for TSC timekeeping usability
o minor cleanups to calibration math.
This patch also includes a one line __cpuinitdata fix from Zwane Mwaikambo.
thanks
-john
arch/i386/kernel/Makefile | 2 arch/i386/kernel/numaq.c | 10 arch/i386/kernel/setup.c | 1 arch/i386/kernel/timers/timer_tsc.c | 178 --------------- arch/i386/kernel/tsc.c | 316 ++++++++++++++++++++++++++++ drivers/acpi/processor_idle.c | 9 include/asm-i386/mach-default/mach_timer.h | 4 include/asm-i386/mach-summit/mach_mpparse.h | 3 include/asm-i386/timex.h | 34 --- include/asm-i386/tsc.h | 49 ++++ 10 files changed, 389 insertions(+), 217 deletions(-)
linux-2.6.16_timeofday-arch-i386-part2_C1.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 \ 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 \ - quirks.o i8237.o i8253.o topology.o + quirks.o i8237.o i8253.o tsc.o topology.o obj-y += cpu/ obj-y += timers/
arch/i386/kernel/numaq.c +6 -4
@@ -79,10 +79,12 @@ int __init get_memcfg_numaq(void)return 1 ; } -static int __init numaq_dsc_disable (void ) +static int __init numaq_tsc_disable (void ) { -printk (KERN_DEBUG "NUMAQ: disabling TSC\n" ); - tsc_disable =1 ; +if (num_online_nodes () >1 ) { +printk (KERN_DEBUG "NUMAQ: disabling TSC\n" ); + tsc_disable =1 ; + }return 0 ; } -core_initcall (numaq_dsc_disable); +arch_initcall (numaq_tsc_disable);
arch/i386/kernel/setup.c +1 -0
@@ -1632,6 +1632,7 @@ void __init setup_arch(char **cmdline_p) conswitchp = &dummy_con;#endif #endif +tsc_init (); }#include "setup_arch_post.h"
arch/i386/kernel/timers/timer_tsc.c +0 -178
208 lines not on this page · raw message
arch/i386/kernel/tsc.c new file +316 -0
316 lines not on this page · raw message
drivers/acpi/processor_idle.c +9 -0
@@ -369,6 +369,11 @@ static void acpi_processor_idle(void) t2 =inl (acpi_fadt.xpm_tmr_blk.address);/* Get end time (ticks) */ t2 =inl (acpi_fadt.xpm_tmr_blk.address); + +#ifdef CONFIG_GENERIC_TIME +/* TSC halts in C2, so notify users */ +mark_tsc_unstable (); +#endif /* Re-enable interrupts */ local_irq_enable ();set_thread_flag (TIF_POLLING_NRFLAG );
@@ -409,6 +414,10 @@ static void acpi_processor_idle(void) ACPI_MTX_DO_NOT_LOCK); } +#ifdef CONFIG_GENERIC_TIME +/* TSC halts in C3, so notify users */ +mark_tsc_unstable (); +#endif /* Re-enable interrupts */ local_irq_enable ();set_thread_flag (TIF_POLLING_NRFLAG );
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 +3 -0
@@ -2,6 +2,7 @@#define __ASM_MACH_MPPARSE_H#include <mach_apic.h> +#include <asm/tsc.h> extern int use_cyclone;
@@ -29,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 ();return 1 ;
@@ -42,6 +44,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 ();return 1 ;
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 +49 -0
49 lines not on this page · raw message
PATCH 8/10 Time: i386 Conversion - part 3: Enable Generic Timekeeping
In reply to john stultz This converts the i386 arch to use the generic timeofday
subsystem. It enabled the GENERIC_TIME option, disables the timer_opts code and other arch specific timekeeping code and reworks the delay code.
While this patch enables the generic timekeeping, please note that this patch does not provide any i386 clocksource. Thus only the jiffies clocksource will be available. To get full replacements for the code being disabled here, the timeofday-clocks-i386 patch will needed.
thanks
-john
arch/i386/Kconfig | 4 + arch/i386/kernel/Makefile | 1 arch/i386/kernel/time.c | 153 +++++----------------------------------------- arch/i386/kernel/tsc.c | 3 arch/i386/lib/delay.c | 65 +++++++++++++++++-- include/asm-i386/delay.h | 2 include/asm-i386/timer.h | 57 ----------------- 7 files changed, 84 insertions(+), 201 deletions(-)
linux-2.6.16_timeofday-arch-i386-part3_C1.patch
============================================
arch/i386/Kconfig +4 -0
@@ -14,6 +14,10 @@ config X86_32 486, 586, Pentiums, and various instruction-set-compatible chips by AMD, Cyrix, and others. +config GENERIC_TIME + 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 quirks.o i8237.o i8253.o tsc.o topology.o obj-y += cpu/ -obj-y += timers/ obj-y += acpi/ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o obj-$(CONFIG_MCA) += mca.o
arch/i386/kernel/time.c +19 -134
223 lines not on this page · raw message
arch/i386/kernel/tsc.c +2 -1
@@ -10,6 +10,7 @@#include <linux/init.h> #include <asm/tsc.h> +#include <asm/delay.h> #include <asm/io.h> #include "mach_timer.h"
@@ -45,7 +46,6 @@ static int __init tsc_setup(char *str)__setup ("notsc" , tsc_setup); -/* * code to mark and check if the TSC is unstable * due to cpufreq or due to unsynced TSCs
@@ -205,6 +205,7 @@ void tsc_init(void) (unsigned long)cpu_khz % 1000);set_cyc2ns_scale (cpu_khz); +use_tsc_delay (); }#ifdef CONFIG_CPU_FREQ
arch/i386/lib/delay.c +57 -8
100 lines not on this page · raw message
include/asm-i386/delay.h +2 -0
@@ -23,4 +23,6 @@ extern void __delay(unsigned long loops) ((n) > 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \ __ndelay(n)) +void use_tsc_delay (void ); +#endif /* defined(_I386_DELAY_H) */
include/asm-i386/timer.h +0 -57
68 lines not on this page · raw message
PATCH 9/10 Time: i386 Conversion - part 4: Remove Old timer_opts Code
In reply to john stultz This patch removes the old timers/timer_opts infrastructure
which has been disabled. It is a fairly straightforward set of deletions
Note that this does not provide any i386 clocksources, so you will only have the jiffies clocksource. To get full replacements for the code being removed here, the timeofday-clocks-i386 patch will be needed.
thanks
-john
Makefile | 9 - common.c | 172 --------------------- timer.c | 75 --------- timer_cyclone.c | 259 --------------------------------- timer_hpet.c | 217 --------------------------- timer_none.c | 39 ---- timer_pit.c | 164 -------------------- timer_pm.c | 268 ---------------------------------- timer_tsc.c | 439 -------------------------------------------------------- 9 files changed, 1642 deletions(-)
linux-2.6.16_timeofday-arch-i386-part4_C1.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 -172
172 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 -217
217 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 -164
164 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 -439
439 lines not on this page · raw message
PATCH 10/10 Time: i386 Clocksource Drivers
In reply to john stultz This patch implements the time sources for i386 (acpi_pm,
cyclone, hpet, pit, and tsc). With this patch, the conversion of the i386 arch to the generic timekeeping code should be complete.
The patch should be fairly straight forward, only adding the new clocksources.
thanks
-john
arch/i386/kernel/Makefile | 1 arch/i386/kernel/hpet.c | 67 +++++++++++++++++ arch/i386/kernel/i8253.c | 53 +++++++++++++ arch/i386/kernel/time.c | 3 arch/i386/kernel/tsc.c | 161 ++++++++++++++++++++++++++++++++++++++++++ drivers/Makefile | 1 drivers/clocksource/Makefile | 2 drivers/clocksource/acpi_pm.c | 89 +++++++++++++++++++++++ drivers/clocksource/cyclone.c | 119 +++++++++++++++++++++++++++++++ kernel/time/clocksource.c | 9 +- 10 files changed, 500 insertions(+), 5 deletions(-)
linux-2.6.16_timeofday-clocks-i386_C1.patch
============================================
arch/i386/kernel/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_EFI) += efi.o efi_stub.o obj-$(CONFIG_DOUBLEFAULT) += doublefault.o obj-$(CONFIG_VM86) += vm86.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o +obj-$(CONFIG_HPET_TIMER) += hpet.o EXTRA_AFLAGS := -traditional
arch/i386/kernel/hpet.c new file +67 -0
67 lines not on this page · raw message
arch/i386/kernel/i8253.c +53 -0
62 lines not on this page · raw message
arch/i386/kernel/time.c +0 -3
@@ -82,9 +82,6 @@ extern unsigned long wall_jiffies;DEFINE_SPINLOCK (rtc_lock);EXPORT_SYMBOL (rtc_lock); -/* XXX - necessary to keep things compiling. to be removed later */ -u32 pmtmr_ioport; -/* * This is a special lock that is owned by the CPU and holds the index * register we are working with. It is required for NMI access to the
arch/i386/kernel/tsc.c +161 -0
175 lines not on this page · raw message
drivers/Makefile +1 -0
@@ -73,3 +73,4 @@ obj-$(CONFIG_SGI_SN) += sn/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_SUPERH) += sh/ +obj-$(CONFIG_GENERIC_TIME) += clocksource/
drivers/clocksource/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o +obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
drivers/clocksource/acpi_pm.c new file +89 -0
89 lines not on this page · raw message
drivers/clocksource/cyclone.c new file +119 -0
119 lines not on this page · raw message
kernel/time/clocksource.c +7 -2
@@ -335,8 +335,13 @@ __setup("clocksource=", boot_override_cl*/ static int __init boot_override_clock (char * str) { -printk ("Warning! clock= boot option is deprecated.\n" ); - +if (!strcmp (str,"pmtmr" )) { +printk ("Warning: clock=pmtmr is depricated. " +"Use clocksource=acpi_pm.\n" ); +return boot_override_clocksource ("acpi_pm" ); + } +printk ("Warning! clock= boot option is deprecated. " +"Use clocksource=xyz\n" );return boot_override_clocksource (str); }
Hi,
Quoted 4 lines · john stultz
Andrew, All,
Here is an updated version of the smaller, reworked and
improved patchset I mailed out monday. Please consider for inclusion into your tree.
It looks pretty good already. :)
Give me a bit of time to rework the middle part a bit and if we can agree to make the new gettimeofday functions optional for an arch, IMO it would be ok for 2.6.17. I think the important part is to get the generic clock infrastructure merged, so it can be used by other kernel parts, the unification of performance sensitive parts can still be done on top of it a bit later.
One general comment: Currently clock relevant source is scattered in kernel/time/, drivers/clocksource and arch/... IMO it would be better to keep at least the first two parts a bit closer, although I'm not sure how to organize it better. I don't know if we can be so bold to add a toplevel time/ (similiar to sound/) or maybe we organize a bit like drivers/ide/. Anyway, maybe someone has a good idea to keep everything a bit closer together.
bye, Roman
Quoted 7 lines · Roman Zippel
One general comment: Currently clock relevant source is scattered in
kernel/time/,drivers/clocksourceandarch/... IMO it would be better to keep at least the first two parts a bit closer, although I'm not sure how to organize it better. I don't know if we can be so bold to add a toplevel time/ (similiar tosound/) or maybe we organize a bit likedrivers/ide/. Anyway, maybe someone has a good idea to keep everything a bit closer together.
IMO it makes completely sense to move the time/timer/clocks related generic code into kernel/time.
drivers/clocksource holds drivers which can be shared between architectures.
The other drivers really should stay in the architecture specific files as they are often deeply embedded in the SoC or chipset support code.
tglx
Hi,
Quoted 2 lines · Thomas Gleixner
IMO it makes completely sense to move the time/timer/clocks related generic code into kernel/time.
Why? Currently it has two files: jiffies.c is a simple clocksource driver and clocksource.c is the driver support code.
It's basically driver code, which only is used by some core kernel parts.
bye, Roman
Quoted 10 lines · Roman Zippel
Hi,
Quoted 4 lines · john stultz
Andrew, All,
Here is an updated version of the smaller, reworked and
improved patchset I mailed out monday. Please consider for inclusion into your tree.It looks pretty good already. :)
</me rubs his eyes and reads that again>
Quoted 3 lines
Give me a bit of time to rework the middle part a bit and if we can agree to make the new gettimeofday functions optional for an arch, IMO it would be ok for 2.6.17.
? The new gettimeofday functions are optional. Don't enable CONFIG_GENERIC_TIME and you're good to go. Could you clarify what you mean?
Quoted 4 lines
I think the important part is to get the generic clock infrastructure merged, so it can be used by other kernel parts, the unification of performance sensitive parts can still be done on top of it a bit later.
Ok, I'm still not sure how you intend to you the clocksource bits outside of timekeeping, but I'm interested in hearing about it.
thanks
-john