Skip to contentSkip to conversation

svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

PATCH In review Boris Ostrovsky 6 participants 19 messages Apr 20, 2012 – Apr 25, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

xen/arch/x86/hvm/svm/svm.c +7 -1
diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
Acked-by Tested-by on v1 1/1
#1 lore raw

Please also backport this patch to xen-4.1. Thanks.

-Wei

-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Thursday, April 19, 2012 9:21 PM
To: [email protected]; [email protected]
Cc: Ostrovsky, Boris; Huang2, Wei; [email protected]
Subject: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

xen/arch/x86/hvm/svm/svm.c +7 -1
diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#2 lore raw
In reply to Boris Ostrovsky
Quoted 7 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 6 lines

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

-- Keir

Quoted 24 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c Thu Apr 19 18:39:30 2012 -0400 renamed from xen/arch/x86/hvm/svm/svm.c Wed Apr 18 16:49:55 2012 +0100 +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#3 lore raw
Quoted 12 lines · Keir Fraser
Quoted 10 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Oh, and apart from that, we're also in feature freeze for 4.2, and this isn't a bug fix. Similarly, it's not really a candidate for the stable 4.1 branch either, at any time.

-- Keir

Quoted 28 lines

-- Keir

Quoted 24 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c Thu Apr 19 18:39:30 2012 -0400 renamed from xen/arch/x86/hvm/svm/svm.c Wed Apr 18 16:49:55 2012 +0100 +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#4 lore raw

Hi Keir,

This patch is a bug fix for 23437:d7c755c25bb9 than new feature. It slipped my hand and Boris fixed it for me. The same applies to Xen-4.1.

===== Changeset 23437 =====

HVM/SVM: enable tsc scaling ratio for SVM

Future AMD CPUs support TSC scaling. It allows guests to have a different TSC frequency from host system using this formula: guest_tsc = host_tsc * tsc_ratio + vmcb_offset. The tsc_ratio is a 64bit MSR contains a fixed-point number in 8.32 format (8 bits for integer part and 32bits for fractional part). For instance 0x00000003_80000000 means tsc_ratio=3.5.

This patch enables TSC scaling ratio for SVM. With it, guest VMs don't need take #VMEXIT to calculate a translated TSC value when it is running under TSC emulation mode. This can substancially reduce the rdtsc overhead.

-Wei

-----Original Message-----
From: Keir Fraser [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Friday, April 20, 2012 3:15 AM
To: Ostrovsky, Boris; [email protected]; Dan Magenheimer
Cc: Huang2, Wei; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 12 lines · Keir Fraser
Quoted 10 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Oh, and apart from that, we're also in feature freeze for 4.2, and this isn't a bug fix. Similarly, it's not really a candidate for the stable 4.1 branch either, at any time.

-- Keir

Quoted 28 lines

-- Keir

Quoted 24 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c Thu Apr 19 18:39:30 2012 -0400 renamed from xen/arch/x86/hvm/svm/svm.c Wed Apr 18 16:49:55 2012 +0100 +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#5 lore raw

Ah, okay. Well, depending on review feedback on list perhaps it can slip into the schedule then. :-)

Quoted 91 lines · Wei

Hi Keir,

This patch is a bug fix for 23437:d7c755c25bb9 than new feature. It slipped my hand and Boris fixed it for me. The same applies to Xen-4.1.

===== Changeset 23437 =====

HVM/SVM: enable tsc scaling ratio for SVM

Future AMD CPUs support TSC scaling. It allows guests to have a different TSC frequency from host system using this formula: guest_tsc = host_tsc * tsc_ratio + vmcb_offset. The tsc_ratio is a 64bit MSR contains a fixed-point number in 8.32 format (8 bits for integer part and 32bits for fractional part). For instance 0x00000003_80000000 means tsc_ratio=3.5.

This patch enables TSC scaling ratio for SVM. With it, guest VMs don't need take #VMEXIT to calculate a translated TSC value when it is running under TSC emulation mode. This can substancially reduce the rdtsc overhead.

-Wei

