提交 f2b96eaa 创建 作者: Robert Morris's avatar Robert Morris

Merge branch 'scale' of git+ssh://pdos.csail.mit.edu/home/am0/6.828/xv6 into scale

...@@ -115,6 +115,7 @@ void sched(void); ...@@ -115,6 +115,7 @@ void sched(void);
void userinit(void); void userinit(void);
int wait(void); int wait(void);
void yield(void); void yield(void);
void migrate(void);
// swtch.S // swtch.S
void swtch(struct context**, struct context*); void swtch(struct context**, struct context*);
......
...@@ -125,7 +125,8 @@ exec(char *path, char **argv) ...@@ -125,7 +125,8 @@ exec(char *path, char **argv)
switchuvm(proc); switchuvm(proc);
vmap_decref(oldvmap); vmap_decref(oldvmap);
// XXX migrate to another core?? migrate();
return 0; return 0;
bad: bad:
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
struct ptable ptables[NCPU]; struct ptable ptables[NCPU];
struct runq runqs[NCPU]; struct runq runqs[NCPU];
int idle[NCPU];
static struct proc *initproc; static struct proc *initproc;
extern void forkret(void); extern void forkret(void);
...@@ -23,6 +24,9 @@ pinit(void) ...@@ -23,6 +24,9 @@ pinit(void)
int i; int i;
for (c = 0; c < NCPU; c++) { for (c = 0; c < NCPU; c++) {
idle[c] = 1;
ptables[c].nextpid = (c << 16) | (1); ptables[c].nextpid = (c << 16) | (1);
ptables[c].name[0] = (char) (c + '0'); ptables[c].name[0] = (char) (c + '0');
safestrcpy(ptables[c].name+1, "ptable", MAXNAME-1); safestrcpy(ptables[c].name+1, "ptable", MAXNAME-1);
...@@ -402,7 +406,31 @@ wait(void) ...@@ -402,7 +406,31 @@ wait(void)
} }
} }
void void
migrate(void)
{
int c;
struct proc *p;
for (c = 0; c < NCPU; c++) {
if (c == cpunum())
continue;
if (idle[c]) { // OK if there is a race
cprintf("migrate to %d\n", c);
p = proc;
p->curcycles = 0;
p->cpuid = c;
addrun(p);
acquire(&p->lock);
p->state = RUNNABLE;
sched();
release(&proc->lock);
return;
}
}
}
int
steal(void) steal(void)
{ {
int c; int c;
...@@ -422,11 +450,12 @@ steal(void) ...@@ -422,11 +450,12 @@ steal(void)
p->curcycles = 0; p->curcycles = 0;
p->cpuid = cpu->id; p->cpuid = cpu->id;
addrun(p); addrun(p);
return; return 1;
} }
} }
release(&runqs[c].lock); release(&runqs[c].lock);
} }
return 0;
} }
//PAGEBREAK: 42 //PAGEBREAK: 42
...@@ -464,6 +493,8 @@ scheduler(void) ...@@ -464,6 +493,8 @@ scheduler(void)
panic("non-runnable process on runq\n"); panic("non-runnable process on runq\n");
STAILQ_REMOVE(&runq->runq, p, proc, run_next); STAILQ_REMOVE(&runq->runq, p, proc, run_next);
if (idle[cpu->id])
idle[cpu->id] = 0;
release(&runq->lock); release(&runq->lock);
// Switch to chosen process. It is the process's job // Switch to chosen process. It is the process's job
...@@ -491,7 +522,8 @@ scheduler(void) ...@@ -491,7 +522,8 @@ scheduler(void)
if(p==0) { if(p==0) {
release(&runq->lock); release(&runq->lock);
steal(); if (!steal())
idle[cpu->id] = 1;
} }
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论