hv: sched: decouple scheduler from schedule framework

This patch decouple some scheduling logic and abstract into a scheduler.
Then we have scheduler, schedule framework. From modulization
perspective, schedule framework provides some APIs for other layers to
use, also interact with scheduler through scheduler interaces.

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-17 17:31:14 +08:00
committed by wenlingz
parent cad195c018
commit f04c491259
10 changed files with 157 additions and 36 deletions

View File

@@ -13,6 +13,8 @@
#define DEL_MODE_INIT (1U)
#define DEL_MODE_IPI (2U)
#define THREAD_DATA_SIZE (256U)
enum thread_object_state {
THREAD_STS_RUNNING = 1,
THREAD_STS_RUNNABLE,
@@ -38,6 +40,8 @@ struct thread_object {
uint64_t host_sp;
switch_t switch_out;
switch_t switch_in;
uint8_t data[THREAD_DATA_SIZE];
};
struct sched_control {
@@ -45,8 +49,37 @@ struct sched_control {
uint64_t flags;
struct thread_object *curr_obj;
spinlock_t scheduler_lock; /* to protect sched_control and thread_object */
struct acrn_scheduler *scheduler;
void *priv;
};
struct thread_object *thread_obj;
#define SCHEDULER_MAX_NUMBER 4U
struct acrn_scheduler {
char name[16];
/* init scheduler */
int32_t (*init)(struct sched_control *ctl);
/* init private data of scheduler */
void (*init_data)(struct thread_object *obj);
/* pick the next thread object */
struct thread_object* (*pick_next)(struct sched_control *ctl);
/* put thread object into sleep */
void (*sleep)(struct thread_object *obj);
/* wake up thread object from sleep status */
void (*wake)(struct thread_object *obj);
/* yield current thread object */
void (*yield)(struct sched_control *ctl);
/* prioritize the thread object */
void (*prioritize)(struct thread_object *obj);
/* deinit private data of scheduler */
void (*deinit_data)(struct thread_object *obj);
/* deinit scheduler */
void (*deinit)(struct sched_control *ctl);
};
extern struct acrn_scheduler sched_noop;
struct sched_noop_control {
struct thread_object *noop_thread_obj;
};
bool is_idle_thread(const struct thread_object *obj);
@@ -54,11 +87,12 @@ uint16_t sched_get_pcpuid(const struct thread_object *obj);
struct thread_object *sched_get_current(uint16_t pcpu_id);
void init_sched(uint16_t pcpu_id);
void deinit_sched(uint16_t pcpu_id);
void get_schedule_lock(uint16_t pcpu_id);
void release_schedule_lock(uint16_t pcpu_id);
void insert_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
void remove_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
void init_thread_data(struct thread_object *obj);
void deinit_thread_data(struct thread_object *obj);
void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode);
bool need_reschedule(uint16_t pcpu_id);