Better proc_kill () and process cleanup
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 27s
This commit is contained in:
@@ -23,6 +23,12 @@
|
||||
#include <amd64/intr_defs.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lock ordering:
|
||||
* 1. proc_tree_lock
|
||||
* 2. [cpu]->lock
|
||||
*/
|
||||
|
||||
static struct rb_node_link* proc_tree = NULL;
|
||||
static spin_lock_t proc_tree_lock = SPIN_LOCK_INIT;
|
||||
|
||||
@@ -113,7 +119,6 @@ static void proc_register (struct proc* proc, struct cpu* cpu) {
|
||||
proc->cpu = cpu;
|
||||
|
||||
spin_lock (&proc_tree_lock);
|
||||
|
||||
spin_lock (&cpu->lock);
|
||||
|
||||
rbtree_insert (struct proc, &cpu->proc_run_q, &proc->cpu_run_q_link, cpu_run_q_link, pid);
|
||||
@@ -123,7 +128,6 @@ static void proc_register (struct proc* proc, struct cpu* cpu) {
|
||||
cpu->proc_current = proc;
|
||||
|
||||
spin_unlock (&cpu->lock);
|
||||
|
||||
spin_unlock (&proc_tree_lock);
|
||||
}
|
||||
|
||||
@@ -147,6 +151,10 @@ static struct proc* proc_find_sched (void) {
|
||||
|
||||
rbtree_next (node, node);
|
||||
|
||||
if (!node) {
|
||||
rbtree_first (&thiscpu->proc_run_q, node);
|
||||
}
|
||||
|
||||
if (node == first)
|
||||
break;
|
||||
}
|
||||
@@ -159,7 +167,7 @@ void proc_sched (void) {
|
||||
|
||||
spin_lock (&thiscpu->lock);
|
||||
|
||||
if (thiscpu->proc_run_q == NULL || thiscpu->proc_current == NULL) {
|
||||
if (thiscpu->proc_run_q == NULL) {
|
||||
spin_unlock (&thiscpu->lock);
|
||||
goto idle;
|
||||
}
|
||||
@@ -179,8 +187,25 @@ idle:
|
||||
}
|
||||
|
||||
void proc_kill (struct proc* proc) {
|
||||
/* mark for garbage collection */
|
||||
atomic_store (&proc->state, PROC_DEAD);
|
||||
|
||||
spin_lock (&proc_tree_lock);
|
||||
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
||||
spin_unlock (&proc_tree_lock);
|
||||
|
||||
struct cpu* cpu = proc->cpu;
|
||||
spin_lock (&cpu->lock);
|
||||
rbtree_delete (&cpu->proc_run_q, &proc->cpu_run_q_link);
|
||||
spin_unlock (&cpu->lock);
|
||||
|
||||
DEBUG ("killed PID %d\n", proc->pid);
|
||||
|
||||
proc_cleanup (proc);
|
||||
|
||||
if (cpu == thiscpu)
|
||||
proc_sched ();
|
||||
else
|
||||
cpu_request_sched (cpu);
|
||||
}
|
||||
|
||||
static void proc_irq_sched (void* arg, void* regs) {
|
||||
@@ -188,12 +213,18 @@ static void proc_irq_sched (void* arg, void* regs) {
|
||||
proc_sched ();
|
||||
}
|
||||
|
||||
static void proc_irq_cpu_request_sched (void* arg, void* regs) {
|
||||
(void)arg, (void)regs;
|
||||
proc_sched ();
|
||||
}
|
||||
|
||||
void proc_init (void) {
|
||||
struct proc* init = proc_spawn_rd ("init.exe");
|
||||
proc_register (init, thiscpu);
|
||||
|
||||
#if defined(__x86_64__)
|
||||
irq_attach (&proc_irq_sched, NULL, SCHED_PREEMPT_TIMER, IRQ_INTERRUPT_SAFE);
|
||||
irq_attach (&proc_irq_cpu_request_sched, NULL, CPU_REQUEST_SCHED, IRQ_INTERRUPT_SAFE);
|
||||
#endif
|
||||
|
||||
do_sched (init);
|
||||
|
||||
Reference in New Issue
Block a user