scheduler: initial implementation

This commit is contained in:
Matheus
2023-04-27 23:34:57 -03:00
parent 03a134445a
commit 5d33fe828f
4 changed files with 345 additions and 1 deletions
+60
View File
@@ -0,0 +1,60 @@
#ifndef _SCHEDULER_H
#define _SCHEDULER_H
#include <arch/context.h>
#include <kernel/vmm.h>
#define SCHED_THREAD_FLAGS_QUEUED 1
#define SCHED_THREAD_FLAGS_RUNNING 2
typedef int pid_t;
typedef int tid_t;
typedef int gid_t;
typedef int uid_t;
typedef unsigned int mode_t;
struct proc_t;
typedef struct thread_t {
struct thread_t *next;
struct thread_t *prev;
struct proc_t *proc;
struct cpu_t *cpu;
context_t context;
extracontext_t extracontext;
void *kernelstack;
void *kernelstacktop;
size_t kernelstacksize;
vmmcontext_t *vmmctx;
tid_t tid;
int flags;
long priority;
} thread_t;
typedef struct proc_t {
spinlock_t lock;
struct proc_t *sibling;
struct proc_t *parent;
struct proc_t *child;
pid_t pid;
gid_t gid;
uid_t uid;
thread_t **threads;
size_t threadtablesize;
size_t runningthreadcount;
mode_t umask;
int flags;
} proc_t;
#include <arch/cpu.h>
void sched_init();
void sched_runinit();
void sched_threadexit();
void sched_queue(thread_t *thread);
void sched_stopcurrentthread();
void sched_yield();
proc_t *sched_newproc();
thread_t *sched_newthread(void *ip, size_t kstacksize, int priority, proc_t *proc, void *ustack);
#endif
+7 -1
View File
@@ -10,8 +10,9 @@
#include <kernel/interrupt.h>
#include <kernel/vmm.h>
#include <kernel/timer.h>
#include <kernel/scheduler.h>
typedef struct {
typedef struct cpu_t {
uint64_t gdt[7];
ist_t ist;
long id;
@@ -21,8 +22,13 @@ typedef struct {
timer_t *timer;
bool intstatus;
long ipl;
thread_t *thread;
thread_t *idlethread;
timerentry_t schedtimerentry;
} cpu_t;
#define CPU_HALT() asm volatile("hlt")
static inline cpu_t *_cpu() {
return (cpu_t *)rdmsr(MSR_GSBASE);
}