2018-03-07 20:57:14 +08:00
|
|
|
/*
|
2022-04-05 18:59:24 +08:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-03-07 20:57:14 +08:00
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-29 15:46:27 +08:00
|
|
|
#ifndef SCHEDULE_H
|
|
|
|
#define SCHEDULE_H
|
2021-04-23 15:50:57 +08:00
|
|
|
#include <asm/lib/spinlock.h>
|
2021-03-04 17:31:05 +08:00
|
|
|
#include <lib/list.h>
|
2021-04-12 13:40:00 +08:00
|
|
|
#include <timer.h>
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-06-30 00:17:34 +08:00
|
|
|
#define NEED_RESCHEDULE (1U)
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2021-12-17 14:02:01 +08:00
|
|
|
#define DEL_MODE_INIT (1U)
|
2019-03-24 18:08:25 +08:00
|
|
|
#define DEL_MODE_IPI (2U)
|
|
|
|
|
2019-06-17 17:31:14 +08:00
|
|
|
#define THREAD_DATA_SIZE (256U)
|
|
|
|
|
2019-06-13 14:32:40 +08:00
|
|
|
enum thread_object_state {
|
|
|
|
THREAD_STS_RUNNING = 1,
|
|
|
|
THREAD_STS_RUNNABLE,
|
|
|
|
THREAD_STS_BLOCKED
|
|
|
|
};
|
|
|
|
|
2019-06-14 13:10:05 +08:00
|
|
|
enum sched_notify_mode {
|
2021-12-17 14:02:01 +08:00
|
|
|
SCHED_NOTIFY_INIT,
|
2019-06-14 13:10:05 +08:00
|
|
|
SCHED_NOTIFY_IPI
|
|
|
|
};
|
|
|
|
|
2021-09-09 16:21:30 +08:00
|
|
|
/* Tools can configure a VM to use PRIO_LOW or PRIO_HIGH */
|
|
|
|
enum thread_priority {
|
|
|
|
PRIO_IDLE = 0,
|
|
|
|
PRIO_LOW,
|
|
|
|
PRIO_HIGH,
|
|
|
|
PRIO_MAX
|
|
|
|
};
|
|
|
|
|
2019-05-23 16:17:28 +08:00
|
|
|
struct thread_object;
|
|
|
|
typedef void (*thread_entry_t)(struct thread_object *obj);
|
|
|
|
typedef void (*switch_t)(struct thread_object *obj);
|
|
|
|
struct thread_object {
|
2019-01-18 16:30:25 +08:00
|
|
|
char name[16];
|
2019-10-14 16:38:58 +08:00
|
|
|
uint16_t pcpu_id;
|
|
|
|
struct sched_control *sched_ctl;
|
2019-05-23 16:17:28 +08:00
|
|
|
thread_entry_t thread_entry;
|
2019-06-13 14:32:40 +08:00
|
|
|
volatile enum thread_object_state status;
|
2020-07-17 23:21:17 +08:00
|
|
|
bool be_blocking;
|
2019-06-14 13:10:05 +08:00
|
|
|
enum sched_notify_mode notify_mode;
|
2019-10-14 16:38:58 +08:00
|
|
|
|
|
|
|
uint64_t host_sp;
|
2019-05-23 16:17:28 +08:00
|
|
|
switch_t switch_out;
|
|
|
|
switch_t switch_in;
|
2019-06-17 17:31:14 +08:00
|
|
|
|
2021-09-09 16:21:30 +08:00
|
|
|
int priority;
|
|
|
|
|
2019-06-17 17:31:14 +08:00
|
|
|
uint8_t data[THREAD_DATA_SIZE];
|
2018-12-20 12:15:25 +08:00
|
|
|
};
|
|
|
|
|
2019-05-23 16:17:28 +08:00
|
|
|
struct sched_control {
|
2019-06-17 11:30:13 +08:00
|
|
|
uint16_t pcpu_id;
|
2018-06-29 14:29:34 +08:00
|
|
|
uint64_t flags;
|
2019-05-23 16:17:28 +08:00
|
|
|
struct thread_object *curr_obj;
|
|
|
|
spinlock_t scheduler_lock; /* to protect sched_control and thread_object */
|
2019-06-17 17:31:14 +08:00
|
|
|
struct acrn_scheduler *scheduler;
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
#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;
|
2019-06-20 11:10:53 +08:00
|
|
|
extern struct acrn_scheduler sched_iorr;
|
2019-10-14 16:28:19 +08:00
|
|
|
|
2019-06-17 17:31:14 +08:00
|
|
|
struct sched_noop_control {
|
|
|
|
struct thread_object *noop_thread_obj;
|
2018-06-05 15:25:07 +08:00
|
|
|
};
|
|
|
|
|
2019-06-20 11:10:53 +08:00
|
|
|
struct sched_iorr_control {
|
|
|
|
struct list_head runqueue;
|
|
|
|
struct hv_timer tick_timer;
|
|
|
|
};
|
|
|
|
|
2020-02-05 22:51:43 +08:00
|
|
|
extern struct acrn_scheduler sched_bvt;
|
|
|
|
struct sched_bvt_control {
|
|
|
|
struct list_head runqueue;
|
|
|
|
struct hv_timer tick_timer;
|
|
|
|
};
|
|
|
|
|
2021-09-09 16:21:30 +08:00
|
|
|
extern struct acrn_scheduler sched_prio;
|
|
|
|
struct sched_prio_control {
|
|
|
|
struct list_head prio_queue;
|
|
|
|
};
|
|
|
|
|
2019-06-10 14:49:57 +08:00
|
|
|
bool is_idle_thread(const struct thread_object *obj);
|
2019-10-14 16:38:58 +08:00
|
|
|
uint16_t sched_get_pcpuid(const struct thread_object *obj);
|
2019-06-10 14:49:57 +08:00
|
|
|
struct thread_object *sched_get_current(uint16_t pcpu_id);
|
2019-10-14 16:38:58 +08:00
|
|
|
|
2019-06-12 18:31:44 +08:00
|
|
|
void init_sched(uint16_t pcpu_id);
|
2019-06-17 17:31:14 +08:00
|
|
|
void deinit_sched(uint16_t pcpu_id);
|
2019-09-05 03:39:54 +08:00
|
|
|
void obtain_schedule_lock(uint16_t pcpu_id, uint64_t *rflag);
|
|
|
|
void release_schedule_lock(uint16_t pcpu_id, uint64_t rflag);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2019-06-17 17:31:14 +08:00
|
|
|
void init_thread_data(struct thread_object *obj);
|
|
|
|
void deinit_thread_data(struct thread_object *obj);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2019-03-24 18:08:25 +08:00
|
|
|
void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode);
|
2018-12-25 14:48:17 +08:00
|
|
|
bool need_reschedule(uint16_t pcpu_id);
|
2018-06-02 22:31:58 +08:00
|
|
|
|
2019-10-16 19:16:37 +08:00
|
|
|
void run_thread(struct thread_object *obj);
|
2019-06-14 13:10:05 +08:00
|
|
|
void sleep_thread(struct thread_object *obj);
|
2020-07-17 23:53:43 +08:00
|
|
|
void sleep_thread_sync(struct thread_object *obj);
|
2019-06-14 13:10:05 +08:00
|
|
|
void wake_thread(struct thread_object *obj);
|
2019-06-18 18:15:12 +08:00
|
|
|
void yield_current(void);
|
2018-03-07 20:57:14 +08:00
|
|
|
void schedule(void);
|
2019-01-18 16:30:25 +08:00
|
|
|
|
2019-01-24 19:31:03 +08:00
|
|
|
void arch_switch_to(void *prev_sp, void *next_sp);
|
2019-10-16 19:16:37 +08:00
|
|
|
void run_idle_thread(void);
|
2018-09-29 15:46:27 +08:00
|
|
|
#endif /* SCHEDULE_H */
|
2018-03-07 20:57:14 +08:00
|
|
|
|