Mercurial > hg > Papers > 2019 > mitsuki-master
view paper/xv6_interface.txt @ 30:8d692d5ff87d
update
author | mir3636 |
---|---|
date | Tue, 05 Feb 2019 17:34:29 +0900 |
parents | 0b7e635fdb8a |
children |
line wrap: on
line source
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]; } ptable; static struct proc *initproc; struct proc *proc; struct Scheduler { union Data * scheduler; __code scheduler(next); __code forkret(); } struct SchedulerImpl { union Data * ptable; union Data * proc; union Data * cpu; } __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(); }