Environment variables WIP, fix waiting scheduling issues + CE cancel proc
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s
This commit is contained in:
@@ -31,14 +31,20 @@ int id_alloc (struct id_alloc* ida) {
|
||||
|
||||
spin_lock (&ida->lock, &fid);
|
||||
|
||||
for (size_t bit = 0; bit < ida->bm.nbits; bit++) {
|
||||
if (!bm_test (&ida->bm, bit)) {
|
||||
bm_set (&ida->bm, bit);
|
||||
size_t start = ida->next_id;
|
||||
size_t current = start;
|
||||
do {
|
||||
if (!bm_test (&ida->bm, current)) {
|
||||
bm_set (&ida->bm, current);
|
||||
|
||||
ida->next_id = (current + 1) % ida->bm.nbits;
|
||||
|
||||
spin_unlock (&ida->lock, fid);
|
||||
return (int)bit;
|
||||
return (int)current;
|
||||
}
|
||||
}
|
||||
|
||||
current = (current + 1) % ida->bm.nbits;
|
||||
} while (current != start);
|
||||
|
||||
spin_unlock (&ida->lock, fid);
|
||||
return -ST_OOM_ERROR;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
struct id_alloc {
|
||||
struct bm bm;
|
||||
spin_lock_t lock;
|
||||
int next_id;
|
||||
};
|
||||
|
||||
int id_alloc (struct id_alloc* ida);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
|
||||
/* process states */
|
||||
#define PROC_READY 0
|
||||
#define PROC_DEAD 1
|
||||
#define PROC_SUSPENDED 2
|
||||
#define PROC_SUSPENDED 1
|
||||
|
||||
/* process flags */
|
||||
#define PROC_USTK_PREALLOC (1 << 0)
|
||||
@@ -34,6 +33,7 @@ struct reschedule_ctx;
|
||||
struct proc {
|
||||
int pid;
|
||||
int exec_pid;
|
||||
struct list_node_link reaper_list_link;
|
||||
struct rb_node_link proc_tree_link;
|
||||
struct rb_node_link procgroup_memb_tree_link;
|
||||
struct list_node_link cpu_run_q_link;
|
||||
@@ -44,6 +44,7 @@ struct proc {
|
||||
spin_lock_t lock;
|
||||
struct cpu* cpu;
|
||||
int state;
|
||||
bool dead;
|
||||
uintptr_t uvaddr_argument;
|
||||
void* mail_recv_buffer;
|
||||
size_t mail_recv_size;
|
||||
|
||||
@@ -47,7 +47,6 @@ int proc_sq_suspend (struct proc* proc, struct proc_suspension_q* sq, spin_lock_
|
||||
if (cpu->proc_current == proc)
|
||||
cpu->proc_current = NULL;
|
||||
|
||||
proc->cpu = NULL;
|
||||
int state = proc->state;
|
||||
|
||||
spin_unlock (&sq->lock, fsq);
|
||||
|
||||
@@ -537,14 +537,7 @@ DEFINE_SYSCALL (sys_get_procgroup) {
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
|
||||
if (target_proc->state == PROC_DEAD) {
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
}
|
||||
|
||||
int pgid = target_proc->procgroup->pgid;
|
||||
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
|
||||
return SYSRESULT (pgid);
|
||||
@@ -681,7 +674,7 @@ DEFINE_SYSCALL (sys_wait_for_pid) {
|
||||
|
||||
spin_lock (&wait_proc->lock, &fp);
|
||||
|
||||
if (wait_proc->state == PROC_DEAD) {
|
||||
if (wait_proc->dead) {
|
||||
spin_unlock (&wait_proc->lock, fp);
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
}
|
||||
@@ -694,7 +687,6 @@ DEFINE_SYSCALL (sys_wait_for_pid) {
|
||||
}
|
||||
|
||||
/* int kill (int pid) */
|
||||
|
||||
DEFINE_SYSCALL (sys_kill) {
|
||||
uint64_t fp;
|
||||
|
||||
@@ -705,15 +697,6 @@ DEFINE_SYSCALL (sys_kill) {
|
||||
if (target_proc == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&target_proc->lock, &fp);
|
||||
|
||||
if (target_proc->state == PROC_DEAD) {
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
}
|
||||
|
||||
spin_unlock (&target_proc->lock, fp);
|
||||
|
||||
proc_kill (target_proc, rctx);
|
||||
|
||||
return ST_OK;
|
||||
|
||||
Reference in New Issue
Block a user