-----Original Message-----
From: Keir Fraser [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Friday, April 20, 2012 3:15 AM
To: Ostrovsky, Boris; [email protected]; Dan Magenheimer
Cc: Huang2, Wei; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 12 lines · Keir Fraser
Quoted 10 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Oh, and apart from that, we're also in feature freeze for 4.2, and this isn't a bug fix. Similarly, it's not really a candidate for the stable 4.1 branch either, at any time.

-- Keir

Quoted 28 lines

-- Keir

Quoted 24 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c Thu Apr 19 18:39:30 2012 -0400 renamed from xen/arch/x86/hvm/svm/svm.c Wed Apr 18 16:49:55 2012 +0100 +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#6 lore raw
In reply to Keir Fraser
Quoted 16 lines

From: Keir Fraser [mailto:[email protected]]
Subject: Re: [Xen-devel] [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 10 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Provided the hypervisor writes the "TSC-scale-register" with the same value when any vcpu for any guest is scheduled, I don't think there is any cross-CPU TSC skew.

But my recollection is that I had a concern that, to work properly after migration, TSC scaling might need to implement:

	((B + cur_tsc) * scale ) + A

and AFAIK the feature only implements this for B==0. Without the rest of the implementation in the hypervisor and tools, it's hard to determine whether my concern is valid or not.

Also, I don't recall the exact scaling process but was also concerned that a guest kernel or userland process approximating the passage of time by counting TSC cycles, they might just estimate the value once at boot (or application startup) and, due to the scaling, post-migration ticks/second might later change enough to be a problem. However, this
is a generic problem with emulation as well, so the concern is really: Does the TSC scaling use the same multiplication precision as is available to emulation in the hypervisor?

Dan

#7 lore raw
Quoted 21 lines · Dan Magenheimer
Quoted 13 lines

From: Keir Fraser [mailto:[email protected]]
Subject: Re: [Xen-devel] [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 7 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky<[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 8 lines
Quoted 6 lines

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Quoted 8 lines

Provided the hypervisor writes the "TSC-scale-register" with the same value when any vcpu for any guest is scheduled, I don't think there is any cross-CPU TSC skew.

But my recollection is that I had a concern that, to work properly after migration, TSC scaling might need to implement:

	((B + cur_tsc) * scale ) + A

Hi Dan,

Thanks for your review. I tried to interpret this formula as the following:

cur_tsc: Guest TSC before migration
B: time elapsed (overhead) during migration
scale: ratio of guest frequency/target host frequency
A: target host TSC

Quoted 4 lines

and AFAIK the feature only implements this for B==0. Without the rest of the implementation in the hypervisor and tools, it's hard to determine whether my concern is valid or not.

If my interpretation above is correct, doesn't emulated TSC have the same problem of B == 0?

Quoted 11 lines

Also, I don't recall the exact scaling process but was also concerned that a guest kernel or userland process approximating the passage of time by counting TSC cycles, they might just estimate the value once at boot (or application startup) and, due to the scaling, post-migration ticks/second might later change enough to be a problem. However, this
is a generic problem with emulation as well, so the concern is really: Does the TSC scaling use the same multiplication precision as is available to emulation in the hypervisor?

Hardware TSC scaling uses 8.32 format: 8 bits for integer part and 32 bits for fraction. Is it enough for the precision from your experience? The details of TSC scaling spec can be found on page 554 of http://support.amd.com/us/Processor_TechDocs/24593_APM_v2.pdf.

Quoted 3 lines

Dan

#8 lore raw
Quoted 21 lines

From: Wei Huang [mailto:[email protected]]
Subject: Re: [Xen-devel] [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Worth an ack/nack from Dan M I'd say. He'll probably have some comment about possible cross-CPU TSC skew.

Quoted 8 lines

Provided the hypervisor writes the "TSC-scale-register" with the same value when any vcpu for any guest is scheduled, I don't think there is any cross-CPU TSC skew.

But my recollection is that I had a concern that, to work properly after migration, TSC scaling might need to implement:

	((B + cur_tsc) * scale ) + A
Quoted 8 lines

Hi Dan,

Thanks for your review. I tried to interpret this formula as the following:

cur_tsc: Guest TSC before migration
B: time elapsed (overhead) during migration
scale: ratio of guest frequency/target host frequency
A: target host TSC

Hi Wei --

I have to admit I don't remember the details of the problem anymore and can't mentally reproduce it right now. If TSC scaling is deployed (on Xen... I imagine it was designed to accommodate VMware) and works as well as emulation but faster, great! I just would hope that there is a great deal of testing done before it becomes the default because if problems do occur, they will be extremely difficult to track down.

Quoted 5 lines
Quoted 3 lines

Without the rest of the implementation in the hypervisor and tools, it's hard to determine whether my concern is valid or not.

If my interpretation above is correct, doesn't emulated TSC have the same problem of B == 0?

That may be true. But if the emulation code for HVM is broken and must be fixed, that's a much easier change than a change to a hardware instruction.

Quoted 4 lines

Hardware TSC scaling uses 8.32 format: 8 bits for integer part and 32 bits for fraction. Is it enough for the precision from your experience? The details of TSC scaling spec can be found on page 554 of
http://support.amd.com/us/Processor_TechDocs/24593_APM_v2.pdf.

I didn't write the emulation scaling code for HVM... if it uses a 32-bit scale factor, your 8+32 should be more precise. If it uses a 64-bit multiplier, it will be less precise. OTOH, the "how many TSC ticks per second" code in Xen may not be precise anyway.

Keir/Jan, I still think it would be a good idea to implement a global boot-time "never trust the hardware TSC" option (default off) which would result in all guests always emulating TSC.
At least this would be a "baseline" and any problems with it are due to hypervisor bugs.

Dan

P.S. About to be away from email for a few days.

#9 lore raw
In reply to Boris Ostrovsky
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

While the patch itself looks fine, I'm having difficulty to connect the mentioning of TSC_MODE_ALWAYS_EMULATE to it - afaics all modes are affected as long as they result in d->arch.vtsc to be set.

Jan

Quoted 27 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#10 lore raw
Quoted 8 lines · Jan Beulich
Quoted 4 lines

svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

While the patch itself looks fine, I'm having difficulty to connect the mentioning of TSC_MODE_ALWAYS_EMULATE to it - afaics all modes are affected as long as they result in d->arch.vtsc to be set.

I think the real point of this patch is they *never* want to trap and emulate RDTSC on these newer processors.

-- Keir

#11 lore raw
Quoted 7 lines · Keir Fraser
Quoted 5 lines · Jan Beulich
Quoted 4 lines

svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

While the patch itself looks fine, I'm having difficulty to connect the mentioning of TSC_MODE_ALWAYS_EMULATE to it - afaics all modes are affected as long as they result in d->arch.vtsc to be set.

I think the real point of this patch is they *never* want to trap and emulate RDTSC on these newer processors.

Right. Mentioning TSC_MODE_ALWAYS_EMULATE explicitly wasn't probably a particularly good idea.

The reason I did that was because with TSC_MODE_DEFAULT guests (at least Linux guests) typically don't use TSC since TSC ends up being declared non-invariant.

-boris

#12 lore raw
In reply to Boris Ostrovsky
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 6 lines

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

So what's the status of the discussion around this patch? Were your concerns all addressed, Dan? Is there any re-submisson necessary/planned?

Jan

Quoted 23 lines

diff -r 7c777cb8f705 -r 55bf11ebce87 xen/arch/x86/hvm/svm/svm.c

xen/arch/x86/hvm/svm/svm.c +7 -1
@@ -724,12 +724,18 @@ static void svm_set_rdtsc_exiting(struct
 {
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     u32 general1_intercepts = vmcb_get_general1_intercepts(vmcb);
+    u32 general2_intercepts = vmcb_get_general2_intercepts(vmcb);
 
     general1_intercepts &= ~GENERAL1_INTERCEPT_RDTSC;
-    if ( enable )
+    general2_intercepts &= ~GENERAL2_INTERCEPT_RDTSCP;
+
+    if ( enable && !cpu_has_tsc_ratio ) {
         general1_intercepts |= GENERAL1_INTERCEPT_RDTSC;
+        general2_intercepts |= GENERAL2_INTERCEPT_RDTSCP;
+    }
 
     vmcb_set_general1_intercepts(vmcb, general1_intercepts);
+    vmcb_set_general2_intercepts(vmcb, general2_intercepts);
 }
 
 static unsigned int svm_get_insn_bytes(struct vcpu *v, uint8_t *buf)
#13 lore raw
Quoted 17 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, April 25, 2012 3:27 AM
To: Boris Ostrovsky; Dan Magenheimer
Cc: [email protected]; xen-devel; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 11 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 7 lines
Quoted 3 lines

So what's the status of the discussion around this patch? Were your concerns all addressed, Dan? Is there any re-submisson necessary/planned?

My concerns will be addressed when there is a fully-functional adequately-tested full-stack implementation, rather than "we have a new instruction that should solve (part of) this problem, let's turn it on by default."

While I wish I could invest the time required to do (or participate in) the testing, sadly I can't, so I understand if my opinion is discarded.

#14 lore raw
Quoted 27 lines
Quoted 6 lines
Quoted 1 line · Dan Magenheimer

From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, April 25, 2012 3:27 AM
To: Boris Ostrovsky; Dan Magenheimer
Cc: [email protected]; xen-devel; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is

supported by hardware

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 7 lines
Quoted 3 lines

So what's the status of the discussion around this patch? Were your concerns all addressed, Dan? Is there any re-submisson necessary/planned?

Quoted 8 lines

My concerns will be addressed when there is a fully-functional adequately-tested full-stack implementation, rather than "we have a new instruction that should solve (part of) this problem, let's turn it on by default."

While I wish I could invest the time required to do (or participate in) the testing, sadly I can't, so I understand if my opinion is discarded.

As Keir had asked to get an ACK/NAK from you - is this then a NAK or a "don't care" or yet something else (it doesn't read anywhere close to an ACK in any case).

Jan

#15 lore raw
Quoted 35 lines

From: Jan Beulich [mailto:[email protected]]
Subject: RE: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 32 lines
Quoted 6 lines
Quoted 1 line · Dan Magenheimer

From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, April 25, 2012 3:27 AM
To: Boris Ostrovsky; Dan Magenheimer
Cc: [email protected]; xen-devel; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is

supported by hardware

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 7 lines
Quoted 3 lines

So what's the status of the discussion around this patch? Were your concerns all addressed, Dan? Is there any re-submisson necessary/planned?

My concerns will be addressed when there is a fully-functional adequately-tested full-stack implementation, rather than "we have a new instruction that should solve (part of) this problem, let's turn it on by default."

Quoted 7 lines
Quoted 3 lines

While I wish I could invest the time required to do (or participate in) the testing, sadly I can't, so I understand if my opinion is discarded.

As Keir had asked to get an ACK/NAK from you - is this then a NAK or a "don't care" or yet something else (it doesn't read anywhere close to an ACK in any case).

Something else ;-)

I certainly don't feel comfortable ACKing it. I'd like to see some testing that demonstrates the patch either improves functionality or performance without breaking other things. But if nobody else shares my concern, I don't feel that I have the right to block it either.

#16 lore raw
Quoted 38 lines · Dan Magenheimer
Quoted 32 lines

From: Jan Beulich [mailto:[email protected]]
Subject: RE: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

Quoted 29 lines
Quoted 6 lines
Quoted 1 line · Dan Magenheimer

From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, April 25, 2012 3:27 AM
To: Boris Ostrovsky; Dan Magenheimer
Cc: [email protected]; xen-devel; [email protected]
Subject: Re: [PATCH] svm: Do not intercept RDTCS(P) when TSC scaling is

supported by hardware

Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

# HG changeset patch
# User Boris Ostrovsky<[email protected]>
# Date 1334875170 14400
# Node ID 55bf11ebce87ceb73fb2c372dcef170ec0bb4a18
# Parent 7c777cb8f705411b77c551f34ba88bdc09e38ab8
svm: Do not intercept RDTCS(P) when TSC scaling is supported by hardware

When running in TSC_MODE_ALWAYS_EMULATE mode on processors that support TSC scaling we don't need to intercept RDTSC/RDTSCP instructions.

Quoted 6 lines
Quoted 3 lines

So what's the status of the discussion around this patch? Were your concerns all addressed, Dan? Is there any re-submisson necessary/planned?

My concerns will be addressed when there is a fully-functional adequately-tested full-stack implementation, rather than "we have a new instruction that should solve (part of) this problem, let's turn it on by default."

Quoted 6 lines
Quoted 3 lines

While I wish I could invest the time required to do (or participate in) the testing, sadly I can't, so I understand if my opinion is discarded.

As Keir had asked to get an ACK/NAK from you - is this then a NAK or a "don't care" or yet something else (it doesn't read anywhere close to an ACK in any case).

Quoted 7 lines

Something else ;-)

I certainly don't feel comfortable ACKing it. I'd like to see some testing that demonstrates the patch either improves functionality or performance without breaking other things. But if nobody else shares my concern, I don't feel that I have the right to block it either.

We can provide some rdtsc performance numbers. Regarding functionality, it is relatively hard to prove unless Dan has some more specific ideas of testing it. I think the hardware rdtsc scaling is inline with software-based emulated approach.

-Wei

Quoted 1 line
#17 lore raw
Quoted 10 lines · Wei Huang
Quoted 5 lines

I certainly don't feel comfortable ACKing it. I'd like to see some testing that demonstrates the patch either improves functionality or performance without breaking other things. But if nobody else shares my concern, I don't feel that I have the right to block it either.

We can provide some rdtsc performance numbers. Regarding functionality, it is relatively hard to prove unless Dan has some more specific ideas of testing it. I think the hardware rdtsc scaling is inline with software-based emulated approach.

I've put it in to xen-unstable. I'm not sure about putting into 4.1 for the forthcoming release from that branch.

-- Keir

#18 lore raw
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Wei Huang
Quoted 5 lines

I certainly don't feel comfortable ACKing it. I'd like to see some testing that demonstrates the patch either improves functionality or performance without breaking other things. But if nobody else shares my concern, I don't feel that I have the right to block it either.

Quoted 7 lines
Quoted 4 lines

We can provide some rdtsc performance numbers. Regarding functionality, it is relatively hard to prove unless Dan has some more specific ideas of testing it. I think the hardware rdtsc scaling is inline with software-based emulated approach.

I've put it in to xen-unstable. I'm not sure about putting into 4.1 for the forthcoming release from that branch.

As far as performance numbers are concerned, with this patch applied (i.e. native execution) RDTSC instruction executed in a loop takes about 150ns per iteration. That's including a few instructions for loop control.

With full SW emulation (pre-patch) the same loop is executed in roughly 6us.

Obviously this is not a realistic scenario but it gives a feel of what the patch provides.

-boris