Skip to contentSkip to conversation

viridian: unify time sources

PATCH In review Paul Durrant 3 participants 7 messages Jun 17, 2019 – Jun 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 viridian: unify time sources

Currently, the time_ref_count enlightened time source maintains an offset such that time is frozen when the domain paused, but the reference_tsc enlightened time source does not. After migrate, the reference_tsc source may become invalidated (e.g. because of host cpu frequency mismatch) which will cause Windows to fall back to time_ref_count. Thus, the guest will observe a jump in time equivalent to the offset.

This patch unifies the two enlightened time sources such that the same offset applies to both of them. Also, it's not really necessary to have two different functions to calculating a 10MHz counter value, time_now() and raw_trc_val(), so this patch removes the latter implementation. The unification also allows removal of the reference_tsc_valid flag.

Whilst in the area, this patch also takes the opportunity to constify a few pointers which were missed in earlier patches.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

v2:
- Expand comments above newly added TscOffset setting

---
 xen/arch/x86/hvm/viridian/time.c   | 105 +++++++++++++----------------
 xen/include/asm-x86/hvm/viridian.h |   1 -
 2 files changed, 45 insertions(+), 61 deletions(-)
xen/arch/x86/hvm/viridian/time.c +45 -60
index 2a3c9697d7..28e3d88ca9 100644
@@ -26,9 +26,10 @@ typedef struct _HV_REFERENCE_TSC_PAGE
     uint64_t Reserved2[509];
 } HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
 
-static void update_reference_tsc(struct domain *d, bool initialize)
+static void update_reference_tsc(const struct domain *d, bool initialize)
 {
     struct viridian_domain *vd = d->arch.hvm.viridian;
+    const struct viridian_time_ref_count *trc = &vd->time_ref_count;
     const struct viridian_page *rt = &vd->reference_tsc;
     HV_REFERENCE_TSC_PAGE *p = rt->ptr;
     uint32_t seq;
@@ -44,7 +45,9 @@ static void update_reference_tsc(struct domain *d, bool initialize)
      * with this, allowing vtsc to be turned off, but support for this is
      * not yet present in the hypervisor. Thus is it is possible that
      * migrating a Windows VM between hosts of differing TSC frequencies
-     * may result in large differences in guest performance.
+     * may result in large differences in guest performance. Any jump in
+     * TSC due to migration down-time can, however, be compensated for by
+     * setting the TscOffset value (see below).
      */
     if ( !host_tsc_is_safe() || d->arch.vtsc )
     {
@@ -62,8 +65,6 @@ static void update_reference_tsc(struct domain *d, bool initialize)
 
         printk(XENLOG_G_INFO "d%d: VIRIDIAN REFERENCE_TSC: invalidated\n",
                d->domain_id);
-
-        vd->reference_tsc_valid = false;
         return;
     }
 
@@ -75,8 +76,11 @@ static void update_reference_tsc(struct domain *d, bool initialize)
      *
      * Windows uses a 100ns tick, so we need a scale which is cpu
      * ticks per 100ns shifted left by 64.
+     * The offset value is calculated on restore after migration and
+     * ensures that Windows will not see a large jump in ReferenceTime.
      */
     p->TscScale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
+    p->TscOffset = trc->off;
     smp_wmb();
 
     seq = p->TscSequence + 1;
@@ -84,46 +88,6 @@ static void update_reference_tsc(struct domain *d, bool initialize)
         seq = 1;
 
     p->TscSequence = seq;
-    vd->reference_tsc_valid = true;
-}
-
-static int64_t raw_trc_val(const struct domain *d)
-{
-    uint64_t tsc;
-    struct time_scale tsc_to_ns;
-
-    tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
-
-    /* convert tsc to count of 100ns periods */
-    set_time_scale(&tsc_to_ns, d->arch.tsc_khz * 1000ul);
-    return scale_delta(tsc, &tsc_to_ns) / 100ul;
-}
-
-static void time_ref_count_freeze(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    if ( test_and_clear_bit(_TRC_running, &trc->flags) )
-        trc->val = raw_trc_val(d) + trc->off;
-}
-
-static void time_ref_count_thaw(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    if ( !d->is_shutting_down &&
-         !test_and_set_bit(_TRC_running, &trc->flags) )
-        trc->off = (int64_t)trc->val - raw_trc_val(d);
-}
-
-static int64_t time_ref_count(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    return raw_trc_val(d) + trc->off;
 }
 
 /*
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
  * 128 bit number which is then shifted 64 times to the right to obtain
  * the high 64 bits."
  */
