changeset 30:8d692d5ff87d

update
author mir3636
date Tue, 05 Feb 2019 17:34:29 +0900
parents 0b7e635fdb8a
children 2c3f12ef8f76
files paper/xv6_interface.txt
diffstat 1 files changed, 80 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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();
+}
+