Environment variables WIP, fix waiting scheduling issues + CE cancel proc
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s

This commit is contained in:
2026-03-17 00:01:15 +01:00
parent 1b1e1e4954
commit b1648a146a
11 changed files with 91 additions and 54 deletions

View File

@@ -221,7 +221,7 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
struct list_node_link *current, *start;
if (cpu->proc_current)
if (cpu->proc_current && cpu->proc_current->cpu_run_q_link.next)
current = cpu->proc_current->cpu_run_q_link.next;
else
current = cpu->proc_run_q;
@@ -231,31 +231,75 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
start = current;
do {
bool wrap = false;
while (current) {
struct proc* proc = list_entry (current, struct proc, cpu_run_q_link);
spin_lock (&proc->lock, &fp);
int state = proc->state;
if (state == PROC_READY && !(proc->flags & PROC_KPROC)) {
if (!proc->dead && state == PROC_READY && !(proc->flags & PROC_KPROC)) {
spin_unlock (&proc->lock, fp);
return proc;
}
spin_unlock (&proc->lock, fp);
current = current->next ? current->next : cpu->proc_run_q;
} while (current != start);
current = current->next;
if (!current && !wrap) {
current = cpu->proc_run_q;
wrap = true;
}
if (wrap && current == start)
break;
}
return NULL;
}
static void proc_reaper (struct reschedule_ctx* rctx) {
uint64_t fpt, fp, fc;
struct list_node_link* reaper_list = NULL;
spin_lock (&proc_tree_lock, &fpt);
spin_lock (&thiscpu->lock, &fc);
struct list_node_link *run_link, *tmp_run_link;
list_foreach (thiscpu->proc_run_q, run_link, tmp_run_link) {
struct proc* proc = list_entry (run_link, struct proc, cpu_run_q_link);
if (!proc->dead)
continue;
spin_lock (&proc->lock, &fp);
list_remove (thiscpu->proc_run_q, &proc->cpu_run_q_link);
rbtree_delete (&proc_tree, &proc->proc_tree_link);
list_append (reaper_list, &proc->reaper_list_link);
spin_unlock (&proc->lock, fp);
}
spin_unlock (&thiscpu->lock, fc);
spin_unlock (&proc_tree_lock, fpt);
struct list_node_link *rlink, *tmp_rlink;
list_foreach (reaper_list, rlink, tmp_rlink) {
struct proc* proc = list_entry (rlink, struct proc, reaper_list_link);
list_remove (reaper_list, &proc->reaper_list_link);
proc_cleanup (proc, rctx);
}
}
void proc_sched (void) {
struct proc* next = NULL;
struct cpu* cpu = thiscpu;
uint64_t fc;
retry:
spin_lock (&cpu->lock, &fc);
next = proc_find_sched (cpu);
@@ -268,7 +312,9 @@ void proc_sched (void) {
cpu->proc_current = NULL;
spin_unlock (&cpu->lock, fc);
spin ();
spin_lock_relax ();
goto retry;
}
}
@@ -288,10 +334,9 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
spin_lock (&cpu->lock, &fc);
spin_lock (&proc->lock, &fp);
proc->state = PROC_DEAD;
proc->cpu = NULL;
proc->dead = true;
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
cpu->proc_run_q_count--;
if (cpu->proc_current == proc)
cpu->proc_current = NULL;
@@ -299,16 +344,6 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
spin_unlock (&proc->lock, fp);
spin_unlock (&cpu->lock, fc);
spin_lock (&proc_tree_lock, &fpt);
spin_lock (&proc->lock, &fp);
rbtree_delete (&proc_tree, &proc->proc_tree_link);
spin_unlock (&proc->lock, fp);
spin_unlock (&proc_tree_lock, fpt);
proc_cleanup (proc, rctx);
rctx_insert_cpu (rctx, cpu);
DEBUG ("killed PID %d\n", proc->pid);
@@ -321,11 +356,13 @@ void proc_wait_for (struct proc* proc, struct reschedule_ctx* rctx, struct proc*
static void proc_irq_sched (void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
(void)arg, (void)regs, (void)rctx;
proc_reaper (rctx);
if (!user) {
return;
}
proc_sched ();
rctx_insert_cpu (rctx, thiscpu);
}
void proc_init (void) {