From 2edf141047eb395ac85d39e2ea7ed51ab5d29e7a Mon Sep 17 00:00:00 2001 From: Wu Zhou Date: Sun, 23 Apr 2023 17:27:34 +0800 Subject: [PATCH] hv: add VHWP guest flag and its helper func Currently CPU frequency control is hidden to guests, and controlled by hypervisor. While it is sufficient in most cases, some guest OS may still need CPU performance info to make multi-core scheduling decisions. This is seen on Linux kernel, which uses HWP highest performance level as CPU core's priority in multi-core scheduling (CONFIG_SCHED_MC_PRIO). Enabling this kernel feature could improve performance as single thread workloads are scheduled on the highest performance cores. This is significantly useful for guests with hybrid cores. The concept is to expose performance interface to guest who exclusively owns pCPU assigned to it. So that Linux guest can load intel_pstate driver which will then provide the kernel with each core's schedule priority. Intel_pstate driver also relies on CONFIG_ACPI_CPPC_LIB to implement this mechanic, this means we also need to provide ACPI _CPC in DM. This patch sets up a guest flag GUEST_FLAG_VHWP to indicate whether the guest can have VHWP feature. Tracked-On: #8414 Signed-off-by: Wu Zhou Reviewed-by: Junjie Mao --- hypervisor/arch/x86/guest/vm.c | 10 ++++++++++ hypervisor/include/arch/x86/asm/guest/vm.h | 1 + hypervisor/include/public/acrn_common.h | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index f197275bc..4a60f8326 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -213,6 +213,16 @@ bool is_static_configured_vm(const struct acrn_vm *vm) return ((vm_config->guest_flags & GUEST_FLAG_STATIC_VM) != 0U); } +/** + * @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM + */ +bool is_vhwp_configured(const struct acrn_vm *vm) +{ + struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); + + return ((vm_config->guest_flags & GUEST_FLAG_VHWP) != 0U); +} + /** * @brief VT-d PI posted mode can possibly be used for PTDEVs assigned * to this VM if platform supports VT-d PI AND lapic passthru is not configured diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index d26869bb9..de7cd090c 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -274,6 +274,7 @@ struct acrn_vm *get_highest_severity_vm(bool runtime); bool vm_hide_mtrr(const struct acrn_vm *vm); void update_vm_vlapic_state(struct acrn_vm *vm); enum vm_vlapic_mode check_vm_vlapic_mode(const struct acrn_vm *vm); +bool is_vhwp_configured(const struct acrn_vm *vm); /* * @pre vm != NULL */ diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index 736e3c891..3c6e4e87a 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -63,7 +63,7 @@ #define GUEST_FLAG_TEE (1UL << 9U) /* Whether the VM is TEE VM */ #define GUEST_FLAG_REE (1UL << 10U) /* Whether the VM is REE VM */ #define GUEST_FLAG_PMU_PASSTHROUGH (1UL << 11U) /* Whether PMU is passed through */ - +#define GUEST_FLAG_VHWP (1UL << 12U) /* Whether the VM supports vHWP */ /* TODO: We may need to get this addr from guest ACPI instead of hardcode here */ #define VIRTUAL_SLEEP_CTL_ADDR 0x400U /* Pre-launched VM uses ACPI reduced HW mode and sleep control register */