-static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
+static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, int64_t offset)
 {
     uint64_t result;
 
@@ -153,22 +117,46 @@ static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
     return result + offset;
 }
 
-static uint64_t time_now(struct domain *d)
+static uint64_t trc_val(const struct domain *d, int64_t offset)
 {
     uint64_t tsc, scale;
 
-    /*
-     * If the reference TSC page is not enabled, or has been invalidated
-     * fall back to the partition reference counter.
-     */
-    if ( !d->arch.hvm.viridian->reference_tsc_valid )
-        return time_ref_count(d);
-
-    /* Otherwise compute reference time in the same way the guest would */
     tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
     scale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
 
-    return scale_tsc(tsc, scale, 0);
+    return scale_tsc(tsc, scale, offset);
+}
+
+static void time_ref_count_freeze(const struct domain *d)
+{
+    struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
+
+    if ( test_and_clear_bit(_TRC_running, &trc->flags) )
+        trc->val = trc_val(d, trc->off);
+}
+
+static void time_ref_count_thaw(const struct domain *d)
+{
+    struct viridian_domain *vd = d->arch.hvm.viridian;
+    struct viridian_time_ref_count *trc = &vd->time_ref_count;
+
+    if ( d->is_shutting_down ||
+         test_and_set_bit(_TRC_running, &trc->flags) )
+        return;
+
+    trc->off = (int64_t)trc->val - trc_val(d, 0);
+
+    if ( vd->reference_tsc.msr.enabled )
+        update_reference_tsc(d, false);
+}
+
+static int64_t time_ref_count(const struct domain *d)
+{
+    const struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
+
+    return trc_val(d, trc->off);
 }
 
 static void stop_stimer(struct viridian_stimer *vs)
@@ -196,7 +184,7 @@ static void start_stimer(struct viridian_stimer *vs)
     const struct vcpu *v = vs->v;
     struct viridian_vcpu *vv = v->arch.hvm.viridian;
     unsigned int stimerx = vs - &vv->stimer[0];
-    int64_t now = time_now(v->domain);
+    int64_t now = time_ref_count(v->domain);
     int64_t expiration;
     s_time_t timeout;
 
@@ -285,7 +273,7 @@ static void poll_stimer(struct vcpu *v, unsigned int stimerx)
 
     if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
                                            stimerx, vs->expiration,
-                                           time_now(v->domain)) )
+                                           time_ref_count(v->domain)) )
         return;
 
     clear_bit(stimerx, &vv->stimer_pending);
@@ -641,10 +629,7 @@ void viridian_time_load_domain_ctxt(
     vd->reference_tsc.msr.raw = ctxt->reference_tsc;
 
     if ( vd->reference_tsc.msr.enabled )
-    {
         viridian_map_guest_page(d, &vd->reference_tsc);
-        update_reference_tsc(d, false);
-    }
 }
 
 /*
xen/include/asm-x86/hvm/viridian.h +0 -1
index 54e46cc4c4..010c8b58d4 100644
@@ -116,7 +116,6 @@ struct viridian_domain
     union viridian_page_msr hypercall_gpa;
     struct viridian_time_ref_count time_ref_count;
     struct viridian_page reference_tsc;
-    bool reference_tsc_valid;
 };
 
 void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

Ping?

Quoted 241 lines

-----Original Message-----
From: Paul Durrant <[email protected]>
Sent: 17 June 2019 09:24
To: [email protected]
Cc: Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>
Subject: [PATCH v2] viridian: unify time sources

Currently, the time_ref_count enlightened time source maintains an offset such that time is frozen when the domain paused, but the reference_tsc enlightened time source does not. After migrate, the reference_tsc source may become invalidated (e.g. because of host cpu frequency mismatch) which will cause Windows to fall back to time_ref_count. Thus, the guest will observe a jump in time equivalent to the offset.

This patch unifies the two enlightened time sources such that the same offset applies to both of them. Also, it's not really necessary to have two different functions to calculating a 10MHz counter value, time_now() and raw_trc_val(), so this patch removes the latter implementation. The unification also allows removal of the reference_tsc_valid flag.

Whilst in the area, this patch also takes the opportunity to constify a few pointers which were missed in earlier patches.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

v2:
- Expand comments above newly added TscOffset setting

---
 xen/arch/x86/hvm/viridian/time.c   | 105 +++++++++++++----------------
 xen/include/asm-x86/hvm/viridian.h |   1 -
 2 files changed, 45 insertions(+), 61 deletions(-)
xen/arch/x86/hvm/viridian/time.c +45 -60
index 2a3c9697d7..28e3d88ca9 100644
@@ -26,9 +26,10 @@ typedef struct _HV_REFERENCE_TSC_PAGE
     uint64_t Reserved2[509];
 } HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
 
-static void update_reference_tsc(struct domain *d, bool initialize)
+static void update_reference_tsc(const struct domain *d, bool initialize)
 {
     struct viridian_domain *vd = d->arch.hvm.viridian;
+    const struct viridian_time_ref_count *trc = &vd->time_ref_count;
     const struct viridian_page *rt = &vd->reference_tsc;
     HV_REFERENCE_TSC_PAGE *p = rt->ptr;
     uint32_t seq;
@@ -44,7 +45,9 @@ static void update_reference_tsc(struct domain *d, bool initialize)
      * with this, allowing vtsc to be turned off, but support for this is
      * not yet present in the hypervisor. Thus is it is possible that
      * migrating a Windows VM between hosts of differing TSC frequencies
-     * may result in large differences in guest performance.
+     * may result in large differences in guest performance. Any jump in
+     * TSC due to migration down-time can, however, be compensated for by
+     * setting the TscOffset value (see below).
      */
     if ( !host_tsc_is_safe() || d->arch.vtsc )
     {
@@ -62,8 +65,6 @@ static void update_reference_tsc(struct domain *d, bool initialize)
 
         printk(XENLOG_G_INFO "d%d: VIRIDIAN REFERENCE_TSC: invalidated\n",
                d->domain_id);
-
-        vd->reference_tsc_valid = false;
         return;
     }
 
