sched: allocate and assign ids to each thread
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
#ifndef SOCKS_SCHED_H_
|
#ifndef SOCKS_SCHED_H_
|
||||||
#define SOCKS_SCHED_H_
|
#define SOCKS_SCHED_H_
|
||||||
|
|
||||||
#include <socks/pmap.h>
|
|
||||||
#include <socks/locks.h>
|
|
||||||
#include <socks/queue.h>
|
|
||||||
#include <socks/object.h>
|
|
||||||
#include <socks/btree.h>
|
#include <socks/btree.h>
|
||||||
|
#include <socks/locks.h>
|
||||||
|
#include <socks/object.h>
|
||||||
|
#include <socks/pmap.h>
|
||||||
|
#include <socks/queue.h>
|
||||||
#include <socks/status.h>
|
#include <socks/status.h>
|
||||||
|
|
||||||
#define TASK_NAME_MAX 64
|
#define TASK_NAME_MAX 64
|
||||||
#define PRIO_MAX 32
|
#define PRIO_MAX 32
|
||||||
#define THREAD_KSTACK_ORDER VM_PAGE_4K
|
#define THREAD_KSTACK_ORDER VM_PAGE_4K
|
||||||
|
#define THREAD_MAX 65536
|
||||||
|
|
||||||
#define wait_event(wq, cond) \
|
#define wait_event(wq, cond) \
|
||||||
({ \
|
({ \
|
||||||
@@ -174,8 +175,14 @@ 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_alloc(void);
|
||||||
static inline struct task *task_ref(struct task *task) { return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base)); }
|
static inline struct task *task_ref(struct task *task)
|
||||||
static inline void task_deref(struct task *task) { object_deref(&task->t_base); }
|
{
|
||||||
|
return OBJECT_CAST(struct task, t_base, object_ref(&task->t_base));
|
||||||
|
}
|
||||||
|
static inline void task_deref(struct task *task)
|
||||||
|
{
|
||||||
|
object_deref(&task->t_base);
|
||||||
|
}
|
||||||
extern struct task *task_from_pid(unsigned int pid);
|
extern struct task *task_from_pid(unsigned int pid);
|
||||||
extern struct task *kernel_task(void);
|
extern struct task *kernel_task(void);
|
||||||
extern struct task *idle_task(void);
|
extern struct task *idle_task(void);
|
||||||
@@ -196,7 +203,9 @@ static inline void task_lock_irqsave(struct task *task, unsigned long *flags)
|
|||||||
object_lock_irqsave(&task->t_base, flags);
|
object_lock_irqsave(&task->t_base, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void task_unlock_irqrestore(struct task *task, unsigned long flags)
|
static inline void task_unlock_irqrestore(
|
||||||
|
struct task *task,
|
||||||
|
unsigned long flags)
|
||||||
{
|
{
|
||||||
object_unlock_irqrestore(&task->t_base, flags);
|
object_unlock_irqrestore(&task->t_base, flags);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#include <socks/sched.h>
|
#include <socks/bitmap.h>
|
||||||
#include <socks/object.h>
|
|
||||||
#include <socks/cpu.h>
|
#include <socks/cpu.h>
|
||||||
#include <socks/machine/thread.h>
|
#include <socks/machine/thread.h>
|
||||||
|
#include <socks/object.h>
|
||||||
|
#include <socks/sched.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)
|
||||||
|
|
||||||
|
static DECLARE_BITMAP(thread_ids, THREAD_MAX) = {0};
|
||||||
|
|
||||||
static struct object_type thread_type = {
|
static struct object_type thread_type = {
|
||||||
.ob_name = "thread",
|
.ob_name = "thread",
|
||||||
.ob_size = sizeof(struct thread),
|
.ob_size = sizeof(struct thread),
|
||||||
@@ -30,6 +33,9 @@ struct thread *thread_alloc(void)
|
|||||||
|
|
||||||
kern_status_t thread_init(struct thread *thr, uintptr_t ip)
|
kern_status_t thread_init(struct thread *thr, uintptr_t ip)
|
||||||
{
|
{
|
||||||
|
thr->tr_id = bitmap_lowest_clear(thread_ids, THREAD_MAX);
|
||||||
|
bitmap_set(thread_ids, thr->tr_id);
|
||||||
|
|
||||||
thr->tr_prio = PRIO_NORMAL;
|
thr->tr_prio = PRIO_NORMAL;
|
||||||
thr->tr_state = THREAD_READY;
|
thr->tr_state = THREAD_READY;
|
||||||
thr->tr_quantum_target = default_quantum();
|
thr->tr_quantum_target = default_quantum();
|
||||||
@@ -39,7 +45,8 @@ kern_status_t thread_init(struct thread *thr, uintptr_t ip)
|
|||||||
return KERN_NO_MEMORY;
|
return KERN_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
thr->tr_sp = (uintptr_t)vm_page_get_vaddr(thr->tr_kstack) + vm_page_order_to_bytes(THREAD_KSTACK_ORDER);
|
thr->tr_sp = (uintptr_t)vm_page_get_vaddr(thr->tr_kstack)
|
||||||
|
+ vm_page_order_to_bytes(THREAD_KSTACK_ORDER);
|
||||||
thr->tr_bp = thr->tr_sp;
|
thr->tr_bp = thr->tr_sp;
|
||||||
|
|
||||||
prepare_stack(ip, &thr->tr_sp);
|
prepare_stack(ip, &thr->tr_sp);
|
||||||
@@ -49,7 +56,6 @@ kern_status_t thread_init(struct thread *thr, uintptr_t ip)
|
|||||||
|
|
||||||
void thread_free(struct thread *thr)
|
void thread_free(struct thread *thr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread *current_thread(void)
|
struct thread *current_thread(void)
|
||||||
@@ -79,6 +85,9 @@ struct thread *create_kernel_thread(void(*fn)(void))
|
|||||||
struct task *kernel = kernel_task();
|
struct task *kernel = kernel_task();
|
||||||
struct thread *thr = thread_alloc();
|
struct thread *thr = thread_alloc();
|
||||||
|
|
||||||
|
thr->tr_id = 1;
|
||||||
|
bitmap_set(thread_ids, 1);
|
||||||
|
|
||||||
thr->tr_parent = kernel;
|
thr->tr_parent = kernel;
|
||||||
thr->tr_prio = PRIO_NORMAL;
|
thr->tr_prio = PRIO_NORMAL;
|
||||||
thr->tr_state = THREAD_READY;
|
thr->tr_state = THREAD_READY;
|
||||||
@@ -101,6 +110,9 @@ struct thread *create_idle_thread(void)
|
|||||||
struct task *idle = idle_task();
|
struct task *idle = idle_task();
|
||||||
struct thread *thr = thread_alloc();
|
struct thread *thr = thread_alloc();
|
||||||
|
|
||||||
|
thr->tr_id = 0;
|
||||||
|
bitmap_set(thread_ids, 0);
|
||||||
|
|
||||||
thr->tr_parent = idle;
|
thr->tr_parent = idle;
|
||||||
thr->tr_prio = PRIO_NORMAL;
|
thr->tr_prio = PRIO_NORMAL;
|
||||||
thr->tr_state = THREAD_READY;
|
thr->tr_state = THREAD_READY;
|
||||||
|
|||||||
Reference in New Issue
Block a user