changeset 32:2c3f12ef8f76

merge
author mir3636
date Wed, 06 Feb 2019 15:56:47 +0900
parents 24f476d2259e (current diff) 8d692d5ff87d (diff)
children a531f74c8ec6
files paper/master_paper.pdf
diffstat 2 files changed, 97 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file paper/master_paper.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/xv6_interface.txt	Wed Feb 06 15:56:47 2019 +0900
@@ -0,0 +1,97 @@
+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();
+}
+