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