scheduler: have a separate stack for yield

This commit is contained in:
Matheus
2023-05-03 19:11:40 -03:00
parent 393e34a04e
commit b5d4fc07e2
4 changed files with 15 additions and 7 deletions
+6 -1
View File
@@ -7,6 +7,7 @@
#include <kernel/alloc.h>
#define QUANTUM_US 100000
#define SCHEDULER_STACK_SIZE 4096
static scache_t *threadcache;
static scache_t *processcache;
@@ -218,7 +219,7 @@ static void yield(context_t *context) {
void sched_yield() {
bool old = interrupt_set(false);
arch_context_saveandcall(yield);
arch_context_saveandcall(yield, _cpu()->schedulerstack);
interrupt_set(old);
}
@@ -258,6 +259,10 @@ void sched_init() {
processcache = slab_newcache(sizeof(proc_t), 0, NULL, NULL);
__assert(processcache);
_cpu()->schedulerstack = alloc(SCHEDULER_STACK_SIZE);
__assert(_cpu()->schedulerstack);
_cpu()->schedulerstack = (void *)((uintptr_t)_cpu()->schedulerstack + SCHEDULER_STACK_SIZE);
_cpu()->schedtimerentry.func = timerhook;
_cpu()->schedtimerentry.repeatus = QUANTUM_US;
SPINLOCK_INIT(runqueuelock);