kvm: x86: Update tsc multiplier on change.
PATCH 1/1 kvm: x86: Update tsc multiplier on change.
vmx.c writes the TSC_MULTIPLIER field in vmx_vcpu_load, but only when a vcpu has migrated physical cpus. Record the last value written and update in vmx_vcpu_load on any change, otherwise a cpu migration must occur for TSC frequency scaling to take effect.
--- arch/x86/kvm/vmx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx.c +9 -5
@@ -596,6 +596,8 @@ struct vcpu_vmx {/* Support for PML */ #define PML_ENTITY_NUM 512struct page *pml_pg; + +u64 current_tsc_ratio; };enum segment_cache_field {
@@ -2127,14 +2129,16 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)rdmsrl (MSR_IA32_SYSENTER_ESP , sysenter_esp);vmcs_writel (HOST_IA32_SYSENTER_ESP , sysenter_esp);/* 22.2.3 */ -/* Setup TSC multiplier */ -if (cpu_has_vmx_tsc_scaling ()) -vmcs_write64 (TSC_MULTIPLIER , - vcpu->arch.tsc_scaling_ratio); - vmx->loaded_vmcs->cpu = cpu; } +/* Setup TSC multiplier */ +if (kvm_has_tsc_control && + vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { + vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; +vmcs_write64 (TSC_MULTIPLIER , vmx->current_tsc_ratio); + } +vmx_vcpu_pi_load (vcpu, cpu); }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
Quoted 7 lines · Owen Hofmann
vmx.cwrites theTSC_MULTIPLIERfield invmx_vcpu_load, but only when a vcpu has migrated physical cpus. Record the last value written and update invmx_vcpu_loadon any change, otherwise a cpu migration must occur for TSC frequency scaling to take effect.Fixes ff2c3a1803775cc72dc6f624b59554956396b0eeSigned-off-by Owen Hofmann <[email protected]>
looks good for me.
Quoted 42 lines
--- arch/x86/kvm/vmx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +9
-5@@ -596,6 +596,8 @@ struct vcpu_vmx {/* Support for PML */ #define PML_ENTITY_NUM 512struct page *pml_pg; + +u64 current_tsc_ratio; };enum segment_cache_field {@@ -2127,14 +2129,16 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)rdmsrl (MSR_IA32_SYSENTER_ESP , sysenter_esp);vmcs_writel (HOST_IA32_SYSENTER_ESP , sysenter_esp);/* 22.2.3 */ -/* Setup TSC multiplier */ -if (cpu_has_vmx_tsc_scaling ()) -vmcs_write64 (TSC_MULTIPLIER , - vcpu->arch.tsc_scaling_ratio); - vmx->loaded_vmcs->cpu = cpu; } +/* Setup TSC multiplier */ +if (kvm_has_tsc_control && + vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { + vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; +vmcs_write64 (TSC_MULTIPLIER , vmx->current_tsc_ratio); + } +vmx_vcpu_pi_load (vcpu, cpu); }Signature · 1 line
2.7.0.rc3.207.g0ac5344
Paolo Bonzini
maintainerQuoted 37 lines · Owen Hofmann
vmx.cwrites theTSC_MULTIPLIERfield invmx_vcpu_load, but only when a vcpu has migrated physical cpus. Record the last value written and update invmx_vcpu_loadon any change, otherwise a cpu migration must occur for TSC frequency scaling to take effect.Fixes ff2c3a1803775cc72dc6f624b59554956396b0eeSigned-off-by Owen Hofmann <[email protected]>--- arch/x86/kvm/vmx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)arch/x86/kvm/vmx.c +2
-5@@ -596,6 +596,8 @@ struct vcpu_vmx {/* Support for PML */ #define PML_ENTITY_NUM 512struct page *pml_pg; + +u64 current_tsc_ratio; };enum segment_cache_field {@@ -2127,14 +2129,16 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)rdmsrl (MSR_IA32_SYSENTER_ESP , sysenter_esp);vmcs_writel (HOST_IA32_SYSENTER_ESP , sysenter_esp);/* 22.2.3 */ -/* Setup TSC multiplier */ -if (cpu_has_vmx_tsc_scaling ()) -vmcs_write64 (TSC_MULTIPLIER , - vcpu->arch.tsc_scaling_ratio); - vmx->loaded_vmcs->cpu = cpu; }
arch/x86/kvm/vmx.c static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) · line 2144
Quoted 10 lines
arch/x86/kvm/vmx.c +7
-0+/* Setup TSC multiplier */ +if (kvm_has_tsc_control && + vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { + vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; +vmcs_write64 (TSC_MULTIPLIER , vmx->current_tsc_ratio); + } +vmx_vcpu_pi_load (vcpu, cpu); }
Applied for 4.5 and Cc: [email protected].
Paolo