diff --git a/hypervisor/common/sched_bvt.c b/hypervisor/common/sched_bvt.c index a673ce913..56470953a 100644 --- a/hypervisor/common/sched_bvt.c +++ b/hypervisor/common/sched_bvt.c @@ -42,6 +42,21 @@ static bool is_inqueue(struct thread_object *obj) return !list_empty(&data->list); } +/* + * @pre bvt_ctl != NULL + */ +static void update_svt(struct sched_bvt_control *bvt_ctl) +{ + struct sched_bvt_data *obj_data; + struct thread_object *tmp_obj; + + if (!list_empty(&bvt_ctl->runqueue)) { + tmp_obj = get_first_item(&bvt_ctl->runqueue, struct thread_object, data); + obj_data = (struct sched_bvt_data *)tmp_obj->data; + bvt_ctl->svt = obj_data->avt; + } +} + /* * @pre obj != NULL * @pre obj->data != NULL @@ -102,16 +117,8 @@ static void runqueue_remove(struct thread_object *obj) static int64_t get_svt(struct thread_object *obj) { struct sched_bvt_control *bvt_ctl = (struct sched_bvt_control *)obj->sched_ctl->priv; - struct sched_bvt_data *obj_data; - struct thread_object *tmp_obj; - int64_t svt = 0; - if (!list_empty(&bvt_ctl->runqueue)) { - tmp_obj = get_first_item(&bvt_ctl->runqueue, struct thread_object, data); - obj_data = (struct sched_bvt_data *)tmp_obj->data; - svt = obj_data->avt; - } - return svt; + return bvt_ctl->svt; } static void sched_tick_handler(void *param) @@ -236,6 +243,8 @@ static struct thread_object *sched_bvt_pick_next(struct sched_control *ctl) if (!is_idle_thread(current)) { update_vt(current); } + /* always align the svt with the avt of the first thread object in runqueue.*/ + update_svt(bvt_ctl); if (!list_empty(&bvt_ctl->runqueue)) { first = bvt_ctl->runqueue.next; diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index b473d8329..abac7b8bb 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -105,6 +105,8 @@ extern struct acrn_scheduler sched_bvt; struct sched_bvt_control { struct list_head runqueue; struct hv_timer tick_timer; + /* The minimum AVT of any runnable threads */ + int64_t svt; }; extern struct acrn_scheduler sched_prio;