Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162714AbbKTOSX (ORCPT ); Fri, 20 Nov 2015 09:18:23 -0500 Received: from smtp.citrix.com ([66.165.176.89]:38780 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162031AbbKTOSA (ORCPT ); Fri, 20 Nov 2015 09:18:00 -0500 X-IronPort-AV: E=Sophos;i="5.20,323,1444694400"; d="scan'208";a="313650070" From: Stefano Stabellini To: CC: , , , , Stefano Stabellini , Arnd Bergmann Subject: [PATCH v5 5/7] xen/arm: introduce xen_read_wallclock Date: Fri, 20 Nov 2015 14:17:42 +0000 Message-ID: <1448029064-22285-5-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2334 Lines: 83 Read the wallclock from the shared info page at boot time. Signed-off-by: Stefano Stabellini Acked-by: Arnd Bergmann --- Changes in v4: - simplify xen_read_wallclock Changes in v3: - use ktime_get_ns instead of calling into the arch_timer functions directly - read the wallclock from the late_initcall Changes in v2: - properly convert arch_timer ticker to nsec - use timespec64 interfaces - use sec_hi to get a 64-bit seconds value --- arch/arm/xen/enlighten.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 2f57ba3..6ae4ef5 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -95,6 +96,27 @@ static unsigned long long xen_stolen_accounting(int cpu) return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline]; } +static void xen_read_wallclock(struct timespec64 *ts) +{ + u32 version; + struct timespec64 now, ts_monotonic; + struct shared_info *s = HYPERVISOR_shared_info; + struct pvclock_wall_clock *wall_clock = &(s->wc); + + /* get wallclock at system boot */ + do { + version = wall_clock->version; + rmb(); /* fetch version before time */ + now.tv_sec = ((uint64_t)wall_clock->sec_hi << 32) | wall_clock->sec; + now.tv_nsec = wall_clock->nsec; + rmb(); /* fetch time before checking version */ + } while ((wall_clock->version & 1) || (version != wall_clock->version)); + + /* time since system boot */ + ktime_get_ts64(&ts_monotonic); + *ts = timespec64_add(now, ts_monotonic); +} + static void xen_percpu_init(void) { struct vcpu_register_vcpu_info info; @@ -303,6 +325,11 @@ static int __init xen_pm_init(void) pm_power_off = xen_power_off; arm_pm_restart = xen_restart; + if (!xen_initial_domain()) { + struct timespec64 ts; + xen_read_wallclock(&ts); + do_settimeofday64(&ts); + } return 0; } -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/