new timeofday core subsystem for -mm (v.B3)
Subsystems (5)
PATCH 1/6 new timeofday core subsystem for -mm (v.B3)
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 and other architecture examples to follow), and it should be able to be applied to a tree without affecting the existing code.
Andrew, please consider for inclusion for testing into your tree.
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.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-core_B3.patch
============================================
Documentation/kernel-parameters.txt +6 -1
@@ -52,6 +52,7 @@ MTD MTD support is enabled. NET Appropriate network support is enabled. NUMA NUMA support is enabled. + NEW_TOD The new timeofday code is enabled. NFS Appropriate NFS support is enabled. OSS OSS sound support is enabled. PARIDE The ParIDE subsystem is enabled.
@@ -309,7 +310,7 @@ 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.
@@ -1443,6 +1444,10 @@ time Show timing data prefixed to each printk message line + timesource= [NEW_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/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 @@#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/Makefile +1 -0
@@ -70,3 +70,4 @@ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/ obj-$(CONFIG_DLM) += dlm/ +obj-$(CONFIG_NEWTOD) += timesource/
drivers/timesource/jiffies.c +69 -0
69 lines not on this page · raw message
drivers/timesource/Makefile +1 -0
@@ -0,0 +1 @@ +obj-y += jiffies.o
include/asm-generic/timeofday.h +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 /* CONFIG_NEWTOD_VSYSCALL */ + +#endif /* CONFIG_NEWTOD */ +#endif
include/linux/ntp.h +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 +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 +59 -0
59 lines not on this page · raw message
include/linux/timesource.h +172 -0
172 lines not on this page · raw message
include/linux/timex.h +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 +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>
@@ -474,6 +475,7 @@pidhash_init ();init_timers ();softirq_init (); +timeofday_init ();time_init ();/*
kernel/Makefile +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 +464 -0
464 lines not on this page · raw message
kernel/time.c +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 +567 -0
567 lines not on this page · raw message
kernel/timer.c +4 -0
@@ -602,6 +602,7 @@int tickadj =500 /HZ ? :1 ;/* microsecs */ +#ifndef CONFIG_NEWTOD /* * phase-lock loop variables */
@@ -832,6 +833,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 +259 -0
259 lines not on this page · raw message
PATCH 2/6 new timeofday i386 arch specific changes, part 1 for -mm (v.B3)
Andrew, All,
To hopefully improve the review-ability of my changes, I've split up my
arch-i386 patch into four chunks. This patch is just a simple cleanup for the i386 arch in preparation of moving the the new timeofday infrastructure. It simply moves some code from timer_pit.c to i8259.c.
It applies on top of my timeofday-core_B3 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).
Andrew, please consider for inclusion for testing into your tree.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-arch-i386-part1_B3.patch
=======================================================
arch/i386/kernel/i8259.c +40 -0
@@ -400,6 +400,46 @@ } } +void setup_pit_timer (void ) +{ +extern spinlock_t i8253_lock; +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/timers/timer_pit.c +0 -41
44 lines not on this page · raw message
PATCH 3/6 new timeofday i386 arch specific changes, part 2 for -mm (v.B3)
Andrew, All,
To hopefully improve the review-ability of my changes, I've split up my
arch-i386 patch into four chunks. This patch is a cleanup patch for the i386 arch in preparation of moving the the new 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_B3 patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile.
Andrew, please consider for inclusion for testing into your tree.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-arch-i386-part2_B3.patch
=======================================================
arch/i386/kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ 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 + doublefault.o quirks.o tsc.o obj-y += cpu/ obj-y += timers/
arch/i386/kernel/timers/common.c +0 -81
90 lines not on this page · raw message
arch/i386/kernel/timers/timer.c +0 -9
@@ -64,12 +64,3 @@panic ("select_timer: Cannot find a suitable timer\n" );return NULL ; } - -int read_current_timer (unsigned long *timer_val) -{ -if (cur_timer->read_timer) { - *timer_val = cur_timer->read_timer (); -return 0 ; - } -return -1 ; -}
arch/i386/kernel/timers/timer_tsc.c +0 -195
225 lines not on this page · raw message
arch/i386/kernel/tsc.c +298 -0
298 lines not on this page · raw message
PATCH 4/6 new timeofday i386 arch specific changes, part 3 for -mm (v.B3)
Andrew, All,
To hopefully improve the review-ability of my changes, I've split up my
arch-i386 patch into four chunks. This patch reworks some of the code in the new tsc.c file. Additionally it adds some new interfaces and hooks to use these new interfaces appropriately. This patch also renames some ACPI PM variables.
It applies on top of my timeofday-arch-i386-part2_B3 patch. This patch is part the timeofday-arch-i386 patchset, so without the following parts it is not expected to compile.
Andrew, please consider for inclusion for testing into your tree.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-arch-i386-part3_B3.patch
=======================================================
arch/i386/kernel/acpi/boot.c +6 -5
@@ -607,7 +607,8 @@#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)
@@ -638,13 +639,13 @@if (fadt->xpm_tmr_blk.address_space_id !=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 ; }
arch/i386/kernel/setup.c +1 -0
@@ -1610,6 +1610,7 @@ 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 +5 -0
@@ -162,6 +162,7 @@return ; } +extern void tsc_c3_compensate (unsigned long usecs);static void acpi_processor_idle (void ) {
@@ -309,6 +310,10 @@ t2 =inl (acpi_fadt.xpm_tmr_blk.address);/* Enable bus master arbitration */ acpi_set_register (ACPI_BITREG_ARB_DISABLE ,0 ,ACPI_MTX_DO_NOT_LOCK ); + +/* compensate for TSC pause */ +tsc_c3_compensate ((((t2-t1)&0xFFFFFF )*286 )>>10 ); +/* 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 @@ (!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 @@if (!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/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 long cpu_khz; -extern int read_current_timer (unsigned long *timer_value);#define ARCH_HAS_READ_CURRENT_TIMER 1
include/asm-i386/tsc.h +50 -0
50 lines not on this page · raw message
PATCH 5/6 new timeofday i386 arch specific changes, part 4 for -mm (v.B3)
Andrew, All,
To hopefully improve the review-ability of my changes, I've split up my
arch-i386 patch into four chunks. This patch converts the i386 arch to use the new timeofday subsystem and removes the old timers/timer_opts infrastructure.
It applies on top of my timeofday-arch-i386-part3_B3 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.
Andrew, please consider for inclusion for testing into your tree.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-arch-i386-part4_B3.patch
=======================================================
arch/i386/Kconfig +4 -0
@@ -14,6 +14,10 @@ 486, 586, Pentiums, and various instruction-set-compatible chips by AMD, Cyrix, and others. +config NEWTOD + bool + default y + config MMU bool default y
arch/i386/kernel/Makefile +0 -1
@@ -10,7 +10,6 @@ doublefault.o quirks.o tsc.o obj-y += cpu/ -obj-y += timers/ obj-$(CONFIG_ACPI_BOOT) += acpi/ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o obj-$(CONFIG_MCA) += mca.o
arch/i386/kernel/time.c +34 -181
307 lines not on this page · raw message
arch/i386/kernel/timers/common.c +0 -90
90 lines not on this page · raw message
arch/i386/kernel/timers/Makefile +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/timer.c +0 -66
66 lines not on this page · raw message
arch/i386/kernel/timers/timer_cyclone.c +0 -259
259 lines not on this page · raw message
arch/i386/kernel/timers/timer_hpet.c +0 -195
195 lines not on this page · raw message
arch/i386/kernel/timers/timer_none.c +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 +0 -165
165 lines not on this page · raw message
arch/i386/kernel/timers/timer_pm.c +0 -259
259 lines not on this page · raw message
arch/i386/kernel/timers/timer_tsc.c +0 -386
386 lines not on this page · raw message
arch/i386/lib/delay.c +13 -3
@@ -14,6 +14,7 @@#include <linux/sched.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/timeofday.h> #include <asm/processor.h> #include <asm/delay.h> #include <asm/timer.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 +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 -55
66 lines not on this page · raw message
PATCH 6/6 new timeofday i386 specific timesources for -mm (v.B3)
Andrew, All,
This patch implements the time sources for i386 (acpi_pm, cyclone,
hpet, pit, tsc and tsc-interp). The patch should apply on top of the timeofday-arch-i386-part4_B3.patch.
The patch should be fairly straight forward, only adding the new timesources.
Andrew, please consider for inclusion for testing into your tree.
thanks
-john
linux-2.6.12-rc6-mm1_timeofday-timesources-i386_B3.patch
========================================================
drivers/timesource/acpi_pm.c +152 -0
@@ -0,0 +1,152 @@ +/* +* linux/drivers/timesource/acpi_pm.c +* +* This file contains the ACPI PM based time source. +* +* This code was largely moved from the i386 timer_pm.c file +* which was (C) Dominik Brodowski <[email protected]> 2003 +* and contained the following comments: +* +* Driver to use the Power Management Timer (PMTMR) available in some +* southbridges as primary timing source for the Linux kernel. +* +* Based on parts of linux/drivers/acpi/hardware/hwtimer.c, timer_pit.c, +* timer_hpet.c, and on Arjan van de Ven's implementation for 2.4. +* +* This file is licensed under the GPL v2. +*/ + + +#include <linux/timesource.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <asm/io.h> + +/* Number of PMTMR ticks expected during calibration run */ +#define PMTMR_TICKS_PER_SEC 3579545 + +#if (CONFIG_X86 && (!CONFIG_X86_64 )) +#include "mach_timer.h" +#define PMTMR_EXPECTED_RATE ((PMTMR_TICKS_PER_SEC*CALIBRATE_TIME_MSEC)/1000) +#endif + +/* The I/O port the PMTMR resides at. +* The location is detected during setup_arch(), +* in arch/i386/acpi/boot.c */ +extern u32 acpi_pmtmr_ioport; +extern int acpi_pmtmr_buggy; + +#define ACPI_PM_MASK 0xFFFFFF/* limit it to 24 bits */ + + +static inline u32 read_pmtmr (void ) +{ +/* mask the output to 24 bits */ +return inl (acpi_pmtmr_ioport) &ACPI_PM_MASK ; +} + +static cycle_t acpi_pm_read_verified (void ) +{ +u32 v1=0 ,v2=0 ,v3=0 ; +/* It has been reported that because of various broken +* chipsets (ICH4, PIIX4 and PIIX4E) where the ACPI PM time +* source is not latched, so you must read it multiple +* times to insure a safe value is read. +*/ +do { + v1 =read_pmtmr (); + v2 =read_pmtmr (); + v3 =read_pmtmr (); + }while ((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) + || (v3 > v1 && v3 < v2)); + +return (cycle_t )v2; +} + + +static cycle_t acpi_pm_read (void ) +{ +return (cycle_t )read_pmtmr (); +} + +struct timesource_t timesource_acpi_pm = { + .name ="acpi_pm" , + .priority =200 , + .type =TIMESOURCE_FUNCTION , + .read_fnct = acpi_pm_read, + .mask = (cycle_t )ACPI_PM_MASK , + .mult =0 ,/*to be caluclated*/ + .shift =22 , +}; + +#if (CONFIG_X86 && (!CONFIG_X86_64 )) +/* +* Some boards have the PMTMR running way too fast. We check +* the PMTMR rate against PIT channel 2 to catch these cases. +*/ +static int __init verify_pmtmr_rate (void ) +{ +u32 value1, value2; +unsigned long count, delta; + +mach_prepare_counter (); + value1 =read_pmtmr (); +mach_countup (&count); + value2 =read_pmtmr (); + delta = (value2 - value1) &ACPI_PM_MASK ; + +/* Check that the PMTMR delta is within 5% of what we expect */ +if (delta < (PMTMR_EXPECTED_RATE *19 ) /20 || + delta > (PMTMR_EXPECTED_RATE *21 ) /20 ) { +printk (KERN_INFO "PM-Timer running at invalid rate: %lu%% of normal - aborting.\n" ,100UL * delta /PMTMR_EXPECTED_RATE ); +return -1 ; + } + +return 0 ; +} +#else +#define verify_pmtmr_rate () (0) +#endif + +static int __init init_acpi_pm_timesource (void ) +{ +u32 value1, value2; +unsigned int i; + +if (!acpi_pmtmr_ioport) +return -ENODEV ; + + timesource_acpi_pm.mult =timesource_hz2mult (PMTMR_TICKS_PER_SEC , + timesource_acpi_pm.shift); + +/* "verify" this timing source */ + value1 =read_pmtmr (); +for (i =0 ; i <10000 ; i++) { + value2 =read_pmtmr (); +if (value2 == value1) +continue ; +if (value2 > value1) + goto pm_good; +if ((value2 < value1) && ((value2) <0xFFF )) + goto pm_good; +printk (KERN_INFO "PM-Timer had inconsistent results: 0x%#x, 0x%#x - aborting.\n" , value1, value2); +return -EINVAL ; + } +printk (KERN_INFO "PM-Timer had no reasonable result: 0x%#x - aborting.\n" , value1); +return -ENODEV ; + +pm_good: +if (verify_pmtmr_rate () !=0 ) +return -ENODEV ; + +/* check to see if pmtmr is known buggy */ +if (acpi_pmtmr_buggy) { + timesource_acpi_pm.read_fnct = acpi_pm_read_verified; + timesource_acpi_pm.priority =110 ; + } + +register_timesource (×ource_acpi_pm); +return 0 ; +} + +module_init (init_acpi_pm_timesource);
drivers/timesource/cyclone.c +138 -0
138 lines not on this page · raw message
drivers/timesource/hpet.c +59 -0
59 lines not on this page · raw message
drivers/timesource/i386_pit.c +64 -0
64 lines not on this page · raw message
drivers/timesource/Makefile +7 -0
@@ -1 +1,8 @@ obj-y += jiffies.o + +obj-$(CONFIG_X86) += tsc.o +obj-$(CONFIG_X86) += i386_pit.o +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/tsc.c +83 -0
83 lines not on this page · raw message
drivers/timesource/tsc-interp.c +112 -0
112 lines not on this page · raw message
Hi,
Quoted 1 line · john stultz
o Uses nanoseconds as the kernel's base time unit
Maybe I missed it, but was there ever a conclusive discussion about the perfomance impact this has?
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
bye, Roman
Quoted 4 lines · Roman Zippel
Hi,
On Fri, 17 Jun 2005, john stultz wrote:
Quoted 8 lines
Quoted 1 line
o Uses nanoseconds as the kernel's base time unit
Maybe I missed it, but was there ever a conclusive discussion about the perfomance impact this has?
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
Hi all!
I had the impression that for slow and small machines every recent Linux distribution is overkill. Whenever I complained every relied "Harddisks are cheap, memory is cheap, get a new CPU". I do understand your doubts however. For my personal experience with my PPSkit patches, I found out that my ols 386/SX @16MHz failed to receive all serial characters when I timestamped each of them using my new clock routines. However a 486@33MHz would do (it had better serial UART chips, too). I would not thing my code was terribly efficient, because I tried to make it "right" first.
And even the 386 had limited support for 64 bit operations. Since the 486 a 32bit add is specified as using 1 CPU cycle (most likely in the optimal case). So doing one more would not harm that much.
Basically, either the new clock system has to be optional (a maintenance nightmare most likely), or you'll have to require a specific amount of performance for the latest software. If you cannot fulfill the requirements, you'll have to stick with an older release of the software.
Maybe let's try to make it as good (correct and efficient (and understandable) as good as we can.
Regards,
Ulrich
Hi,
Quoted 7 lines · Ulrich Windl
Basically, either the new clock system has to be optional (a maintenance nightmare most likely), or you'll have to require a specific amount of performance for the latest software. If you cannot fulfill the requirements, you'll have to stick with an older release of the software.
Maybe let's try to make it as good (correct and efficient (and understandable) as good as we can.
If nobody can explain to me the perfomance impact of patch, maybe the patch isn't so understandable in first place?
I could also have asked how that code scales up, e.g. how much more work has to be done for a thousand Linux images. (AFAICR this question also came up in the context of tickless systems).
This patch is really damned hard to read as it changes too many things at once. Maybe it does some necessary cleanups, but they are hard see, as they pretty much get lost in all the functional changes.
I'm pretty close to suggest to reject this patch until it clearly separates new functionality from cleanups. If the current system is broken fix it first, if the current system is a mess clean it up first, but don't mix these two steps, unless you want to introduce more broken mess.
bye, Roman
On 20 Jun 2005 at 12:22, Roman Zippel wrote:
[...]
Quoted 5 lines
This patch is really damned hard to read as it changes too many things at once. Maybe it does some necessary cleanups, but they are hard see, as they pretty much get lost in all the functional changes.
I'm pretty close to suggest to reject this patch until it clearly separates new functionality from cleanups. If the current system is broken
Roman,
it seems you don't like the patch for some personal reasons, and now your are trying to find arguments against it. The best method to get the perfomance implications is trying it (the patched kernel).
Quoted 2 lines
fix it first, if the current system is a mess clean it up first, but don't mix these two steps, unless you want to introduce more broken mess.
If you introduce something new (higher resolution clock), you should start with something clean. Just hacking it in the first attempt, anf then making it beautiful in a second attempt is a waste of time IMHO.
Regards,
Ulrich
Hi,
Quoted 2 lines · Ulrich Windl
it seems you don't like the patch for some personal reasons, and now your are trying to find arguments against it.
Please stop trying such mind reading tricks.
Quoted 6 lines
Quoted 2 lines
fix it first, if the current system is a mess clean it up first, but don't mix these two steps, unless you want to introduce more broken mess.
If you introduce something new (higher resolution clock), you should start with something clean. Just hacking it in the first attempt, anf then making it beautiful in a second attempt is a waste of time IMHO.
Well, I'm not really convinced of the quality of the patch, if nobody can explain it to me and I don't think my questions were that unreasonable. We are talking about a core subsystem here, which IMO justifies a little more care. Maybe you should follow the fs development a bit for an example how to do even large changes in relatively simple steps.
bye, Roman
Quoted 3 lines · Ulrich Windl
it seems you don't like the patch for some personal reasons, and now your are trying to find arguments against it. The best method to get the perfomance implications is trying it (the patched kernel).
Roman is just asking for explanations. The patches approach might be really great but if no one understands it that doesn't help. And it's a very sensitive part of the kernel so it needs to be understood very well.
Quoted 10 lines · Roman Zippel
Quoted 1 line · john stultz
o Uses nanoseconds as the kernel's base time unit
Maybe I missed it, but was there ever a conclusive discussion about the perfomance impact this has?
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
Hey Roman,
That's a good issue to bring up. With regards to the timeofday
infrastructure, there are two performance concerns (though let me know if I'm forgetting something):
1. timer interrupt processing overhead
2. gettimeofday() syscall performance
On smaller systems, timer interrupt processing is a concern, with the shift to HZ=1000, we got a number of complaints from folks w/ old 486s where time would drift due lost ticks. This would happen when something (usually IDE in PIO mode) would disable interrupts and they would miss a ton of timer interrupts. Also the impact of running the timekeeping code 10x more frequently was seen in a number of cases.
With the new infrastructure, timekeeping is all done via a soft-timer outside of interrupt context. In fact, the timekeeping soft-timer is setup to run every 50ms instead of every ms. This should help overall performance on slower systems using high HZ values.
As for gettimefoday() syscall performance, I one had some numbers, but I would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers. The gettimeofday() path is fairly streamlined and should be pretty straight forward in the patch (see kernel/timeofday.c), so let me know if you have specific concerns.
There will probably be a bit of a drop, but I have some ideas for cacheing a precomputed timeval in the timekeeping soft-timer if its a serious issue.
thanks
-john
Quoted 4 lines · john stultz
As for
gettimefoday()syscall performance, I one had some numbers, but I
would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers.
I ran some tests lately that showed gettimeofday() to be 50x slower than rdtsc() on my 600Mhz machine. Many userspace apps that need a cheap high res timer have to use rdtsc now due to the excessive overhead of gettimeofday(). It would be more correct if these apps could use gettimeofday() for various reasons (cpufreq and SMP issues).
So this patch is addressing a real problem. I'd be interested to see if the performance is good enough to replace rdtsc in these cases.
Lee
Quoted 11 lines · Lee Revell
Quoted 4 lines · john stultz
As for
gettimefoday()syscall performance, I one had some numbers, but I
would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers.I ran some tests lately that showed
gettimeofday()to be 50x slower thanrdtsc()on my 600Mhz machine. Many userspace apps that need a cheap high res timer have to use rdtsc now due to the excessive overhead ofgettimeofday(). It would be more correct if these apps could usegettimeofday()for various reasons (cpufreq and SMP issues).
Yea, I would strongly dissuade anyone from using the rdtsc counter for anything but statistical analysis of code performance.
Quoted 2 lines
So this patch is addressing a real problem. I'd be interested to see if the performance is good enough to replace rdtsc in these cases.
Yea, honestly I doubt gettimefoday performance will ever be as good as rdtsc. I mean, that's a single instruction vs syscall overhead + hardware clock reading + frequency conversion + ntp adjustment. Its just not a fair comparison.
On the other hand, I bet reading a random 64 bits out of memory is also a bit faster then gettimeofday() as well ;)
I don't mean to promise the world. The point of the patch is not to improve gettimeofday performance, it is to improve the subsystem so it is correct and manageable, so that we have the flexibility to make future improvements (such as High-res Timers, Dynamic Ticks/Variable system timer, and virtualization needs) without impacting performance.
The best payout for gettimeofday performance will probably be in vsyscall implementations such as what x86-64 already has. My new infrastructure also supports this (it had to for x86-64), and I've even got a proof of concept patch for i386 (see the lkml archives for details).
thanks
-john
Quoted 4 lines · john stultz
Yea, honestly I doubt gettimefoday performance will ever be as good as rdtsc. I mean, that's a single instruction vs syscall overhead + hardware clock reading + frequency conversion + ntp adjustment. Its just not a fair comparison.
Of course not, the patch would have to be magic for that to happen.
But some user space apps are now *required* to use rdtsc for timing due to the massive performance difference. If we only took a 5x or 10x performance hit vs rdtsc, rather than the current 50x, it might be enough that user space apps won't have to do this.
Lee
Quoted 4 lines · Lee Revell
But some user space apps are now *required* to use rdtsc for timing due to the massive performance difference. If we only took a 5x or 10x performance hit vs rdtsc, rather than the current 50x, it might be enough that user space apps won't have to do this.
For my userspace apps I've actually switched to clock_gettime(CLOCK_MONOTONIC, &ts);
This at least guarantees that it will never go backwards.
For the experts: Is there a clock exported to userspace that is both monotonic and uniform? Does CLOCK_MONOTONIC give this on linux?
Chris
Quoted 7 lines · Chris Friesen
Quoted 4 lines · Lee Revell
But some user space apps are now *required* to use rdtsc for timing due to the massive performance difference. If we only took a 5x or 10x performance hit vs rdtsc, rather than the current 50x, it might be enough that user space apps won't have to do this.
Quoted 7 lines
For my userspace apps I've actually switched to
clock_gettime(CLOCK_MONOTONIC, &ts);This at least guarantees that it will never go backwards.
For the experts: Is there a clock exported to userspace that is both monotonic and uniform? Does
CLOCK_MONOTONICgive this on linux?
clock_gettime(CLOCK_MONOTONIC) should be what you're looking for. Since that still uses do_gettimeofday internally, it is still possible in some conditions for the current code to have time inconsistencies caused by interpolation error. This is one of the major reasons for my work.
thanks
-john
Quoted 8 lines · Lee Revell
Quoted 4 lines · john stultz
As for
gettimefoday()syscall performance, I one had some numbers, but I
would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers.I ran some tests lately that showed
gettimeofday()to be 50x slower thanrdtsc()on my 600Mhz machine. Many userspace apps that need a cheap
Hello!
Isn't that a kind of absurd comparison: rdtsc is one or two instructions, while gettimeofday is a complete syscall with some many instructions: rdtsc will never give you the time of day besides of that. Are you voting for replacing gettimeofday with rdtsc?
Quoted 2 lines
high res timer have to use rdtsc now due to the excessive overhead of
gettimeofday(). It would be more correct if these apps could use
You can either have it accurate, or you can have it fast. Also gettimeofday works on any UNIX platform, rdtsc does not.
Quoted 1 line
gettimeofday()for various reasons (cpufreq and SMP issues).
Good point, but you don't get that higher reliability and accuracy for free.
Quoted 3 lines
So this patch is addressing a real problem. I'd be interested to see if the performance is good enough to replace rdtsc in these cases.
In which applications (Java excepted maybe) do you really need to call gettimeofday more than a few thousand times per second? Most likely you are working around a different issue then.
Regards,
Ulrich
Hi,
Quoted 10 lines · john stultz
Quoted 4 lines
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
Hey Roman,
That's a good issue to bring up. With regards to the timeofday
infrastructure, there are two performance concerns (though let me know if I'm forgetting something):
You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Quoted 11 lines
On smaller systems, timer interrupt processing is a concern, with the shift to HZ=1000, we got a number of complaints from folks w/ old 486s where time would drift due lost ticks. This would happen when something (usually IDE in PIO mode) would disable interrupts and they would miss a ton of timer interrupts. Also the impact of running the timekeeping code 10x more frequently was seen in a number of cases.
With the new infrastructure, timekeeping is all done via a soft-timer outside of interrupt context. In fact, the timekeeping soft-timer is setup to run every 50ms instead of every ms. This should help overall performance on slower systems using high HZ values.
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value. So now I still like to know how does the complexity change compared to the old code?
Quoted 9 lines
As for
gettimefoday()syscall performance, I one had some numbers, but I would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers. Thegettimeofday()path is fairly streamlined and should be pretty straight forward in the patch (seekernel/timeofday.c), so let me know if you have specific concerns.There will probably be a bit of a drop, but I have some ideas for cacheing a precomputed timeval in the timekeeping soft-timer if its a serious issue.
Well, AFAICT on slower machines (older and embedded stuff) it's a serious issue. The current code calculates the timeval with some simple 32bit calculations. Your code introduces the nsec step, which means several 64bit calculations and suddenly the overhead explodes on some machines.
As m68k maintainer I see no reason to ever switch to your new code, which might leave you with the dilemma having to maintain two versions of the timer code. What reason could I have to switch to the new timer code?
I had no problems with a little more overhead, like a _few_ more 64bit operations per second (and preferably add/shifts), but I'm not really enthusiastic about the new code. Why don't you keep the main part 32 bits (or long)? What's wrong with using timeval or timespec?
I like the concept of the a time source in your patch. m68k already uses a number of timer related callbacks into machine specific code. If I could replace that with a timer driver, I'd be really happy. OTOH if it requires several expensive conversion between different time formats, I rather keep the current code.
bye, Roman
Quoted 3 lines · Roman Zippel
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value.
That does not solve anything, going back to HZ=100 is a big user-visible regression because the resolution of sleep() (and poll, etc) is now 10ms rather than 1ms. Many apps have RT constraints between 1ms and 10ms.
Lee
Quoted 10 lines · Roman Zippel
Hi,
Quoted 6 lines · john stultz
Quoted 4 lines
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
Quoted 7 lines
Quoted 4 lines
Hey Roman,
That's a good issue to bring up. With regards to the timeofday
infrastructure, there are two performance concerns (though let me know if I'm forgetting something):You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Well, for a reasonable range of timesource frequencies and interval lengths, the cycle values needs to be 64 bits wide and the mult/shift operation to convert cycles to time is going to need to done with 64 bits.
Since xtime is currently a timespec, we already keep nanosecond precision using 64 bits. It was then just a question of how complicated is it to do the manipulations with timespecs vs flat 64 bits worth of nanoseconds. Nanoseconds made the design cleaner, so I went with them keeping the option to optimize in the future when real issues arose.
Quoted 12 lines
Quoted 11 lines
On smaller systems, timer interrupt processing is a concern, with the shift to HZ=1000, we got a number of complaints from folks w/ old 486s where time would drift due lost ticks. This would happen when something (usually IDE in PIO mode) would disable interrupts and they would miss a ton of timer interrupts. Also the impact of running the timekeeping code 10x more frequently was seen in a number of cases.
With the new infrastructure, timekeeping is all done via a soft-timer outside of interrupt context. In fact, the timekeeping soft-timer is setup to run every 50ms instead of every ms. This should help overall performance on slower systems using high HZ values.
Quoted 4 lines
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value. So now I still like to know how does the complexity change compared to the old code?
Well, even if it is less of a concern with lower HZ values, my code should still reduce the interrupt overhead for those who would like to have higher HZ values to improve latency. (Although until I have numbers, its all just talk. :)
Quoted 15 lines
Quoted 9 lines
As for
gettimefoday()syscall performance, I one had some numbers, but I would need to re-create them. I'll see if I can grab a slower box and give you some hard numbers. Thegettimeofday()path is fairly streamlined and should be pretty straight forward in the patch (seekernel/timeofday.c), so let me know if you have specific concerns.There will probably be a bit of a drop, but I have some ideas for cacheing a precomputed timeval in the timekeeping soft-timer if its a serious issue.
Well, AFAICT on slower machines (older and embedded stuff) it's a serious issue. The current code calculates the timeval with some simple 32bit calculations. Your code introduces the nsec step, which means several 64bit calculations and suddenly the overhead explodes on some machines.
Quoted 8 lines
As m68k maintainer I see no reason to ever switch to your new code, which might leave you with the dilemma having to maintain two versions of the timer code. What reason could I have to switch to the new timer code?
I had no problems with a little more overhead, like a _few_ more 64bit operations per second (and preferably add/shifts), but I'm not really enthusiastic about the new code. Why don't you keep the main part 32 bits (or long)? What's wrong with using timeval or timespec?
Well, I think the only overhead to be worried with is just in gettimeofday(), but let me get some hard numbers to show that. I've already implemented some optimized caching for x86-64's vsyscall-gtod implementation, so let me also try to make an arch generic version and see if I cannot settle your concerns.
Quoted 5 lines
I like the concept of the a time source in your patch. m68k already uses a number of timer related callbacks into machine specific code. If I could replace that with a timer driver, I'd be really happy. OTOH if it requires several expensive conversion between different time formats, I rather keep the current code.
Thanks, I really appreciate your review and feedback. I very much want this to be a solution everyone can be happy (or at least indifferent) with.
thanks
-john
Hi,
Quoted 9 lines · john stultz
Quoted 2 lines
You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Well, for a reasonable range of timesource frequencies and interval lengths, the cycle values needs to be 64 bits wide and the mult/shift operation to convert cycles to time is going to need to done with 64 bits.
Quoted 5 lines
Since xtime is currently a timespec, we already keep nanosecond precision using 64 bits. It was then just a question of how complicated is it to do the manipulations with timespecs vs flat 64 bits worth of nanoseconds. Nanoseconds made the design cleaner, so I went with them keeping the option to optimize in the future when real issues arose.
That might be the case, but your patch makes it very hard to verify. You don't fix the old code, you just drop in a complete new implementation, so you have to explain it a bit more. What's exactly wrong with old design and why wasn't possible to fix it incrementally? How exactly is your new design superior?
Quoted 9 lines
Quoted 4 lines
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value. So now I still like to know how does the complexity change compared to the old code?
Well, even if it is less of a concern with lower HZ values, my code should still reduce the interrupt overhead for those who would like to have higher HZ values to improve latency. (Although until I have numbers, its all just talk. :)
For machines where it actually matters, I can only see that calculations have gotten more complex and thus slower. You need to provide a little more detailed information, why this necessary.
Quoted 5 lines
Well, I think the only overhead to be worried with is just in
gettimeofday(), but let me get some hard numbers to show that. I've already implemented some optimized caching for x86-64's vsyscall-gtod implementation, so let me also try to make an arch generic version and see if I cannot settle your concerns.
I don't need any practical numbers, I can already see from the code, that it's much worse and unless you eliminate the 64bit calculations from the fast path, I don't know what you are trying to optimize.
Quoted 9 lines
Quoted 5 lines
I like the concept of the a time source in your patch. m68k already uses a number of timer related callbacks into machine specific code. If I could replace that with a timer driver, I'd be really happy. OTOH if it requires several expensive conversion between different time formats, I rather keep the current code.
Thanks, I really appreciate your review and feedback. I very much want this to be a solution everyone can be happy (or at least indifferent) with.
I would seriously suggest you rework the first patch and fix the existing code instead or you have to explain why the current code is unfixable, but that would require to actually replace the old code. Having two alternative implementations is really the worst solution.
John, you are _very_ vague here, could you please go into more detail, why you did certain design decisions? "Simplicity" can't be the only reason, good perfomance is far more important.
bye, Roman
Quoted 19 lines · Roman Zippel
Hi,
Quoted 9 lines · john stultz
Quoted 2 lines
You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Well, for a reasonable range of timesource frequencies and interval lengths, the cycle values needs to be 64 bits wide and the mult/shift operation to convert cycles to time is going to need to done with 64 bits.
Quoted 5 lines
Since xtime is currently a timespec, we already keep nanosecond precision using 64 bits. It was then just a question of how complicated is it to do the manipulations with timespecs vs flat 64 bits worth of nanoseconds. Nanoseconds made the design cleaner, so I went with them keeping the option to optimize in the future when real issues arose.
Quoted 5 lines
That might be the case, but your patch makes it very hard to verify. You don't fix the old code, you just drop in a complete new implementation, so you have to explain it a bit more. What's exactly wrong with old design and why wasn't possible to fix it incrementally? How exactly is your new design superior?
That's a fair criticism. Early in the design phase I spent a lot more time explaining the reasons for doing this, but more recently I've been focused on the code issues and haven't maintained that documentation. Since I'm doing an OLS talk on this work, I need to refresh the documents anyway, so I'll include that with my next submission.
Briefly the big issues are:
Correctness: The current timekeeping code is tick based with interpolation for high res granularity. There are many causes of interpolation error which can cause either time inconsistencies or NTP skew:
o tick/timesource calibration errors
o NTP adjustments are not done consistently, only at interrupt time
o Delayed, or lost ticks caused by interrupt starvation, drivers disabling interrupts for too long, BIOS SMIs
o Fixes like lost tick compensation break virtualized systems
Flexibility: The various tick-less system (Dynamic ticks, NO_IDLE_HZ, VST) projects are continually needed to add hacks to avoid breaking the time subsystem. George's HRT patches needed to rework a good chunk of the timeofday subsystem as well. When HZ was changed time was affected, when interrupt routing changes time is affected. It just goes on and on. Having a timeofday subsystem that is somewhat isolated and doesn't break when someone sneezes near it will help allow for other improvements.
Maintainability: Most arches do basically the same thing for their timeofday code, time bugs are frequently only fixed in a few arches, leaving other arches prone to the problems. Also the collection of global variables used to keep time and ntp adjustments are getting unmanageable and are not well understood by everyone resulting in bugs when folks access them directly. There is a need for some opaqueness to those variables. Additionally, The number of timesources is increasing as is the number of different architectures that share them. Some cross- architecture method for sharing timesources is needed.
The biggest improvement with my rework is for correctness. Timekeeping is no longer tick based, so there is no interpolation (or interpolation error) in the core algorithm. Delayed, or lost timer interrupt do not affect timekeeping with my code. This also allows tick-less system projects or any other projects that deal with timers to not worry about affecting time with their changes. It also makes NTP adjustments smoothly across intervals to avoid time inconsistencies.
My rework also provides an arch generic timeofday framework, which manages arch specific timesource drivers. Using the existing interfaces as well as a few new functions, it provides full coverage for the existing users of the timeofday code, keeping the internal timekeeping variables opaque.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value. So now I still like to know how does the complexity change compared to the old code?
Quoted 8 lines
Quoted 4 lines
Well, even if it is less of a concern with lower HZ values, my code should still reduce the interrupt overhead for those who would like to have higher HZ values to improve latency. (Although until I have numbers, its all just talk. :)
For machines where it actually matters, I can only see that calculations have gotten more complex and thus slower. You need to provide a little more detailed information, why this necessary.
Indeed, the periodic timekeeping function is likely more computationally costly (although I don't have hard numbers on that yet, I will soon), however we run it less frequently (50x actually) and we do it outside of the interrupt context. I do not believe the periodic timekeeping path is going to be a performance concern.
Quoted 9 lines
Quoted 5 lines
Well, I think the only overhead to be worried with is just in
gettimeofday(), but let me get some hard numbers to show that. I've already implemented some optimized caching for x86-64's vsyscall-gtod implementation, so let me also try to make an arch generic version and see if I cannot settle your concerns.I don't need any practical numbers, I can already see from the code, that it's much worse and unless you eliminate the 64bit calculations from the fast path, I don't know what you are trying to optimize.
That's exactly what I'm trying to optimize. By precalculating some of the 64 bit manipulations, we can remove them from the fast path.
Ok, from my initial tests on my i686 laptop (@600Mhz), using the cheapest timesource available (the TSC), the unoptimized B3 version of the code I sent out shows a 17% performance hit in gettimeofday(). That ratio will be even smaller if you use a more expensive timesource. So starting there, let me see how much I can shave off.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I like the concept of the a time source in your patch. m68k already uses a number of timer related callbacks into machine specific code. If I could replace that with a timer driver, I'd be really happy. OTOH if it requires several expensive conversion between different time formats, I rather keep the current code.
Quoted 7 lines
Quoted 3 lines
Thanks, I really appreciate your review and feedback. I very much want this to be a solution everyone can be happy (or at least indifferent) with.
I would seriously suggest you rework the first patch and fix the existing code instead or you have to explain why the current code is unfixable, but that would require to actually replace the old code.
Forgive me for not communicating this well enough, I guess I've been just a bit too stuck in the code to realize others aren't seeing the problems I am.
It is my feeling that the current interpolated based timekeeping is not easily fixable. In order to move to a non-interpolated method of timekeeping, first each architecture has to provide some timesource like interface that will give us a free running counter. So we provide some form of timesource interface, and some form of generic timeofday code and since all the arches won't switch on the same day we'll have to stage it and then we're almost to where I am today.
The only other option I see is to let each arch sort it out for itself, some using interpolation, and some not, maybe using a method similar to what PPC64 does. Then we still have the duplicated effort having to work on each arch and the unique bugs in each. Future changes like the tick- less projects will have to conditionally work based on which arch has which method.
Quoted 2 lines
Having two
alternative implementations is really the worst solution.
It is not my intention to have two alternative implementations. I am just trying to stage the transition so every arch doesn't have to move all at once.
Quoted 3 lines
John, you are _very_ vague here, could you please go into more detail, why you did certain design decisions? "Simplicity" can't be the only reason, good perfomance is far more important.
Performance is more important then simplicity, however correctness and flexibility are necessary as well. Hopefully the discussion above will answer some of your questions. I'll try to make a more thorough writeup and include it with my next submission.
I really appreciate the feedback and questions.
thanks
-john
Quoted 4 lines · john stultz
Quoted 3 lines
I don't need any practical numbers, I can already see from the code, that it's much worse and unless you eliminate the 64bit calculations from the fast path, I don't know what you are trying to optimize.
Quoted 8 lines
That's exactly what I'm trying to optimize. By precalculating some of the 64 bit manipulations, we can remove them from the fast path.
Ok, from my initial tests on my i686 laptop (@600Mhz), using the cheapest timesource available (the TSC), the unoptimized B3 version of the code I sent out shows a 17% performance hit in
gettimeofday(). That ratio will be even smaller if you use a more expensive timesource. So starting there, let me see how much I can shave off.
Just a quick update: With a bit of quick optimizing the current design, removing most of the 64bit math from the gettimeofday fast path, I've managed to cut it down to within 2% of the current code using the c3tsc vs tsc. The c3tsc timesource adds a bit of overhead that the mainline code doesn't do, so I'm going to see how a more comparable TSC vs TSC test goes.
thanks
-john
Hi,
Quoted 1 line · john stultz
Briefly the big issues are:
That's interesting, but it mainly describes your design goals, but I'm more interested why you did certain design decisions.
The main problem is that you try to fix all these issues with a single patch and I'd like to know why you don't pick a single issue and fix it first.
Quoted 2 lines
o Delayed, or lost ticks caused by interrupt starvation, drivers disabling interrupts for too long, BIOS SMIs
These are actually different error sources. Ticks lost due to disabled interrupt can't be detected unless you have a second timer source and the generic code doesn't really know about this. If an arch has a second time source this is fixable, but I would consider this optional, that means adjustments are only done, iff this source is available.
The current concept of lost ticks simply means delayed soft interrupt handling. IMO this could be a good starting point to fix the timer code, by making it possible to call update_wall_time() with a reduced frequency. If you move in a _later_ step from ticks to 32bit nanoseconds, that would give you still a 4 second window, which should be more than enough, so e.g. I don't see any reason to use any 64bit math here.
Quoted 3 lines
The biggest improvement with my rework is for correctness. Timekeeping is no longer tick based, so there is no interpolation (or interpolation error) in the core algorithm.
AFAICS the interpolation is needed because some arch use different time sources for the scheduler and timeofday, but I don't see why fixing the timer code immediately requires a generic timer source infrastructure. You have to be more explicit why it's not possible to fix the generic timer code first.
Quoted 9 lines
Quoted 3 lines
For machines where it actually matters, I can only see that calculations have gotten more complex and thus slower. You need to provide a little more detailed information, why this necessary.
Indeed, the periodic timekeeping function is likely more computationally costly (although I don't have hard numbers on that yet, I will soon), however we run it less frequently (50x actually) and we do it outside of the interrupt context. I do not believe the periodic timekeeping path is going to be a performance concern.
Please give me _some_ concrete information, why this code has to be more complex than the current code.
Quoted 6 lines
Quoted 3 lines
I don't need any practical numbers, I can already see from the code, that it's much worse and unless you eliminate the 64bit calculations from the fast path, I don't know what you are trying to optimize.
That's exactly what I'm trying to optimize. By precalculating some of the 64 bit manipulations, we can remove them from the fast path.
I want to remove all that, why do you need 64bit calculations in there? What's wrong with a base xtime + 32bit nanosecond offset?
Quoted 5 lines
Ok, from my initial tests on my i686 laptop (@600Mhz), using the cheapest timesource available (the TSC), the unoptimized B3 version of the code I sent out shows a 17% performance hit in
gettimeofday(). That ratio will be even smaller if you use a more expensive timesource. So starting there, let me see how much I can shave off.
That's hardly a fair comparison, you cannot use an expensive timesource to make your time code look cheap.
Quoted 4 lines
It is my feeling that the current interpolated based timekeeping is not easily fixable. In order to move to a non-interpolated method of timekeeping, first each architecture has to provide some timesource like interface that will give us a free running counter.
Why is not possible to fix the generic time code first, so you can later drop the interpolation and use time sources instead?
For all archs where timeofday and tick has the same source you can easily upgrade to the new code, only the rest needs to do a bit more to update xtime from a different source. This way you break much less code and give arch maintainers much less headache.
If you think this is not possible, please give me some more concrete information.
bye, Roman
Quoted 9 lines · Roman Zippel
Quoted 1 line · john stultz
Briefly the big issues are:
That's interesting, but it mainly describes your design goals, but I'm more interested why you did certain design decisions.
The main problem is that you try to fix all these issues with a single patch and I'd like to know why you don't pick a single issue and fix it first.
I've actually spent quite a bit of time working to fix these single issues, and that is why I'm proposing this. The best example is the lost tick compensation. There I have added code in the i386 arch that attempts to notice when a tick has been lost (two or more ticks worth of time passed without an interrupt) and add in the appropriate number of jiffies. This helped for systems that were losing ticks due to BIOS SMIs or interrupt starvation. However that broke some VM systems because they effectively disable interrupts for a period of time, and then re-play interrupts to try to catch up. The first interrupt would trigger the lost tick detection code bringing us up to the current time, then the following catch-up interrupts would advance time again, causing the system to go too far forward.
Some other architectures try to handle these situations as well. One good example is PPC64 (which has greatly influenced my design). For correctness PPC64 goes as far as not using interpolation by avoiding almost all of the arch generic time code. It even has its own NTP adjustment code!
I have come to believe the current arch generic tick based timekeeping is not sustainable. It seems to me in order to avoid bugs that customers are seeing, arches are going to have to avoid the current tick based arch generic code and implement their own non-interpolated based timekeeping code. So that is why I've created this proposal and implementation instead of just "fixing one issue".
So the question becomes: in order to achieve correctness, should every architecture implement a full timeofday subsystem of its own? I designed a system that would work, but instead of making it i386 and copying it for x86-64 and whatever else I end up working on, I propose we make it a common implementation.
Now, my proposal might not currently satisfy everyone's needs for flexibility and performance in the timekeeping subsystem. But I'd like to try, and letting me know your issues (such as the use of 64bit math) helps me work to resolve them, so I really appreciate your feedback. I really do want this to be something that every arch can use.
Although I hope it doesn't, but if it comes down to there being no reasonable way for every arch to share the my proposed common infrastructure, them maybe I need to add some code so those arches can opt out and maintain their own timekeeping code. Does that sound reasonable?
Quoted 19 lines
Quoted 2 lines
o Delayed, or lost ticks caused by interrupt starvation, drivers disabling interrupts for too long, BIOS SMIs
These are actually different error sources. Ticks lost due to disabled interrupt can't be detected unless you have a second timer source and the generic code doesn't really know about this. If an arch has a second time source this is fixable, but I would consider this optional, that means adjustments are only done, iff this source is available.
The current concept of lost ticks simply means delayed soft interrupt handling. IMO this could be a good starting point to fix the timer code, by making it possible to callupdate_wall_time()with a reduced frequency. If you move in a _later_ step from ticks to 32bit nanoseconds, that would give you still a 4 second window, which should be more than enough, so e.g. I don't see any reason to use any 64bit math here.Quoted 3 lines
The biggest improvement with my rework is for correctness. Timekeeping is no longer tick based, so there is no interpolation (or interpolation error) in the core algorithm.
Quoted 5 lines
AFAICS the interpolation is needed because some arch use different time sources for the scheduler and timeofday, but I don't see why fixing the timer code immediately requires a generic timer source infrastructure. You have to be more explicit why it's not possible to fix the generic timer code first.
No, I don't believe high res time interpolation does not have anything to do with the scheduler. It is used by gettimeofday() to give better then tick-granular time resolution. In fact, the current generic timekeeping code doesn't even acknowledge interpolation goes on. It just believes time is incremented in tick units. Every tick, xtime gets incremented one ticks worth of time.
So if we were going to fix that, we would have to change the code so that every tick the amount of time that has passed since the last tick was added to xtime. In order for this to occur, we need some arch specific accessor to find out how much time actually passed. This is very similar what the timesource drivers provide. And once you have that it is almost the same as my new code.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
For machines where it actually matters, I can only see that calculations have gotten more complex and thus slower. You need to provide a little more detailed information, why this necessary.
Quoted 8 lines
Quoted 5 lines
Indeed, the periodic timekeeping function is likely more computationally costly (although I don't have hard numbers on that yet, I will soon), however we run it less frequently (50x actually) and we do it outside of the interrupt context. I do not believe the periodic timekeeping path is going to be a performance concern.
Please give me _some_ concrete information, why this code has to be more complex than the current code.
Honestly it isn't that much more complex. It is however consistent. We increment the timekeeping variables in the exact same way we generate gettimeofday(). This is what avoids time inconsistencies. Additionally, NTP adjustments are integrated into how we calculate gettimeofday() so there is not inconsistencies caused by only applying NTP correction at the tick.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I don't need any practical numbers, I can already see from the code, that it's much worse and unless you eliminate the 64bit calculations from the fast path, I don't know what you are trying to optimize.
That's exactly what I'm trying to optimize. By precalculating some of the 64 bit manipulations, we can remove them from the fast path.
I want to remove all that, why do you need 64bit calculations in there? What's wrong with a base xtime + 32bit nanosecond offset?
I'm actually doing almost just that! I've cut the cycle_t down to an unsigned long, and while nanoseconds are still 64bits (in order to have a precise cyc2ns conversion), we only use 32bits of them for the most part.
Quoted 8 lines
Quoted 5 lines
Ok, from my initial tests on my i686 laptop (@600Mhz), using the cheapest timesource available (the TSC), the unoptimized B3 version of the code I sent out shows a 17% performance hit in
gettimeofday(). That ratio will be even smaller if you use a more expensive timesource. So starting there, let me see how much I can shave off.That's hardly a fair comparison, you cannot use an expensive timesource to make your time code look cheap.
That was not my intent. The numbers I'm using are using the fastest timesource available (the TSC). I'm just saying that the 17% performance impact was as bad as it gets. And currently I'm down to just 2% using the same timesource with some of the optimizations I mentioned above.
Quoted 7 lines
Quoted 4 lines
It is my feeling that the current interpolated based timekeeping is not easily fixable. In order to move to a non-interpolated method of timekeeping, first each architecture has to provide some timesource like interface that will give us a free running counter.
Why is not possible to fix the generic time code first, so you can later drop the interpolation and use time sources instead?
It is my opinion that dropping interpolation is what is needed in order to fix the generic timekeeping code.
Quoted 6 lines
For all archs where timeofday and tick has the same source you can easily upgrade to the new code, only the rest needs to do a bit more to update xtime from a different source. This way you break much less code and give arch maintainers much less headache.
If you think this is not possible, please give me some more concrete information.
I'm not sure I exactly follow what you're proposing. It may be possible that there is a way to implement my design in a more piecemeal fashion, and I would very much welcome specific suggestions on how to do so. So please do explain in a bit more detail.
Once again, thanks again for your feedback. Its not my intention for giving arch maintainers a headache (it is my hope that the new subsystem will lessen the impact of future changes on arch specific code).
thanks
-john
Hi,
Quoted 6 lines · john stultz
Some other architectures try to handle these situations as well. One good example is PPC64 (which has greatly influenced my design). For correctness PPC64 goes as far as not using interpolation by avoiding almost all of the arch generic time code. It even has its own NTP adjustment code!
Quoted 6 lines
I have come to believe the current arch generic tick based timekeeping is not sustainable. It seems to me in order to avoid bugs that customers are seeing, arches are going to have to avoid the current tick based arch generic code and implement their own non-interpolated based timekeeping code. So that is why I've created this proposal and implementation instead of just "fixing one issue".
I agree with you that the current time code is a problem for machines like ppc64, which basically use two different time sources.
We basically have two timer architectures: timer tick and continuous timer. The latter currently has to emulate the timer tick. Your patch completely reverses the rolls and forces everybody to produce a continuous timer, which I think is equally bad, as some simple computations become a lot more complex. Why should it not be possible to support both equally?
Quoted 5 lines
So the question becomes: in order to achieve correctness, should every architecture implement a full timeofday subsystem of its own? I designed a system that would work, but instead of making it i386 and copying it for x86-64 and whatever else I end up working on, I propose we make it a common implementation.
That might result in the worst of both worlds. If I look at the ppc64 implementation of gettimeofday, it's really nice and your (current) code would make this worse again. So why not leave it to the timer source, if it wants to manage a cycle counter or a xtime+offset? The common code can provide some helper functions to manage either of this. Converting everything to nanoseconds looks like a really bad compromise.
In the ppc64 example the main problem is that the generic tries to adjust for the wrong for the time source - the scheduler tick, which is derived from the cycle counter, so it has to redo all the work. Your code now introduces an abstract concept of nanosecond which adds extra overhead to either timer concept. Why not integrating what ppc64 does into the current timer code instead of replacing the current code with something else?
For tick based timer sources there is not much to do than incrementing xtime by precomputed constant. If I take ppc64 as an example for continuous time sources it does a lot less than your timeofday_periodic_hook(). Why is all this needed?
John, what I'd really like to see here is some math or code examples, which demonstrate how your new code is better compared to the old code. Your code makes a _huge_ transformation jump and I'd like you to explain some of the steps inbetween.
bye, Roman
Quoted 17 lines · Roman Zippel
Hi,
Quoted 6 lines · john stultz
Some other architectures try to handle these situations as well. One good example is PPC64 (which has greatly influenced my design). For correctness PPC64 goes as far as not using interpolation by avoiding almost all of the arch generic time code. It even has its own NTP adjustment code!
Quoted 6 lines
I have come to believe the current arch generic tick based timekeeping is not sustainable. It seems to me in order to avoid bugs that customers are seeing, arches are going to have to avoid the current tick based arch generic code and implement their own non-interpolated based timekeeping code. So that is why I've created this proposal and implementation instead of just "fixing one issue".
Quoted 8 lines
I agree with you that the current time code is a problem for machines like ppc64, which basically use two different time sources.
We basically have two timer architectures: timer tick and continuous timer. The latter currently has to emulate the timer tick. Your patch completely reverses the rolls and forces everybody to produce a continuous timer, which I think is equally bad, as some simple computations become a lot more complex. Why should it not be possible to support both equally?
Yep, I think this is really the core contention.
In my design I've reworked the time subsystem to assume time flows continuously as provided by the timesource. On systems that do not have a continuous counters like the PPC timebase, they can use a similar tick based interpolation method to provide continuous time. However this interpolation is done in the timesource driver instead of in the generic code.
I do feel my design is more flexible then the current tick based code as it can accommodate both methods equally and correctly. However your complaint is that it is more computationally expensive for the tick based systems, and that is a fair criticism.
So what I'm working on now is to get some more detailed numbers and analysis of the code paths so we can be more specific in our discussion. Hopefully this will help narrow the concern so I can properly address it.
Quoted 9 lines
Quoted 5 lines
So the question becomes: in order to achieve correctness, should every architecture implement a full timeofday subsystem of its own? I designed a system that would work, but instead of making it i386 and copying it for x86-64 and whatever else I end up working on, I propose we make it a common implementation.
That might result in the worst of both worlds. If I look at the ppc64 implementation of gettimeofday, it's really nice and your (current) code would make this worse again.
Could you be more specific about how you feel the ppc64 is nice and how my code is worse? My code is actually quite influenced by the ppc64 code, so specific details might help me respond.
Quoted 11 lines
So why not leave it to the timer source, if
it wants to manage a cycle counter or a xtime+offset? The common code can provide some helper functions to manage either of this. Converting everything to nanoseconds looks like a really bad compromise.In the ppc64 example the main problem is that the generic tries to adjust for the wrong for the time source - the scheduler tick, which is derived from the cycle counter, so it has to redo all the work. Your code now introduces an abstract concept of nanosecond which adds extra overhead to either timer concept. Why not integrating what ppc64 does into the current timer code instead of replacing the current code with something else?
I'm not sure I followed that paragraph. Would you clarify a bit?
Also I'd not consider the concept of a nanosecond to be abstract at all. :) In fact one of the reasons I worked around nanoseconds is because it is very clear and understandable as to what it means. Now,I agree that performance should override clarity, but clarity should be a goal. A complaint I've dealt with is that the current time subsystem is too fragile and confusing, so some cleanups are in order.
That said, I also agree that if possible cleanups and functional changes should be separated. I'm looking to see how this might be possible.
Quoted 4 lines
For tick based timer sources there is not much to do than incrementing xtime by precomputed constant. If I take ppc64 as an example for continuous time sources it does a lot less than your
timeofday_periodic_hook(). Why is all this needed?
timeofday_periodic_hook() does the following every 50ms:
o read the timesource, save it as now
o calculate the amount of NTP adjusted time that has past
o calculate the amount of raw time that has past
o Increment the system_time by the calculated NTP adjusted time
o advance the NTP state machine by the raw time interval
o do leapsecond processing
o syncs the persistent clock (if appropriate)
o do a bit of timesource management
o calculate NTP adjustment for the current timesource
o update legacy time variables (xtime, wall_to_monotonic)
o update vsyscall info (if used)
o reprogram soft-timer
ppc64's timer_interrupt code does the following each tick.
o reads the timebase
o calculates the amount of time that has past
o saves the current offset
o calls do_timer
o increments xtime by one tick
o increments the generic NTP state machine
o Does leapsecond processing
o overwrites xtime (to avoids interpolation)
o sync the persistent clock (if appropriate)
o Calls into their internal NTP code
o calculates the NTP adjustment for their timebase
Just logically (as opposed to computationally), my code isn't all that more complex. I'm a little more explicit with my NTP adjustments because I wanted to be very careful to do them properly and insure we do not get time inconsistencies. And the timesource management is new but is reasonably cheap. Maybe you can point to a specific component of the above that you dislike?
Computationally, there are two 64bit mult/shifts (in the interval calculations) and a 64 bit divide that occurs in my code. However this is only done every 50ms instead of every tick, so I don't believe there is much of a performance impact.
Quoted 4 lines
John, what I'd really like to see here is some math or code examples, which demonstrate how your new code is better compared to the old code. Your code makes a _huge_ transformation jump and I'd like you to explain some of the steps inbetween.
This discussion is difficult to have with the current large patch. I'm trying to see where I can split it up into components that will help narrow the discussion. First up, I'm going to try to make the NTP cleanups on their own. Then I can see what else can be moved in.
Thanks again, I'll look forward to your feedback on future releases. -john
Hi,
Quoted 6 lines · john stultz
Quoted 5 lines
We basically have two timer architectures: timer tick and continuous timer. The latter currently has to emulate the timer tick. Your patch completely reverses the rolls and forces everybody to produce a continuous timer, which I think is equally bad, as some simple computations become a lot more complex. Why should it not be possible to support both equally?
Quoted 8 lines
Yep, I think this is really the core contention.
In my design I've reworked the time subsystem to assume time flows continuously as provided by the timesource. On systems that do not have a continuous counters like the PPC timebase, they can use a similar tick based interpolation method to provide continuous time. However this interpolation is done in the timesource driver instead of in the generic code.
By introducing extra overhead, which is difficult to get rid of again.
Quoted 7 lines
Quoted 3 lines
That might result in the worst of both worlds. If I look at the ppc64 implementation of gettimeofday, it's really nice and your (current) code would make this worse again.
Could you be more specific about how you feel the ppc64 is nice and how my code is worse? My code is actually quite influenced by the ppc64 code, so specific details might help me respond.
The ppc64 converts the timebase directly to a timeval, your code puts the nanosecond step inbetween.
Quoted 5 lines
Quoted 5 lines
So why not leave it to the timer source, if
it wants to manage a cycle counter or a xtime+offset? The common code can provide some helper functions to manage either of this. Converting everything to nanoseconds looks like a really bad compromise.
Quoted 8 lines
Quoted 6 lines
In the ppc64 example the main problem is that the generic tries to adjust for the wrong for the time source - the scheduler tick, which is derived from the cycle counter, so it has to redo all the work. Your code now introduces an abstract concept of nanosecond which adds extra overhead to either timer concept. Why not integrating what ppc64 does into the current timer code instead of replacing the current code with something else?
I'm not sure I followed that paragraph. Would you clarify a bit?
What exactly?
Quoted 4 lines
Computationally, there are two 64bit mult/shifts (in the interval calculations) and a 64 bit divide that occurs in my code. However this is only done every 50ms instead of every tick, so I don't believe there is much of a performance impact.
You forgot the cyc2ns conversions. Compare this now to some simple 32bit math executed every 100ms. Just look at all 32bit archs which use the generic do_div and you get an idea, who will not be happy with your new code.
Why do you do the adjustment at _every_ call? Why don't you take advantage of the fact, that you can be called regularly? In a tick based system you can be called every n*tick_nsec ns (without even the need to read a possibly expensive timer offset), in a cycle counter system you can trigger a call when the counter is past a certain value. In either case you know the callback function is called on average in a regular interval, so you can precompute adjustments based on this. Ignoring this possibility looks like a huge step back to me.
bye, Roman
Quoted 10 lines · Roman Zippel
Hi,
Quoted 6 lines · john stultz
Quoted 4 lines
I see lots of new u64 variables. I'm especially interested how this code scales down to small and slow machines, where such a precision is absolute overkill. How do these patches change current and possibly common time operations?
Quoted 7 lines
Quoted 4 lines
Hey Roman,
That's a good issue to bring up. With regards to the timeofday
infrastructure, there are two performance concerns (though let me know if I'm forgetting something):You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Because just multiplying the microseconds by one thousand doesn't really provide a nanosecond clock, maybe?
[...]
Quoted 2 lines
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value.
Did you ever do an analysis how this affected clock quality? See comp.protocols.time.ntp for all the complains about broken kernels (I think Redhat had it first, then the others followed).
Quoted 2 lines
So now I still like to know how does the complexity change compared to the old code?
You can have a look at the code. That's the point where you can decide about complexity. I haven't looked closely, but I guess it was O(1) before, and now also is O(1).
[...]
Quoted 8 lines
Well, AFAICT on slower machines (older and embedded stuff) it's a serious issue. The current code calculates the timeval with some simple 32bit calculations. Your code introduces the nsec step, which means several 64bit calculations and suddenly the overhead explodes on some machines.
As m68k maintainer I see no reason to ever switch to your new code, which might leave you with the dilemma having to maintain two versions of the timer code. What reason could I have to switch to the new timer code?
I never knew the 68k has such a poor performance.
Quoted 11 lines
I had no problems with a little more overhead, like a _few_ more 64bit operations per second (and preferably add/shifts), but I'm not really enthusiastic about the new code. Why don't you keep the main part 32 bits (or long)? What's wrong with using timeval or timespec?
I like the concept of the a time source in your patch. m68k already uses a number of timer related callbacks into machine specific code. If I could replace that with a timer driver, I'd be really happy. OTOH if it requires several expensive conversion between different time formats, I rather keep the current code.
If everybody would be keeping the current code, we wouldn't have any problems with the new code (as I said before). New features do cost some power unfortunately.
Regards,
Ulrich
Hi,
Quoted 5 lines · Ulrich Windl
Quoted 2 lines
You don't really answer the core question, why do you change everything to nanoseconds and 64bit values?
Because just multiplying the microseconds by one thousand doesn't really provide a nanosecond clock, maybe?
What are you trying to tell me?
Quoted 6 lines
Quoted 2 lines
With -mm you can now choose the HZ value, so that's not really the problem anymore. A lot of archs even never changed to a higher HZ value.
Did you ever do an analysis how this affected clock quality? See comp.protocols.time.ntp for all the complains about broken kernels (I think Redhat had it first, then the others followed).
So how exactly does this patch fix this?
Quoted 6 lines
Quoted 2 lines
So now I still like to know how does the complexity change compared to the old code?
You can have a look at the code. That's the point where you can decide about complexity. I haven't looked closely, but I guess it was O(1) before, and now also is O(1).
You guess or you know?
Quoted 5 lines
Quoted 3 lines
As m68k maintainer I see no reason to ever switch to your new code, which might leave you with the dilemma having to maintain two versions of the timer code. What reason could I have to switch to the new timer code?
I never knew the 68k has such a poor performance.
Usually it's code that either is efficient or performs badly.
bye, Roman