From 9b8c6e6a90864f5437853aed76c8172191e6d3d8 Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Thu, 13 Jun 2019 14:32:40 +0800 Subject: [PATCH] hv: sched: add status for thread_object Now, we have three valid status for thread_object: THREAD_STS_RUNNING, THREAD_STS_RUNNABLE, THREAD_STS_BLOCKED. This patch also provide several helpers to check the thread's status and a status set wrapper function. Tracked-On: #3813 Signed-off-by: Jason Chen CJ Signed-off-by: Yu Wang Signed-off-by: Shuo A Liu Acked-by: Eddie Dong --- hypervisor/common/schedule.c | 27 +++++++++++++++++++++++++++ hypervisor/include/common/schedule.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c index 0d2de9322..8a47676f1 100644 --- a/hypervisor/common/schedule.c +++ b/hypervisor/common/schedule.c @@ -19,6 +19,26 @@ bool is_idle_thread(const struct thread_object *obj) return (obj == &per_cpu(idle, pcpu_id)); } +static inline bool is_blocked(const struct thread_object *obj) +{ + return obj->status == THREAD_STS_BLOCKED; +} + +static inline bool is_runnable(const struct thread_object *obj) +{ + return obj->status == THREAD_STS_RUNNABLE; +} + +static inline bool is_running(const struct thread_object *obj) +{ + return obj->status == THREAD_STS_RUNNING; +} + +static inline void set_thread_status(struct thread_object *obj, enum thread_object_state status) +{ + obj->status = status; +} + /** * @pre obj != NULL */ @@ -128,6 +148,12 @@ void schedule(void) next = get_next_sched_obj(ctl); 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); + if (prev == next) { release_schedule_lock(pcpu_id); } else { @@ -160,6 +186,7 @@ void switch_to_idle(thread_entry_t idle_thread) idle->switch_out = NULL; idle->switch_in = NULL; get_cpu_var(sched_ctl).curr_obj = idle; + set_thread_status(idle, THREAD_STS_RUNNING); run_sched_thread(idle); } diff --git a/hypervisor/include/common/schedule.h b/hypervisor/include/common/schedule.h index 0228ac9c6..cdfa2c1be 100644 --- a/hypervisor/include/common/schedule.h +++ b/hypervisor/include/common/schedule.h @@ -13,6 +13,12 @@ #define DEL_MODE_INIT (1U) #define DEL_MODE_IPI (2U) +enum thread_object_state { + THREAD_STS_RUNNING = 1, + THREAD_STS_RUNNABLE, + THREAD_STS_BLOCKED +}; + struct thread_object; typedef void (*thread_entry_t)(struct thread_object *obj); typedef void (*switch_t)(struct thread_object *obj); @@ -21,6 +27,7 @@ struct thread_object { uint16_t pcpu_id; struct sched_control *sched_ctl; thread_entry_t thread_entry; + volatile enum thread_object_state status; uint64_t host_sp; switch_t switch_out;