Skip to contentSkip to conversation

KVM clock, new iteration

PATCH In review Glauber de Oliveira Costa 5 participants 12 messages Jan 11, 2008 – Jan 12, 2008 7 messages not in the archive

Subsystems (5)
x86 KVM KVM x86 Xen hypervisor x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover KVM clock, new iteration

Hi folks,

A lot of time has been elapsed since I last sent a version of kvm clock, with a lot of things in the middle, including my vacations and a nasty bug in the clock itself ;-)

Here it is a new version. I'm following avi's last suggestion of using an msr to make it more migration-proof. If it's not approved, we can easily switch back to the hypercall mechanism. That's the easy part ;-)

Clock updates are done every time we're scheduled. It is _not_ enough to check if we're changing cpus, because the tsc will change its frequency when the cpu is idle (if using the mwait idle). So after a long idle period, one cpu will end up stepping ahead causing a backward time (remember the bug I talked about? :-) )

As I fell it ready for inclusion (which obviously does not mean it is perfect, nor that I don't value any further comments ), I'm also posting the userspace patches in a separate series that will follow shortly.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#2 lore raw

PATCH 1/3 put kvm_para.h include outside __KERNEL__

In reply to a message not in the archive

kvm_para.h potentially contains definitions that are to be used by kvm-userspace, so it should not be included inside the __KERNEL__ block. To protect its own data structures, kvm_para.h already includes its own __KERNEL__ block.

---
 include/linux/kvm_para.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/kvm_para.h +1 -1
index 6af91a5..5497aac 100644
@@ -14,12 +14,12 @@
 
 #define KVM_HC_VAPIC_POLL_IRQ            1
 
-#ifdef __KERNEL__
 /*
  * hypercalls use architecture specific
  */
 #include <asm/kvm_para.h>
 
+#ifdef __KERNEL__
 static inline int kvm_para_has_feature(unsigned int feature)
 {
 	if (kvm_arch_para_features() & (1UL << feature))
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
#4 lore raw

PATCH 2/3 kvmclock - the host part.

In reply to a message not in the archive

This is the host part of kvm clocksource implementation. As it does not include clockevents, it is a fairly simple implementation. We only have to register a per-vcpu area, and start writting to it periodically.

The area is binary compatible with xen, as we use the same shadow_info structure.

---
 arch/x86/kvm/x86.c         |   64 +++++++++++++++++++++++++++++++++++++++++++-
 include/asm-x86/kvm_host.h |    5 +++
 include/asm-x86/kvm_para.h |    5 +++
 include/linux/kvm.h        |    1 +
 4 files changed, 74 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +63 -1
index 8a90403..d3fd920 100644
@@ -19,6 +19,7 @@
 #include "irq.h"
 #include "mmu.h"
 
+#include <linux/clocksource.h>
 #include <linux/kvm.h>
 #include <linux/fs.h>
 #include <linux/vmalloc.h>
@@ -412,7 +413,7 @@ static u32 msrs_to_save[] = {
 #ifdef CONFIG_X86_64
 	MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
 #endif
-	MSR_IA32_TIME_STAMP_COUNTER,
+	MSR_IA32_TIME_STAMP_COUNTER, MSR_PARAVIRT_CLOCK,
 };
 
 static unsigned num_msrs_to_save;
@@ -467,6 +468,50 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
 	return kvm_set_msr(vcpu, index, *data);
 }
 
+#define WC_OFFSET offsetof(struct shared_info, wc_version)
+
+static void kvm_write_guest_time(struct kvm_vcpu *v)
+{
+	struct timespec ts, wc_ts;
+	int wc_args[3]; /* version, wc_sec, wc_nsec */
+	unsigned long flags;
+	struct kvm_vcpu_arch *vcpu = &v->arch;
+
+	if (!vcpu->shared_info)
+		return;
+
+	/* Make the update of both version numbers visible to guest */
+	wc_args[0] = ++vcpu->wc_version;
+	kvm_write_guest(v->kvm, vcpu->shared_info + WC_OFFSET, wc_args,
+			sizeof(wc_args));
+	vcpu->hv_clock.version++;
+	kvm_write_guest(v->kvm, vcpu->clock_addr, &vcpu->hv_clock,
+			sizeof(vcpu->hv_clock));
+
+	/* Keep irq disabled to prevent changes to the clock */
+	local_irq_save(flags);
+	kvm_get_msr(v, MSR_IA32_TIME_STAMP_COUNTER,
+			  &vcpu->hv_clock.tsc_timestamp);
+	wc_ts = current_kernel_time();
+	ktime_get_ts(&ts);
+	local_irq_restore(flags);
+
+	/* With all the info we got, fill in the values */
+	wc_args[1] = wc_ts.tv_sec;
+	wc_args[2] = wc_ts.tv_nsec;
+	wc_args[0] = ++vcpu->wc_version;
+
+	vcpu->hv_clock.system_time = ts.tv_nsec +
+				     (NSEC_PER_SEC * (u64)ts.tv_sec);
+	vcpu->hv_clock.version++;
+
+	/* And finally, let the guest see them */
+	kvm_write_guest(v->kvm, vcpu->shared_info + WC_OFFSET, wc_args,
+			sizeof(wc_args));
+	kvm_write_guest(v->kvm, vcpu->clock_addr, &vcpu->hv_clock,
+			sizeof(vcpu->hv_clock));
+}
+
 
 int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 {
@@ -494,6 +539,18 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 	case MSR_IA32_MISC_ENABLE:
 		vcpu->arch.ia32_misc_enable_msr = data;
 		break;
+	case MSR_PARAVIRT_CLOCK: {
+		vcpu->arch.shared_info = data;
+
+		vcpu->arch.clock_addr = data + offsetof(struct vcpu_info, time)
+				 + sizeof(struct vcpu_info) * vcpu->vcpu_id;
+
+		vcpu->arch.hv_clock.tsc_to_system_mul =
+				clocksource_khz2mult(tsc_khz, 22);
+		vcpu->arch.hv_clock.tsc_shift = 22;
+		kvm_write_guest_time(vcpu);
+		break;
+	}
 	default:
 		pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", msr, data);
 		return 1;
@@ -553,6 +610,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
 		data = vcpu->arch.shadow_efer;
 		break;
 #endif
+	case MSR_PARAVIRT_CLOCK:
+		data = vcpu->arch.shared_info;
+		break;
 	default:
 		pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr);
 		return 1;
@@ -680,6 +740,7 @@ int kvm_dev_ioctl_check_extension(long ext)
 	case KVM_CAP_USER_MEMORY:
 	case KVM_CAP_SET_TSS_ADDR:
 	case KVM_CAP_EXT_CPUID:
+	case KVM_CAP_CLOCKSOURCE:
 		r = 1;
 		break;
 	case KVM_CAP_VAPIC:
@@ -737,6 +798,7 @@ out:
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 	kvm_x86_ops->vcpu_load(vcpu, cpu);
+	kvm_write_guest_time(vcpu);
 }
 
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
include/asm-x86/kvm_host.h +5 -0
index d6db0de..bbc4b51 100644
@@ -261,6 +261,11 @@ struct kvm_vcpu_arch {
 	/* emulate context */
 
 	struct x86_emulate_ctxt emulate_ctxt;
+
+	struct vcpu_time_info hv_clock;
+	gpa_t shared_info;
+	gpa_t clock_addr; /* so we avoid computing it every time */
+	int wc_version;
 };
 
 struct kvm_mem_alias {
include/asm-x86/kvm_para.h +5 -0
index c6f3fd8..abe412a 100644
@@ -1,5 +1,6 @@
 #ifndef __X86_KVM_PARA_H
 #define __X86_KVM_PARA_H
+#include <xen/interface/xen.h>
 
 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
  * should be used to determine that a VM is running under KVM.
@@ -10,9 +11,13 @@
  * paravirtualization, the appropriate feature bit should be checked.
  */
 #define KVM_CPUID_FEATURES	0x40000001
+#define KVM_FEATURE_CLOCKSOURCE 0
 
+#define MSR_PARAVIRT_CLOCK	0x11
 #ifdef __KERNEL__
 #include <asm/processor.h>
+extern void kvmclock_init(void);
+
 
 /* This instruction is vmcall.  On non-VT architectures, it will generate a
  * trap that we will then rewrite to the appropriate instruction.
include/linux/kvm.h +1 -0
index 4de4fd2..78ce53f 100644
@@ -232,6 +232,7 @@ struct kvm_vapic_addr {
 #define KVM_CAP_SET_TSS_ADDR 4
 #define KVM_CAP_EXT_CPUID 5
 #define KVM_CAP_VAPIC 6
+#define KVM_CAP_CLOCKSOURCE 7
 
 /*
  * ioctls for VM fds
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
#6 lore raw

PATCH 3/3 kvmclock implementation, the guest part.

In reply to a message not in the archive

This is the guest part of kvm clock implementation It does not do tsc-only timing, as tsc can have deltas between cpus, and it did not seem worthy to me to keep adjusting them.

We do use it, however, for fine-grained adjustment.

Other than that, time comes from the host.

---
 arch/x86/Kconfig            |   10 +++
 arch/x86/kernel/Makefile_32 |    1 +
 arch/x86/kernel/kvmclock.c  |  160 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/setup_32.c  |    5 ++
 arch/x86/xen/time.c         |    6 +-
 5 files changed, 179 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/kernel/kvmclock.c
arch/x86/Kconfig +10 -0
index ab2df55..968315e 100644
@@ -350,6 +350,16 @@ config VMI
 	  at the moment), by linking the kernel to a GPL-ed ROM module
 	  provided by the hypervisor.
 
+config KVM_CLOCK
+	bool "KVM paravirtualized clock"
+	select PARAVIRT
+	help
+	  Turning on this option will allow you to run a paravirtualized clock
+	  when running over the KVM hypervisor. Instead of relying on a PIT
+	  (or probably other) emulation by the underlying device model, the host
+	  provides the guest with timing infrastructure, as time of day, and
+	  timer expiration.
+
 source "arch/x86/lguest/Kconfig"
 
 endif
arch/x86/kernel/Makefile_32 +1 -0
index a7bc93c..f6332b6 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_K8_NB)		+= k8.o
 obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o
 
 obj-$(CONFIG_VMI)		+= vmi_32.o vmiclock_32.o
+obj-$(CONFIG_KVM_CLOCK)		+= kvmclock.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt_32.o
 obj-y				+= pcspeaker.o
 
arch/x86/kernel/kvmclock.c new file +160 -0

160 lines not on this page · raw message

arch/x86/kernel/setup_32.c +5 -0
index 9c24b45..89c0eb2 100644
@@ -44,6 +44,7 @@
 #include <linux/crash_dump.h>
 #include <linux/dmi.h>
 #include <linux/pfn.h>
+#include <linux/kvm_para.h>
 
 #include <video/edid.h>
 
@@ -614,6 +615,10 @@ void __init setup_arch(char **cmdline_p)
 
 	max_low_pfn = setup_memory();
 
+#ifdef CONFIG_KVM_CLOCK
+	kvmclock_init();
+#endif
+
 #ifdef CONFIG_VMI
 	/*
 	 * Must be after max_low_pfn is determined, and before kernel
arch/x86/xen/time.c +3 -3
index d083ff5..7728b87 100644
@@ -28,7 +28,7 @@
 #define TIMER_SLOP	100000
 #define NS_PER_TICK	(1000000000LL / HZ)
 
-static cycle_t xen_clocksource_read(void);
+cycle_t xen_clocksource_read(void);
 
 /* These are perodically updated in shared_info, and then copied here. */
 struct shadow_time_info {
@@ -304,7 +304,7 @@ static u64 get_nsec_offset(struct shadow_time_info *shadow)
 	return scale_delta(delta, shadow->tsc_to_nsec_mul, shadow->tsc_shift);
 }
 
-static cycle_t xen_clocksource_read(void)
+cycle_t xen_clocksource_read(void)
 {
 	struct shadow_time_info *shadow = &get_cpu_var(shadow_time);
 	cycle_t ret;
@@ -322,7 +322,7 @@ static cycle_t xen_clocksource_read(void)
 	return ret;
 }
 
-static void xen_read_wallclock(struct timespec *ts)
+void xen_read_wallclock(struct timespec *ts)
 {
 	const struct shared_info *s = HYPERVISOR_shared_info;
 	u32 version;
Signature · 8 lines
1.5.0.6


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
#8 lore raw

Re: [PATCH 3/3] [PATCH] kvmclock implementation, the guest part.

In reply to a message not in the archive

Hi,

arch/x86/xen/time.c line 31

Quoted 6 lines
arch/x86/xen/time.c +1 -1
index d083ff5..7728b87 100644
-static cycle_t xen_clocksource_read(void);
+cycle_t xen_clocksource_read(void);

Huh? You kill the static, but don't use the functions anywhere? Looks like half-done code sharing with xen paravirt clock ...

cheers,
Gerd

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#10 lore raw

Re: [PATCH 3/3] [PATCH] kvmclock implementation, the guest part.

In reply to a message not in the archive
Quoted 12 lines · Gerd Hoffmann

Hi,

arch/x86/xen/time.c line 31

Quoted 6 lines
arch/x86/xen/time.c +1 -1
index d083ff5..7728b87 100644
-static cycle_t xen_clocksource_read(void);
+cycle_t xen_clocksource_read(void);

Huh? You kill the static, but don't use the functions anywhere? Looks like half-done code sharing with xen paravirt clock ...

Quoted 3 lines

cheers,
Gerd

It's called experimentation. I was sure I deleted this part of the patch altogheter, but I must have
missed it. Thanks for the point out.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

Acked-by
#17 lore raw

Re: [PATCH 1/3] put kvm_para.h include outside __KERNEL__

In reply to a message not in the archive
Quoted 6 lines · On Friday 11 January 2008 18:40:54 Glauber de Oliveira Costa wrote:

kvm_para.h potentially contains definitions that are to be used by kvm-userspace, so it should not be included inside the __KERNEL__ block. To protect its own data structures, kvm_para.h already includes its own __KERNEL__ block.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#11 lore raw

Re: [PATCH 2/3] [PATCH] kvmclock - the host part.

In reply to a message not in the archive
Quoted 11 lines · Glauber de Oliveira Costa

This is the host part of kvm clocksource implementation. As it does not include clockevents, it is a fairly simple implementation. We only have to register a per-vcpu area, and start writting to it periodically.

The area is binary compatible with xen, as we use the same shadow_info structure.

include/asm-x86/kvm_para.h +0 -0
index c6f3fd8..abe412a 100644

include/asm-x86/kvm_para.h line 3

Quoted 3 lines
include/asm-x86/kvm_para.h +1 -0
@@ -1,5 +1,6 @@
 #ifndef __X86_KVM_PARA_H
 #define __X86_KVM_PARA_H
+#include <xen/interface/xen.h>

Can we abstract that out into a neutral header instead of including the Xen headers directly in KVM. Please rename the structure too to something neutral.

Including something as generic as xen/interface/xen.h when CONFIG_XEN may not be set is not a good thing, I believe.

Regards,

Anthony Liguori

Quoted 23 lines
include/asm-x86/kvm_para.h +4 -0
 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
  * should be used to determine that a VM is running under KVM.
@@ -10,9 +11,13 @@
  * paravirtualization, the appropriate feature bit should be checked.
  */
 #define KVM_CPUID_FEATURES	0x40000001
+#define KVM_FEATURE_CLOCKSOURCE 0
 
+#define MSR_PARAVIRT_CLOCK	0x11
 #ifdef __KERNEL__
 #include <asm/processor.h>
+extern void kvmclock_init(void);
+
 
 /* This instruction is vmcall.  On non-VT architectures, it will generate a
  * trap that we will then rewrite to the appropriate instruction.
include/linux/kvm.h +0 -0
index 4de4fd2..78ce53f 100644

include/linux/kvm.h struct kvm_vapic_addr { · line 238

Quoted 7 lines
include/linux/kvm.h +1 -0
@@ -232,6 +232,7 @@ struct kvm_vapic_addr {
 #define KVM_CAP_SET_TSS_ADDR 4
 #define KVM_CAP_EXT_CPUID 5
 #define KVM_CAP_VAPIC 6
+#define KVM_CAP_CLOCKSOURCE 7
 
 /*
  * ioctls for VM fds

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#18 lore raw
In reply to a message not in the archive
Quoted 10 lines · Glauber de Oliveira Costa

Hi folks,

A lot of time has been elapsed since I last sent a version of kvm clock, with a lot of things in the middle, including my vacations and a nasty bug in the clock itself ;-)

Here it is a new version. I'm following avi's last suggestion of using an msr to make it more migration-proof. If it's not approved, we can easily switch back to the hypercall mechanism. That's the easy part ;-)

Quoted 10 lines

Clock updates are done every time we're scheduled. It is _not_ enough to check if we're changing cpus, because the tsc will change its frequency when the cpu is idle (if using the mwait idle). So after a long idle period, one cpu will end up stepping ahead causing a backward time (remember the bug I talked about? :-) )

As I fell it ready for inclusion (which obviously does not mean it is perfect, nor that I don't value any further comments ), I'm also posting the userspace patches in a separate series that will follow shortly.

This patch series is looking good. I like the switch to an MSR.

Regards,

Anthony Liguori

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#16 lore raw

Re: [PATCH 2/3] [PATCH] kvmclock - the host part.

In reply to a message not in the archive
Quoted 7 lines · Glauber de Oliveira Costa

This is the host part of kvm clocksource implementation. As it does not include clockevents, it is a fairly simple implementation. We only have to register a per-vcpu area, and start writting to it periodically.

The area is binary compatible with xen, as we use the same shadow_info structure.

arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 418

Quoted 7 lines
arch/x86/kvm/x86.c +1 -1
@@ -412,7 +413,7 @@ static u32 msrs_to_save[] = {
 #ifdef CONFIG_X86_64
 	MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
 #endif
-	MSR_IA32_TIME_STAMP_COUNTER,
+	MSR_IA32_TIME_STAMP_COUNTER, MSR_PARAVIRT_CLOCK,
 };
 

Let us be good citizens and put the msr into our private MSR_KVM_* namespace.

Quoted 37 lines
arch/x86/kvm/x86.c +34 -0
+#define WC_OFFSET offsetof(struct shared_info, wc_version)
+
+static void kvm_write_guest_time(struct kvm_vcpu *v)
+{
+	struct timespec ts, wc_ts;
+	int wc_args[3]; /* version, wc_sec, wc_nsec */
+	unsigned long flags;
+	struct kvm_vcpu_arch *vcpu = &v->arch;
+
+	if (!vcpu->shared_info)
+		return;
+
+	/* Make the update of both version numbers visible to guest */
+	wc_args[0] = ++vcpu->wc_version;
+	kvm_write_guest(v->kvm, vcpu->shared_info + WC_OFFSET, wc_args,
+			sizeof(wc_args));
+	vcpu->hv_clock.version++;
+	kvm_write_guest(v->kvm, vcpu->clock_addr, &vcpu->hv_clock,
+			sizeof(vcpu->hv_clock));
+
+	/* Keep irq disabled to prevent changes to the clock */
+	local_irq_save(flags);
+	kvm_get_msr(v, MSR_IA32_TIME_STAMP_COUNTER,
+			  &vcpu->hv_clock.tsc_timestamp);
+	wc_ts = current_kernel_time();
+	ktime_get_ts(&ts);
+	local_irq_restore(flags);
+
+	/* With all the info we got, fill in the values */
+	wc_args[1] = wc_ts.tv_sec;
+	wc_args[2] = wc_ts.tv_nsec;
+	wc_args[0] = ++vcpu->wc_version;
+
+	vcpu->hv_clock.system_time = ts.tv_nsec +

arch/x86/kvm/x86.c static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) · line 514

Quoted 10 lines
arch/x86/kvm/x86.c +10 -0
+				     (NSEC_PER_SEC * (u64)ts.tv_sec);
+	vcpu->hv_clock.version++;
+
+	/* And finally, let the guest see them */
+	kvm_write_guest(v->kvm, vcpu->shared_info + WC_OFFSET, wc_args,
+			sizeof(wc_args));
+	kvm_write_guest(v->kvm, vcpu->clock_addr, &vcpu->hv_clock,
+			sizeof(vcpu->hv_clock));
+}
+

