From 2cc45534d61f858f7549cdcd769df8b878e3756c Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Tue, 21 May 2019 11:52:21 +0800 Subject: [PATCH] hv: move pcpu offline request and vm shutdown request from schedule From modulization perspective, it's not suitable to put pcpu and vm related request operations in schedule. So move them to pcpu and vm module respectively. Also change need_offline return value to bool. Tracked-On: #3663 Signed-off-by: Jason Chen CJ Signed-off-by: Yu Wang Signed-off-by: Shuo A Liu --- hypervisor/arch/x86/cpu.c | 13 ++++++++++ hypervisor/arch/x86/guest/vm.c | 15 ++++++++++++ hypervisor/common/schedule.c | 34 -------------------------- hypervisor/include/arch/x86/cpu.h | 5 ++++ hypervisor/include/arch/x86/guest/vm.h | 2 ++ hypervisor/include/arch/x86/per_cpu.h | 1 + hypervisor/include/common/schedule.h | 6 ----- 7 files changed, 36 insertions(+), 40 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 1fd09294f..807e4b0a7 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -342,6 +342,19 @@ bool start_pcpus(uint64_t mask) return ((pcpu_active_bitmap & mask) == mask); } +void make_pcpu_offline(uint16_t pcpu_id) +{ + bitmap_set_lock(NEED_OFFLINE, &per_cpu(pcpu_flag, pcpu_id)); + if (get_pcpu_id() != pcpu_id) { + send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU); + } +} + +bool need_offline(uint16_t pcpu_id) +{ + return bitmap_test_and_clear_lock(NEED_OFFLINE, &per_cpu(pcpu_flag, pcpu_id)); +} + void wait_pcpus_offline(uint64_t mask) { uint32_t timeout; diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 9104828c8..a8cbd9d94 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -878,3 +880,16 @@ bool has_rt_vm(void) return ((vm_id == CONFIG_MAX_VM_NUM) ? false : true); } + +void make_shutdown_vm_request(uint16_t pcpu_id) +{ + bitmap_set_lock(NEED_SHUTDOWN_VM, &per_cpu(pcpu_flag, pcpu_id)); + if (get_pcpu_id() != pcpu_id) { + send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU); + } +} + +bool need_shutdown_vm(uint16_t pcpu_id) +{ + return bitmap_test_and_clear_lock(NEED_SHUTDOWN_VM, &per_cpu(pcpu_flag, pcpu_id)); +} diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 928bdb3e8..aaf58d580 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -126,40 +126,6 @@ bool need_reschedule(uint16_t pcpu_id) return bitmap_test(NEED_RESCHEDULE, &ctx->flags); } -void make_pcpu_offline(uint16_t pcpu_id) -{ - struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); - - bitmap_set_lock(NEED_OFFLINE, &ctx->flags); - if (get_pcpu_id() != pcpu_id) { - send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU); - } -} - -bool need_offline(uint16_t pcpu_id) -{ - struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); - - return bitmap_test_and_clear_lock(NEED_OFFLINE, &ctx->flags); -} - -void make_shutdown_vm_request(uint16_t pcpu_id) -{ - struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); - - bitmap_set_lock(NEED_SHUTDOWN_VM, &ctx->flags); - if (get_pcpu_id() != pcpu_id) { - send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU); - } -} - -bool need_shutdown_vm(uint16_t pcpu_id) -{ - struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id); - - return bitmap_test_and_clear_lock(NEED_SHUTDOWN_VM, &ctx->flags); -} - static void prepare_switch(struct sched_object *prev, struct sched_object *next) { if ((prev != NULL) && (prev->prepare_switch_out != NULL)) { diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index 603b2c099..5087cec45 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -264,6 +264,11 @@ enum pcpu_boot_state { PCPU_STATE_DEAD, }; +#define NEED_OFFLINE (1U) +#define NEED_SHUTDOWN_VM (2U) +void make_pcpu_offline(uint16_t pcpu_id); +bool need_offline(uint16_t pcpu_id); + /* Function prototypes */ void cpu_do_idle(void); void cpu_dead(void); diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 23a9a206e..3ae1bfc55 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -198,6 +198,8 @@ static inline uint16_t vmid_2_rel_vmid(uint16_t sos_vmid, uint16_t vmid) { return (vmid - sos_vmid); } +void make_shutdown_vm_request(uint16_t pcpu_id); +bool need_shutdown_vm(uint16_t pcpu_id); int32_t shutdown_vm(struct acrn_vm *vm); void pause_vm(struct acrn_vm *vm); void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec); diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index e3ab7aa24..706ae3ed8 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -42,6 +42,7 @@ struct per_cpu_region { struct host_gdt gdt; struct tss_64 tss; enum pcpu_boot_state boot_state; + uint64_t pcpu_flag; uint8_t mc_stack[CONFIG_STACK_SIZE] __aligned(16); uint8_t df_stack[CONFIG_STACK_SIZE] __aligned(16); uint8_t sf_stack[CONFIG_STACK_SIZE] __aligned(16); diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index 2b7fab59d..b82533494 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -9,8 +9,6 @@ #include #define NEED_RESCHEDULE (1U) -#define NEED_OFFLINE (2U) -#define NEED_SHUTDOWN_VM (3U) #define DEL_MODE_INIT (1U) #define DEL_MODE_IPI (2U) @@ -48,10 +46,6 @@ void remove_from_cpu_runqueue(struct sched_object *obj); void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode); bool need_reschedule(uint16_t pcpu_id); -void make_pcpu_offline(uint16_t pcpu_id); -bool need_offline(uint16_t pcpu_id); -void make_shutdown_vm_request(uint16_t pcpu_id); -bool need_shutdown_vm(uint16_t pcpu_id); void schedule(void); void run_sched_thread(struct sched_object *obj);