From 2abbb99f6ac52552f21d69424f2adb2c3fdca25a Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Fri, 17 Jul 2020 23:21:17 +0800 Subject: [PATCH] hv: make thread status more accurate 1. Update thread status after switch_in/switch_out. 2. Add 'be_blocking' to represent the intermediate state during sleep_thread and switch_out. After switch_out, the thread status update to THREAD_STS_BLOCKED. Tracked-On: #5057 Signed-off-by: Conghui Chen Reviewed-by: Shuo A Liu Acked-by: Eddie Dong --- hypervisor/common/schedule.c | 25 +++++++++++++------------ hypervisor/include/common/schedule.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 74c75338b..8709afadc 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -169,25 +169,26 @@ void schedule(void) } bitmap_clear_lock(NEED_RESCHEDULE, &ctl->flags); - /* Don't change prev object's status if it's not running */ - if (is_running(prev)) { - set_thread_status(prev, THREAD_STS_RUNNABLE); - } - set_thread_status(next, THREAD_STS_RUNNING); - ctl->curr_obj = next; - release_schedule_lock(pcpu_id, rflag); - /* If we picked different sched object, switch context */ if (prev != next) { - if ((prev != NULL) && (prev->switch_out != NULL)) { - prev->switch_out(prev); + if (prev != NULL) { + if (prev->switch_out != NULL) { + prev->switch_out(prev); + } + set_thread_status(prev, prev->be_blocking ? THREAD_STS_BLOCKED : THREAD_STS_RUNNABLE); + prev->be_blocking = false; } - if ((next != NULL) && (next->switch_in != NULL)) { + if (next->switch_in != NULL) { next->switch_in(next); } + set_thread_status(next, THREAD_STS_RUNNING); + ctl->curr_obj = next; + release_schedule_lock(pcpu_id, rflag); arch_switch_to(&prev->host_sp, &next->host_sp); + } else { + release_schedule_lock(pcpu_id, rflag); } } @@ -208,7 +209,7 @@ void sleep_thread(struct thread_object *obj) make_reschedule_request(pcpu_id, DEL_MODE_IPI); } } - set_thread_status(obj, THREAD_STS_BLOCKED); + obj->be_blocking = true; release_schedule_lock(pcpu_id, rflag); } diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index 6786fce10..aa2fad463 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -37,6 +37,7 @@ struct thread_object { struct sched_control *sched_ctl; thread_entry_t thread_entry; volatile enum thread_object_state status; + bool be_blocking; enum sched_notify_mode notify_mode; uint64_t host_sp;