Why write things twice? This is per-vcpu, and the guest cannot see anything between the two writes.

Also, kvm_write_guest() needs mmap_sem for read. Suggest you grab the page using gfn_to_page() and kmap_atomic() it instead.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
#13 lore raw

Re: [PATCH 2/3] [PATCH] kvmclock - the host part.

In reply to a message not in the archive
Quoted 22 lines · Anthony Liguori
Quoted 11 lines · Glauber de Oliveira Costa

This is the host part of kvm clocksource implementation. As it does not include clockevents, it is a fairly simple implementation. We only have to register a per-vcpu area, and start writting to it periodically.

The area is binary compatible with xen, as we use the same shadow_info structure.

include/asm-x86/kvm_para.h +0 -0
index c6f3fd8..abe412a 100644

include/asm-x86/kvm_para.h line 4

Quoted 4 lines
include/asm-x86/kvm_para.h +1 -0
@@ -1,5 +1,6 @@
 #ifndef __X86_KVM_PARA_H
 #define __X86_KVM_PARA_H
+#include <xen/interface/xen.h>
 

Can we abstract that out into a neutral header instead of including the Xen headers directly in KVM. Please rename the structure too to something neutral.

Quoted 3 lines

Including something as generic as xen/interface/xen.h when CONFIG_XEN may not be set is not a good thing, I believe.

