Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752630AbdH3SFj (ORCPT ); Wed, 30 Aug 2017 14:05:39 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:28624 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751770AbdH3SFi (ORCPT ); Wed, 30 Aug 2017 14:05:38 -0400 From: Pavel Tatashin To: linux@armlinux.org.uk, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, john.stultz@linaro.org, sboyd@codeaurora.org, pasha.tatashin@oracle.com, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com Subject: [PATCH v6 3/4] x86/time: read_boot_clock64() implementation Date: Wed, 30 Aug 2017 14:03:24 -0400 Message-Id: <1504116205-355281-4-git-send-email-pasha.tatashin@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1504116205-355281-1-git-send-email-pasha.tatashin@oracle.com> References: <1504116205-355281-1-git-send-email-pasha.tatashin@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1946 Lines: 57 read_boot_clock64() returns time of when system started. Now, that sched_clock_early() is available on systems with unstable clocks it is possible to implement x86 specific version of read_boot_clock64() that takes advantage of this new interface. Signed-off-by: Pavel Tatashin --- arch/x86/kernel/time.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c index e0754cdbad37..fbad8bf2fa24 100644 --- a/arch/x86/kernel/time.c +++ b/arch/x86/kernel/time.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -95,3 +96,32 @@ void __init time_init(void) { late_time_init = x86_late_time_init; } + +/* + * Called once during to boot to initialize boot time. + * This function returns timestamp in timespec format which is sec/nsec from + * epoch of when boot started. + * We use sched_clock_early() that gives us nanoseconds from when this clock has + * been started and it happens quiet early during boot process. To calculate + * offset from epoch we use information provided in 'now' by the caller + * + * If sched_clock_early() is not available or if there is any kind of error + * i.e. time from epoch is smaller than boot time, we must return zeros in ts, + * and the caller will take care of the error: by assuming that the time when + * this function was called is the beginning of boot time. + */ +void __init read_boot_clock64(struct timespec64 *now, struct timespec64 *ts) +{ + u64 ns_boot = sched_clock_early(); + bool valid_clock; + u64 ns_now; + + ns_now = timespec64_to_ns(now); + valid_clock = ns_boot && timespec64_valid_strict(now) && + (ns_now > ns_boot); + + if (!valid_clock) + *ts = (struct timespec64){0, 0}; + else + *ts = ns_to_timespec64(ns_now - ns_boot); +} -- 2.14.1