2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
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
|
2019-02-02 22:45:21 +08:00
|
|
|
#include <spinlock.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
|
|
|
|
2019-03-24 18:08:25 +08:00
|
|
|
#define DEL_MODE_INIT (1U)
|
|
|
|
#define DEL_MODE_IPI (2U)
|
|
|
|
|
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 {
|
|
|
|
SCHED_NOTIFY_INIT,
|
|
|
|
SCHED_NOTIFY_IPI
|
|
|
|
};
|
|
|
|
|
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;
|
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;
|
2018-12-20 12:15:25 +08:00
|
|
|
};
|
|
|
|
|
2019-05-23 16:17:28 +08:00
|
|
|
struct sched_control {
|
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-10-14 16:28:19 +08:00
|
|
|
|
|
|
|
struct thread_object *thread_obj;
|
2018-06-05 15:25:07 +08:00
|
|
|
};
|
|
|
|
|
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);
|
2018-06-20 15:42:52 +08:00
|
|
|
void get_schedule_lock(uint16_t pcpu_id);
|
|
|
|
void release_schedule_lock(uint16_t pcpu_id);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2019-10-14 16:28:19 +08:00
|
|
|
void insert_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
|
|
|
|
void remove_thread_obj(struct thread_object *obj, uint16_t pcpu_id);
|
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);
|
|
|
|
void wake_thread(struct thread_object *obj);
|
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
|
|
|
|