Skip to contentSkip to conversation

x86/viridian: Add Partition Reference Time enlightenment

PATCH New Paul Durrant 1 participant 1 message Jan 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 x86/viridian: Add Partition Reference Time enlightenment

The presence of the partition reference time enlightenment persuades newer versions of Windows to prefer the TSC as their primary time source. Hence, if rdtsc is not being emulated and is invariant then many vmexits (for alternative time sources such as the HPET or reference counter MSR) can be avoided.

The implementation is not yet complete as no attempt is made to prevent emulation of rdtsc if the enlightenment is active and guest and host TSC frequencies differ. To do that requires invasive changes in the core x86 time code and hence a lot more testing.

This patch avoids the issue by disabling the enlightenment if rdtsc is being emulated, causing Windows to choose another time source. This is safe, but may cause a big variation in performance of guests migrated between hosts of differing TSC frequency. Thus the enlightenment is not enabled in the default set, but may be enabled to improve guest performance where such migrations are not a concern.

See section 15.4 of the Microsoft Hypervisor Top Level Functional Specification v4.0a for details.

---
v5:
- Re-based to staging

 docs/man/xl.cfg.pod.5                  |    6 ++
 tools/libxl/libxl_dom.c                |    3 +
 tools/libxl/libxl_types.idl            |    1 +
 xen/arch/x86/hvm/viridian.c            |  111 ++++++++++++++++++++++++++++++++
 xen/include/asm-x86/hvm/viridian.h     |   25 +++++++
 xen/include/public/arch-x86/hvm/save.h |   11 ++++
 xen/include/public/hvm/params.h        |    7 +-
 7 files changed, 163 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +6 -0
index 622ea53..e2f91fc 100644
@@ -1231,6 +1231,12 @@ This group incorporates Partition Time Reference Counter MSR. This
 enlightenment can improve performance of Windows 8 and Windows
 Server 2012 onwards.
 
+=item B<reference_tsc>
+
+This set incorporates the Partition Reference TSC MSR. This
+enlightenment can improve performance of Windows 7 and Windows
+Server 2008 R2 onwards.
+
 =item B<defaults>
 
 This is a special value that enables the default set of groups, which
tools/libxl/libxl_dom.c +3 -0
index 1d33a18..48d661a 100644
@@ -263,6 +263,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_TIME_REF_COUNT))
         mask |= HVMPV_time_ref_count;
 
+    if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_REFERENCE_TSC))
+        mask |= HVMPV_reference_tsc;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +1 -0
index f7fc695..1214d2e 100644
@@ -192,6 +192,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [
     (0, "base"),
     (1, "freq"),
     (2, "time_ref_count"),
+    (3, "reference_tsc"),
     ])
 
 #
xen/arch/x86/hvm/viridian.c +111 -0

165 lines not on this page · raw message

xen/include/asm-x86/hvm/viridian.h +25 -0
index 4cab2e8..c4319d7 100644
@@ -61,11 +61,36 @@ struct viridian_time_ref_count
     int64_t off;
 };
 
+union viridian_reference_tsc
+{
+    uint64_t raw;
+    struct
+    {
+        uint64_t enabled:1;
+        uint64_t reserved_preserved:11;
+        uint64_t pfn:48;
+    } fields;
+};
+
+/*
+ * Type defintion as in Microsoft Hypervisor Top-Level Functional
+ * Specification v4.0a, section 15.4.2.
+ */
+typedef struct _HV_REFERENCE_TSC_PAGE
+{
+    uint32_t TscSequence;
+    uint32_t Reserved1;
+    uint64_t TscScale;
+    int64_t  TscOffset;
+    uint64_t Reserved2[509];
+} HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
+
 struct viridian_domain
 {
     union viridian_guest_os_id guest_os_id;
     union viridian_hypercall_gpa hypercall_gpa;
     struct viridian_time_ref_count time_ref_count;
+    union viridian_reference_tsc reference_tsc;
 };
 
 int
xen/include/public/arch-x86/hvm/save.h +11 -0
index 88aab7e..efb0b62 100644
@@ -569,6 +569,7 @@ struct hvm_viridian_domain_context {
     uint64_t hypercall_gpa;
     uint64_t guest_os_id;
     uint64_t time_ref_count;
+    uint64_t reference_tsc;
 };
 
 DECLARE_HVM_SAVE_TYPE(VIRIDIAN_DOMAIN, 15, struct hvm_viridian_domain_context);
@@ -617,3 +618,13 @@ struct hvm_msr {
 #define HVM_SAVE_CODE_MAX 20
 
 #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/public/hvm/params.h +6 -1
index 3c51072..a2d43bc 100644
@@ -92,10 +92,15 @@
 #define _HVMPV_time_ref_count 2
 #define HVMPV_time_ref_count  (1 << _HVMPV_time_ref_count)
 
+/* Enable Reference TSC Page (HV_X64_MSR_REFERENCE_TSC) */
+#define _HVMPV_reference_tsc 3
+#define HVMPV_reference_tsc  (1 << _HVMPV_reference_tsc)
+
 #define HVMPV_feature_mask \
 	(HVMPV_base_freq | \
 	 HVMPV_no_freq | \
-	 HVMPV_time_ref_count)
+	 HVMPV_time_ref_count | \
+	 HVMPV_reference_tsc)
 
 #endif
 
Signature · 1 line
1.7.10.4