Spinlock save cpu flags
This commit is contained in:
@@ -177,21 +177,25 @@ struct proc* proc_from_file (struct proc* proc1, const char* volume, const char*
|
||||
}
|
||||
|
||||
struct proc* proc_find_pid (int pid) {
|
||||
uint64_t fpt;
|
||||
|
||||
struct proc* proc = NULL;
|
||||
|
||||
spin_lock (&proc_tree_lock);
|
||||
spin_lock (&proc_tree_lock, &fpt);
|
||||
rbtree_find (struct proc, &proc_tree, pid, proc, proc_tree_link, pid);
|
||||
spin_unlock (&proc_tree_lock);
|
||||
spin_unlock (&proc_tree_lock, fpt);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedule_ctx* rctx) {
|
||||
uint64_t fpt, fc, fp;
|
||||
|
||||
struct cpu* cpu = register_cpu != NULL ? register_cpu : cpu_find_lightest ();
|
||||
|
||||
spin_lock (&proc_tree_lock);
|
||||
spin_lock (&cpu->lock);
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&proc_tree_lock, &fpt);
|
||||
spin_lock (&cpu->lock, &fc);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
|
||||
proc->cpu = cpu;
|
||||
|
||||
@@ -202,15 +206,17 @@ void proc_register (struct proc* proc, struct cpu* register_cpu, struct reschedu
|
||||
if (cpu->proc_current == NULL)
|
||||
cpu->proc_current = proc;
|
||||
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&cpu->lock);
|
||||
spin_unlock (&proc_tree_lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
spin_unlock (&cpu->lock, fc);
|
||||
spin_unlock (&proc_tree_lock, fpt);
|
||||
|
||||
rctx_insert_cpu (rctx, cpu);
|
||||
}
|
||||
|
||||
/* caller holds cpu->lock */
|
||||
static struct proc* proc_find_sched (struct cpu* cpu) {
|
||||
uint64_t fp;
|
||||
|
||||
if (!cpu->proc_run_q)
|
||||
return NULL;
|
||||
|
||||
@@ -229,16 +235,16 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
|
||||
do {
|
||||
struct proc* proc = list_entry (current, struct proc, cpu_run_q_link);
|
||||
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
|
||||
int state = proc->state;
|
||||
|
||||
if (state == PROC_READY && !(proc->flags & PROC_KPROC)) {
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
return proc;
|
||||
}
|
||||
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
current = current->next ? current->next : cpu->proc_run_q;
|
||||
} while (current != start);
|
||||
@@ -249,36 +255,39 @@ static struct proc* proc_find_sched (struct cpu* cpu) {
|
||||
void proc_sched (void) {
|
||||
struct proc* next = NULL;
|
||||
struct cpu* cpu = thiscpu;
|
||||
uint64_t fc;
|
||||
|
||||
spin_lock (&cpu->lock);
|
||||
spin_lock (&cpu->lock, &fc);
|
||||
|
||||
next = proc_find_sched (cpu);
|
||||
|
||||
if (next) {
|
||||
cpu->proc_current = next;
|
||||
|
||||
do_sched (next, &cpu->lock);
|
||||
do_sched (next, &cpu->lock, fc);
|
||||
} else {
|
||||
cpu->proc_current = NULL;
|
||||
spin_unlock (&cpu->lock);
|
||||
spin_unlock (&cpu->lock, fc);
|
||||
|
||||
spin ();
|
||||
}
|
||||
}
|
||||
|
||||
void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
spin_lock (&proc->lock);
|
||||
uint64_t fp, fc, fpt;
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
|
||||
if ((proc->flags & PROC_KPROC)) {
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
return;
|
||||
}
|
||||
|
||||
struct cpu* cpu = proc->cpu;
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
spin_lock (&cpu->lock);
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&cpu->lock, &fc);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
|
||||
proc->state = PROC_DEAD;
|
||||
proc->cpu = NULL;
|
||||
@@ -288,16 +297,16 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
if (cpu->proc_current == proc)
|
||||
cpu->proc_current = NULL;
|
||||
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&cpu->lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
spin_unlock (&cpu->lock, fc);
|
||||
|
||||
spin_lock (&proc_tree_lock);
|
||||
spin_lock (&proc->lock);
|
||||
spin_lock (&proc_tree_lock, &fpt);
|
||||
spin_lock (&proc->lock, &fp);
|
||||
|
||||
rbtree_delete (&proc_tree, &proc->proc_tree_link);
|
||||
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (&proc_tree_lock);
|
||||
spin_unlock (&proc->lock, fp);
|
||||
spin_unlock (&proc_tree_lock, fpt);
|
||||
|
||||
proc_cleanup (proc, rctx);
|
||||
|
||||
@@ -307,7 +316,7 @@ void proc_kill (struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
}
|
||||
|
||||
void proc_wait_for (struct proc* proc, struct reschedule_ctx* rctx, struct proc* wait_proc) {
|
||||
proc_sq_suspend (proc, &wait_proc->done_sq, NULL, rctx);
|
||||
proc_sq_suspend (proc, &wait_proc->done_sq, NULL, 0, rctx);
|
||||
}
|
||||
|
||||
static void proc_irq_sched (void* arg, void* regs, struct reschedule_ctx* rctx) {
|
||||
@@ -323,6 +332,8 @@ static void proc_irq_sched (void* arg, void* regs, struct reschedule_ctx* rctx)
|
||||
}
|
||||
|
||||
void proc_init (void) {
|
||||
uint64_t fc;
|
||||
|
||||
#if defined(__x86_64__)
|
||||
irq_attach (&proc_irq_sched, NULL, SCHED_PREEMPT_TIMER);
|
||||
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
|
||||
@@ -338,6 +349,6 @@ void proc_init (void) {
|
||||
init->procgroup->capabilities |= (PROC_CAP_TERMINAL | PROC_CAP_KB);
|
||||
proc_register (init, thiscpu, &rctx);
|
||||
|
||||
spin_lock (&spin_proc->cpu->lock);
|
||||
do_sched (spin_proc, &spin_proc->cpu->lock);
|
||||
spin_lock (&spin_proc->cpu->lock, &fc);
|
||||
do_sched (spin_proc, &spin_proc->cpu->lock, fc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user