hv: sched: add kick_thread to support notification

kick means to notify one thread_object. If the target thread object is
running, send a IPI to notify it; if the target thread object is
runnable, make reschedule on it.

Also add kick_vcpu API in vcpu layer to notify vcpu.

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-18 17:49:56 +08:00 committed by wenlingz
parent 810305be98
commit 5f8e7a6cb7
5 changed files with 36 additions and 14 deletions

View File

@ -598,6 +598,11 @@ void offline_vcpu(struct acrn_vcpu *vcpu)
vcpu->state = VCPU_OFFLINE;
}
void kick_vcpu(const struct acrn_vcpu *vcpu)
{
kick_thread(&vcpu->thread_obj);
}
/*
* @pre (&vcpu->stack[CONFIG_STACK_SIZE] & (CPU_STACK_ALIGN - 1UL)) == 0
*/

View File

@ -106,21 +106,8 @@ static bool is_guest_irq_enabled(struct acrn_vcpu *vcpu)
void vcpu_make_request(struct acrn_vcpu *vcpu, uint16_t eventid)
{
uint16_t pcpu_id = pcpuid_from_vcpu(vcpu);
bitmap_set_lock(eventid, &vcpu->arch.pending_req);
/*
* if current hostcpu is not the target vcpu's hostcpu, we need
* to invoke IPI to wake up target vcpu
*
* TODO: Here we just compare with cpuid, since cpuid currently is
* global under pCPU / vCPU 1:1 mapping. If later we enabled vcpu
* scheduling, we need change here to determine it target vcpu is
* VMX non-root or root mode
*/
if (get_pcpu_id() != pcpu_id) {
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
}
kick_vcpu(vcpu);
}
/*

View File

@ -222,6 +222,24 @@ void wake_thread(struct thread_object *obj)
release_schedule_lock(pcpu_id, rflag);
}
void kick_thread(const struct thread_object *obj)
{
uint16_t pcpu_id = obj->pcpu_id;
uint64_t rflag;
obtain_schedule_lock(pcpu_id, &rflag);
if (is_running(obj)) {
if (get_pcpu_id() != pcpu_id) {
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
}
} else if (is_runnable(obj)) {
make_reschedule_request(pcpu_id, DEL_MODE_IPI);
} else {
/* do nothing */
}
release_schedule_lock(pcpu_id, rflag);
}
void run_thread(struct thread_object *obj)
{
uint64_t rflag;

View File

@ -636,6 +636,17 @@ void resume_vcpu(struct acrn_vcpu *vcpu);
*/
void launch_vcpu(struct acrn_vcpu *vcpu);
/**
* @brief kick the vcpu and let it handle pending events
*
* Kick a vCPU to handle the pending events.
*
* @param[in] vcpu pointer to vcpu data structure
*
* @return None
*/
void kick_vcpu(const struct acrn_vcpu *vcpu);
/**
* @brief create a vcpu for the vm and mapped to the pcpu.
*

View File

@ -100,6 +100,7 @@ bool need_reschedule(uint16_t pcpu_id);
void run_thread(struct thread_object *obj);
void sleep_thread(struct thread_object *obj);
void wake_thread(struct thread_object *obj);
void kick_thread(const struct thread_object *obj);
void schedule(void);
void arch_switch_to(void *prev_sp, void *next_sp);