Skip to content

Commit

Permalink
hv: PAUSE-loop exiting support in hypervisor
Browse files Browse the repository at this point in the history
As we enabled cpu sharing, PAUSE-loop exiting can help vcpu
to release its pcpu proactively. It's good for performance.

VMX_PLE_GAP: upper bound on the amount of time between two successive
executions of PAUSE in a loop.
VMX_PLE_WINDOW: upper bound on the amount of time a guest is allowed to
execute in a PAUSE loop

Tracked-On: #4329
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
Shuo A Liu authored and wenlingz committed Jan 7, 2020
1 parent bfecf30 commit 4115dd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion hypervisor/arch/x86/guest/vmcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ static void init_exec_ctrl(struct acrn_vcpu *vcpu)
*/
value32 = check_vmx_ctrl(MSR_IA32_VMX_PROCBASED_CTLS2,
VMX_PROCBASED_CTLS2_VAPIC | VMX_PROCBASED_CTLS2_EPT |VMX_PROCBASED_CTLS2_VPID |
VMX_PROCBASED_CTLS2_RDTSCP | VMX_PROCBASED_CTLS2_UNRESTRICT);
VMX_PROCBASED_CTLS2_RDTSCP | VMX_PROCBASED_CTLS2_UNRESTRICT |
VMX_PROCBASED_CTLS2_PAUSE_LOOP);

/* SDM Vol3, 25.3, setting "enable INVPCID" VM-execution to 1 with "INVLPG exiting" disabled,
* passes-through INVPCID instruction to guest if the instruction is supported.
Expand Down Expand Up @@ -425,6 +426,10 @@ static void init_exec_ctrl(struct acrn_vcpu *vcpu)
exec_vmwrite(VMX_CR3_TARGET_1, 0UL);
exec_vmwrite(VMX_CR3_TARGET_2, 0UL);
exec_vmwrite(VMX_CR3_TARGET_3, 0UL);

/* Setup PAUSE-loop exiting - 24.6.13 */
exec_vmwrite(VMX_PLE_GAP, 128U);
exec_vmwrite(VMX_PLE_WINDOW, 4096U);
}

static void init_entry_ctrl(const struct acrn_vcpu *vcpu)
Expand Down
9 changes: 8 additions & 1 deletion hypervisor/arch/x86/guest/vmexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static int32_t unhandled_vmexit_handler(struct acrn_vcpu *vcpu);
static int32_t xsetbv_vmexit_handler(struct acrn_vcpu *vcpu);
static int32_t wbinvd_vmexit_handler(struct acrn_vcpu *vcpu);
static int32_t undefined_vmexit_handler(struct acrn_vcpu *vcpu);
static int32_t pause_vmexit_handler(__unused struct acrn_vcpu *vcpu);

/* VM Dispatch table for Exit condition handling */
static const struct vm_exit_dispatch dispatch_table[NR_VMX_EXIT_REASONS] = {
Expand Down Expand Up @@ -113,7 +114,7 @@ static const struct vm_exit_dispatch dispatch_table[NR_VMX_EXIT_REASONS] = {
[VMX_EXIT_REASON_MONITOR] = {
.handler = unhandled_vmexit_handler},
[VMX_EXIT_REASON_PAUSE] = {
.handler = unhandled_vmexit_handler},
.handler = pause_vmexit_handler},
[VMX_EXIT_REASON_ENTRY_FAILURE_MACHINE_CHECK] = {
.handler = unhandled_vmexit_handler},
[VMX_EXIT_REASON_TPR_BELOW_THRESHOLD] = {
Expand Down Expand Up @@ -277,6 +278,12 @@ static int32_t triple_fault_vmexit_handler(struct acrn_vcpu *vcpu)
return 0;
}

static int32_t pause_vmexit_handler(__unused struct acrn_vcpu *vcpu)
{
yield_current();
return 0;
}

int32_t cpuid_vmexit_handler(struct acrn_vcpu *vcpu)
{
uint64_t rax, rbx, rcx, rdx;
Expand Down

0 comments on commit 4115dd6

Please sign in to comment.