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

better migration

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