Skip to content

Commit 5f8e7a6

Browse files
Shuo A Liuwenlingz
authored andcommitted
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>
1 parent 810305b commit 5f8e7a6

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@ void offline_vcpu(struct acrn_vcpu *vcpu)
598598
vcpu->state = VCPU_OFFLINE;
599599
}
600600

601+
void kick_vcpu(const struct acrn_vcpu *vcpu)
602+
{
603+
kick_thread(&vcpu->thread_obj);
604+
}
605+
601606
/*
602607
* @pre (&vcpu->stack[CONFIG_STACK_SIZE] & (CPU_STACK_ALIGN - 1UL)) == 0
603608
*/

hypervisor/arch/x86/guest/virq.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,8 @@ static bool is_guest_irq_enabled(struct acrn_vcpu *vcpu)
106106

107107
void vcpu_make_request(struct acrn_vcpu *vcpu, uint16_t eventid)
108108
{
109-
uint16_t pcpu_id = pcpuid_from_vcpu(vcpu);
110-
111109
bitmap_set_lock(eventid, &vcpu->arch.pending_req);
112-
/*
113-
* if current hostcpu is not the target vcpu's hostcpu, we need
114-
* to invoke IPI to wake up target vcpu
115-
*
116-
* TODO: Here we just compare with cpuid, since cpuid currently is
117-
* global under pCPU / vCPU 1:1 mapping. If later we enabled vcpu
118-
* scheduling, we need change here to determine it target vcpu is
119-
* VMX non-root or root mode
120-
*/
121-
if (get_pcpu_id() != pcpu_id) {
122-
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
123-
}
110+
kick_vcpu(vcpu);
124111
}
125112

126113
/*

hypervisor/common/schedule.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ void wake_thread(struct thread_object *obj)
222222
release_schedule_lock(pcpu_id, rflag);
223223
}
224224

225+
void kick_thread(const struct thread_object *obj)
226+
{
227+
uint16_t pcpu_id = obj->pcpu_id;
228+
uint64_t rflag;
229+
230+
obtain_schedule_lock(pcpu_id, &rflag);
231+
if (is_running(obj)) {
232+
if (get_pcpu_id() != pcpu_id) {
233+
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
234+
}
235+
} else if (is_runnable(obj)) {
236+
make_reschedule_request(pcpu_id, DEL_MODE_IPI);
237+
} else {
238+
/* do nothing */
239+
}
240+
release_schedule_lock(pcpu_id, rflag);
241+
}
242+
225243
void run_thread(struct thread_object *obj)
226244
{
227245
uint64_t rflag;

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,17 @@ void resume_vcpu(struct acrn_vcpu *vcpu);
636636
*/
637637
void launch_vcpu(struct acrn_vcpu *vcpu);
638638

639+
/**
640+
* @brief kick the vcpu and let it handle pending events
641+
*
642+
* Kick a vCPU to handle the pending events.
643+
*
644+
* @param[in] vcpu pointer to vcpu data structure
645+
*
646+
* @return None
647+
*/
648+
void kick_vcpu(const struct acrn_vcpu *vcpu);
649+
639650
/**
640651
* @brief create a vcpu for the vm and mapped to the pcpu.
641652
*

hypervisor/include/common/schedule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ bool need_reschedule(uint16_t pcpu_id);
100100
void run_thread(struct thread_object *obj);
101101
void sleep_thread(struct thread_object *obj);
102102
void wake_thread(struct thread_object *obj);
103+
void kick_thread(const struct thread_object *obj);
103104
void schedule(void);
104105

105106
void arch_switch_to(void *prev_sp, void *next_sp);

0 commit comments

Comments
 (0)