summaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/vmx.c
diff options
context:
space:
mode:
authorBabu Moger2018-03-16 21:37:24 +0100
committerRadim Krčmář2018-03-28 22:47:06 +0200
commitc8e88717cfc6b36bedea22368d97667446318291 (patch)
treee5de741d9cf03b50bf5f25035347de39c6728b24 /arch/x86/kvm/vmx.c
parentKVM: VMX: Remove ple_window_actual_max (diff)
downloadkernel-qcow2-linux-c8e88717cfc6b36bedea22368d97667446318291.tar.gz
kernel-qcow2-linux-c8e88717cfc6b36bedea22368d97667446318291.tar.xz
kernel-qcow2-linux-c8e88717cfc6b36bedea22368d97667446318291.zip
KVM: VMX: Bring the common code to header file
This patch brings some of the code from vmx to x86.h header file. Now, we can share this code between vmx and svm. Modified couple functions to make it common. Signed-off-by: Babu Moger <babu.moger@amd.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Diffstat (limited to 'arch/x86/kvm/vmx.c')
-rw-r--r--arch/x86/kvm/vmx.c51
1 files changed, 9 insertions, 42 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7a92e2e1ea2e..48d93d8cb883 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -168,24 +168,17 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
* Time is measured based on a counter that runs at the same rate as the TSC,
* refer SDM volume 3b section 21.6.13 & 22.1.3.
*/
-#define KVM_VMX_DEFAULT_PLE_GAP 128
-#define KVM_VMX_DEFAULT_PLE_WINDOW 4096
-#define KVM_VMX_DEFAULT_PLE_WINDOW_GROW 2
-#define KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK 0
-#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX UINT_MAX
-
-static unsigned int ple_gap = KVM_VMX_DEFAULT_PLE_GAP;
-module_param(ple_gap, uint, 0444);
+static unsigned int ple_gap = KVM_DEFAULT_PLE_GAP;
static unsigned int ple_window = KVM_VMX_DEFAULT_PLE_WINDOW;
module_param(ple_window, uint, 0444);
/* Default doubles per-vcpu window every exit. */
-static unsigned int ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW;
+static unsigned int ple_window_grow = KVM_DEFAULT_PLE_WINDOW_GROW;
module_param(ple_window_grow, uint, 0444);
/* Default resets per-vcpu window every exit to ple_window. */
-static unsigned int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
+static unsigned int ple_window_shrink = KVM_DEFAULT_PLE_WINDOW_SHRINK;
module_param(ple_window_shrink, uint, 0444);
/* Default is to compute the maximum so we can never overflow. */
@@ -6982,41 +6975,14 @@ out:
return ret;
}
-static unsigned int __grow_ple_window(unsigned int val)
-{
- u64 ret = val;
-
- if (ple_window_grow < 1)
- return ple_window;
-
- if (ple_window_grow < ple_window)
- ret *= ple_window_grow;
- else
- ret += ple_window_grow;
-
- return min(ret, (u64)ple_window_max);
-}
-
-static unsigned int __shrink_ple_window(unsigned int val,
- unsigned int modifier, unsigned int minimum)
-{
- if (modifier < 1)
- return ple_window;
-
- if (modifier < ple_window)
- val /= modifier;
- else
- val -= modifier;
-
- return max(val, minimum);
-}
-
static void grow_ple_window(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
int old = vmx->ple_window;
- vmx->ple_window = __grow_ple_window(old);
+ vmx->ple_window = __grow_ple_window(old, ple_window,
+ ple_window_grow,
+ ple_window_max);
if (vmx->ple_window != old)
vmx->ple_window_dirty = true;
@@ -7029,8 +6995,9 @@ static void shrink_ple_window(struct kvm_vcpu *vcpu)
struct vcpu_vmx *vmx = to_vmx(vcpu);
int old = vmx->ple_window;
- vmx->ple_window = __shrink_ple_window(old,
- ple_window_shrink, ple_window);
+ vmx->ple_window = __shrink_ple_window(old, ple_window,
+ ple_window_shrink,
+ ple_window);
if (vmx->ple_window != old)
vmx->ple_window_dirty = true;