Skip to contentSkip to conversation

x86/vtsc: update vcpu_time in hvm_set_guest_time

PATCH In review Roger Pau Monne 5 participants 9 messages Jun 4, 2013 – Jun 6, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86/vtsc: update vcpu_time in hvm_set_guest_time

When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset, which is used in the vcpu time structure to calculate the tsc_timestamp, so after updating stime_offset we need to propagate the change to vcpu_time in order for the guest to get the right time if using the PV clock.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc George Dunlap <[email protected]>

---
Changes since v2:
* Check for v == current instead of v->is_running to know if the vcpu is running.
Changes since v1:
* Perform the call to update_vcpu_system_time in hvm_set_guest_time if the offset has changed and the vCPU is running.

---
 xen/arch/x86/hvm/vpt.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/vpt.c +12 -1
index 8dee662..4b1e1a3 100644
@@ -57,7 +57,18 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
 void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
 {
-    v->arch.hvm_vcpu.stime_offset += guest_time - hvm_get_guest_time(v);
+    u64 offset = guest_time - hvm_get_guest_time(v);
+
+    if ( offset ) {
+        v->arch.hvm_vcpu.stime_offset += offset;
+        /*
+         * If hvm_vcpu.stime_offset is updated make sure to
+         * also update vcpu time, since this value is used to
+         * calculate the TSC.
+         */
+        if ( v == current )
+            update_vcpu_system_time(v);
+    }
 }
 
 static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Roger Pau Monne

When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset, which is used in the vcpu time structure to calculate the tsc_timestamp, so after updating stime_offset we need to propagate the change to vcpu_time in order for the guest to get the right time if using the PV clock.

Quoted 8 lines
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc George Dunlap <[email protected]>

---
Changes since v2:
* Check for v == current instead of v->is_running to know if the vcpu is running.

It might not be bad at some point to add an ASSERT() in __update_vcpu_system_time() that v == current.

-George

Tested-by on v3 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset, which is used in the vcpu time structure to calculate the tsc_timestamp, so after updating stime_offset we need to propagate the change to vcpu_time in order for the guest to get the right time if using the PV clock.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc George Dunlap <[email protected]>
Quoted 25 lines

---
Changes since v2:
* Check for v == current instead of v->is_running to know if the vcpu is running.
Changes since v1:
* Perform the call to update_vcpu_system_time in hvm_set_guest_time if the offset has changed and the vCPU is running.

---
  xen/arch/x86/hvm/vpt.c |   13 ++++++++++++-
  1 files changed, 12 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/vpt.c +5 -1
index 8dee662..4b1e1a3 100644
@@ -57,7 +57,18 @@ u64 hvm_get_guest_time(struct vcpu *v)
 
  void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
  {
-    v->arch.hvm_vcpu.stime_offset += guest_time - hvm_get_guest_time(v);
+    u64 offset = guest_time - hvm_get_guest_time(v);
+
+    if ( offset ) {
+        v->arch.hvm_vcpu.stime_offset += offset;
+        /*

xen/arch/x86/hvm/vpt.c u64 hvm_get_guest_time(struct vcpu *v) · line 74

Quoted 10 lines
xen/arch/x86/hvm/vpt.c +7 -0
+         * If hvm_vcpu.stime_offset is updated make sure to
+         * also update vcpu time, since this value is used to
+         * calculate the TSC.
+         */
+        if ( v == current )
+            update_vcpu_system_time(v);
+    }
  }
 
  static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Thanks,
Diana

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 42 lines · Diana Crisan
Quoted 10 lines · Roger Pau Monne

When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset, which is used in the vcpu time structure to calculate the tsc_timestamp, so after updating stime_offset we need to propagate the change to vcpu_time in order for the guest to get the right time if using the PV clock.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc George Dunlap <[email protected]>
Quoted 30 lines

---
Changes since v2:
* Check for v == current instead of v->is_running to know if the vcpu is running.
Changes since v1:
* Perform the call to update_vcpu_system_time in hvm_set_guest_time if the offset has changed and the vCPU is running.

---
  xen/arch/x86/hvm/vpt.c |   13 ++++++++++++-
  1 files changed, 12 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/vpt.c +10 -1
