All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: johnstul@us.ibm.com, jeremy@goop.org,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 14/15] time: export time information for KVM pvclock
Date: Tue, 16 Oct 2012 14:56:33 -0300	[thread overview]
Message-ID: <20121016180137.923799800@redhat.com> (raw)
In-Reply-To: 20121016175619.194848607@redhat.com

[-- Attachment #1: 13-time-add-pvclock-gtod-data --]
[-- Type: text/plain, Size: 2535 bytes --]

As suggested by John, export time data similarly to how its
by vsyscall support. This allows KVM to retrieve necessary
information to implement vsyscall support in KVM guests.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: vsyscall/include/linux/pvclock_gtod.h
===================================================================
--- /dev/null
+++ vsyscall/include/linux/pvclock_gtod.h
@@ -0,0 +1,23 @@
+#ifndef _PVCLOCK_GTOD_H
+#define _PVCLOCK_GTOD_H
+
+#include <linux/clocksource.h>
+
+struct pvclock_gtod_data {
+	seqcount_t	seq;
+
+	struct { /* extract of a clocksource struct */
+		int vclock_mode;
+		cycle_t	cycle_last;
+		cycle_t	mask;
+		u32	mult;
+		u32	shift;
+	} clock;
+
+	/* open coded 'struct timespec' */
+	u64		monotonic_time_snsec;
+	time_t		monotonic_time_sec;
+};
+extern struct pvclock_gtod_data pvclock_gtod_data;
+
+#endif /* _PVCLOCK_GTOD_H */
Index: vsyscall/kernel/time/timekeeping.c
===================================================================
--- vsyscall.orig/kernel/time/timekeeping.c
+++ vsyscall/kernel/time/timekeeping.c
@@ -21,6 +21,7 @@
 #include <linux/time.h>
 #include <linux/tick.h>
 #include <linux/stop_machine.h>
+#include <linux/pvclock_gtod.h>
 
 
 static struct timekeeper timekeeper;
@@ -180,6 +181,37 @@ static inline s64 timekeeping_get_ns_raw
 	return nsec + arch_gettimeoffset();
 }
 
+struct pvclock_gtod_data pvclock_gtod_data;
+EXPORT_SYMBOL_GPL(pvclock_gtod_data);
+
+static void update_pvclock_gtod(struct timekeeper *tk)
+{
+	struct pvclock_gtod_data *vdata = &pvclock_gtod_data;
+
+	write_seqcount_begin(&vdata->seq);
+
+	/* copy vsyscall data */
+	vdata->clock.vclock_mode	= tk->clock->archdata.vclock_mode;
+	vdata->clock.cycle_last		= tk->clock->cycle_last;
+	vdata->clock.mask		= tk->clock->mask;
+	vdata->clock.mult		= tk->mult;
+	vdata->clock.shift		= tk->shift;
+
+	vdata->monotonic_time_sec	= tk->xtime_sec
+					+ tk->wall_to_monotonic.tv_sec;
+	vdata->monotonic_time_snsec	= tk->xtime_nsec
+					+ (tk->wall_to_monotonic.tv_nsec
+						<< tk->shift);
+	while (vdata->monotonic_time_snsec >=
+					(((u64)NSEC_PER_SEC) << tk->shift)) {
+		vdata->monotonic_time_snsec -=
+					((u64)NSEC_PER_SEC) << tk->shift;
+		vdata->monotonic_time_sec++;
+	}
+
+	write_seqcount_end(&vdata->seq);
+}
+
 /* must hold write on timekeeper.lock */
 static void timekeeping_update(struct timekeeper *tk, bool clearntp)
 {
@@ -188,6 +220,7 @@ static void timekeeping_update(struct ti
 		ntp_clear();
 	}
 	update_vsyscall(tk);
+	update_pvclock_gtod(tk);
 }
 
 /**



  parent reply	other threads:[~2012-10-16 17:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16 17:56 [patch 00/15] pvclock vsyscall support + KVM hypervisor support Marcelo Tosatti
2012-10-16 17:56 ` [patch 01/15] KVM: x86: retain pvclock guest stopped bit in guest memory Marcelo Tosatti
2012-10-16 17:56 ` [patch 02/15] x86: pvclock: make sure rdtsc doesnt speculate out of region Marcelo Tosatti
2012-10-16 17:56 ` [patch 03/15] x86: pvclock: remove pvclock_shadow_time Marcelo Tosatti
2012-10-16 17:56 ` [patch 04/15] x86: pvclock: create helper for pvclock data retrieval Marcelo Tosatti
2012-10-16 17:56 ` [patch 05/15] x86: pvclock: fix flags usage race Marcelo Tosatti
2012-10-16 17:56 ` [patch 06/15] x86: pvclock: introduce helper to read flags Marcelo Tosatti
2012-10-16 17:56 ` [patch 07/15] sched: add notifier for cross-cpu migrations Marcelo Tosatti
2012-10-16 17:56 ` [patch 08/15] x86: pvclock: generic pvclock vsyscall initialization Marcelo Tosatti
2012-10-16 17:56 ` [patch 09/15] x86: kvm guest: pvclock vsyscall support Marcelo Tosatti
2012-10-16 17:56 ` [patch 10/15] x86: vsyscall: pass mode to gettime backend Marcelo Tosatti
2012-10-16 17:56 ` [patch 11/15] x86: vdso: pvclock gettime support Marcelo Tosatti
2012-10-16 17:56 ` [patch 12/15] KVM: x86: introduce facility to support vsyscall pvclock, via MSR Marcelo Tosatti
2012-10-16 17:56 ` [patch 13/15] KVM: x86: pass host_tsc to read_l1_tsc Marcelo Tosatti
2012-10-16 17:56 ` Marcelo Tosatti [this message]
2012-10-16 17:56 ` [patch 15/15] KVM: x86: implement PVCLOCK_TSC_STABLE_BIT pvclock flag Marcelo Tosatti

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=20121016180137.923799800@redhat.com \
    --to=mtosatti@redhat.com \
    --cc=jeremy@goop.org \
    --cc=johnstul@us.ibm.com \
    --cc=kvm@vger.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 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.