@@ -75,8 +76,11 @@ static void update_reference_tsc(struct domain *d, bool initialize)
      *
      * Windows uses a 100ns tick, so we need a scale which is cpu
      * ticks per 100ns shifted left by 64.
+     * The offset value is calculated on restore after migration and
+     * ensures that Windows will not see a large jump in ReferenceTime.
      */
     p->TscScale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
+    p->TscOffset = trc->off;
     smp_wmb();
 
     seq = p->TscSequence + 1;
@@ -84,46 +88,6 @@ static void update_reference_tsc(struct domain *d, bool initialize)
         seq = 1;
 
     p->TscSequence = seq;
-    vd->reference_tsc_valid = true;
-}
-
-static int64_t raw_trc_val(const struct domain *d)
-{
-    uint64_t tsc;
-    struct time_scale tsc_to_ns;
-
-    tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
-
-    /* convert tsc to count of 100ns periods */
-    set_time_scale(&tsc_to_ns, d->arch.tsc_khz * 1000ul);
-    return scale_delta(tsc, &tsc_to_ns) / 100ul;
-}
-
-static void time_ref_count_freeze(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    if ( test_and_clear_bit(_TRC_running, &trc->flags) )
-        trc->val = raw_trc_val(d) + trc->off;
-}
-
-static void time_ref_count_thaw(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    if ( !d->is_shutting_down &&
-         !test_and_set_bit(_TRC_running, &trc->flags) )
-        trc->off = (int64_t)trc->val - raw_trc_val(d);
-}
-
-static int64_t time_ref_count(const struct domain *d)
-{
-    struct viridian_time_ref_count *trc =
-        &d->arch.hvm.viridian->time_ref_count;
-
-    return raw_trc_val(d) + trc->off;
 }
 
 /*
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
  * 128 bit number which is then shifted 64 times to the right to obtain
  * the high 64 bits."
  */
-static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
+static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, int64_t offset)
 {
     uint64_t result;
 
@@ -153,22 +117,46 @@ static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
     return result + offset;
 }
 
-static uint64_t time_now(struct domain *d)
+static uint64_t trc_val(const struct domain *d, int64_t offset)
 {
     uint64_t tsc, scale;
 
-    /*
-     * If the reference TSC page is not enabled, or has been invalidated
-     * fall back to the partition reference counter.
-     */
-    if ( !d->arch.hvm.viridian->reference_tsc_valid )
-        return time_ref_count(d);
-
-    /* Otherwise compute reference time in the same way the guest would */
     tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
     scale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
 
-    return scale_tsc(tsc, scale, 0);
+    return scale_tsc(tsc, scale, offset);
+}
+
+static void time_ref_count_freeze(const struct domain *d)
+{
+    struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
+
+    if ( test_and_clear_bit(_TRC_running, &trc->flags) )
+        trc->val = trc_val(d, trc->off);
+}
+
+static void time_ref_count_thaw(const struct domain *d)
+{
+    struct viridian_domain *vd = d->arch.hvm.viridian;
+    struct viridian_time_ref_count *trc = &vd->time_ref_count;
+
+    if ( d->is_shutting_down ||
+         test_and_set_bit(_TRC_running, &trc->flags) )
+        return;
+
+    trc->off = (int64_t)trc->val - trc_val(d, 0);
+
+    if ( vd->reference_tsc.msr.enabled )
+        update_reference_tsc(d, false);
+}
+
+static int64_t time_ref_count(const struct domain *d)
+{
+    const struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
+
+    return trc_val(d, trc->off);
 }
 
 static void stop_stimer(struct viridian_stimer *vs)
