From e278b38ec4de7981caade01e135ece4ed5b7f28b Mon Sep 17 00:00:00 2001 From: Xue Bosheng Date: Mon, 25 Aug 2025 20:05:23 +0800 Subject: [PATCH] hv: move percpu delivery mode and idle mode from common to x86 delivery mode and idle mode are x86 specific percpu, so move it from common to x86 arch, also change the name of mode_to_idle to be idle_mode, change the name of mode_to_kick_pcpu to be kick_pcpu_mode. Tracked-On: #8812 Signed-off-by: Xue Bosheng Acked-by: Wang, Yu1 --- hypervisor/arch/x86/cpu.c | 10 +++++++++- hypervisor/arch/x86/guest/vcpu.c | 12 ++++++------ hypervisor/arch/x86/lapic.c | 2 +- hypervisor/common/schedule.c | 6 ------ hypervisor/include/arch/x86/asm/cpu.h | 6 ++++++ hypervisor/include/arch/x86/asm/per_cpu.h | 2 ++ hypervisor/include/common/per_cpu.h | 2 -- hypervisor/include/common/schedule.h | 6 ------ 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index de38e67e0..2d4e61ab1 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -108,6 +108,12 @@ static void enable_gp_for_uclock(void) #endif /*CONFIG_UC_LOCK_DETECTION_ENABLED*/ } +static void init_pcpu_idle_and_kick(uint16_t pcpu_id) +{ + per_cpu(arch.idle_mode, pcpu_id) = IDLE_MODE_HLT; + per_cpu(arch.kick_pcpu_mode, pcpu_id) = DEL_MODE_IPI; +} + void init_pcpu_pre(bool is_bsp) { uint16_t pcpu_id; @@ -292,6 +298,8 @@ void init_pcpu_post(uint16_t pcpu_id) apply_frequency_policy(); + init_pcpu_idle_and_kick(pcpu_id); + init_sched(pcpu_id); #ifdef CONFIG_RDT_ENABLED @@ -391,7 +399,7 @@ void cpu_do_idle(void) #else uint16_t pcpu_id = get_pcpu_id(); - if (per_cpu(mode_to_idle, pcpu_id) == IDLE_MODE_HLT) { + if (per_cpu(arch.idle_mode, pcpu_id) == IDLE_MODE_HLT) { asm_safe_hlt(); } else { struct acrn_vcpu *vcpu = get_ever_run_vcpu(pcpu_id); diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 4de3beddd..e93eab3e9 100755 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -536,17 +536,17 @@ int32_t create_vcpu(uint16_t pcpu_id, struct acrn_vm *vm, struct acrn_vcpu **rtn * idle, the kick mode is certainly ipi kick) will change * it to PAUSE idle right away. */ - if (per_cpu(mode_to_idle, pcpu_id) == IDLE_MODE_HLT) { - per_cpu(mode_to_idle, pcpu_id) = IDLE_MODE_PAUSE; + if (per_cpu(arch.idle_mode, pcpu_id) == IDLE_MODE_HLT) { + per_cpu(arch.idle_mode, pcpu_id) = IDLE_MODE_PAUSE; kick_pcpu(pcpu_id); } - per_cpu(mode_to_kick_pcpu, pcpu_id) = DEL_MODE_INIT; + per_cpu(arch.kick_pcpu_mode, pcpu_id) = DEL_MODE_INIT; } else { - per_cpu(mode_to_kick_pcpu, pcpu_id) = DEL_MODE_IPI; - per_cpu(mode_to_idle, pcpu_id) = IDLE_MODE_HLT; + per_cpu(arch.kick_pcpu_mode, pcpu_id) = DEL_MODE_IPI; + per_cpu(arch.idle_mode, pcpu_id) = IDLE_MODE_HLT; } pr_info("pcpu=%d, kick-mode=%d, use_init_flag=%d", pcpu_id, - per_cpu(mode_to_kick_pcpu, pcpu_id), is_using_init_ipi()); + per_cpu(arch.kick_pcpu_mode, pcpu_id), is_using_init_ipi()); /* Initialize the parent VM reference */ vcpu->vm = vm; diff --git a/hypervisor/arch/x86/lapic.c b/hypervisor/arch/x86/lapic.c index 2edff7139..7a80d6643 100644 --- a/hypervisor/arch/x86/lapic.c +++ b/hypervisor/arch/x86/lapic.c @@ -297,7 +297,7 @@ void send_single_init(uint16_t pcpu_id) void kick_pcpu(uint16_t pcpu_id) { - if (per_cpu(mode_to_kick_pcpu, pcpu_id) == DEL_MODE_INIT) { + if (per_cpu(arch.kick_pcpu_mode, pcpu_id) == DEL_MODE_INIT) { send_single_init(pcpu_id); } else { send_single_ipi(pcpu_id, NOTIFY_VCPU_VECTOR); diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index e0626fd12..060cc1f1a 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -65,9 +65,6 @@ void init_sched(uint16_t pcpu_id) { struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id); - per_cpu(mode_to_idle, pcpu_id) = IDLE_MODE_HLT; - per_cpu(mode_to_kick_pcpu, pcpu_id) = DEL_MODE_IPI; - spinlock_init(&ctl->scheduler_lock); ctl->flags = 0UL; ctl->curr_obj = NULL; @@ -145,9 +142,6 @@ struct thread_object *sched_get_current(uint16_t pcpu_id) return ctl->curr_obj; } -/** - * @pre delmode == DEL_MODE_IPI || delmode == DEL_MODE_INIT - */ void make_reschedule_request(uint16_t pcpu_id) { struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id); diff --git a/hypervisor/include/arch/x86/asm/cpu.h b/hypervisor/include/arch/x86/asm/cpu.h index ba7ff7444..ec90f92d1 100644 --- a/hypervisor/include/arch/x86/asm/cpu.h +++ b/hypervisor/include/arch/x86/asm/cpu.h @@ -294,6 +294,12 @@ extern uint64_t secondary_cpu_stack[1]; */ #define BROADCAST_CPU_ID 0xfffeU +#define DEL_MODE_INIT (1U) +#define DEL_MODE_IPI (2U) + +#define IDLE_MODE_PAUSE (1U) +#define IDLE_MODE_HLT (2U) + struct descriptor_table { uint16_t limit; uint64_t base; diff --git a/hypervisor/include/arch/x86/asm/per_cpu.h b/hypervisor/include/arch/x86/asm/per_cpu.h index 2cfe93b7f..83212a425 100644 --- a/hypervisor/include/arch/x86/asm/per_cpu.h +++ b/hypervisor/include/arch/x86/asm/per_cpu.h @@ -30,6 +30,8 @@ struct per_cpu_arch { #endif uint64_t tsc_suspend; struct acrn_vcpu *whose_iwkey; + uint32_t kick_pcpu_mode; + uint32_t idle_mode; } __aligned(PAGE_SIZE); /* per_cpu_region size aligned with PAGE_SIZE */ diff --git a/hypervisor/include/common/per_cpu.h b/hypervisor/include/common/per_cpu.h index 21d8be0ce..0ba038dec 100644 --- a/hypervisor/include/common/per_cpu.h +++ b/hypervisor/include/common/per_cpu.h @@ -47,8 +47,6 @@ struct per_cpu_region { struct thread_object idle; uint64_t pcpu_flag; uint32_t softirq_servicing; - uint32_t mode_to_kick_pcpu; - uint32_t mode_to_idle; struct smp_call_info_data smp_call_info; struct list_head softirq_dev_entry_list; enum pcpu_boot_state boot_state; diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index dd701c1f6..caa0a00f1 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -12,12 +12,6 @@ #define NEED_RESCHEDULE (1U) -#define DEL_MODE_INIT (1U) -#define DEL_MODE_IPI (2U) - -#define IDLE_MODE_PAUSE (1U) -#define IDLE_MODE_HLT (2U) - #define THREAD_DATA_SIZE (256U) enum thread_object_state {