mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pavel Tatashin <pasha.tatashin@oracle.com>
To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com,
	linux@armlinux.org.uk, schwidefsky@de.ibm.com,
	heiko.carstens@de.ibm.com, john.stultz@linaro.org,
	sboyd@codeaurora.org, x86@kernel.org,
	linux-kernel@vger.kernel.org, mingo@redhat.com,
	tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com
Subject: [PATCH v7 3/6] x86/time: read_boot_clock64() implementation
Date: Thu,  2 Nov 2017 13:26:41 -0400	[thread overview]
Message-ID: <20171102172644.28555-4-pasha.tatashin@oracle.com> (raw)
In-Reply-To: <20171102172644.28555-1-pasha.tatashin@oracle.com>

read_boot_clock64() returns time of when system started. Now, that
early boot clock is available on x86 it is possible to implement x86
specific version of read_boot_clock64() that takes advantage of this new
interface.

Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
---
 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..3104c5304529 100644
--- a/arch/x86/kernel/time.c
+++ b/arch/x86/kernel/time.c
@@ -14,6 +14,7 @@
 #include <linux/i8253.h>
 #include <linux/time.h>
 #include <linux/export.h>
+#include <linux/sched/clock.h>
 
 #include <asm/vsyscall.h>
 #include <asm/x86_init.h>
@@ -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_cpu() 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_cpu() 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_cpu(smp_processor_id());
+	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.15.0

  parent reply	other threads:[~2017-11-02 17:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 17:26 [PATCH v7 0/6] Early boot time stamps for x86 Pavel Tatashin
2017-11-02 17:26 ` [PATCH v7 1/6] x86/tsc: remove tsc_disabled flag Pavel Tatashin
2017-11-03  1:58   ` Dou Liyang
2017-11-03 14:23     ` Pavel Tatashin
2017-11-08  8:52       ` Dou Liyang
2017-11-08 17:23         ` Pavel Tatashin
2017-11-02 17:26 ` [PATCH v7 2/6] time: sync read_boot_clock64() with persistent clock Pavel Tatashin
2017-11-02 17:26 ` Pavel Tatashin [this message]
2017-11-02 17:26 ` [PATCH v7 4/6] sched: early boot clock Pavel Tatashin
2017-11-02 17:26 ` [PATCH v7 5/6] x86/paravirt: add active_sched_clock to pv_time_ops Pavel Tatashin
2017-11-02 17:26 ` [PATCH v7 6/6] x86/tsc: use tsc early Pavel Tatashin
2017-11-03  2:54   ` Dou Liyang
2017-11-03 14:30     ` Pavel Tatashin
2017-11-08  9:17   ` Dou Liyang
2017-11-08 17:24     ` Pavel Tatashin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171102172644.28555-4-pasha.tatashin@oracle.com \
    --to=pasha.tatashin@oracle.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=douly.fnst@cn.fujitsu.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mingo@redhat.com \
    --cc=sboyd@codeaurora.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=steven.sistare@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®