index 8dee662..4b1e1a3 100644
@@ -57,7 +57,18 @@ u64 hvm_get_guest_time(struct vcpu *v)
    void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
  {
-    v->arch.hvm_vcpu.stime_offset += guest_time - 
 hvm_get_guest_time(v);
+    u64 offset = guest_time - hvm_get_guest_time(v);
+
+    if ( offset ) {
+        v->arch.hvm_vcpu.stime_offset += offset;
+        /*
+         * If hvm_vcpu.stime_offset is updated make sure to
+         * also update vcpu time, since this value is used to
+         * calculate the TSC.
+         */
+        if ( v == current )
Quoted 8 lines

xen/arch/x86/hvm/vpt.c u64 hvm_get_guest_time(struct vcpu *v)

Quoted 5 lines
xen/arch/x86/hvm/vpt.c +2 -0
+            update_vcpu_system_time(v);
+    }
  }
    static int pt_irq_vector(struct periodic_time *pt, enum 
 hvm_intsrc src)

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Great, thanks Diana.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
Quoted 52 lines · George Dunlap
Quoted 42 lines · Diana Crisan
Quoted 10 lines · Roger Pau Monne

When using a vtsc, hvm_set_guest_time changes hvm_vcpu.stime_offset, which is used in the vcpu time structure to calculate the tsc_timestamp, so after updating stime_offset we need to propagate the change to vcpu_time in order for the guest to get the right time if using the PV clock.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc George Dunlap <[email protected]>
Quoted 30 lines

---
Changes since v2:
* Check for v == current instead of v->is_running to know if the vcpu is running.
Changes since v1:
* Perform the call to update_vcpu_system_time in hvm_set_guest_time if the offset has changed and the vCPU is running.

---
  xen/arch/x86/hvm/vpt.c |   13 ++++++++++++-
  1 files changed, 12 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/vpt.c +10 -1
index 8dee662..4b1e1a3 100644
@@ -57,7 +57,18 @@ u64 hvm_get_guest_time(struct vcpu *v)
    void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
  {
-    v->arch.hvm_vcpu.stime_offset += guest_time - 
 hvm_get_guest_time(v);
+    u64 offset = guest_time - hvm_get_guest_time(v);
+
+    if ( offset ) {
+        v->arch.hvm_vcpu.stime_offset += offset;
+        /*
+         * If hvm_vcpu.stime_offset is updated make sure to
+         * also update vcpu time, since this value is used to
+         * calculate the TSC.
+         */
+        if ( v == current )
Quoted 8 lines

xen/arch/x86/hvm/vpt.c u64 hvm_get_guest_time(struct vcpu *v)

Quoted 5 lines
xen/arch/x86/hvm/vpt.c +2 -0
+            update_vcpu_system_time(v);
+    }
  }
    static int pt_irq_vector(struct periodic_time *pt, enum 
 hvm_intsrc src)

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Quoted 2 lines

Great, thanks Diana.

No problem.

On a side note, the patch applied cleanly to 4.2.2 and it works as expected too.

Quoted 2 lines

-George

--
Diana

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
In reply to George Dunlap

George, Roger,

Quoted 8 lines · --On 5 June 2013 14:06:09 +0100 George Dunlap <[email protected]>…
Quoted 6 lines

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Great, thanks Diana.

I see this has made master: commit 32c864a35ece2c24a336d183869a546798a4b241.

Do you plan to backport this to 4.2? Diana has verified it applies and fixes the same issue there.

Signature · 1 line
Alex Bligh
#6 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Alex Bligh
Quoted 7 lines · --On 5 June 2013 14:06:09 +0100 George Dunlap <[email protected]>…
Quoted 6 lines

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Quoted 6 lines
Quoted 1 line

Great, thanks Diana.

I see this has made master: commit 32c864a35ece2c24a336d183869a546798a4b241.

Do you plan to backport this to 4.2? Diana has verified it applies and fixes the same issue there.

Yes, I have this on my list of pending backports, but currently there's no rush.

Jan

#7 lore raw
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Alex Bligh
Quoted 6 lines · --On 5 June 2013 14:06:09 +0100 George Dunlap <[email protected]>…
Quoted 6 lines

I have tested this patch and I have not been able to reproduce the guest stuck-clock problem we were seeing before (see *HVM Migration of domU on Qemu-upstream DM causes stuck system clock with ACPI* for details of the problem).
Note: this was tested without the temporary fix to our problem ( which is specifying tsc_mode='native_paravirt').

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Great, thanks Diana.

I see this has made master: commit 32c864a35ece2c24a336d183869a546798a4b241.

Do you plan to backport this to 4.2? Diana has verified it applies and fixes the same issue there.

Yes, I have this on my list of pending backports, but currently there's no rush.

...but thank you for chasing it to make sure that it was on somebody's list and didn't get forgotten. :-)

-George