timer changes for v3.10
Subsystems (12)
Ingo Molnar
maintainerLinus,
Please pull the latest timers-core-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers-core-for-linus
HEAD: 6f7a05d7018de222e40ca003721037a530979974 clockevents: Set dummy handler on CPU_DEAD shutdown
The main changes in this cycle's merge are:
- Implement shadow timekeeper to shorten in kernel reader side blocking, by Thomas Gleixner.
- Posix timers enhancements by Pavel Emelyanov:
- allocate timer ID per process, so that exact timer ID allocations can be re-created be checkpoint/restore code.
- debuggability and tooling (/proc/PID/timers, etc.) improvements.
- suspend/resume enhancements by Feng Tang: on certain new Intel Atom processors (Penwell and Cloverview), there is a feature that the TSC won't stop in S3 state, so the TSC value won't be reset to 0 after resume. This can be taken advantage of by the generic via the CLOCK_SOURCE_SUSPEND_NONSTOP flag: instead of using the RTC to recover/approximate sleep time, the main (and precise) clocksource can be used.
- Fix /proc/timer_list for 4096 CPUs by Nathan Zimmer: on so many CPUs the file goes beyond 4MB of size and thus the current simplistic seqfile approach fails. Convert /proc/timer_list to a proper seq_file with its own iterator.
- Cleanups and refactorings of the core timekeeping code by John Stultz.
- International Atomic Clock time is managed by the NTP code internally currently but not exposed externally. Separate the TAI code out and add CLOCK_TAI support and TAI support to the hrtimer and posix-timer code, by John Stultz.
- Add deep idle support enhacement to the broadcast clockevents core timer code, by Daniel Lezcano: add an opt-in CLOCK_EVT_FEAT_DYNIRQ clockevents feature (which will be utilized by future clockevents driver updates), which allows the use of IRQ affinities to avoid spurious wakeups of idle CPUs - the right CPU with an expiring timer will be woken.
- Add new ARM bcm281xx clocksource driver, by Christian Daudt
- ... various other fixes and cleanups
Thanks,
Ingo
------------------>
Christian Daudt (1):
ARM: bcm281xx: Add timer driver (driver portion)
Daniel Lezcano (2):
tick: Pass broadcast device to tick_broadcast_set_event()
tick: Dynamically set broadcast irq affinity
David Daney (1):
hrtimer/trivial: Fix comment text in hrtimer.c
David Engraf (1):
hrtimer: Fix ktime_add_ns() overflow on 32bit architectures
Dong Zhu (1):
timekeeping: Avoid adjust kernel time once hwclock kept in UTC time
Feng Tang (4):
x86: Add cpu capability flag X86_FEATURE_NONSTOP_TSC_S3
clocksource: Add new feature flag CLOCK_SOURCE_SUSPEND_NONSTOP
x86: tsc: Add support for new S3_NONSTOP feature
timekeeping: utilize the suspend-nonstop clocksource to count suspended time
Fengguang Wu (1):
timekeeping: __timekeeping_set_tai_offset can be static
John Stultz (13):
timekeeping: Use inject_offset in warp_clock
timekeeping: Move TAI managment into timekeeping core from ntp
timekeeping: Add CLOCK_TAI clockid
hrtimer: Add hrtimer support for CLOCK_TAI
ntp: Split out timex validation from do_adjtimex
ntp: Move do_adjtimex() and hardpps() functions to timekeeping.c
ntp: Move timex validation to timekeeping do_adjtimex call.
ntp: Rework do_adjtimex to take timespec and tai arguments
timekeeping: Move ADJ_SETOFFSET to top level do_adjtimex()
timekeeping: Hold timekeepering locks in do_adjtimex and hardpps
timekeeping: Simplify tai updating from do_adjtimex
ntp: Remove ntp_lock, using the timekeeping locks to protect ntp state
timekeeping: Make sure to notify hrtimers when TAI offset changes
Nathan Zimmer (2):
timer_list: Split timer_list_show_tickdevices
timer_list: Convert timer list to be a proper seq_file
Pavel Emelyanov (3):
posix timers: Allocate timer id per process (v2)
posix-timers: Introduce /proc/PID/timers file
posix-timers: Show sigevent info in proc file
Prarit Bhargava (2):
x86: Do full rtc synchronization with ntp
hrtimer: Add expiry time overflow check in hrtimer_interrupt
Rado Vrbovsky (1):
tick: Change log level of NOHZ: local_softirq_pending message
Stephen Boyd (1):
clockevents: Switch into oneshot mode even if broadcast registered late
Thomas Gleixner (19):
tick: Call tick_init late
tick: Convert broadcast cpu bitmaps to cpumask_var_t
tick: Avoid programming the local cpu timer if broadcast pending
tick: Handle broadcast wakeup of multiple cpus
tick: Provide a check for a forced broadcast pending
arm: Use tick broadcast expired check
x86: Use tick broadcast expired check
clockevents: Add missing tick_check_broadcast_expired() for CLOCKEVENTS=n
timekeeping: Calc stuff once
timekeeping: Make jiffies_lock internal
timekeeping: Move lock out of timekeeper struct
timekeeping: Split timekeeper_lock into lock and seqcount
timekeeping: Store cycle_last value in timekeeper struct as well
timekeeping: Delay update of clock->cycle_last
timekeeping: Implement a shadow timekeeper
timekeeping: Shorten seq_count region
posix-timers: Remove unused variable
timekeeping: Update tk->cycle_last in resume
clockevents: Set dummy handler on CPU_DEAD shutdown
arch/arm/kernel/process.c | 11 +- arch/arm/mach-bcm/Kconfig | 1 + arch/arm/mach-bcm/board_bcm.c | 7 +- arch/x86/Kconfig | 1 + arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/intel.c | 12 ++ arch/x86/kernel/process.c | 12 ++ arch/x86/kernel/rtc.c | 69 ++---- arch/x86/kernel/tsc.c | 6 +- arch/x86/platform/efi/efi.c | 24 ++- arch/x86/platform/mrst/vrtc.c | 44 ++-- drivers/clocksource/Makefile | 1 + drivers/clocksource/bcm_kona_timer.c | 211 +++++++++++++++++++ fs/proc/base.c | 100 +++++++++ include/linux/clockchips.h | 12 ++ include/linux/clocksource.h | 1 + include/linux/hrtimer.h | 5 +- include/linux/jiffies.h | 1 - include/linux/posix-timers.h | 1 + include/linux/sched.h | 3 +- include/linux/time.h | 3 + include/linux/timekeeper_internal.h | 9 +- include/linux/timex.h | 7 - include/uapi/linux/time.h | 6 +- init/main.c | 2 +- kernel/hrtimer.c | 26 ++- kernel/posix-timers.c | 121 +++++++---- kernel/time.c | 11 +- kernel/time/ntp.c | 105 +++------- kernel/time/ntp_internal.h | 12 ++ kernel/time/tick-broadcast.c | 239 ++++++++++++++++----- kernel/time/tick-common.c | 2 + kernel/time/tick-internal.h | 5 +- kernel/time/tick-sched.c | 4 +- kernel/time/timekeeping.c | 396 ++++++++++++++++++++++++++++------- kernel/time/timer_list.c | 104 +++++++-- 36 files changed, 1190 insertions(+), 385 deletions(-) create mode 100644 drivers/clocksource/bcm_kona_timer.c create mode 100644 kernel/time/ntp_internal.h
arch/arm/kernel/process.c +10 -1
@@ -199,7 +199,16 @@ void cpu_idle(void)#ifdef CONFIG_PL310_ERRATA_769419 wmb ();#endif -if (hlt_counter) { +/* +* In poll mode we reenable interrupts and spin. +* +* Also if we detected in the wakeup from idle +* path that the tick broadcast device expired +* for us, we don't want to go deep idle as we +* know that the IPI is going to arrive right +* away +*/ +if (hlt_counter ||tick_check_broadcast_expired ()) {local_irq_enable ();cpu_relax (); }else if (!need_resched ()) {
arch/arm/mach-bcm/Kconfig +1 -0
@@ -6,6 +6,7 @@ config ARCH_BCM select ARM_ERRATA_764369 if SMP select ARM_GIC select CPU_V7 + select CLKSRC_OF select GENERIC_CLOCKEVENTS select GENERIC_TIME select GPIO_BCM
arch/arm/mach-bcm/board_bcm.c +2 -5
@@ -16,14 +16,11 @@#include <linux/device.h> #include <linux/platform_device.h> #include <linux/irqchip.h> +#include <linux/clocksource.h> #include <asm/mach/arch.h> #include <asm/mach/time.h> -static void timer_init (void ) -{ -} -static void __init board_init (void ) {
@@ -35,7 +32,7 @@ static const char * const bcm11351_dt_compat[] = { "bcm,bcm11351", NULL, };DT_MACHINE_START (BCM11351_DT ,"Broadcom Application Processor" ) .init_irq = irqchip_init, - .init_time = timer_init, + .init_time = clocksource_of_init, .init_machine = board_init, .dt_compat = bcm11351_dt_compat,MACHINE_END
arch/x86/Kconfig +1 -0
@@ -120,6 +120,7 @@ config X86 select OLD_SIGSUSPEND3 if X86_32 || IA32_EMULATION select OLD_SIGACTION if X86_32 select COMPAT_OLD_SIGACTION if IA32_EMULATION + select RTC_LIB config INSTRUCTION_DECODER def_bool y
arch/x86/include/asm/cpufeature.h +1 -0
@@ -100,6 +100,7 @@#define X86_FEATURE_AMD_DCM (3*32+27)/* multi-node processor */ #define X86_FEATURE_APERFMPERF (3*32+28)/* APERFMPERF */ #define X86_FEATURE_EAGER_FPU (3*32+29)/* "eagerfpu" Non lazy FPU restore */ +#define X86_FEATURE_NONSTOP_TSC_S3 (3*32+30)/* TSC doesn't stop in S3 state */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* "pni" SSE-3 */
arch/x86/kernel/cpu/intel.c +12 -0
@@ -96,6 +96,18 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) sched_clock_stable =1 ; } +/* Penwell and Cloverview have the TSC which doesn't sleep on S3 */ +if (c->x86 ==6 ) { +switch (c->x86_model) { +case 0x27 :/* Penwell */ +case 0x35 :/* Cloverview */ +set_cpu_cap (c,X86_FEATURE_NONSTOP_TSC_S3 ); +break ; +default : +break ; + } + } +/* * There is a known erratum on Pentium III and Core Solo * and Core Duo CPUs.
arch/x86/kernel/process.c +12 -0
@@ -336,6 +336,18 @@ void cpu_idle(void)local_touch_nmi ();local_irq_disable (); +/* +* We detected in the wakeup path that the +* tick broadcast device expired for us, but +* we raced with the other CPU and came back +* here before it was able to fire the IPI. +* No point in going idle. +*/ +if (tick_check_broadcast_expired ()) { +local_irq_enable (); +continue ; + } +enter_idle ();/* Don't trace irqs off for idle */
arch/x86/kernel/rtc.c +12 -57
88 lines not on this page · raw message
arch/x86/kernel/tsc.c +5 -1
@@ -768,7 +768,8 @@ static cycle_t read_tsc(struct clocksource *cs)static void resume_tsc (struct clocksource *cs) { - clocksource_tsc.cycle_last =0 ; +if (!boot_cpu_has (X86_FEATURE_NONSTOP_TSC_S3 )) + clocksource_tsc.cycle_last =0 ; }static struct clocksource clocksource_tsc = {
@@ -939,6 +940,9 @@ static int __init init_tsc_clocksource(void) clocksource_tsc.flags &= ~CLOCK_SOURCE_IS_CONTINUOUS ; } +if (boot_cpu_has (X86_FEATURE_NONSTOP_TSC_S3 )) + clocksource_tsc.flags |=CLOCK_SOURCE_SUSPEND_NONSTOP ; +/* * Trust the results of the earlier calibration on systems * exporting a reliable TSC.
arch/x86/platform/efi/efi.c +16 -8
@@ -49,6 +49,7 @@#include <asm/cacheflush.h> #include <asm/tlbflush.h> #include <asm/x86_init.h> +#include <asm/rtc.h> #define EFI_DEBUG 1
@@ -352,10 +353,10 @@ static efi_status_t __init phys_efi_get_time(efi_time_t *tm,int efi_set_rtc_mmss (unsigned long nowtime) { -int real_seconds, real_minutes;efi_status_t status;efi_time_t eft;efi_time_cap_t cap; +struct rtc_time tm; status = efi.get_time (&eft, &cap);if (status !=EFI_SUCCESS ) {
@@ -363,13 +364,20 @@ int efi_set_rtc_mmss(unsigned long nowtime)return -1 ; } - real_seconds = nowtime %60 ; - real_minutes = nowtime /60 ; -if (((abs (real_minutes - eft.minute) +15 )/30 ) &1 ) - real_minutes +=30 ; - real_minutes %=60 ; - eft.minute = real_minutes; - eft.second = real_seconds; +rtc_time_to_tm (nowtime, &tm); +if (!rtc_valid_tm (&tm)) { + eft.year = tm.tm_year +1900 ; + eft.month = tm.tm_mon +1 ; + eft.day = tm.tm_mday; + eft.minute = tm.tm_min; + eft.second = tm.tm_sec; + eft.nanosecond =0 ; + }else { +printk (KERN_ERR +"%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n" , + __FUNCTION__, nowtime); +return -1 ; + } status = efi.set_time (&eft);if (status !=EFI_SUCCESS ) {
arch/x86/platform/mrst/vrtc.c +26 -18
53 lines not on this page · raw message
drivers/clocksource/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_ARCH_BCM2835) += bcm2835_timer.o obj-$(CONFIG_SUNXI_TIMER) += sunxi_timer.o obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o obj-$(CONFIG_VT8500_TIMER) += vt8500_timer.o +obj-$(CONFIG_ARCH_BCM) += bcm_kona_timer.o obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o
drivers/clocksource/bcm_kona_timer.c new file +211 -0
211 lines not on this page · raw message
fs/proc/base.c +100 -0
118 lines not on this page · raw message
include/linux/clockchips.h +12 -0
@@ -55,6 +55,11 @@ enum clock_event_nofitiers {#define CLOCK_EVT_FEAT_C3STOP 0x000008#define CLOCK_EVT_FEAT_DUMMY 0x000010 +/* +* Core shall set the interrupt affinity dynamically in broadcast mode +*/ +#define CLOCK_EVT_FEAT_DYNIRQ 0x000020 +/** * struct clock_event_device - clock event device descriptor * @event_handler: Assigned by the framework to be called by the low
@@ -170,6 +175,12 @@ extern void tick_broadcast(const struct cpumask *mask);extern int tick_receive_broadcast (void );#endif +#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST ) && defined(CONFIG_TICK_ONESHOT ) +extern int tick_check_broadcast_expired (void ); +#else +static inline int tick_check_broadcast_expired (void ) {return 0 ; } +#endif +#ifdef CONFIG_GENERIC_CLOCKEVENTS extern void clockevents_notify (unsigned long reason,void *arg);#else
@@ -182,6 +193,7 @@ static inline void clockevents_suspend(void) {}static inline void clockevents_resume (void ) {}#define clockevents_notify (reason, arg) do { } while (0) +static inline int tick_check_broadcast_expired (void ) {return 0 ; }#endif
include/linux/clocksource.h +1 -0
@@ -206,6 +206,7 @@ struct clocksource {#define CLOCK_SOURCE_WATCHDOG 0x10#define CLOCK_SOURCE_VALID_FOR_HRES 0x20#define CLOCK_SOURCE_UNSTABLE 0x40 +#define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80/* simplify initialization of mask field */ #define CLOCKSOURCE_MASK (bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
include/linux/hrtimer.h +4 -1
@@ -157,6 +157,7 @@ enum hrtimer_base_type {HRTIMER_BASE_MONOTONIC ,HRTIMER_BASE_REALTIME ,HRTIMER_BASE_BOOTTIME , +HRTIMER_BASE_TAI , HRTIMER_MAX_CLOCK_BASES, };
@@ -327,7 +328,9 @@ extern ktime_t ktime_get(void);extern ktime_t ktime_get_real (void );extern ktime_t ktime_get_boottime (void );extern ktime_t ktime_get_monotonic_offset (void ); -extern ktime_t ktime_get_update_offsets (ktime_t *offs_real,ktime_t *offs_boot); +extern ktime_t ktime_get_clocktai (void ); +extern ktime_t ktime_get_update_offsets (ktime_t *offs_real,ktime_t *offs_boot, +ktime_t *offs_tai); DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
include/linux/jiffies.h +0 -1
@@ -75,7 +75,6 @@ extern int register_refined_jiffies(long clock_tick_rate);*/ extern u64 __jiffy_data jiffies_64;extern unsigned long volatile __jiffy_data jiffies; -extern seqlock_t jiffies_lock;#if (BITS_PER_LONG <64 )u64 get_jiffies_64 (void );
include/linux/posix-timers.h +1 -0
@@ -55,6 +55,7 @@ struct cpu_timer_list {/* POSIX.1b interval timer structure. */ struct k_itimer {struct list_head list;/* free/ allocate list */ +struct hlist_node t_hash;spinlock_t it_lock;clockid_t it_clock;/* which timer type */ timer_t it_id;/* timer id */
include/linux/sched.h +2 -1
@@ -527,7 +527,8 @@ struct signal_struct { unsigned int has_child_subreaper:1;/* POSIX.1b Interval Timers */ -struct list_head posix_timers; +int posix_timer_id; +struct list_head posix_timers;/* ITIMER_REAL timer for the process */ struct hrtimer real_timer;
include/linux/time.h +3 -0
@@ -181,6 +181,9 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran);extern int timekeeping_valid_for_hres (void );extern u64 timekeeping_max_deferment (void );extern int timekeeping_inject_offset (struct timespec *ts); +extern s32 timekeeping_get_tai_offset (void ); +extern void timekeeping_set_tai_offset (s32 tai_offset); +extern void timekeeping_clocktai (struct timespec *ts);struct tms ;extern void do_sys_times (struct tms *);
include/linux/timekeeper_internal.h +7 -2
@@ -20,6 +20,8 @@ struct timekeeper {u32 shift;/* Number of clock cycles in one NTP interval. */ cycle_t cycle_interval; +/* Last cycle value (also stored in clock->cycle_last) */ +cycle_t cycle_last;/* Number of clock shifted nano seconds in one NTP interval. */ u64 xtime_interval;/* shifted nano seconds left over when rounding cycle_interval */
@@ -62,8 +64,11 @@ struct timekeeper {ktime_t offs_boot;/* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ struct timespec raw_time; -/* Seqlock for all timekeeper values */ -seqlock_t lock; +/* The current UTC to TAI offset in seconds */ +s32 tai_offset; +/* Offset clock monotonic -> clock tai */ +ktime_t offs_tai; + };static inline struct timespec tk_xtime (struct timekeeper *tk)
include/linux/timex.h +0 -7
@@ -125,9 +125,6 @@extern unsigned long tick_usec;/* USER_HZ period (usec) */ extern unsigned long tick_nsec;/* SHIFTED_HZ period (nsec) */ -extern void ntp_init (void ); -extern void ntp_clear (void ); -/* Required to safely shift negative values */ #define shift_right (x, s) ({ \ __typeof__(x) __x = (x); \
@@ -140,10 +137,6 @@ extern void ntp_clear(void);#define NTP_INTERVAL_FREQ (HZ)#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ) -/* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ -extern u64 ntp_tick_length (void ); - -extern int second_overflow (unsigned long secs);extern int do_adjtimex (struct timex *);extern void hardpps (const struct timespec *,const struct timespec *);
include/uapi/linux/time.h +2 -4
@@ -54,11 +54,9 @@ struct itimerval {#define CLOCK_BOOTTIME 7#define CLOCK_REALTIME_ALARM 8#define CLOCK_BOOTTIME_ALARM 9 +#define CLOCK_SGI_CYCLE 10/* Hardware specific */ +#define CLOCK_TAI 11 -/* -* The IDs of various hardware clocks: -*/ -#define CLOCK_SGI_CYCLE 10#define MAX_CLOCKS 16#define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC)#define CLOCKS_MONO CLOCK_MONOTONIC
init/main.c +1 -1
@@ -494,7 +494,6 @@ asmlinkage void __init start_kernel(void)* Interrupts are still disabled. Do necessary setups, then * enable them */ -tick_init ();boot_cpu_init ();page_address_init ();printk (KERN_NOTICE "%s" , linux_banner);
@@ -551,6 +550,7 @@ asmlinkage void __init start_kernel(void)/* init some links before init_ISA_irqs() */ early_irq_init ();init_IRQ (); +tick_init ();init_timers ();hrtimers_init ();softirq_init ();
kernel/hrtimer.c +23 -3
@@ -84,6 +84,12 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) = .get_time = &ktime_get_boottime, .resolution = KTIME_LOW_RES, }, + { + .index = HRTIMER_BASE_TAI, + .clockid = CLOCK_TAI, + .get_time = &ktime_get_clocktai, + .resolution = KTIME_LOW_RES, + }, } };
@@ -91,6 +97,7 @@ static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = { [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME, [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC, [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME, + [CLOCK_TAI] = HRTIMER_BASE_TAI, };static inline int hrtimer_clockid_to_base (clockid_t clock_id)
@@ -107,8 +114,10 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base) {ktime_t xtim, mono, boot;struct timespec xts, tom, slp; +s32 tai_offset;get_xtime_and_monotonic_and_sleep_offset (&xts, &tom, &slp); + tai_offset =timekeeping_get_tai_offset (); xtim =timespec_to_ktime (xts); mono =ktime_add (xtim,timespec_to_ktime (tom));
@@ -116,6 +125,8 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base) base->clock_base[HRTIMER_BASE_REALTIME ].softirq_time = xtim; base->clock_base[HRTIMER_BASE_MONOTONIC ].softirq_time = mono; base->clock_base[HRTIMER_BASE_BOOTTIME ].softirq_time = boot; + base->clock_base[HRTIMER_BASE_TAI ].softirq_time = +ktime_add (xtim,ktime_set (tai_offset,0 )); }/*
@@ -276,6 +287,10 @@ ktime_t ktime_add_ns(const ktime_t kt, u64 nsec) }else {unsigned long rem =do_div (nsec,NSEC_PER_SEC ); +/* Make sure nsec fits into long */ +if (unlikely (nsec >KTIME_SEC_MAX )) +return (ktime_t ){ .tv64 =KTIME_MAX }; + tmp =ktime_set ((long )nsec, rem); }
@@ -652,8 +667,9 @@ static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base) {ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME ].offset;ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME ].offset; +ktime_t *offs_tai = &base->clock_base[HRTIMER_BASE_TAI ].offset; -return ktime_get_update_offsets (offs_real, offs_boot); +return ktime_get_update_offsets (offs_real, offs_boot, offs_tai); }/*
@@ -1011,7 +1027,8 @@ int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,* @timer: the timer to be added * @tim: expiry time * @delta_ns: "slack" range for the timer -* @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) +* @mode: expiry mode: absolute (HRTIMER_MODE_ABS) or +* relative (HRTIMER_MODE_REL) * * Returns: * 0 on success
@@ -1028,7 +1045,8 @@ EXPORT_SYMBOL_GPL(hrtimer_start_range_ns);* hrtimer_start - (re)start an hrtimer on the current CPU * @timer: the timer to be added * @tim: expiry time -* @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) +* @mode: expiry mode: absolute (HRTIMER_MODE_ABS) or +* relative (HRTIMER_MODE_REL) * * Returns: * 0 on success
@@ -1310,6 +1328,8 @@ retry: expires =ktime_sub (hrtimer_get_expires (timer), base->offset); +if (expires.tv64 <0 ) + expires.tv64 =KTIME_MAX ;if (expires.tv64 < expires_next.tv64) expires_next = expires;break ;
kernel/posix-timers.c +84 -37
189 lines not on this page · raw message
kernel/time.c +6 -5
@@ -138,13 +138,14 @@ int persistent_clock_is_local;*/ static inline void warp_clock (void ) { -struct timespec adjust; +if (sys_tz.tz_minuteswest !=0 ) { +struct timespec adjust; - adjust =current_kernel_time (); -if (sys_tz.tz_minuteswest !=0 ) persistent_clock_is_local =1 ; - adjust.tv_sec += sys_tz.tz_minuteswest *60 ; -do_settimeofday (&adjust); + adjust.tv_sec = sys_tz.tz_minuteswest *60 ; + adjust.tv_nsec =0 ; +timekeeping_inject_offset (&adjust); + } }/*
kernel/time/ntp.c +32 -73
262 lines not on this page · raw message
kernel/time/ntp_internal.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LINUX_NTP_INTERNAL_H +#define _LINUX_NTP_INTERNAL_H + +extern void ntp_init (void ); +extern void ntp_clear (void ); +/* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ +extern u64 ntp_tick_length (void ); +extern int second_overflow (unsigned long secs); +extern int ntp_validate_timex (struct timex *); +extern int __do_adjtimex (struct timex *,struct timespec *,s32 *); +extern void __hardpps (const struct timespec *,const struct timespec *); +#endif /* _LINUX_NTP_INTERNAL_H */
kernel/time/tick-broadcast.c +184 -55
416 lines not on this page · raw message
kernel/time/tick-common.c +2 -0
@@ -323,6 +323,7 @@ static void tick_shutdown(unsigned int *cpup)*/ dev->mode =CLOCK_EVT_MODE_UNUSED ;clockevents_exchange_device (dev,NULL ); + dev->event_handler = clockevents_handle_noop; td->evtdev =NULL ; }raw_spin_unlock_irqrestore (&tick_device_lock, flags);
@@ -416,4 +417,5 @@ static struct notifier_block tick_notifier = {void __init tick_init (void ) {clockevents_register_notifier (&tick_notifier); +tick_broadcast_init (); }
kernel/time/tick-internal.h +4 -1
@@ -4,6 +4,8 @@#include <linux/hrtimer.h> #include <linux/tick.h> +extern seqlock_t jiffies_lock; +#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD #define TICK_DO_TIMER_NONE -1
@@ -94,7 +96,7 @@ extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);extern void tick_shutdown_broadcast (unsigned int *cpup);extern void tick_suspend_broadcast (void );extern int tick_resume_broadcast (void ); - +extern void tick_broadcast_init (void );extern void tick_set_periodic_handler (struct clock_event_device *dev,int broadcast);
@@ -119,6 +121,7 @@ static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }static inline void tick_shutdown_broadcast (unsigned int *cpup) { }static inline void tick_suspend_broadcast (void ) { }static inline int tick_resume_broadcast (void ) {return 0 ; } +static inline void tick_broadcast_init (void ) { }/* * Set the periodic handler in non broadcast mode
kernel/time/tick-sched.c +2 -2
@@ -482,8 +482,8 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)if (ratelimit <10 && (local_softirq_pending () &SOFTIRQ_STOP_IDLE_MASK )) { -printk (KERN_ERR "NOHZ: local_softirq_pending %02x\n" , - (unsigned int )local_softirq_pending ()); +pr_warn ("NOHZ: local_softirq_pending %02x\n" , + (unsigned int )local_softirq_pending ()); ratelimit++; }return false;
kernel/time/timekeeping.c +315 -81
748 lines not on this page · raw message
kernel/time/timer_list.c +83 -21
168 lines not on this page · raw message
Quoted 4 lines · Ingo Molnar
Please pull the latest timers-core-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gittimers-core-for-linus
Hmm.. The "Use generic idle loop" patches from the SMP/hotplug pull conflicted with the "Use tick broadcast expired check" patches in this one for both x86 and ARM.
Both sets of patches were done by Thomas, and I *really* want you guys to take a look at my conflict resolution. I effectively moved the new "don't go into deep idle if boradcast timer is pending" check from x86 and arm into the generic idle loop. So my merge resolution is semantically quite different from either branch, but the alternative seemed to be to remove the new check entirely.
I pushed my merge out, please take a look.
Linus
Ingo Molnar
maintainerQuoted 10 lines · Linus Torvalds
Quoted 4 lines · Ingo Molnar
Please pull the latest timers-core-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gittimers-core-for-linusHmm.. The "Use generic idle loop" patches from the SMP/hotplug pull conflicted with the "Use tick broadcast expired check" patches in this one for both x86 and ARM.
Quoted 8 lines
Both sets of patches were done by Thomas, and I *really* want you guys to take a look at my conflict resolution. I effectively moved the new "don't go into deep idle if boradcast timer is pending" check from x86 and arm into the generic idle loop. So my merge resolution is semantically quite different from either branch, but the alternative seemed to be to remove the new check entirely.
I pushed my merge out, please take a look.
It looks good to me (in fact I missed that semantic conflict when I merged these two myself :-/ ) - but it would be nice if Thomas double checked it as well.
Thanks,
Ingo
Quoted 8 lines · Linus Torvalds
Both sets of patches were done by Thomas, and I *really* want you guys to take a look at my conflict resolution. I effectively moved the new "don't go into deep idle if boradcast timer is pending" check from x86 and arm into the generic idle loop. So my merge resolution is semantically quite different from either branch, but the alternative seemed to be to remove the new check entirely.
I pushed my merge out, please take a look.
Perfect!
tglx
Hi!
Quoted 7 lines
- suspend/resume enhancements by Feng Tang: on certain new Intel Atom processors (Penwell and Cloverview), there is a feature that the TSC won't stop in S3 state, so the TSC value won't be reset to 0 after resume. This can be taken advantage of by the generic via the
CLOCK_SOURCE_SUSPEND_NONSTOPflag: instead of using the RTC to recover/approximate sleep time, the main (and precise) clocksource can be used.
Ok, so for system time, we use three different timers:
1) RTC, while system is off
2) PIT, while system is running (plus TSC for parts of second)
3) TSC, while system is sleeping
Now. we have ntpd that is trying to compute "speed of clock", and adjust accordingly (adjtimex). But will it still do the right thing when we switch to different source during sleep?
And is the TSC even good enough? According to man page, PIT is not precise enough, so we sync from RTC every 11 minutes. I'd imagine TSC is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 10 lines · Pavel Machek
Hi!
Quoted 7 lines
- suspend/resume enhancements by Feng Tang: on certain new Intel Atom processors (Penwell and Cloverview), there is a feature that the TSC won't stop in S3 state, so the TSC value won't be reset to 0 after resume. This can be taken advantage of by the generic via the
CLOCK_SOURCE_SUSPEND_NONSTOPflag: instead of using the RTC to recover/approximate sleep time, the main (and precise) clocksource can be used.
Quoted 5 lines
Ok, so for system time, we use three different timers:
1) RTC, while system is off
2) PIT, while system is running (plus TSC for parts of second)
? We've not used interpolated timekeeping (PIT + TSC) since 2.6.18/2.6.21. Instead only a single clocksource is used (TSC, hpet, acpi_pm being the most common on x86, and PIT or jiffies on much older systems).
Quoted 1 line
3) TSC, while system is sleeping
So this is only used when the TSC has the SUSPEND_NONSTOP flag. Otherwise we use the CMOS/RTC clock.
Quoted 3 lines
Now. we have ntpd that is trying to compute "speed of clock", and adjust accordingly (adjtimex). But will it still do the right thing when we switch to different source during sleep?
Its true any frequency error we have will grow during suspend. Additionally, if the frequency of the hardware changes during suspend, correcting that will be difficult as well. It has yet to be seen how the TSC hardware that enabled this NONSTOP flag will preform in this regard. If it proves problematic, we'll likely have to add additional checks against the RTC.
Even so, I suspect the hardware that likely to gain this feature is targeted for mobile devices where they're likely to wake up periodically. In this case, the extra precision of the fine-grained clocksource, compared to the second granular CMOS is a much greater benefit, as injecting 1second of error on each suspend/resume cycle isn't good for timekeeping either.
Additionally, some ARM boards do something very similar with the 32k-timer (albeit hidden behind the persistent_clock interface) so we should eventually be able to share the logic here.
Quoted 2 lines
And is the TSC even good enough? According to man page, PIT is not precise enough, so we sync from RTC every 11 minutes. I'd imagine TSC
?? I think you're confusing the RTC being synced to the system time every 11 minutes while we're in sync w/ ntp servers here.
thanks
-john
Hi Pavel,
Quoted 20 lines · Feng Tang
---------- Forwarded message ----------
From: Pavel Machek <[email protected]>
Date: 2013/5/7
Subject: Re: [GIT PULL] timer changes for v3.10
To: Ingo Molnar <[email protected]>
Cc: Linus Torvalds <[email protected]>, [email protected], Thomas Gleixner <[email protected]>, Peter Zijlstra <[email protected]>, Andrew Morton <[email protected]>Hi!
Quoted 7 lines
- suspend/resume enhancements by Feng Tang: on certain new Intel Atom processors (Penwell and Cloverview), there is a feature that the TSC won't stop in S3 state, so the TSC value won't be reset to 0 after resume. This can be taken advantage of by the generic via the
CLOCK_SOURCE_SUSPEND_NONSTOPflag: instead of using the RTC to recover/approximate sleep time, the main (and precise) clocksource can be used.
Quoted 5 lines
Ok, so for system time, we use three different timers:
1) RTC, while system is off
2) PIT, while system is running (plus TSC for parts of second)
Not exactly. AFAIK, in most morden x86 processors, the TSC is the primary clocksource for system time counting.
If you grep clocksource in arch/x86/, there are some clockcources:
HPET, TSC, i8253(PIT you mentioned), APBT and some other xen/kvm clocksources.
Each of them has a "rating", and the clocksource with highest rating will be selected for system time counting. Here are the ratings:
HPET: 250
TSC: 300
APBT: 250
PIT: 110
So for a system with TSC, unless the TSC is detected or claimed to be "unstable", it will be used as the runtime clocksource.
Quoted 2 lines
3) TSC, while system is sleeping
This happens Only if we explicitly claim one processor's TSC has S3_NONSTOP_TSC feature. Detail could be found in patches.
For other cases, system will still use persistent_clock or RTC to calculate the sleep/suspended time
In short, most of existing X86 platforms will not be affected
Quoted 7 lines
Now. we have ntpd that is trying to compute "speed of clock", and adjust accordingly (adjtimex). But will it still do the right thing when we switch to different source during sleep?
And is the TSC even good enough? According to man page, PIT is not precise enough, so we sync from RTC every 11 minutes. I'd imagine TSC
My understanding, the reason for this 11 minutes sync is due to the PIT's register value has wrapped around .
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Thanks,
Feng
Ingo Molnar
maintainerQuoted 10 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Nice result ...
Is that with NTP running?
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
Thanks,
Ingo
Hi Ingo,
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Quoted 3 lines
Nice result ...
Is that with NTP running?
No, we haven't tested it with NTP yet.
Quoted 3 lines
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
For the some Atom processor like the Moorestown, Medfield, we use a fast TSC calibration by check the FSB freq and ratio from MSRs. See mrst_calibrate_tsc() in arch/x86/platform/mrst/mrst.c, and the calculated value is precise based on our test.
Thanks,
Feng
Quoted 11 lines · Ingo Molnar
Quoted 9 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Quoted 6 lines
Nice result ...
Is that with NTP running?
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
We also do refined calibration now on the TSC asynchronously over a period of seconds at boot up that gives us much better accuracy then the fast calibration. This helps provide much more consistent boot-to-boot TSC frequencies.
thanks
-john
Ingo Molnar
maintainerQuoted 16 lines · John Stultz
Quoted 15 lines · Ingo Molnar
Quoted 9 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Nice result ...
Is that with NTP running?
Quoted 7 lines
Quoted 2 lines
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
We also do refined calibration now on the TSC asynchronously over a period of seconds at boot up that gives us much better accuracy then the fast calibration. This helps provide much more consistent boot-to-boot TSC frequencies.
Indeed, I just checked from the logs of a system booting newer kernels how well it works in practice, and it's about 10 ppm or better, which is much better than the ~1000 ppm calibration inaccuracy I remembered.
Thanks,
Ingo
Quoted 16 lines · John Stultz
Quoted 15 lines · Ingo Molnar
Quoted 9 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Nice result ...
Is that with NTP running?
Quoted 7 lines
Quoted 2 lines
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
We also do refined calibration now on the TSC asynchronously over a period of seconds at boot up that gives us much better accuracy then the fast calibration. This helps provide much more consistent boot-to-boot TSC frequencies.
On android (and this is targetted at android, right?) system is going to suspend basically as soon as it boots. Will refined calibration have enough time to do its job?
And... reason for all this is that RTC has one second granularity when accessed naively. But surely we could poll RTC X times a second, getting error down by factor of X?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 19 lines · Pavel Machek
Quoted 18 lines · John Stultz
Quoted 17 lines · Ingo Molnar
Quoted 9 lines · Feng Tang
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Nice result ...
Is that with NTP running?
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
Quoted 7 lines
Quoted 4 lines
We also do refined calibration now on the TSC asynchronously over a period of seconds at boot up that gives us much better accuracy then the fast calibration. This helps provide much more consistent boot-to-boot TSC frequencies.
On android (and this is targetted at android, right?) system is going to suspend basically as soon as it boots. Will refined calibration have enough time to do its job?
I don't *think* this is a concern. The refined calibration only takes a few seconds while the system is booting and has always completed before userspace starts on the systems I have. Even so, I don't believe on boot Android will trigger the autosleep code until its userland is up and running, which takes more then a few seconds on the devices I've seen.
Quoted 3 lines
And... reason for all this is that RTC has one second granularity when accessed naively. But surely we could poll RTC X times a second, getting error down by factor of X?
Well, we can poll the RTC trying to get closer to the second edge, but that's somewhat expensive, and for suspend/resume would delay things more then whats acceptable.
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
thanks
-john
Hi!
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 4 lines
is even worse than that. Machine can stay is s2ram for weeks (for a lot more if it is desktop and you do s2ram for powersaving). Also temperature of CPU varies a lot between active and s2ram states. Is TSC good enough?
Yes, I think it is relatively precise. Per our test, system time backed by the S3 non stop TSC only has 1 second drift after 4 days running (with mixed running and S3 states). And before using this feature, we've seen many time drift problems due to the RTC HW or system FW with our platforms.
Nice result ...
Is that with NTP running?
Without NTP, the TSC fast-calibration on bootup is not (expected to be) nearly as precise as the 1:345600 precision you've measured.
Quoted 7 lines
Quoted 4 lines
We also do refined calibration now on the TSC asynchronously over a period of seconds at boot up that gives us much better accuracy then the fast calibration. This helps provide much more consistent boot-to-boot TSC frequencies.
On android (and this is targetted at android, right?) system is going to suspend basically as soon as it boots. Will refined calibration have enough time to do its job?
Quoted 6 lines
I don't *think* this is a concern. The refined calibration only takes a few seconds while the system is booting and has always completed before userspace starts on the systems I have. Even so, I don't believe on boot Android will trigger the autosleep code until its userland is up and running, which takes more then a few seconds on the devices I've seen.
Userspace has to be running, right. It should boot in 10 seconds or so.
Quoted 6 lines
Quoted 3 lines
And... reason for all this is that RTC has one second granularity when accessed naively. But surely we could poll RTC X times a second, getting error down by factor of X?
Well, we can poll the RTC trying to get closer to the second edge, but that's somewhat expensive, and for suspend/resume would delay things more then whats acceptable.
Well, if
Quoted 2 lines
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
I'm not exactly sure what my objections are.
TSC was not designed for long-term precise timekeeping. I guess it may work ok for short naps, but some people suspend their machines for longer than that. Plus I wonder how it will interfere with /etc/adjtime.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Ingo Molnar
maintainerQuoted 6 lines · Pavel Machek
Quoted 2 lines
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
I'm not exactly sure what my objections are.
TSC was not designed for long-term precise timekeeping. [...]
The TSC is just a 64-bit counter that can be read very cheaply.
If the TSC is _implemented_ precisely in hardware and is kept in sync over CPUs then it's obviously fit for long-term precise timekeeping from that point on.
Quoted 1 line
[...] I guess it may work ok for short naps, [...]
Historically the TSC was not very precise nor kept in sync, but see the measurements from Feng Tang, it's very precise now on good hardware - and it's also a very cheap to read clocksource.
Quoted 2 lines
[...] but some people suspend their machines for longer than that. Plus I wonder how it will interfere with
/etc/adjtime.
If it's precise then why should it interfere?
The history of the TSC being problematic can be ignored the moment CPU makers fix it completely - and apparently that is happening...
Thanks,
Ingo
Hi!
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
I'm not exactly sure what my objections are.
Quoted 7 lines
Quoted 1 line
TSC was not designed for long-term precise timekeeping. [...]
The TSC is just a 64-bit counter that can be read very cheaply.
If the TSC is _implemented_ precisely in hardware and is kept in sync over CPUs then it's obviously fit for long-term precise timekeeping from that point on.
Yes. But the clock for TSC is not being generated in CPU (right?) and AFAICT, the code said "if the CPU is new enough, assume TSC is good timesource". You need good clock for good timesource.
Quoted 7 lines
Quoted 2 lines
[...] but some people suspend their machines for longer than that. Plus I wonder how it will interfere with
/etc/adjtime.If it's precise then why should it interfere?
The history of the TSC being problematic can be ignored the moment CPU makers fix it completely - and apparently that is happening...
AFAICT we normally use RTC/PIT during runtime. If we switch to TSC during suspend, surely /etc/adjtime will be confused. (RTC has its own timesource, so it is unlikely to have same error as TSC).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
Quoted 22 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
I'm not exactly sure what my objections are.
Quoted 7 lines
Quoted 1 line
TSC was not designed for long-term precise timekeeping. [...]
The TSC is just a 64-bit counter that can be read very cheaply.
If the TSC is _implemented_ precisely in hardware and is kept in sync over CPUs then it's obviously fit for long-term precise timekeeping from that point on.
Yes. But the clock for TSC is not being generated in CPU (right?) and AFAICT, the code said "if the CPU is new enough, assume TSC is good timesource". You need good clock for good timesource.
Quoted 3 lines
Quoted 2 lines
[...] but some people suspend their machines for longer than that. Plus I wonder how it will interfere with
/etc/adjtime.
Quoted 6 lines
Quoted 4 lines
If it's precise then why should it interfere?
The history of the TSC being problematic can be ignored the moment CPU makers fix it completely - and apparently that is happening...
AFAICT we normally use RTC/PIT during runtime.
This is not true. AFAIK, most modern X86 processors used by Laptop/Desktop/Servers/Smartphone is not using PIT as the runtime clocksource. If you check the Linux laptop/desktop you are using, most probably it is using TSC as clocksource, less likely the "hpet", and not likey the "pit".
Thanks,
Feng
Pavel,
Quoted 9 lines · Pavel Machek
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Sorry. You seem to not like the merged change, but I guess I'm not quite sure what exactly your objection is here.
I'm not exactly sure what my objections are.
TSC was not designed for long-term precise timekeeping. [...]
The TSC is just a 64-bit counter that can be read very cheaply.
Quoted 7 lines
Quoted 3 lines
If the TSC is _implemented_ precisely in hardware and is kept in sync over CPUs then it's obviously fit for long-term precise timekeeping from that point on.
Yes. But the clock for TSC is not being generated in CPU (right?) and AFAICT, the code said "if the CPU is new enough, assume TSC is good timesource". You need good clock for good timesource.
TSC is a good clock source if:
- Frequency constant (>= Core2)
- Not affected by C-States (>= Nehalem)
- Running during Suspend (>= Haswell)
So we only use TSC across Suspend for Haswell and newer. On older systems we use RTC during suspend, but we still use the TSC as a clocksource during normal operation.
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
[...] but some people suspend their machines for longer than that. Plus I wonder how it will interfere with
/etc/adjtime.If it's precise then why should it interfere?
The history of the TSC being problematic can be ignored the moment CPU makers fix it completely - and apparently that is happening...
AFAICT we normally use RTC/PIT during runtime. If we switch to TSC
No, we do NOT use RTC/PIT during runtime. That's the worst choice one could make. If TSC is non frequency constant or affected by C-States we use HPET or PM-Timer, and we only ever use the PIT if nothing else is available.
RTC is not used at all for timekeeping. RTC is only used at system start and when we resume and the TSC stopped during that time, which is true for hibernation even on Haswell and newer.
Quoted 2 lines
during suspend, surely
/etc/adjtimewill be confused. (RTC has its own timesource, so it is unlikely to have same error as TSC).
Nothing gets confused. It's all handled proper in the core code and the clock source drivers.
Thanks,
tglx
Hi!
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
[...] but some people suspend their machines for longer than that. Plus I wonder how it will interfere with
/etc/adjtime.If it's precise then why should it interfere?
The history of the TSC being problematic can be ignored the moment CPU makers fix it completely - and apparently that is happening...
AFAICT we normally use RTC/PIT during runtime. If we switch to TSC
Quoted 8 lines
No, we do NOT use RTC/PIT during runtime. That's the worst choice one could make. If TSC is non frequency constant or affected by C-States we use HPET or PM-Timer, and we only ever use the PIT if nothing else is available.
RTC is not used at all for timekeeping. RTC is only used at system start and when we resume and the TSC stopped during that time, which is true for hibernation even on Haswell and newer.
Ok, that was part I was missing.
Quoted 5 lines
Quoted 2 lines
during suspend, surely
/etc/adjtimewill be confused. (RTC has its own timesource, so it is unlikely to have same error as TSC).Nothing gets confused. It's all handled proper in the core code and the clock source drivers.
Ok, so this patch means that we will use
TSC(runtime)+TSC(s2ram). That's improvement over
TSC(runtime)+RTC(s2ram).
[I still wonder how adjtime is going to work in TSC(runtime)+RTC(s2disk) case; surely TSC has different drift than RTC, and so adjtime will have fun trying to estimate the drift... but that's not new problem and not affected by that patch.]
Ok, thanks for explanation, and sorry it took me so long.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Ingo Molnar
maintainerQuoted 4 lines · Pavel Machek
[I still wonder how adjtime is going to work in TSC(runtime)+RTC(s2disk) case; surely TSC has different drift than RTC, and so adjtime will have fun trying to estimate the drift... but that's not new problem and not affected by that patch.]
NTP, once it has settled, typically deals with millisecond, microsecond level adjustments.
The RTC has a basic granularity of 1 second - so s2ram is a ~500 msecs kick in the guts for NTP and drift is the least of the problems.
On future systems it won't matter, as the TSC will be used for everything that does not completely power off the system, as Thomas explained it.
Thanks,
Ingo