From aeb3690b6fe67b61eebd443063299bb025398c6d Mon Sep 17 00:00:00 2001 From: Zide Chen Date: Fri, 20 Aug 2021 22:11:22 -0700 Subject: [PATCH] hv: simplify is_lapic_pt_enabled() is_lapic_pt_enabled() is called at least twice in one loop of the vCPU thread, and it's called in vmexit_handler() frequently if LAPIC is not pass-through. Thus the efficiency of this function has direct impact to the system performance. Since the LAPIC mode is not changed in run time, we don't have to calculate it on the fly in is_lapic_pt_enabled(). BTW, removed the unused lapic_mask from struct acrn_vcpu_arch. Tracked-On: #6289 Signed-off-by: Zide Chen Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 15 +-------------- hypervisor/arch/x86/guest/vlapic.c | 1 + hypervisor/include/arch/x86/asm/guest/vcpu.h | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index f02c1a152..6a7785ca9 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -256,6 +256,7 @@ static void vcpu_reset_internal(struct acrn_vcpu *vcpu, enum reset_mode mode) vcpu->arch.exception_info.exception = VECTOR_INVALID; vcpu->arch.cur_context = NORMAL_WORLD; + vcpu->arch.lapic_pt_enabled = false; vcpu->arch.irq_window_enabled = false; vcpu->arch.emulating_lock = false; (void)memset((void *)vcpu->arch.vmcs, 0U, PAGE_SIZE); @@ -980,20 +981,6 @@ uint64_t vcpumask2pcpumask(struct acrn_vm *vm, uint64_t vdmask) return dmask; } -/* - * @brief Check if vCPU uses LAPIC in x2APIC mode and the VM, vCPU belongs to, is configured for - * LAPIC Pass-through - * - * @pre vcpu != NULL - * - * @return true, if vCPU LAPIC is in x2APIC mode and VM, vCPU belongs to, is configured for - * LAPIC Pass-through - */ -bool is_lapic_pt_enabled(struct acrn_vcpu *vcpu) -{ - return ((is_x2apic_enabled(vcpu_vlapic(vcpu))) && (is_lapic_pt_configured(vcpu->vm))); -} - /* * @brief handle posted interrupts * diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index 0e94e2ca1..456943eb9 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -1702,6 +1702,7 @@ int32_t vlapic_set_apicbase(struct acrn_vlapic *vlapic, uint64_t new) if (is_lapic_pt_configured(vcpu->vm)) { /* vlapic need to be reset to make sure it is in correct state */ vlapic_reset(vlapic, &ptapic_ops, SOFTWARE_RESET); + vcpu->arch.lapic_pt_enabled = true; } vlapic->msr_apicbase = new; vlapic_build_x2apic_id(vlapic); diff --git a/hypervisor/include/arch/x86/asm/guest/vcpu.h b/hypervisor/include/arch/x86/asm/guest/vcpu.h index 807e8f7fb..6c12300c5 100644 --- a/hypervisor/include/arch/x86/asm/guest/vcpu.h +++ b/hypervisor/include/arch/x86/asm/guest/vcpu.h @@ -249,7 +249,7 @@ struct acrn_vcpu_arch { uint32_t error; } exception_info; - uint8_t lapic_mask; + bool lapic_pt_enabled; bool irq_window_enabled; bool emulating_lock; bool xsave_enabled; @@ -728,7 +728,20 @@ int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id); * @return The physical destination CPU mask */ uint64_t vcpumask2pcpumask(struct acrn_vm *vm, uint64_t vdmask); -bool is_lapic_pt_enabled(struct acrn_vcpu *vcpu); + +/* + * @brief Check if vCPU uses LAPIC in x2APIC mode and the VM, vCPU belongs to, is configured for + * LAPIC Pass-through + * + * @pre vcpu != NULL + * + * @return true, if vCPU LAPIC is in x2APIC mode and VM, vCPU belongs to, is configured for + * LAPIC Pass-through + */ +static inline bool is_lapic_pt_enabled(struct acrn_vcpu *vcpu) +{ + return vcpu->arch.lapic_pt_enabled; +} /** * @brief handle posted interrupts