All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: <xen-devel@lists.xensource.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<Stefano.Stabellini@eu.citrix.com>, <Ian.Campbell@citrix.com>,
	<linux-kernel@vger.kernel.org>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock
Date: Wed, 11 Nov 2015 16:51:35 +0000	[thread overview]
Message-ID: <1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1511111639500.5676@kaball.uk.xensource.com>

Read the wallclock from the shared info page at boot time.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

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 |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 2f57ba3..eede8e9 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -28,6 +28,7 @@
 #include <linux/cpufreq.h>
 #include <linux/cpu.h>
 #include <linux/console.h>
+#include <linux/timekeeping.h>
 
 #include <linux/mm.h>
 
@@ -95,6 +96,30 @@ 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;
+	u64 delta;
+	struct timespec64 now;
+	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 */
+	delta = ktime_get_ns();
+	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;
+
+	*ts = ns_to_timespec64(delta);
+}
+
 static void xen_percpu_init(void)
 {
 	struct vcpu_register_vcpu_info info;
@@ -303,6 +328,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


WARNING: multiple messages have this Message-ID (diff)
From: stefano.stabellini@eu.citrix.com (Stefano Stabellini)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock
Date: Wed, 11 Nov 2015 16:51:35 +0000	[thread overview]
Message-ID: <1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1511111639500.5676@kaball.uk.xensource.com>

Read the wallclock from the shared info page at boot time.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

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 |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 2f57ba3..eede8e9 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -28,6 +28,7 @@
 #include <linux/cpufreq.h>
 #include <linux/cpu.h>
 #include <linux/console.h>
+#include <linux/timekeeping.h>
 
 #include <linux/mm.h>
 
@@ -95,6 +96,30 @@ 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;
+	u64 delta;
+	struct timespec64 now;
+	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 */
+	delta = ktime_get_ns();
+	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;
+
+	*ts = ns_to_timespec64(delta);
+}
+
 static void xen_percpu_init(void)
 {
 	struct vcpu_register_vcpu_info info;
@@ -303,6 +328,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

WARNING: multiple messages have this Message-ID (diff)
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: linux-arm-kernel@lists.infradead.org,
	Stefano.Stabellini@eu.citrix.com, Ian.Campbell@citrix.com,
	linux-kernel@vger.kernel.org,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock
Date: Wed, 11 Nov 2015 16:51:35 +0000	[thread overview]
Message-ID: <1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1511111639500.5676@kaball.uk.xensource.com>

Read the wallclock from the shared info page at boot time.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

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 |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 2f57ba3..eede8e9 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -28,6 +28,7 @@
 #include <linux/cpufreq.h>
 #include <linux/cpu.h>
 #include <linux/console.h>
+#include <linux/timekeeping.h>
 
 #include <linux/mm.h>
 
@@ -95,6 +96,30 @@ 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;
+	u64 delta;
+	struct timespec64 now;
+	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 */
+	delta = ktime_get_ns();
+	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;
+
+	*ts = ns_to_timespec64(delta);
+}
+
 static void xen_percpu_init(void)
 {
 	struct vcpu_register_vcpu_info info;
@@ -303,6 +328,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

  parent reply	other threads:[~2015-11-11 16:51 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-11 16:49 [PATCH v3 0/6] Xen wallclock on arm and arm64 Stefano Stabellini
2015-11-11 16:49 ` Stefano Stabellini
2015-11-11 16:49 ` Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 1/6] xen: rename dom0_op to platform_op Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-12 15:01   ` Stefano Stabellini
2015-11-12 15:01     ` Stefano Stabellini
2015-11-12 15:01     ` Stefano Stabellini
2015-11-12 15:23   ` Boris Ostrovsky
2015-11-12 15:23     ` Boris Ostrovsky
2015-11-11 16:51 ` [PATCH v3 2/6] xen/arm: introduce HYPERVISOR_platform_op on arm and arm64 Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 3/6] xen: introduce XENPF_settime64 Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-12 15:30   ` Boris Ostrovsky
2015-11-12 15:30     ` Boris Ostrovsky
2015-11-12 16:10     ` Arnd Bergmann
2015-11-12 16:10       ` Arnd Bergmann
2015-11-12 16:34     ` Stefano Stabellini
2015-11-12 16:34       ` Stefano Stabellini
2015-11-12 16:34       ` Stefano Stabellini
2015-11-12 17:16       ` Boris Ostrovsky
2015-11-12 17:16         ` Boris Ostrovsky
2015-11-12 19:27         ` Arnd Bergmann
2015-11-12 19:27           ` Arnd Bergmann
2015-11-11 16:51 ` [PATCH v3 4/6] arm: extend pvclock_wall_clock with sec_hi Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51 ` Stefano Stabellini [this message]
2015-11-11 16:51   ` [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 20:33   ` Arnd Bergmann
2015-11-11 20:33     ` Arnd Bergmann
2015-11-12 11:28     ` Stefano Stabellini
2015-11-12 11:28       ` Stefano Stabellini
2015-11-12 11:28       ` Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 6/6] xen/arm: set the system time in Xen via the XENPF_settime64 hypercall Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 16:51   ` Stefano Stabellini
2015-11-11 20:35   ` Arnd Bergmann
2015-11-11 20:35     ` Arnd Bergmann

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=1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.