Well, one of the motivations behind this is to actually supply a Xen clock to Xen guests. So maybe we can call the feature a "kvm xenclock" instead and feel justified in including Xen headers.

However, you are probably right in that we are getting into a dependency and kconfig hell we do not yet deserve. Not even mentioning that CONFIG_XEN is a guest thing while kvmclock is also a host thing.

So we are probably better of using a non-Xen structure that accidentally happens to be binary compatible with the Xen interface. Stranger things have happened.

If we agree on this, please define _only_ the time-related parts so we have a decoupled interface. We'll need two msrs: one for wc and one for vcpu time.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
#15 lore raw

Re: [PATCH 2/3] [PATCH] kvmclock - the host part.

In reply to a message not in the archive
Quoted 33 lines · Avi Kivity
Quoted 24 lines · Anthony Liguori
Quoted 13 lines · Glauber de Oliveira Costa

This is the host part of kvm clocksource implementation. As it does not include clockevents, it is a fairly simple implementation. We only have to register a per-vcpu area, and start writting to it periodically.

The area is binary compatible with xen, as we use the same shadow_info structure.

include/asm-x86/kvm_para.h +0 -0
index c6f3fd8..abe412a 100644

include/asm-x86/kvm_para.h line 4

Quoted 4 lines
include/asm-x86/kvm_para.h +1 -0
@@ -1,5 +1,6 @@
 #ifndef __X86_KVM_PARA_H
 #define __X86_KVM_PARA_H
+#include <xen/interface/xen.h>
 

Can we abstract that out into a neutral header instead of including the Xen headers directly in KVM. Please rename the structure too to something neutral.

Quoted 3 lines

Including something as generic as xen/interface/xen.h when CONFIG_XEN may not be set is not a good thing, I believe.

Well, one of the motivations behind this is to actually supply a Xen clock to Xen guests. So maybe we can call the feature a "kvm xenclock" instead and feel justified in including Xen headers.

Quoted 8 lines

However, you are probably right in that we are getting into a dependency and kconfig hell we do not yet deserve. Not even mentioning that CONFIG_XEN is a guest thing while kvmclock is also a host thing.

So we are probably better of using a non-Xen structure that accidentally happens to be binary compatible with the Xen interface. Stranger things have happened.

Yes, this is what I meant. My concerns is dependencies and namespace pollution. I think using the same interface is a very Good Thing.

Regards,

Anthony Liguori

Quoted 4 lines

If we agree on this, please define _only_ the time-related parts so we have a decoupled interface. We'll need two msrs: one for wc and one for vcpu time.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace