mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-27 15:56:54 +00:00
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:
parent
fafd5cf063
commit
9b8c6e6a90
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user