# HG changeset patch # User mir3636 # Date 1549355669 -32400 # Node ID 8d692d5ff87db5d5c359cbccd95a5ac934b5bc75 # Parent 0b7e635fdb8aa6a97d37a0c3ed6c219f57c4445a update diff -r 0b7e635fdb8a -r 8d692d5ff87d paper/xv6_interface.txt --- a/paper/xv6_interface.txt Tue Feb 05 01:47:08 2019 +0900 +++ b/paper/xv6_interface.txt Tue Feb 05 17:34:29 2019 +0900 @@ -1,3 +1,16 @@ +struct cpu { + uchar id; // index into cpus[] below + struct context* scheduler; // swtch() here to enter scheduler + volatile uint started; // Has the CPU started? + + int ncli; // Depth of pushcli nesting. + int intena; // Were interrupts enabled before pushcli? + + // Cpu-local storage variables; see below + struct cpu* cpu; + struct proc* proc; // The currently-running process. +}; + struct { struct spinlock lock; struct proc proc[NPROC]; @@ -6,23 +19,79 @@ static struct proc *initproc; struct proc *proc; - -struct Scheduler () { - union Data * sched; - union Data * ptable; - +struct Scheduler { + union Data * scheduler; + __code scheduler(next); + __code forkret(); } -scheduler() { - sti(); - acquire(&ptable.lock); - goto scheduler1(); +struct SchedulerImpl { + union Data * ptable; + union Data * proc; + union Data * cpu; } -scheduler1() { - if (ptable.proc < &ptable.proc[NPROC]){ +__code scheduler(__code(*next)()) { + sti(); + acquire(&scheduler->ptable.lock); + goto scheduler1(scheduler->ptable.proc); +} + +__code scheduler1(struct proc *proc, struct vm *vm) { + if (proc < &scheduler->ptable.proc[NPROC]){ if(p->state != RUNNABLE) { goto scheduler1(); } + scheduler->proc = proc; + goto vm->switch(proc,scheduler2); } + release(&scheduler->ptable.lock); + goto next(); } + +__code scheduler2(struct proc *proc) { + proc->state = RUNNING; + swtch(&scheduler->cpu->scheduler, proc->context); + scheduler->proc = 0; + proc++; + goto scheduler1(proc); +} + +__code forkret(__code(*next)()) { + static int first = 1; + release(&scheduler->ptable.lock); + + if (first) { + first = 0; + initlog(); + } + goto next(); +} + +__code cbc_sched(__code(*next)()) +{ + int intena; + + if(!holding(&scheduler->ptable.lock)) { + panic("sched ptable.lock"); + } + + if(scheduler->cpu->ncli != 1) { + panic("sched locks"); + } + + if(scheduler->proc->state == RUNNING) { + panic("sched running"); + } + + if(int_enabled ()) { + panic("sched interruptible"); + } + + intena = scheduler->cpu->intena; + swtch(&scheduler->proc->context, scheduler->cpu->scheduler); + scheduler->cpu->intena = intena; + + goto next(); +} +