@@ -196,7 +184,7 @@ static void start_stimer(struct viridian_stimer *vs)
     const struct vcpu *v = vs->v;
     struct viridian_vcpu *vv = v->arch.hvm.viridian;
     unsigned int stimerx = vs - &vv->stimer[0];
-    int64_t now = time_now(v->domain);
+    int64_t now = time_ref_count(v->domain);
     int64_t expiration;
     s_time_t timeout;
 
@@ -285,7 +273,7 @@ static void poll_stimer(struct vcpu *v, unsigned int stimerx)
 
     if ( !viridian_synic_deliver_timer_msg(v, vs->config.sintx,
                                            stimerx, vs->expiration,
-                                           time_now(v->domain)) )
+                                           time_ref_count(v->domain)) )
         return;
 
     clear_bit(stimerx, &vv->stimer_pending);
@@ -641,10 +629,7 @@ void viridian_time_load_domain_ctxt(
     vd->reference_tsc.msr.raw = ctxt->reference_tsc;
 
     if ( vd->reference_tsc.msr.enabled )
-    {
         viridian_map_guest_page(d, &vd->reference_tsc);
-        update_reference_tsc(d, false);
-    }
 }
 
 /*
xen/include/asm-x86/hvm/viridian.h +0 -2
index 54e46cc4c4..010c8b58d4 100644
@@ -116,7 +116,6 @@ struct viridian_domain
     union viridian_page_msr hypercall_gpa;
     struct viridian_time_ref_count time_ref_count;
     struct viridian_page reference_tsc;
-    bool reference_tsc_valid;
 };
 
 void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
--
Quoted 1 line

2.20.1.2.gb21ebb671

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Paul Durrant

xen/arch/x86/hvm/viridian/time.c static int64_t time_ref_count(const struct domain *d) · line 102

Quoted 5 lines

/*

xen/arch/x86/hvm/viridian/time.c +0 -0
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
   * 128 bit number which is then shifted 64 times to the right to obtain
   * the high 64 bits."
   */

Is there a good reason for using signed offset here? If so then maybe you should change the return type or check for bounds.

Quoted 18 lines
xen/arch/x86/hvm/viridian/time.c +2 -6
-static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
+static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, int64_t offset)
  {
      uint64_t result;
 
@@ -153,22 +117,46 @@ static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
      return result + offset;
  }
 
-static uint64_t time_now(struct domain *d)
+static uint64_t trc_val(const struct domain *d, int64_t offset)
  {
      uint64_t tsc, scale;
 
-    /*
-     * If the reference TSC page is not enabled, or has been invalidated
-     * fall back to the partition reference counter.
-     */

xen/arch/x86/hvm/viridian/time.c static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset) · line 128

Quoted 10 lines
xen/arch/x86/hvm/viridian/time.c +2 -5
-    if ( !d->arch.hvm.viridian->reference_tsc_valid )
-        return time_ref_count(d);
-
-    /* Otherwise compute reference time in the same way the guest would */
      tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
      scale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
 
-    return scale_tsc(tsc, scale, 0);
+    return scale_tsc(tsc, scale, offset);
+}

Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 8 lines

-----Original Message-----
From: Alexandru Stefan ISAILA <[email protected]>
Sent: 21 June 2019 14:49
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] viridian: unify time sources

Quoted 8 lines

xen/arch/x86/hvm/viridian/time.c static int64_t time_ref_count(const struct domain *d) · line 102

Quoted 5 lines

/*

xen/arch/x86/hvm/viridian/time.c +0 -0
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
   * 128 bit number which is then shifted 64 times to the right to obtain
   * the high 64 bits."
   */

Is there a good reason for using signed offset here? If so then maybe you should change the return type or check for bounds.

The offset is actually negative most of the time but the resulting reference time should be unsigned so the return type of time_ref_count() does need fixing.

Paul

Quoted 26 lines
Quoted 26 lines
xen/arch/x86/hvm/viridian/time.c +2 -10
-static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
+static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, int64_t offset)
  {
      uint64_t result;
 
@@ -153,22 +117,46 @@ static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset)
      return result + offset;
  }
 
