summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-21 21:45:23 -0400
committerIan Moffett <ian@osmora.org>2024-04-21 21:45:23 -0400
commit6318eaf21fd2fceaae6101a7e015157b226c690c (patch)
tree0f3db6bfa5be42cecab237e08db0e377784195f6
parent66cd6cbaa3f58a6ceb5eb0de92b74bf25845909a (diff)
kernel: sched: Create idle thread
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/kern/kern_sched.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 214032a..1d9ba11 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -104,7 +104,7 @@ sched_enqueue_td(struct proc *td)
spinlock_acquire(&tdq_lock);
- td->pid = ++nthread;
+ td->pid = nthread++;
TAILQ_INSERT_TAIL(&td_queue, td, link);
spinlock_release(&tdq_lock);
@@ -130,6 +130,13 @@ sched_dequeue_td(void)
return td;
}
+__noreturn static void
+sched_idle(void)
+{
+ for (;;) {
+ hint_spinwait();
+ }
+}
/*
* Processor awaiting tasks to be assigned will be here spinning.
@@ -138,9 +145,8 @@ __noreturn static void
sched_enter(void)
{
sched_oneshot();
- for (;;) {
- hint_spinwait();
- }
+ sched_idle();
+ __builtin_unreachable();
}
static uintptr_t
@@ -322,6 +328,24 @@ sched_destroy_td(struct proc *td)
dynfree(td);
}
+/*
+ * Create the idle thread.
+ */
+static void
+sched_make_idletd(void)
+{
+ char *argv[] = {NULL};
+ char *envp[] = {NULL};
+ struct auxval auxv = {0};
+ struct vm_range range;
+ struct proc *td;
+
+ td = sched_create_td((uintptr_t)sched_idle, argv, envp,
+ auxv, pmap_read_vas(), false, &range);
+
+ sched_enqueue_td(td);
+}
+
void
sched_exit(void)
{
@@ -419,6 +443,7 @@ sched_init(void)
char *envp[] = {NULL};
TAILQ_INIT(&td_queue);
+ sched_make_idletd();
if ((init_bin = initramfs_open("/usr/sbin/init")) == NULL) {
panic("Could not open /usr/boot/init\n");