提交 8d8cc662 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

better migration

上级 c2e3947e
...@@ -18,6 +18,8 @@ static struct proc *initproc __attribute__ ((aligned (CACHELINE))); ...@@ -18,6 +18,8 @@ static struct proc *initproc __attribute__ ((aligned (CACHELINE)));
extern void forkret(void); extern void forkret(void);
extern void trapret(void); extern void trapret(void);
enum { sched_debug = 0 };
void void
pinit(void) pinit(void)
{ {
...@@ -413,17 +415,20 @@ migrate(struct proc *p) ...@@ -413,17 +415,20 @@ migrate(struct proc *p)
if (c == cpu->id) if (c == cpu->id)
continue; continue;
if (idle[c]) { // OK if there is a race if (idle[c]) { // OK if there is a race
// cprintf("migrate to %d\n", c);
acquire(&p->lock); acquire(&p->lock);
if (p->state != RUNNABLE) { if (p->state != RUNNABLE) {
release(&p->lock); release(&p->lock);
continue; continue;
} }
if (sched_debug)
cprintf("cpu%d: migrate %d to %d\n", cpu->id, p->pid, c);
delrun(p); delrun(p);
p->curcycles = 0; p->curcycles = 0;
p->cpuid = c; p->cpuid = c;
addrun(p); addrun(p);
idle[c] = 0;
if (p == proc) { if (p == proc) {
proc->state = RUNNABLE; proc->state = RUNNABLE;
...@@ -442,13 +447,15 @@ steal_cb(int k, void *v) ...@@ -442,13 +447,15 @@ steal_cb(int k, void *v)
struct proc *p = v; struct proc *p = v;
acquire(&p->lock); acquire(&p->lock);
if (p->state != RUNNABLE) { if (p->state != RUNNABLE || p->cpuid == cpu->id) {
release(&p->lock); release(&p->lock);
return 0; return 0;
} }
if (p->curcycles == 0 || p->curcycles > MINCYCTHRESH) { if (p->curcycles == 0 || p->curcycles > MINCYCTHRESH) {
// cprintf("%d: steal %d (%d) from %d\n", cpu->id, p->pid, p->curcycles, c); if (sched_debug)
cprintf("cpu%d: steal %d (cycles=%d) from %d\n",
cpu->id, p->pid, (int)p->curcycles, p->cpuid);
delrun(p); delrun(p);
p->curcycles = 0; p->curcycles = 0;
p->cpuid = cpu->id; p->cpuid = cpu->id;
......
...@@ -14,8 +14,8 @@ struct rcu { ...@@ -14,8 +14,8 @@ struct rcu {
struct rcu *rcu; struct rcu *rcu;
void (*dofree)(void *); void (*dofree)(void *);
}; };
static struct rcu *rcu_delayed_head[NCPU] __attribute__ ((aligned (CACHELINE))); static struct { struct rcu *x __attribute__((aligned (CACHELINE))); } rcu_delayed_head[NCPU];
static struct rcu *rcu_delayed_tail[NCPU] __attribute__ ((aligned (CACHELINE))); static struct { struct rcu *x __attribute__((aligned (CACHELINE))); } rcu_delayed_tail[NCPU];
static uint global_epoch __attribute__ ((aligned (CACHELINE))); static uint global_epoch __attribute__ ((aligned (CACHELINE)));
static uint min_epoch __attribute__ ((aligned (CACHELINE))); static uint min_epoch __attribute__ ((aligned (CACHELINE)));
static struct spinlock rcu_lock __attribute__ ((aligned (CACHELINE))); static struct spinlock rcu_lock __attribute__ ((aligned (CACHELINE)));
...@@ -54,7 +54,7 @@ rcu_gc(void) ...@@ -54,7 +54,7 @@ rcu_gc(void)
ns_enumerate(nspid, rcu_min); ns_enumerate(nspid, rcu_min);
acquire(&rcu_lock); acquire(&rcu_lock);
for (r = rcu_delayed_head[cpu->id]; r != NULL; r = nr) { for (r = rcu_delayed_head[cpu->id].x; r != NULL; r = nr) {
if (r->epoch >= min_epoch) if (r->epoch >= min_epoch)
break; break;
// cprintf("free: %d\n", r->epoch); // cprintf("free: %d\n", r->epoch);
...@@ -63,9 +63,9 @@ rcu_gc(void) ...@@ -63,9 +63,9 @@ rcu_gc(void)
r->dofree(r->item); r->dofree(r->item);
delayed_nfree--; delayed_nfree--;
n++; n++;
rcu_delayed_head[cpu->id] = r->rcu; rcu_delayed_head[cpu->id].x = r->rcu;
if (rcu_delayed_head[cpu->id] == 0) if (rcu_delayed_head[cpu->id].x == 0)
rcu_delayed_tail[cpu->id] = 0; rcu_delayed_tail[cpu->id].x = 0;
nr = r->rcu; nr = r->rcu;
kmfree(r); kmfree(r);
} }
...@@ -86,11 +86,11 @@ rcu_delayed(void *e, void (*dofree)(void *)) ...@@ -86,11 +86,11 @@ rcu_delayed(void *e, void (*dofree)(void *))
r->epoch = global_epoch; r->epoch = global_epoch;
acquire(&rcu_lock); acquire(&rcu_lock);
// cprintf("rcu_delayed: %d\n", global_epoch); // cprintf("rcu_delayed: %d\n", global_epoch);
if (rcu_delayed_tail[cpu->id] != 0) if (rcu_delayed_tail[cpu->id].x != 0)
rcu_delayed_tail[cpu->id]->rcu = r; rcu_delayed_tail[cpu->id].x->rcu = r;
rcu_delayed_tail[cpu->id] = r; rcu_delayed_tail[cpu->id].x = r;
if (rcu_delayed_head[cpu->id] == 0) if (rcu_delayed_head[cpu->id].x == 0)
rcu_delayed_head[cpu->id] = r; rcu_delayed_head[cpu->id].x = r;
release(&rcu_lock); release(&rcu_lock);
delayed_nfree++; delayed_nfree++;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论