提交 0ee57d47 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Merge..i confused git somehow..

...@@ -72,4 +72,3 @@ enum { ...@@ -72,4 +72,3 @@ enum {
}; };
extern percpu<kmem> kmems; extern percpu<kmem> kmems;
extern percpu<kmem> slabmem[slab_type_max];
...@@ -102,7 +102,7 @@ class xns : public rcu_freed { ...@@ -102,7 +102,7 @@ class xns : public rcu_freed {
e->next = root.load(); e->next = root.load();
if (cmpxch(&table[i].chain, e->next.load(), e)) { if (cmpxch(&table[i].chain, e->next.load(), e)) {
int c = mycpuid(); int c = myid();
acquire(&percore_lock[c]); acquire(&percore_lock[c]);
e->percore_c = c; e->percore_c = c;
e->percore_next = percore[c].load(); e->percore_next = percore[c].load();
...@@ -180,7 +180,7 @@ class xns : public rcu_freed { ...@@ -180,7 +180,7 @@ class xns : public rcu_freed {
template<class CB> template<class CB>
void enumerate(CB cb) { void enumerate(CB cb) {
scoped_gc_epoch gc; scoped_gc_epoch gc;
int cpuoffset = mycpuid(); int cpuoffset = myid();
for (int i = 0; i < NCPU; i++) { for (int i = 0; i < NCPU; i++) {
auto e = percore[(i + cpuoffset) % NCPU].load(); auto e = percore[(i + cpuoffset) % NCPU].load();
while (e) { while (e) {
......
#pragma once #pragma once
extern int mycpuid(void); #include "cpu.hh"
template <typename T> template <typename T>
struct percpu { struct percpu {
...@@ -11,15 +11,15 @@ struct percpu { ...@@ -11,15 +11,15 @@ struct percpu {
percpu &operator=(const percpu &o) = delete; percpu &operator=(const percpu &o) = delete;
T* get() const { T* get() const {
return cpu(mycpuid()); return cpu(myid());
} }
T* operator->() const { T* operator->() const {
return cpu(mycpuid()); return cpu(myid());
} }
T& operator*() const { T& operator*() const {
return *cpu(mycpuid()); return *cpu(myid());
} }
T& operator[](int id) const { T& operator[](int id) const {
......
...@@ -243,6 +243,8 @@ struct radix_iterator { ...@@ -243,6 +243,8 @@ struct radix_iterator {
} }
radix_elem* operator*() const { radix_elem* operator*() const {
// XXX(austin) If we don't hold a lock on this element, it's
// possible it will morph into a node under us.
return path_[level_]->load().elem(); return path_[level_]->load().elem();
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "uwq.hh" #include "uwq.hh"
#include "wqtypes.hh" #include "wqtypes.hh"
int mycpuid(void);
uwq_ipcbuf* allocipc(void); uwq_ipcbuf* allocipc(void);
static inline void* static inline void*
......
...@@ -191,7 +191,7 @@ ialloc(u32 dev, short type) ...@@ -191,7 +191,7 @@ ialloc(u32 dev, short type)
struct superblock sb; struct superblock sb;
readsb(dev, &sb); readsb(dev, &sb);
for (int k = mycpuid()*IPB; k < sb.ninodes; k += (NCPU*IPB)) { for (int k = myid()*IPB; k < sb.ninodes; k += (NCPU*IPB)) {
for(int inum = k; inum < k+IPB && inum < sb.ninodes; inum++){ for(int inum = k; inum < k+IPB && inum < sb.ninodes; inum++){
if (inum == 0) if (inum == 0)
continue; continue;
......
...@@ -269,7 +269,4 @@ initfutex(void) ...@@ -269,7 +269,4 @@ initfutex(void)
nsfutex = new xns<futexkey_t, futexaddr*, futexkey_hash>(false); nsfutex = new xns<futexkey_t, futexaddr*, futexkey_hash>(false);
if (nsfutex == 0) if (nsfutex == 0)
panic("initfutex"); panic("initfutex");
for (int i = 0; i < NCPU; i++)
new (&nscache_[i]) nscache();
} }
...@@ -149,9 +149,9 @@ initidle(void) ...@@ -149,9 +149,9 @@ initidle(void)
assert((u16)ebx == 0x40); assert((u16)ebx == 0x40);
} }
} }
SLIST_INIT(&idlem[myid()].zombies); SLIST_INIT(&idlem->zombies);
initlock(&idlem[myid()].lock, "idle_lock", LOCKSTAT_IDLE); initlock(&idlem->lock, "idle_lock", LOCKSTAT_IDLE);
snprintf(p->name, sizeof(p->name), "idle_%u", myid()); snprintf(p->name, sizeof(p->name), "idle_%u", myid());
mycpu()->proc = p; mycpu()->proc = p;
......
...@@ -141,7 +141,7 @@ cmain(u64 mbmagic, u64 mbaddr) ...@@ -141,7 +141,7 @@ cmain(u64 mbmagic, u64 mbaddr)
initmp(); initmp();
inittls(); // thread local storage inittls(); // thread local storage
// Some global constructors require mycpu()->id (via mycpuid()) // Some global constructors require mycpu()->id (via myid())
// which we setup in inittls // which we setup in inittls
extern const uptr sctors[], ectors[]; extern const uptr sctors[], ectors[];
for (const uptr *ctorva = ectors; ctorva > sctors; ) { for (const uptr *ctorva = ectors; ctorva > sctors; ) {
......
...@@ -21,12 +21,6 @@ proc::hash(const u32 &p) ...@@ -21,12 +21,6 @@ proc::hash(const u32 &p)
return p; return p;
} }
int
mycpuid(void)
{
return mycpu()->id;
}
xns<u32, proc*, proc::hash> *xnspid __mpalign__; xns<u32, proc*, proc::hash> *xnspid __mpalign__;
struct proc *bootproc __mpalign__; struct proc *bootproc __mpalign__;
......
...@@ -339,9 +339,6 @@ statread(struct inode *inode, char *dst, u32 off, u32 n) ...@@ -339,9 +339,6 @@ statread(struct inode *inode, char *dst, u32 off, u32 n)
void void
initsched(void) initsched(void)
{ {
for (int i = 0; i < NCPU; i++)
new (&schedule_[i]) schedule();
devsw[MAJ_STAT].write = nullptr; devsw[MAJ_STAT].write = nullptr;
devsw[MAJ_STAT].read = statread; devsw[MAJ_STAT].read = statread;
} }
...@@ -174,7 +174,7 @@ trap(struct trapframe *tf) ...@@ -174,7 +174,7 @@ trap(struct trapframe *tf)
// In user space, assume process misbehaved. // In user space, assume process misbehaved.
uerr.println("pid ", myproc()->pid, ' ', myproc()->name, uerr.println("pid ", myproc()->pid, ' ', myproc()->name,
": trap ", (u64)tf->trapno, " err ", (u32)tf->err, ": trap ", (u64)tf->trapno, " err ", (u32)tf->err,
" on cpu ", mycpuid(), " rip ", shex(tf->rip), " on cpu ", myid(), " rip ", shex(tf->rip),
" rsp ", shex(tf->rsp), " addr ", shex(rcr2()), " rsp ", shex(tf->rsp), " addr ", shex(rcr2()),
"--kill proc"); "--kill proc");
myproc()->killed = 1; myproc()->killed = 1;
...@@ -291,7 +291,8 @@ getcallerpcs(void *v, uptr pcs[], int n) ...@@ -291,7 +291,8 @@ getcallerpcs(void *v, uptr pcs[], int n)
if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL) || if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL) ||
(rbp >= (uptr*)KBASEEND && rbp < (uptr*)KCODE)) (rbp >= (uptr*)KBASEEND && rbp < (uptr*)KCODE))
break; break;
pcs[i] = rbp[1]; // saved %rip pcs[i] = rbp[1] - 1; // saved %rip; - 1 so it points to the call
// instruction
rbp = (uptr*)rbp[0]; // saved %rbp rbp = (uptr*)rbp[0]; // saved %rbp
} }
for(; i < n; i++) for(; i < n; i++)
......
...@@ -28,7 +28,7 @@ uwq_trywork(void) ...@@ -28,7 +28,7 @@ uwq_trywork(void)
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU; u64 j = (i+k) % NCPU;
if (j == mycpuid()) if (j == myid())
continue; continue;
struct cpu *c = &cpus[j]; struct cpu *c = &cpus[j];
...@@ -199,7 +199,7 @@ uwq::tryworker(void) ...@@ -199,7 +199,7 @@ uwq::tryworker(void)
proc* p = w->proc_; proc* p = w->proc_;
acquire(&p->lock); acquire(&p->lock);
p->cpuid = mycpuid(); p->cpuid = myid();
release(&p->lock); release(&p->lock);
w->running_ = true; w->running_ = true;
...@@ -226,7 +226,7 @@ again: ...@@ -226,7 +226,7 @@ again:
w->running_ = true; w->running_ = true;
acquire(&p->lock); acquire(&p->lock);
p->cpuid = mycpuid(); p->cpuid = myid();
addrun(p); addrun(p);
release(&p->lock); release(&p->lock);
......
...@@ -270,9 +270,9 @@ vmap::replace_vma(vma *a, vma *b) ...@@ -270,9 +270,9 @@ vmap::replace_vma(vma *a, vma *b)
assert(a->vma_start == b->vma_start); assert(a->vma_start == b->vma_start);
assert(a->vma_end == b->vma_end); assert(a->vma_end == b->vma_end);
auto span = vmas.search_lock(a->vma_start, a->vma_end - a->vma_start); auto span = vmas.search_lock(a->vma_start, a->vma_end - a->vma_start);
#if VM_CRANGE
if (a->deleted()) if (a->deleted())
return false; return false;
#if VM_CRANGE
for (auto e: span) for (auto e: span)
assert(a == e); assert(a == e);
span.replace(b); span.replace(b);
...@@ -477,11 +477,6 @@ again: ...@@ -477,11 +477,6 @@ again:
updatepages(pml4, e->vma_start, e->vma_end, [&needtlb](atomic<pme_t> *p) { updatepages(pml4, e->vma_start, e->vma_end, [&needtlb](atomic<pme_t> *p) {
for (;;) { for (;;) {
pme_t v = p->load(); pme_t v = p->load();
// XXX(austin) Huh? Why is it okay to skip it if it's
// locked? The page fault could be faulting in a page from
// the old VMA, in which case we need to shoot it down
// (though if it's already faulting a page from the new VMA,
// we need to *not* shoot it down).
if (v & PTE_LOCK) if (v & PTE_LOCK)
continue; continue;
if (!(v & PTE_P)) if (!(v & PTE_P))
...@@ -623,7 +618,12 @@ vmap::pagefault(uptr va, u32 err) ...@@ -623,7 +618,12 @@ vmap::pagefault(uptr va, u32 err)
} }
scoped_gc_epoch gc; scoped_gc_epoch gc;
#if VM_CRANGE
vma *m = lookup(va, 1); vma *m = lookup(va, 1);
#elif VM_RADIX
auto vma_it = vmas.find(va);
vma *m = static_cast<vma*>(*vma_it);
#endif
if (m == 0) if (m == 0)
return -1; return -1;
...@@ -664,10 +664,20 @@ vmap::pagefault(uptr va, u32 err) ...@@ -664,10 +664,20 @@ vmap::pagefault(uptr va, u32 err)
if (!cmpxch(pte, ptev, ptev | PTE_LOCK)) if (!cmpxch(pte, ptev, ptev | PTE_LOCK))
goto retry; goto retry;
#if VM_CRANGE
if (m->deleted()) { if (m->deleted()) {
*pte = ptev; *pte = ptev;
goto retry; goto retry;
} }
#elif VM_RADIX
// The radix tree is the source of truth about where the VMA is
// mapped. It might have been unmapped from this va but still be
// around, so we can't just test if it's deleted.
if (*vma_it != m) {
*pte = ptev;
goto retry;
}
#endif
if (m->va_type == COW) { if (m->va_type == COW) {
*pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_COW; *pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_COW;
......
...@@ -31,7 +31,7 @@ int ...@@ -31,7 +31,7 @@ int
wq_push(work *w) wq_push(work *w)
{ {
assert(wq_); assert(wq_);
return wq_->push(w, mycpuid()); return wq_->push(w, myid());
} }
void void
......
...@@ -158,7 +158,7 @@ wq::trywork(bool dosteal) ...@@ -158,7 +158,7 @@ wq::trywork(bool dosteal)
// A "random" victim CPU // A "random" victim CPU
k = rdtsc(); k = rdtsc();
w = pop(mycpuid()); w = pop(myid());
if (w != nullptr) { if (w != nullptr) {
w->run(); w->run();
return 1; return 1;
...@@ -170,7 +170,7 @@ wq::trywork(bool dosteal) ...@@ -170,7 +170,7 @@ wq::trywork(bool dosteal)
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU; u64 j = (i+k) % NCPU;
if (j == mycpuid()) if (j == myid())
continue; continue;
w = steal(j); w = steal(j);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论