scheduler: runqueuenext() priority checking and intstatus fix

This commit is contained in:
Matheus
2023-04-28 22:35:41 -03:00
parent 1bcf8dfcf3
commit 459f1d6b92
+6 -9
View File
@@ -75,7 +75,7 @@ void sched_destroyproc(proc_t *proc) {
slab_free(processcache, proc); slab_free(processcache, proc);
} }
static thread_t *runqueuenext() { static thread_t *runqueuenext(int minprio) {
bool intstate = interrupt_set(false); bool intstate = interrupt_set(false);
thread_t *thread = NULL; thread_t *thread = NULL;
@@ -84,7 +84,7 @@ static thread_t *runqueuenext() {
goto leave; goto leave;
// TODO use the bitmap for this // TODO use the bitmap for this
for (int i = 0; i < RUNQUEUE_COUNT; ++i) { for (int i = 0; i < RUNQUEUE_COUNT && i <= minprio; ++i) {
if (runqueue[i].list) { if (runqueue[i].list) {
thread = runqueue[i].list; thread = runqueue[i].list;
runqueue[i].list = thread->next; runqueue[i].list = thread->next;
@@ -112,6 +112,7 @@ static __attribute__((noreturn)) void switchthread(thread_t *thread) {
if(current == NULL || thread->vmmctx != current->vmmctx) if(current == NULL || thread->vmmctx != current->vmmctx)
vmm_switchcontext(thread->vmmctx); vmm_switchcontext(thread->vmmctx);
_cpu()->intstatus = ARCH_CONTEXT_INTSTATUS(&thread->context);
ARCH_CONTEXT_SWITCHTHREAD(thread); ARCH_CONTEXT_SWITCHTHREAD(thread);
__builtin_unreachable(); __builtin_unreachable();
@@ -153,7 +154,7 @@ __attribute__((noreturn)) void sched_stopcurrentthread() {
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
thread_t *next = runqueuenext(); thread_t *next = runqueuenext(0x0fffffff);
if (next == NULL) if (next == NULL)
next = _cpu()->idlethread; next = _cpu()->idlethread;
@@ -202,9 +203,7 @@ static void yield(context_t *context) {
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
thread_t *next = runqueuenext(); thread_t *next = runqueuenext(thread->priority);
// TODO priority checking and stuff
if (next) { if (next) {
ARCH_CONTEXT_THREADSAVE(thread, context); ARCH_CONTEXT_THREADSAVE(thread, context);
@@ -228,9 +227,7 @@ static void timerhook(void *private, context_t *context) {
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
thread_t *next = runqueuenext(); thread_t *next = runqueuenext(current->priority);
// TODO priority handling here
if (next) { if (next) {
current->flags &= ~SCHED_THREAD_FLAGS_RUNNING; current->flags &= ~SCHED_THREAD_FLAGS_RUNNING;