-static uint64_t time_now(struct domain *d)
+static uint64_t trc_val(const struct domain *d, int64_t offset)
  {
      uint64_t tsc, scale;
 
-    /*
-     * If the reference TSC page is not enabled, or has been invalidated
-     * fall back to the partition reference counter.
-     */
-    if ( !d->arch.hvm.viridian->reference_tsc_valid )
-        return time_ref_count(d);
-
-    /* Otherwise compute reference time in the same way the guest would */
      tsc = hvm_get_guest_tsc(pt_global_vcpu_target(d));
      scale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
 
Quoted 5 lines

xen/arch/x86/hvm/viridian/time.c static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, uint64_t offset) · line 128

Quoted 3 lines
xen/arch/x86/hvm/viridian/time.c +2 -1
-    return scale_tsc(tsc, scale, 0);
+    return scale_tsc(tsc, scale, offset);
+}

Alex

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 19 lines
Quoted 6 lines
Quoted 1 line · On 21.06.19 at 15:58, <[email protected]> wrote:

-----Original Message-----
From: Alexandru Stefan ISAILA <[email protected]>
Sent: 21 June 2019 14:49
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Jan Beulich

<[email protected]>;

Quoted 11 lines

Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] viridian: unify time sources

xen/arch/x86/hvm/viridian/time.c static int64_t time_ref_count(const struct domain *d) · line 102

Quoted 5 lines

/*

xen/arch/x86/hvm/viridian/time.c +0 -0
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
   * 128 bit number which is then shifted 64 times to the right to obtain
   * the high 64 bits."
   */

Is there a good reason for using signed offset here? If so then maybe you should change the return type or check for bounds.

Quoted 3 lines

The offset is actually negative most of the time but the resulting reference time should be unsigned so the return type of time_ref_count() does need fixing.

Is switching it from int64_t to uint64_t all that's needed? I could do this while committing (which I was about to).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 21 June 2019 16:21
To: Paul Durrant <[email protected]>
Cc: [email protected]; Andrew Cooper <[email protected]>; Roger Pau Monne <[email protected]>; xen-devel <[email protected]>; WeiLiu <[email protected]>
Subject: RE: [Xen-devel] [PATCH v2] viridian: unify time sources

Quoted 19 lines
Quoted 6 lines
Quoted 1 line · On 21.06.19 at 15:58, <[email protected]> wrote:

-----Original Message-----
From: Alexandru Stefan ISAILA <[email protected]>
Sent: 21 June 2019 14:49
To: Paul Durrant <[email protected]>; [email protected]
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Jan Beulich

<[email protected]>;

Quoted 11 lines

Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] viridian: unify time sources

xen/arch/x86/hvm/viridian/time.c static int64_t time_ref_count(const struct domain *d) · line 102

Quoted 5 lines

/*

xen/arch/x86/hvm/viridian/time.c +0 -0
@@ -136,7 +100,7 @@ static int64_t time_ref_count(const struct domain *d)
   * 128 bit number which is then shifted 64 times to the right to obtain
   * the high 64 bits."
   */

Is there a good reason for using signed offset here? If so then maybe you should change the return type or check for bounds.

Quoted 6 lines
Quoted 3 lines

The offset is actually negative most of the time but the resulting reference time should be unsigned so the return type of time_ref_count() does need fixing.

Is switching it from int64_t to uint64_t all that's needed? I could do this while committing (which I was about to).

Yes, that's all that's needed and it would be nice to avoid sending a v3.

Thanks,

Paul

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v2 1/1
#6 lore raw
In reply to Paul Durrant
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 17.06.19 at 10:23, <[email protected]> wrote:

Currently, the time_ref_count enlightened time source maintains an offset such that time is frozen when the domain paused, but the reference_tsc enlightened time source does not. After migrate, the reference_tsc source may become invalidated (e.g. because of host cpu frequency mismatch) which will cause Windows to fall back to time_ref_count. Thus, the guest will observe a jump in time equivalent to the offset.

This patch unifies the two enlightened time sources such that the same offset applies to both of them. Also, it's not really necessary to have two different functions to calculating a 10MHz counter value, time_now() and raw_trc_val(), so this patch removes the latter implementation. The unification also allows removal of the reference_tsc_valid flag.

Quoted 4 lines

Whilst in the area, this patch also takes the opportunity to constify a few pointers which were missed in earlier patches.

This looks okay to me now, but I don't feel qualified to give an R-b. While not strictly applicable for a file maintained by you,

will have to do here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel