提交 e7260cf3 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

migrate in exec when a processor is idle

上级 ebba3c91
...@@ -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);
...@@ -394,6 +398,30 @@ wait(void) ...@@ -394,6 +398,30 @@ 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;
...@@ -413,11 +441,12 @@ steal(void) ...@@ -413,11 +441,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
...@@ -455,6 +484,8 @@ scheduler(void) ...@@ -455,6 +484,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
...@@ -482,7 +513,8 @@ scheduler(void) ...@@ -482,7 +513,8 @@ scheduler(void)
if(p==0) { if(p==0) {
release(&runq->lock); release(&runq->lock);
steal(); if (!steal())
idle[cpu->id] = 1;
} }
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论