This is a very large patch. Don't feel like splitting it up. Change locking discipline for rbtrees. Most changes are this. Fix stack init logic for application processors, and start them up. Signed-off-by: Michael Shaw <m@michaelsshaw.com>
78 lines
1.5 KiB
C
78 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#include <arch/proc.h>
|
|
#include <arch/page.h>
|
|
#include <kernel/thread.h>
|
|
#include <kernel/sched.h>
|
|
|
|
static struct {
|
|
struct thread *head;
|
|
struct thread *tail;
|
|
spinlock_t lock;
|
|
} sched_queue;
|
|
|
|
void sched_add_thread(struct thread *t)
|
|
{
|
|
spinlock_acquire(&sched_queue.lock);
|
|
t->next = NULL;
|
|
if (sched_queue.tail)
|
|
sched_queue.tail->next = t;
|
|
sched_queue.tail = t;
|
|
if (!sched_queue.head)
|
|
sched_queue.head = t;
|
|
spinlock_release(&sched_queue.lock);
|
|
}
|
|
|
|
void sched_remove_thread(struct thread *del)
|
|
{
|
|
spinlock_acquire(&sched_queue.lock);
|
|
struct thread *t = sched_queue.head;
|
|
struct thread *p = NULL;
|
|
while (t) {
|
|
if (t == del) {
|
|
if (p)
|
|
p->next = t->next;
|
|
else
|
|
sched_queue.head = t->next;
|
|
|
|
if (!t->next)
|
|
sched_queue.tail = p;
|
|
|
|
t->next = NULL;
|
|
break;
|
|
}
|
|
p = t;
|
|
t = t->next;
|
|
}
|
|
spinlock_release(&sched_queue.lock);
|
|
}
|
|
|
|
static struct thread *dequeue_thread()
|
|
{
|
|
spinlock_acquire(&sched_queue.lock);
|
|
struct thread *t = sched_queue.head;
|
|
if (t) {
|
|
sched_queue.head = t->next;
|
|
if (!sched_queue.head)
|
|
sched_queue.tail = NULL;
|
|
t->next = NULL;
|
|
} else {
|
|
t = tls_get()->idle_thread;
|
|
}
|
|
spinlock_release(&sched_queue.lock);
|
|
return t;
|
|
}
|
|
|
|
void schedule()
|
|
{
|
|
struct thread *next = dequeue_thread();
|
|
if (!next)
|
|
return;
|
|
|
|
struct cpu_local *tls = tls_get();
|
|
tls->cur_thread = next;
|
|
tls->kernel_rsp = next->kstack_top;
|
|
tls->tss.rsp0 = next->kstack_top;
|
|
pgd_load(next->pgd);
|
|
|
|
sched_restore_state(next);
|
|
}
|