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

use templatized namespace for nspid, and fix stupid bug forgetting to initialize lock flag

上级 3e7c413f
......@@ -10,6 +10,9 @@ extern "C" {
#include "cpu.h"
}
#include "ns.hh"
extern xns<u32, proc*> *xnspid;
// GC scheme based on Fraser's:
// a machine has a global_epoch
// a process maintain an epoch (>= global_epoch)
......@@ -69,24 +72,6 @@ gc_alloc()
return r;
}
static void *
gc_min(void *vkey, void *v, void *arg){
u64 *min_epoch_p = (u64*) arg;
struct proc *p = (struct proc *) v;
// Some threads may never call begin/end_epoch(), and never update
// p->epoch, so gc_thread does it for them. XXX get rid off lock?
acquire(&p->gc_epoch_lock);
if (p->epoch_depth == 0) {
p->epoch = global_epoch;
}
release(&p->gc_epoch_lock);
// cprintf("gc_min %d(%s): %lu %ld\n", p->pid, p->name, p->epoch, p->epoch_depth);
if (*min_epoch_p > p->epoch) {
*min_epoch_p = p->epoch;
}
return NULL;
}
static void
gc_free_elem(struct gc *r)
{
......@@ -185,8 +170,19 @@ gc_delayfreelist(void)
if (gc_debug) {
cprintf("(%d,%d) (%s): min %lu global %lu\n", myproc()->cpuid, myproc()->pid, myproc()->name, min, global);
}
myproc()->epoch_depth++;// ensure ns_enumate's call to gc_begin_epoch doesn't have sideeffects
ns_enumerate(nspid, gc_min, &min);
myproc()->epoch_depth++; // ensure enumerate's call to gc_begin_epoch doesn't have sideeffects
xnspid->enumerate([&min](u32, proc *p) {
// Some threads may never call begin/end_epoch(), and never update
// p->epoch, so gc_thread does it for them. XXX get rid off lock?
acquire(&p->gc_epoch_lock);
if (p->epoch_depth == 0)
p->epoch = global_epoch;
release(&p->gc_epoch_lock);
// cprintf("gc_min %d(%s): %lu %ld\n", p->pid, p->name, p->epoch, p->epoch_depth);
if (min > p->epoch)
min = p->epoch;
return false;
});
myproc()->epoch_depth--;
if (min >= global) {
gc_move_to_tofree(min);
......
......@@ -23,7 +23,7 @@ class xelem {
xelem<K, V> * volatile next;
K key;
xelem(const K &k, const V &v) : val(v), key(k) {}
xelem(const K &k, const V &v) : val(v), next_lock(0), next(0), key(k) {}
};
template<class K, class V>
......
......@@ -14,8 +14,10 @@ extern "C" {
#include "sched.h"
}
#include "ns.hh"
int __mpalign__ idle[NCPU];
struct ns *nspid __mpalign__;
xns<u32, proc*> *xnspid __mpalign__;
static struct proc *bootproc __mpalign__;
#if MTRACE
......@@ -193,7 +195,7 @@ allocproc(void)
memset(p, 0, sizeof(*p));
p->state = EMBRYO;
p->pid = ns_allockey(nspid);
p->pid = xnspid->allockey();
p->cpuid = mycpu()->id;
p->on_runq = -1;
p->cpu_pin = 0;
......@@ -207,12 +209,12 @@ allocproc(void)
initcondvar(&p->cv, p->lockname);
initcilkframe(&p->cilkframe);
if (ns_insert(nspid, KI(p->pid), (void *) p) < 0)
if (xnspid->insert(p->pid, p) < 0)
panic("allocproc: ns_insert");
// Allocate kernel stack if possible.
if((p->kstack = (char*) ksalloc(slab_stack)) == 0){
if (ns_remove(nspid, KI(p->pid), p) == 0)
if (!xnspid->remove(p->pid, &p))
panic("allocproc: ns_remove");
freeproc(p);
return 0;
......@@ -281,8 +283,8 @@ initproc(void)
{
int c;
nspid = nsalloc(0);
if (nspid == 0)
xnspid = new xns<u32, proc*>(false);
if (xnspid == 0)
panic("pinit");
for (c = 0; c < NCPU; c++)
......@@ -469,7 +471,7 @@ kill(int pid)
{
struct proc *p;
p = (struct proc *) ns_lookup(nspid, KI(pid));
p = xnspid->lookup(pid);
if (p == 0) {
panic("kill");
return -1;
......@@ -492,7 +494,8 @@ kill(int pid)
return 0;
}
void *procdump(void *vk, void *v, void *arg)
bool
procdump(u32 pid, proc *p)
{
static const char *states[] = {
/* [UNUSED] = */ "unused",
......@@ -502,7 +505,6 @@ void *procdump(void *vk, void *v, void *arg)
/* [RUNNING] = */ "run ",
/* [ZOMBIE] = */ "zombie"
};
struct proc *p = (struct proc *) v;
const char *name = "(no name)";
const char *state;
uptr pc[10];
......@@ -522,7 +524,8 @@ void *procdump(void *vk, void *v, void *arg)
for(int i=0; i<10 && pc[i] != 0; i++)
cprintf(" %lx\n", pc[i]);
}
return 0;
return false;
}
// Print a process listing to console. For debugging.
......@@ -531,7 +534,7 @@ void *procdump(void *vk, void *v, void *arg)
void
procdumpall(void)
{
ns_enumerate(nspid, procdump, 0);
xnspid->enumerate(procdump);
}
// Create a new process copying p as the parent.
......@@ -556,7 +559,7 @@ fork(int flags)
ksfree(slab_stack, np->kstack);
np->kstack = 0;
np->state = UNUSED;
if (ns_remove(nspid, KI(np->pid), np) == 0)
if (!xnspid->remove(np->pid, &np))
panic("fork: ns_remove");
freeproc(np);
return -1;
......@@ -618,7 +621,7 @@ wait(void)
p->kstack = 0;
vmap_decref(p->vmap);
p->state = UNUSED;
if (ns_remove(nspid, KI(p->pid), p) == 0)
if (!xnspid->remove(p->pid, &p))
panic("wait: ns_remove");
p->pid = 0;
p->parent = 0;
......
......@@ -71,5 +71,3 @@ struct proc {
LIST_ENTRY(proc) cv_waiters; // Linked list of processes waiting for oncv
LIST_ENTRY(proc) cv_sleep; // Linked list of processes sleeping on a cv
};
extern struct ns *nspid;
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论