Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752600AbdH3SEy (ORCPT ); Wed, 30 Aug 2017 14:04:54 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:43557 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752527AbdH3SEf (ORCPT ); Wed, 30 Aug 2017 14:04:35 -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 2/4] time: sync read_boot_clock64() with persistent clock Date: Wed, 30 Aug 2017 14:03:23 -0400 Message-Id: <1504116205-355281-3-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: 3712 Lines: 95 read_boot_clock64() returns a boot start timestamp from epoch. Some arches may need to access the persistent clock interface in order to calculate the epoch offset. However, the resolution of the persistent clock might be low. Therefore, in order to avoid time discrepancies a new argument 'now' is added to read_boot_clock64() parameters. Arch may decide to use it instead of accessing persistent clock again. Also, change read_boot_clock64() to have __init prototype since it is accessed only during boot. Signed-off-by: Pavel Tatashin --- arch/arm/kernel/time.c | 2 +- arch/s390/kernel/time.c | 2 +- include/linux/timekeeping.h | 10 +++++----- kernel/time/timekeeping.c | 8 ++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c index 629f8e9981f1..5b259261a268 100644 --- a/arch/arm/kernel/time.c +++ b/arch/arm/kernel/time.c @@ -90,7 +90,7 @@ void read_persistent_clock64(struct timespec64 *ts) __read_persistent_clock(ts); } -void read_boot_clock64(struct timespec64 *ts) +void __init read_boot_clock64(struct timespec64 *now, struct timespec64 *ts) { __read_boot_clock(ts); } diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c index 192efdfac918..fd3050e2e825 100644 --- a/arch/s390/kernel/time.c +++ b/arch/s390/kernel/time.c @@ -203,7 +203,7 @@ void read_persistent_clock64(struct timespec64 *ts) tod_to_timeval(clock - TOD_UNIX_EPOCH, ts); } -void read_boot_clock64(struct timespec64 *ts) +void __init read_boot_clock64(struct timespec64 *now, struct timespec64 *ts) { __u64 clock; diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index ddc229ff6d1e..ffe5705bd064 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -340,11 +340,11 @@ extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot); */ extern int persistent_clock_is_local; -extern void read_persistent_clock(struct timespec *ts); -extern void read_persistent_clock64(struct timespec64 *ts); -extern void read_boot_clock64(struct timespec64 *ts); -extern int update_persistent_clock(struct timespec now); -extern int update_persistent_clock64(struct timespec64 now); +void read_persistent_clock(struct timespec *ts); +void read_persistent_clock64(struct timespec64 *ts); +void read_boot_clock64(struct timespec64 *now, struct timespec64 *ts); +int update_persistent_clock(struct timespec now); +int update_persistent_clock64(struct timespec64 now); #endif diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index cedafa008de5..a74f4c3a46a4 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1468,9 +1468,13 @@ void __weak read_persistent_clock64(struct timespec64 *ts64) * Function to read the exact time the system has been started. * Returns a timespec64 with tv_sec=0 and tv_nsec=0 if unsupported. * + * Argument 'now' contains time from persistent clock to calculate offset from + * epoch. May contain zeros if persist ant clock is not available. + * * XXX - Do be sure to remove it once all arches implement it. */ -void __weak read_boot_clock64(struct timespec64 *ts) +void __weak __init read_boot_clock64(struct timespec64 *now, + struct timespec64 *ts) { ts->tv_sec = 0; ts->tv_nsec = 0; @@ -1501,7 +1505,7 @@ void __init timekeeping_init(void) } else if (now.tv_sec || now.tv_nsec) persistent_clock_exists = true; - read_boot_clock64(&boot); + read_boot_clock64(&now, &boot); if (!timespec64_valid_strict(&boot)) { pr_warn("WARNING: Boot clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n"); -- 2.14.1