hv: sched: use get_running_vcpu to replace per_cpu vcpu with cpu sharing

With cpu sharing enabled, per_cpu vcpu cannot work properly as we might
has multiple vcpus running on one pcpu.
Add a schedule API sched_get_current to get current thread_object on
specific pcpu, also add a vcpu API get_running_vcpu to get corresponding
vcpu of the thread_object.

Tracked-On: #3813
Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Signed-off-by: Yu Wang <yu1.wang@intel.com>
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Shuo A Liu 2019-06-10 14:49:57 +08:00 committed by ACRN System Integration
parent 891e46453d
commit 7e66c0d4fa
8 changed files with 30 additions and 6 deletions

View File

@ -193,6 +193,18 @@ void vcpu_reset_eoi_exit_bitmaps(struct acrn_vcpu *vcpu)
vcpu_make_request(vcpu, ACRN_REQUEST_EOI_EXIT_BITMAP_UPDATE);
}
struct acrn_vcpu *get_running_vcpu(uint16_t pcpu_id)
{
struct thread_object *curr = sched_get_current(pcpu_id);
struct acrn_vcpu *vcpu = NULL;
if ((curr != NULL) && (!is_idle_thread(curr))) {
vcpu = list_entry(curr, struct acrn_vcpu, thread_obj);
}
return vcpu;
}
struct acrn_vcpu *get_ever_run_vcpu(uint16_t pcpu_id)
{
return per_cpu(ever_run_vcpu, pcpu_id);
@ -400,8 +412,6 @@ int32_t create_vcpu(uint16_t pcpu_id, struct acrn_vm *vm, struct acrn_vcpu **rtn
* needs revise.
*/
per_cpu(vcpu, pcpu_id) = vcpu;
pr_info("Create VM%d-VCPU%d, Role: %s",
vcpu->vm->vm_id, vcpu->vcpu_id,
is_vcpu_bsp(vcpu) ? "PRIMARY" : "SECONDARY");

View File

@ -14,6 +14,7 @@
#include <vlapic.h>
#include <lapic.h>
#include <per_cpu.h>
#include <guest/vm.h>
#include <multiboot.h>
#include <deprivilege_boot.h>

View File

@ -270,7 +270,7 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
static void depri_boot_spurious_handler(uint32_t vector)
{
if (get_pcpu_id() == BOOT_CPU_ID) {
struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID);
struct acrn_vcpu *vcpu = vcpu_from_vid(get_sos_vm(), BOOT_CPU_ID);
if (vcpu != NULL) {
vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE);

View File

@ -13,6 +13,12 @@
#include <schedule.h>
#include <sprintf.h>
bool is_idle_thread(const struct thread_object *obj)
{
uint16_t pcpu_id = obj->pcpu_id;
return (obj == &per_cpu(idle, pcpu_id));
}
/**
* @pre obj != NULL
*/
@ -67,6 +73,12 @@ static struct thread_object *get_next_sched_obj(const struct sched_control *ctl)
return ctl->thread_obj == NULL ? &get_cpu_var(idle) : ctl->thread_obj;
}
struct thread_object *sched_get_current(uint16_t pcpu_id)
{
struct sched_control *ctl = &per_cpu(sched_ctl, pcpu_id);
return ctl->curr_obj;
}
/**
* @pre delmode == DEL_MODE_IPI || delmode == DEL_MODE_INIT
*/

View File

@ -183,9 +183,8 @@ static void show_guest_call_trace(struct acrn_vcpu *vcpu)
static void dump_guest_context(uint16_t pcpu_id)
{
struct acrn_vcpu *vcpu;
struct acrn_vcpu *vcpu = get_running_vcpu(pcpu_id);
vcpu = per_cpu(vcpu, pcpu_id);
if (vcpu != NULL) {
dump_guest_reg(vcpu);
dump_guest_stack(vcpu);

View File

@ -538,6 +538,7 @@ static inline bool is_pae(struct acrn_vcpu *vcpu)
return (vcpu_get_cr4(vcpu) & CR4_PAE) != 0UL;
}
struct acrn_vcpu *get_running_vcpu(uint16_t pcpu_id);
struct acrn_vcpu* get_ever_run_vcpu(uint16_t pcpu_id);
/**

View File

@ -31,7 +31,6 @@ struct per_cpu_region {
uint64_t irq_count[NR_IRQS];
uint64_t softirq_pending;
uint64_t spurious;
struct acrn_vcpu *vcpu;
struct acrn_vcpu *ever_run_vcpu;
#ifdef STACK_PROTECTOR
struct stack_canary stk_canary;

View File

@ -35,7 +35,9 @@ struct sched_control {
struct thread_object *thread_obj;
};
bool is_idle_thread(const struct thread_object *obj);
uint16_t sched_get_pcpuid(const struct thread_object *obj);
struct thread_object *sched_get_current(uint16_t pcpu_id);
void init_scheduler(void);
void switch_to_idle(thread_entry_t idle_thread);