From: Tim Deegan Subject: [PATCH v3] x86/time: Always count s_time from Xen boot Date: Thu, 6 Mar 2014 17:01:50 +0100 Message-ID: <20140306160150.GJ11475@deinos.phlegethon.org> References: <1393613824-13230-1-git-send-email-andrew.cooper3@citrix.com> <1393613824-13230-3-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1393613824-13230-3-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Keir Fraser , Jan Beulich , Xen-devel List-Id: xen-devel@lists.xenproject.org Timestamped printks() can call NOW() before init_xen_time(). Set a baseline TSC as soon as we've calibrated the TSC rate, so that NOW() consistently counts from boot time. Signed-off-by: Tim Deegan Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich --- v2: use TSC from __start() rather than from early_time_init(). v3: remove later reset of TSC baseline from init_xen_time(). diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index b12eefb..d62eaae 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -136,6 +136,12 @@ __start: /* Check for availability of long mode. */ bt $29,%edx jnc bad_cpu + + /* Stash TSC to calculate a good approximation of time-since-boot */ + rdtsc + mov %eax,sym_phys(boot_tsc_stamp) + mov %edx,sym_phys(boot_tsc_stamp+4) + /* Initialise L2 boot-map page table entries (16MB). */ mov $sym_phys(l2_bootmap),%edx mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax @@ -203,6 +209,10 @@ GLOBAL(trampoline_end) __high_start: #include "x86_64.S" + .section .init.data, "a", @progbits +GLOBAL(boot_tsc_stamp) + .quad 0 + .section .data.page_aligned, "aw", @progbits .p2align PAGE_SHIFT /* diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 000191b..a5e7eca 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -84,6 +84,9 @@ static u16 pit_stamp16; static u32 pit_stamp32; static bool_t __read_mostly using_pit; +/* Boot timestamp, filled in head.S (initdata) */ +extern u64 boot_tsc_stamp; + /* * 32-bit division of integer dividend and integer divisor yielding * 32-bit fractional quotient. @@ -1433,9 +1436,6 @@ int __init init_xen_time(void) open_softirq(TIME_CALIBRATE_SOFTIRQ, local_time_calibration); - /* System time (get_s_time()) starts ticking from now. */ - rdtscll(this_cpu(cpu_time).local_tsc_stamp); - /* NB. get_cmos_time() can take over one second to execute. */ do_settime(get_cmos_time(), 0, NOW()); @@ -1456,6 +1456,7 @@ void __init early_time_init(void) u64 tmp = init_pit_and_calibrate_tsc(); set_time_scale(&this_cpu(cpu_time).tsc_scale, tmp); + this_cpu(cpu_time).local_tsc_stamp = boot_tsc_stamp; do_div(tmp, 1000); cpu_khz = (unsigned long)tmp;