sched: split sched.h into separate header files
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
#include <kernel/sched.h>
|
|
||||||
#include <kernel/compiler.h>
|
#include <kernel/compiler.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
|
||||||
//size_t THREAD_sp = offsetof(struct thread, tr_sp);
|
// size_t THREAD_sp = offsetof(struct thread, tr_sp);
|
||||||
|
|
||||||
/* Use %a0 instead of %0 to prevent gcc from emitting a $ before the symbol value
|
/* Use %a0 instead of %0 to prevent gcc from emitting a $ before the symbol
|
||||||
in the generated assembly.
|
value in the generated assembly.
|
||||||
|
|
||||||
emitting
|
emitting
|
||||||
.set TASK_sp, $56
|
.set TASK_sp, $56
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <kernel/pmap.h>
|
#include <kernel/pmap.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include <kernel/vm-object.h>
|
#include <kernel/vm-object.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <kernel/ringbuffer.h>
|
#include <kernel/ringbuffer.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/vm.h>
|
||||||
|
|
||||||
size_t ringbuffer_unread(struct ringbuffer *ring_buffer)
|
size_t ringbuffer_unread(struct ringbuffer *ring_buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#ifndef KERNEL_CPU_H_
|
#ifndef KERNEL_CPU_H_
|
||||||
#define KERNEL_CPU_H_
|
#define KERNEL_CPU_H_
|
||||||
|
|
||||||
#include <kernel/types.h>
|
|
||||||
#include <kernel/machine/cpu.h>
|
#include <kernel/machine/cpu.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/types.h>
|
||||||
|
#include <kernel/work.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <kernel/flags.h>
|
#include <kernel/flags.h>
|
||||||
#include <kernel/locks.h>
|
#include <kernel/locks.h>
|
||||||
#include <kernel/vm.h>
|
#include <kernel/vm.h>
|
||||||
|
#include <kernel/wait.h>
|
||||||
#include <mango/status.h>
|
#include <mango/status.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifndef KERNEL_RINGBUFFER_H_
|
#ifndef KERNEL_RINGBUFFER_H_
|
||||||
#define KERNEL_RINGBUFFER_H_
|
#define KERNEL_RINGBUFFER_H_
|
||||||
|
|
||||||
|
#include <kernel/flags.h>
|
||||||
#include <kernel/locks.h>
|
#include <kernel/locks.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/types.h>
|
||||||
|
#include <kernel/wait.h>
|
||||||
|
|
||||||
struct ringbuffer {
|
struct ringbuffer {
|
||||||
unsigned char *r_buffer;
|
unsigned char *r_buffer;
|
||||||
|
|||||||
@@ -4,32 +4,11 @@
|
|||||||
#include <kernel/btree.h>
|
#include <kernel/btree.h>
|
||||||
#include <kernel/handle.h>
|
#include <kernel/handle.h>
|
||||||
#include <kernel/locks.h>
|
#include <kernel/locks.h>
|
||||||
#include <kernel/msg.h>
|
|
||||||
#include <kernel/object.h>
|
|
||||||
#include <kernel/pmap.h>
|
|
||||||
#include <kernel/queue.h>
|
#include <kernel/queue.h>
|
||||||
|
#include <kernel/types.h>
|
||||||
#include <mango/status.h>
|
#include <mango/status.h>
|
||||||
|
|
||||||
#define TASK_NAME_MAX 64
|
|
||||||
#define PRIO_MAX 32
|
#define PRIO_MAX 32
|
||||||
#define PID_MAX 99999
|
|
||||||
#define THREAD_KSTACK_ORDER VM_PAGE_4K
|
|
||||||
#define THREAD_MAX 65536
|
|
||||||
|
|
||||||
#define wait_event(wq, cond) \
|
|
||||||
({ \
|
|
||||||
struct thread *self = current_thread(); \
|
|
||||||
struct wait_item waiter; \
|
|
||||||
wait_item_init(&waiter, self); \
|
|
||||||
for (;;) { \
|
|
||||||
thread_wait_begin(&waiter, wq); \
|
|
||||||
if (cond) { \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
schedule(SCHED_NORMAL); \
|
|
||||||
} \
|
|
||||||
thread_wait_end(&waiter, wq); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -37,23 +16,6 @@ extern "C" {
|
|||||||
|
|
||||||
struct channel;
|
struct channel;
|
||||||
struct runqueue;
|
struct runqueue;
|
||||||
struct work_item;
|
|
||||||
|
|
||||||
enum task_state {
|
|
||||||
TASK_RUNNING,
|
|
||||||
TASK_STOPPED,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum thread_state {
|
|
||||||
THREAD_READY = 1,
|
|
||||||
THREAD_SLEEPING = 2,
|
|
||||||
THREAD_STOPPED = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum thread_flags {
|
|
||||||
THREAD_F_NEED_RESCHED = 0x01u,
|
|
||||||
THREAD_F_NO_PREEMPT = 0x02u,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum sched_priority {
|
enum sched_priority {
|
||||||
PRIO_IDLE = 4,
|
PRIO_IDLE = 4,
|
||||||
@@ -75,55 +37,6 @@ enum sched_mode {
|
|||||||
SCHED_IRQ = 1,
|
SCHED_IRQ = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct task {
|
|
||||||
struct object t_base;
|
|
||||||
|
|
||||||
struct task *t_parent;
|
|
||||||
long t_id;
|
|
||||||
enum task_state t_state;
|
|
||||||
char t_name[TASK_NAME_MAX];
|
|
||||||
|
|
||||||
pmap_t t_pmap;
|
|
||||||
struct vm_region *t_address_space;
|
|
||||||
spin_lock_t t_handles_lock;
|
|
||||||
struct handle_table *t_handles;
|
|
||||||
struct btree b_channels;
|
|
||||||
|
|
||||||
struct btree_node t_tasklist;
|
|
||||||
struct queue_entry t_child_entry;
|
|
||||||
|
|
||||||
size_t t_next_thread_id;
|
|
||||||
struct queue t_threads;
|
|
||||||
struct queue t_children;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct thread {
|
|
||||||
struct object thr_base;
|
|
||||||
|
|
||||||
enum thread_state tr_state;
|
|
||||||
enum thread_flags tr_flags;
|
|
||||||
struct task *tr_parent;
|
|
||||||
|
|
||||||
unsigned int tr_id;
|
|
||||||
unsigned int tr_prio;
|
|
||||||
|
|
||||||
cycles_t tr_charge_period_start;
|
|
||||||
cycles_t tr_quantum_cycles, tr_quantum_target;
|
|
||||||
cycles_t tr_total_cycles;
|
|
||||||
|
|
||||||
virt_addr_t tr_ip, tr_sp, tr_bp;
|
|
||||||
virt_addr_t tr_cpu_user_sp, tr_cpu_kernel_sp;
|
|
||||||
|
|
||||||
struct runqueue *tr_rq;
|
|
||||||
struct msg tr_msg;
|
|
||||||
|
|
||||||
struct queue_entry tr_parent_entry;
|
|
||||||
struct queue_entry tr_rqentry;
|
|
||||||
|
|
||||||
struct vm_page *tr_kstack;
|
|
||||||
struct vm_object *tr_ustack;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct runqueue {
|
struct runqueue {
|
||||||
struct queue rq_queues[PRIO_MAX];
|
struct queue rq_queues[PRIO_MAX];
|
||||||
uint32_t rq_readybits;
|
uint32_t rq_readybits;
|
||||||
@@ -141,34 +54,6 @@ struct timer {
|
|||||||
void (*t_callback)(struct timer *);
|
void (*t_callback)(struct timer *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wait_item {
|
|
||||||
struct thread *w_thread;
|
|
||||||
struct queue_entry w_entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct waitqueue {
|
|
||||||
struct queue wq_waiters;
|
|
||||||
spin_lock_t wq_lock;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*work_func_t)(struct work_item *);
|
|
||||||
|
|
||||||
struct work_item {
|
|
||||||
void *w_data;
|
|
||||||
work_func_t w_func;
|
|
||||||
struct queue_entry w_head;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct worker_pool {
|
|
||||||
struct thread **wp_workers;
|
|
||||||
size_t wp_nworkers;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct workqueue {
|
|
||||||
spin_lock_t wq_lock;
|
|
||||||
struct queue wq_queue; /* list of struct work_item */
|
|
||||||
};
|
|
||||||
|
|
||||||
extern kern_status_t sched_init(void);
|
extern kern_status_t sched_init(void);
|
||||||
extern void schedule(enum sched_mode mode);
|
extern void schedule(enum sched_mode mode);
|
||||||
extern void preempt_disable(void);
|
extern void preempt_disable(void);
|
||||||
@@ -188,38 +73,6 @@ static inline void rq_unlock(struct runqueue *rq, unsigned long flags)
|
|||||||
extern void rq_remove_thread(struct runqueue *rq, struct thread *thr);
|
extern void rq_remove_thread(struct runqueue *rq, struct thread *thr);
|
||||||
extern struct runqueue *cpu_rq(unsigned int cpu);
|
extern struct runqueue *cpu_rq(unsigned int cpu);
|
||||||
|
|
||||||
extern struct task *task_alloc(void);
|
|
||||||
extern struct task *task_cast(struct object *obj);
|
|
||||||
extern struct task *task_create(const char *name, size_t name_len);
|
|
||||||
static inline struct task *task_ref(struct task *task)
|
|
||||||
{
|
|
||||||
return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base));
|
|
||||||
}
|
|
||||||
static inline void task_unref(struct task *task)
|
|
||||||
{
|
|
||||||
object_unref(&task->t_base);
|
|
||||||
}
|
|
||||||
extern kern_status_t task_add_child(struct task *parent, struct task *child);
|
|
||||||
extern kern_status_t task_add_channel(
|
|
||||||
struct task *task,
|
|
||||||
struct channel *channel,
|
|
||||||
unsigned int id);
|
|
||||||
extern struct channel *task_get_channel(struct task *task, unsigned int id);
|
|
||||||
extern struct task *task_from_tid(tid_t id);
|
|
||||||
extern kern_status_t task_open_handle(
|
|
||||||
struct task *task,
|
|
||||||
struct object *obj,
|
|
||||||
handle_flags_t flags,
|
|
||||||
kern_handle_t *out);
|
|
||||||
extern kern_status_t task_resolve_handle(
|
|
||||||
struct task *task,
|
|
||||||
kern_handle_t handle,
|
|
||||||
struct object **out_obj,
|
|
||||||
handle_flags_t *out_flags);
|
|
||||||
extern kern_status_t task_close_handle(struct task *task, kern_handle_t handle);
|
|
||||||
extern struct thread *task_create_thread(struct task *parent);
|
|
||||||
extern struct task *kernel_task(void);
|
|
||||||
extern struct task *idle_task(void);
|
|
||||||
extern cycles_t default_quantum(void);
|
extern cycles_t default_quantum(void);
|
||||||
|
|
||||||
extern bool need_resched(void);
|
extern bool need_resched(void);
|
||||||
@@ -232,45 +85,12 @@ extern void schedule_thread_on_cpu(struct thread *thr);
|
|||||||
extern void start_charge_period(void);
|
extern void start_charge_period(void);
|
||||||
extern void end_charge_period(void);
|
extern void end_charge_period(void);
|
||||||
|
|
||||||
DEFINE_OBJECT_LOCK_FUNCTION(task, t_base)
|
|
||||||
|
|
||||||
extern struct thread *thread_alloc(void);
|
|
||||||
extern struct thread *thread_cast(struct object *obj);
|
|
||||||
extern kern_status_t thread_init_kernel(struct thread *thr, virt_addr_t ip);
|
|
||||||
extern kern_status_t thread_init_user(
|
|
||||||
struct thread *thr,
|
|
||||||
virt_addr_t ip,
|
|
||||||
virt_addr_t sp,
|
|
||||||
const uintptr_t *args,
|
|
||||||
size_t nr_args);
|
|
||||||
extern int thread_priority(struct thread *thr);
|
|
||||||
extern void thread_awaken(struct thread *thr);
|
|
||||||
extern void idle(void);
|
|
||||||
extern struct thread *create_kernel_thread(void (*fn)(void));
|
|
||||||
extern struct thread *create_idle_thread(void);
|
|
||||||
|
|
||||||
extern void add_timer(struct timer *timer);
|
extern void add_timer(struct timer *timer);
|
||||||
extern void remove_timer(struct timer *timer);
|
extern void remove_timer(struct timer *timer);
|
||||||
extern unsigned long schedule_timeout(unsigned long clock_ticks);
|
extern unsigned long schedule_timeout(unsigned long clock_ticks);
|
||||||
extern unsigned long milli_sleep(unsigned long ms);
|
extern unsigned long milli_sleep(unsigned long ms);
|
||||||
extern void sleep_forever(void);
|
extern void sleep_forever(void);
|
||||||
|
|
||||||
extern void wait_item_init(struct wait_item *item, struct thread *thr);
|
|
||||||
extern void thread_wait_begin(struct wait_item *waiter, struct waitqueue *q);
|
|
||||||
extern void thread_wait_end(struct wait_item *waiter, struct waitqueue *q);
|
|
||||||
extern void wait_on_queue(struct waitqueue *q);
|
|
||||||
extern void wakeup_queue(struct waitqueue *q);
|
|
||||||
extern void wakeup_one(struct waitqueue *q);
|
|
||||||
|
|
||||||
extern void work_item_init(work_func_t func, void *data, struct work_item *out);
|
|
||||||
extern void workqueue_init(struct workqueue *wq);
|
|
||||||
extern struct worker_pool *worker_pool_create(size_t nworkers);
|
|
||||||
extern struct worker_pool *global_worker_pool(void);
|
|
||||||
extern bool schedule_work_on(struct workqueue *wq, struct work_item *work);
|
|
||||||
extern bool schedule_work(struct work_item *work);
|
|
||||||
|
|
||||||
extern void wake_workers(struct workqueue *wq, struct worker_pool *pool);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define KERNEL_SYSCALL_H_
|
#define KERNEL_SYSCALL_H_
|
||||||
|
|
||||||
#include <kernel/handle.h>
|
#include <kernel/handle.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/task.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
#include <kernel/vm.h>
|
#include <kernel/vm.h>
|
||||||
#include <mango/status.h>
|
#include <mango/status.h>
|
||||||
|
|||||||
75
include/kernel/task.h
Normal file
75
include/kernel/task.h
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#ifndef KERNEL_TASK_H_
|
||||||
|
#define KERNEL_TASK_H_
|
||||||
|
|
||||||
|
#include <kernel/handle.h>
|
||||||
|
#include <kernel/object.h>
|
||||||
|
#include <kernel/pmap.h>
|
||||||
|
|
||||||
|
#define TASK_NAME_MAX 64
|
||||||
|
#define PID_MAX 99999
|
||||||
|
|
||||||
|
struct channel;
|
||||||
|
|
||||||
|
enum task_state {
|
||||||
|
TASK_RUNNING,
|
||||||
|
TASK_STOPPED,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct task {
|
||||||
|
struct object t_base;
|
||||||
|
|
||||||
|
struct task *t_parent;
|
||||||
|
long t_id;
|
||||||
|
enum task_state t_state;
|
||||||
|
char t_name[TASK_NAME_MAX];
|
||||||
|
|
||||||
|
pmap_t t_pmap;
|
||||||
|
struct vm_region *t_address_space;
|
||||||
|
spin_lock_t t_handles_lock;
|
||||||
|
struct handle_table *t_handles;
|
||||||
|
struct btree b_channels;
|
||||||
|
|
||||||
|
struct btree_node t_tasklist;
|
||||||
|
struct queue_entry t_child_entry;
|
||||||
|
|
||||||
|
size_t t_next_thread_id;
|
||||||
|
struct queue t_threads;
|
||||||
|
struct queue t_children;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct task *task_alloc(void);
|
||||||
|
extern struct task *task_cast(struct object *obj);
|
||||||
|
extern struct task *task_create(const char *name, size_t name_len);
|
||||||
|
static inline struct task *task_ref(struct task *task)
|
||||||
|
{
|
||||||
|
return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base));
|
||||||
|
}
|
||||||
|
static inline void task_unref(struct task *task)
|
||||||
|
{
|
||||||
|
object_unref(&task->t_base);
|
||||||
|
}
|
||||||
|
extern kern_status_t task_add_child(struct task *parent, struct task *child);
|
||||||
|
extern kern_status_t task_add_channel(
|
||||||
|
struct task *task,
|
||||||
|
struct channel *channel,
|
||||||
|
unsigned int id);
|
||||||
|
extern struct channel *task_get_channel(struct task *task, unsigned int id);
|
||||||
|
extern struct task *task_from_tid(tid_t id);
|
||||||
|
extern kern_status_t task_open_handle(
|
||||||
|
struct task *task,
|
||||||
|
struct object *obj,
|
||||||
|
handle_flags_t flags,
|
||||||
|
kern_handle_t *out);
|
||||||
|
extern kern_status_t task_resolve_handle(
|
||||||
|
struct task *task,
|
||||||
|
kern_handle_t handle,
|
||||||
|
struct object **out_obj,
|
||||||
|
handle_flags_t *out_flags);
|
||||||
|
extern kern_status_t task_close_handle(struct task *task, kern_handle_t handle);
|
||||||
|
extern struct thread *task_create_thread(struct task *parent);
|
||||||
|
extern struct task *kernel_task(void);
|
||||||
|
extern struct task *idle_task(void);
|
||||||
|
|
||||||
|
DEFINE_OBJECT_LOCK_FUNCTION(task, t_base)
|
||||||
|
|
||||||
|
#endif
|
||||||
64
include/kernel/thread.h
Normal file
64
include/kernel/thread.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#ifndef KERNEL_THREAD_H_
|
||||||
|
#define KERNEL_THREAD_H_
|
||||||
|
|
||||||
|
#include <kernel/msg.h>
|
||||||
|
#include <kernel/object.h>
|
||||||
|
#include <kernel/vm-controller.h>
|
||||||
|
|
||||||
|
#define THREAD_KSTACK_ORDER VM_PAGE_4K
|
||||||
|
|
||||||
|
enum thread_state {
|
||||||
|
THREAD_READY = 1,
|
||||||
|
THREAD_SLEEPING = 2,
|
||||||
|
THREAD_STOPPED = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum thread_flags {
|
||||||
|
THREAD_F_NEED_RESCHED = 0x01u,
|
||||||
|
THREAD_F_NO_PREEMPT = 0x02u,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct thread {
|
||||||
|
struct object thr_base;
|
||||||
|
|
||||||
|
enum thread_state tr_state;
|
||||||
|
enum thread_flags tr_flags;
|
||||||
|
struct task *tr_parent;
|
||||||
|
|
||||||
|
unsigned int tr_id;
|
||||||
|
unsigned int tr_prio;
|
||||||
|
|
||||||
|
cycles_t tr_charge_period_start;
|
||||||
|
cycles_t tr_quantum_cycles, tr_quantum_target;
|
||||||
|
cycles_t tr_total_cycles;
|
||||||
|
|
||||||
|
virt_addr_t tr_ip, tr_sp, tr_bp;
|
||||||
|
virt_addr_t tr_cpu_user_sp, tr_cpu_kernel_sp;
|
||||||
|
|
||||||
|
struct runqueue *tr_rq;
|
||||||
|
struct msg tr_msg;
|
||||||
|
struct page_request tr_page_req;
|
||||||
|
|
||||||
|
struct queue_entry tr_parent_entry;
|
||||||
|
struct queue_entry tr_rqentry;
|
||||||
|
|
||||||
|
struct vm_page *tr_kstack;
|
||||||
|
struct vm_object *tr_ustack;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct thread *thread_alloc(void);
|
||||||
|
extern struct thread *thread_cast(struct object *obj);
|
||||||
|
extern kern_status_t thread_init_kernel(struct thread *thr, virt_addr_t ip);
|
||||||
|
extern kern_status_t thread_init_user(
|
||||||
|
struct thread *thr,
|
||||||
|
virt_addr_t ip,
|
||||||
|
virt_addr_t sp,
|
||||||
|
const uintptr_t *args,
|
||||||
|
size_t nr_args);
|
||||||
|
extern int thread_priority(struct thread *thr);
|
||||||
|
extern void thread_awaken(struct thread *thr);
|
||||||
|
extern void idle(void);
|
||||||
|
extern struct thread *create_kernel_thread(void (*fn)(void));
|
||||||
|
extern struct thread *create_idle_thread(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
39
include/kernel/wait.h
Normal file
39
include/kernel/wait.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef KERNEL_WAIT_H_
|
||||||
|
#define KERNEL_WAIT_H_
|
||||||
|
|
||||||
|
#include <kernel/locks.h>
|
||||||
|
#include <kernel/queue.h>
|
||||||
|
|
||||||
|
#define wait_event(wq, cond) \
|
||||||
|
({ \
|
||||||
|
struct thread *self = current_thread(); \
|
||||||
|
struct wait_item waiter; \
|
||||||
|
wait_item_init(&waiter, self); \
|
||||||
|
for (;;) { \
|
||||||
|
thread_wait_begin(&waiter, wq); \
|
||||||
|
if (cond) { \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
schedule(SCHED_NORMAL); \
|
||||||
|
} \
|
||||||
|
thread_wait_end(&waiter, wq); \
|
||||||
|
})
|
||||||
|
|
||||||
|
struct wait_item {
|
||||||
|
struct thread *w_thread;
|
||||||
|
struct queue_entry w_entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct waitqueue {
|
||||||
|
struct queue wq_waiters;
|
||||||
|
spin_lock_t wq_lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void wait_item_init(struct wait_item *item, struct thread *thr);
|
||||||
|
extern void thread_wait_begin(struct wait_item *waiter, struct waitqueue *q);
|
||||||
|
extern void thread_wait_end(struct wait_item *waiter, struct waitqueue *q);
|
||||||
|
extern void wait_on_queue(struct waitqueue *q);
|
||||||
|
extern void wakeup_queue(struct waitqueue *q);
|
||||||
|
extern void wakeup_one(struct waitqueue *q);
|
||||||
|
|
||||||
|
#endif
|
||||||
37
include/kernel/work.h
Normal file
37
include/kernel/work.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef KERNEL_WORK_H_
|
||||||
|
#define KERNEL_WORK_H_
|
||||||
|
|
||||||
|
#include <kernel/locks.h>
|
||||||
|
#include <kernel/queue.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
struct work_item;
|
||||||
|
|
||||||
|
typedef void (*work_func_t)(struct work_item *);
|
||||||
|
|
||||||
|
struct work_item {
|
||||||
|
void *w_data;
|
||||||
|
work_func_t w_func;
|
||||||
|
struct queue_entry w_head;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct worker_pool {
|
||||||
|
struct thread **wp_workers;
|
||||||
|
size_t wp_nworkers;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct workqueue {
|
||||||
|
spin_lock_t wq_lock;
|
||||||
|
struct queue wq_queue; /* list of struct work_item */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void work_item_init(work_func_t func, void *data, struct work_item *out);
|
||||||
|
extern void workqueue_init(struct workqueue *wq);
|
||||||
|
extern struct worker_pool *worker_pool_create(size_t nworkers);
|
||||||
|
extern struct worker_pool *global_worker_pool(void);
|
||||||
|
extern bool schedule_work_on(struct workqueue *wq, struct work_item *work);
|
||||||
|
extern bool schedule_work(struct work_item *work);
|
||||||
|
|
||||||
|
extern void wake_workers(struct workqueue *wq, struct worker_pool *pool);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,7 +13,9 @@
|
|||||||
#include <kernel/port.h>
|
#include <kernel/port.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
#include <kernel/test.h>
|
#include <kernel/test.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/vm-object.h>
|
#include <kernel/vm-object.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <kernel/handle.h>
|
#include <kernel/handle.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/util.h>
|
#include <kernel/util.h>
|
||||||
#include <kernel/vm-object.h>
|
#include <kernel/vm-object.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include <kernel/channel.h>
|
#include <kernel/channel.h>
|
||||||
#include <kernel/msg.h>
|
#include <kernel/msg.h>
|
||||||
#include <kernel/port.h>
|
#include <kernel/port.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/util.h>
|
#include <kernel/util.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include <kernel/locks.h>
|
#include <kernel/locks.h>
|
||||||
#include <kernel/object.h>
|
#include <kernel/object.h>
|
||||||
#include <kernel/queue.h>
|
#include <kernel/queue.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
|
||||||
#define HAS_OP(obj, opname) ((obj)->ob_type->ob_ops.opname)
|
#define HAS_OP(obj, opname) ((obj)->ob_type->ob_ops.opname)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include <kernel/libc/stdio.h>
|
#include <kernel/libc/stdio.h>
|
||||||
#include <kernel/machine/panic.h>
|
#include <kernel/machine/panic.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
static int has_panicked = 0;
|
static int has_panicked = 0;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <kernel/channel.h>
|
#include <kernel/channel.h>
|
||||||
#include <kernel/port.h>
|
#include <kernel/port.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/util.h>
|
#include <kernel/util.h>
|
||||||
|
|
||||||
#define PORT_CAST(p) OBJECT_C_CAST(struct port, p_base, &port_type, p)
|
#define PORT_CAST(p) OBJECT_C_CAST(struct port, p_base, &port_type, p)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <kernel/object.h>
|
#include <kernel/object.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|
||||||
extern kern_status_t setup_kernel_task(void);
|
extern kern_status_t setup_kernel_task(void);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <kernel/sched.h>
|
|
||||||
#include <kernel/percpu.h>
|
|
||||||
#include <kernel/cpu.h>
|
#include <kernel/cpu.h>
|
||||||
|
#include <kernel/percpu.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
|
||||||
#define PRIO_MASK(p) (((uint32_t)1) << (p))
|
#define PRIO_MASK(p) (((uint32_t)1) << (p))
|
||||||
#define FIRST_PRIO(m) (m > 0 ? (PRIO_MAX - __builtin_clz(m) - 1) : -1)
|
#define FIRST_PRIO(m) (m > 0 ? (PRIO_MAX - __builtin_clz(m) - 1) : -1)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <kernel/object.h>
|
#include <kernel/object.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/util.h>
|
#include <kernel/util.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include <kernel/cpu.h>
|
#include <kernel/cpu.h>
|
||||||
#include <kernel/machine/thread.h>
|
#include <kernel/machine/thread.h>
|
||||||
#include <kernel/object.h>
|
#include <kernel/object.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
|
||||||
#define THREAD_CAST(p) OBJECT_C_CAST(struct thread, thr_base, &thread_type, p)
|
#define THREAD_CAST(p) OBJECT_C_CAST(struct thread, thr_base, &thread_type, p)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include <kernel/sched.h>
|
|
||||||
#include <kernel/printk.h>
|
|
||||||
#include <kernel/cpu.h>
|
|
||||||
#include <kernel/clock.h>
|
#include <kernel/clock.h>
|
||||||
|
#include <kernel/cpu.h>
|
||||||
|
#include <kernel/printk.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
|
||||||
static void timeout_expiry(struct timer *timer)
|
static void timeout_expiry(struct timer *timer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <kernel/cpu.h>
|
#include <kernel/cpu.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
#include <kernel/wait.h>
|
||||||
|
|
||||||
void wait_item_init(struct wait_item *item, struct thread *thr)
|
void wait_item_init(struct wait_item *item, struct thread *thr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include <kernel/sched.h>
|
|
||||||
#include <kernel/vm.h>
|
|
||||||
#include <kernel/util.h>
|
|
||||||
#include <kernel/cpu.h>
|
#include <kernel/cpu.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
|
#include <kernel/util.h>
|
||||||
|
#include <kernel/vm.h>
|
||||||
|
|
||||||
static struct worker_pool *__global_worker_pool = NULL;
|
static struct worker_pool *__global_worker_pool = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
|
||||||
kern_status_t sys_kern_log(const char *s)
|
kern_status_t sys_kern_log(const char *s)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/syscall.h>
|
#include <kernel/syscall.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|
||||||
kern_status_t sys_channel_create(unsigned int id, kern_handle_t *out)
|
kern_status_t sys_channel_create(unsigned int id, kern_handle_t *out)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/syscall.h>
|
#include <kernel/syscall.h>
|
||||||
|
#include <kernel/task.h>
|
||||||
|
#include <kernel/thread.h>
|
||||||
#include <kernel/vm-region.h>
|
#include <kernel/vm-region.h>
|
||||||
|
|
||||||
extern kern_status_t sys_task_exit(int status)
|
extern kern_status_t sys_task_exit(int status)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
#include <kernel/util.h>
|
#include <kernel/util.h>
|
||||||
#include <kernel/vm-object.h>
|
#include <kernel/vm-object.h>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user