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 <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-13 14:32:40 +08:00
committed by ACRN System Integration
parent fafd5cf063
commit 9b8c6e6a90
2 changed files with 34 additions and 0 deletions

View File

@@ -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);
}