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

Merge branch 'scale-amd64' of git+ssh://pdos.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

...@@ -8,7 +8,6 @@ class work; ...@@ -8,7 +8,6 @@ class work;
int wq_trywork(void); int wq_trywork(void);
int wq_push(work *w); int wq_push(work *w);
int wq_pushto(work *w, int tcpuid);
void wq_dump(void); void wq_dump(void);
size_t wq_size(void); size_t wq_size(void);
void initwq(void); void initwq(void);
...@@ -48,7 +47,7 @@ class wq { ...@@ -48,7 +47,7 @@ class wq {
public: public:
wq(); wq();
int push(work *w, int tcpuid); int push(work *w, int tcpuid);
int trywork(); int trywork(bool steal = true);
void dump(); void dump();
static void* operator new(unsigned long); static void* operator new(unsigned long);
...@@ -85,6 +84,10 @@ private: ...@@ -85,6 +84,10 @@ private:
void* xallocwork(unsigned long nbytes); void* xallocwork(unsigned long nbytes);
void xfreework(void* ptr, unsigned long nbytes); void xfreework(void* ptr, unsigned long nbytes);
#if defined(XV6_KERNEL)
int wqcrit_push(work* w, int c);
#endif
#if defined(XV6_USER) #if defined(XV6_USER)
void* wqalloc(unsigned long nbytes); void* wqalloc(unsigned long nbytes);
void wqfree(void *ptr); void wqfree(void *ptr);
......
...@@ -248,7 +248,7 @@ exec(const char *path, char **argv, void *ascopev) ...@@ -248,7 +248,7 @@ exec(const char *path, char **argv, void *ascopev)
w->rip = (void*) exec_cleanup; w->rip = (void*) exec_cleanup;
w->arg0 = oldvmap; w->arg0 = oldvmap;
w->arg1 = olduwq; w->arg1 = olduwq;
assert(wq_pushto(w, myproc()->exec_cpuid_) >= 0); assert(wqcrit_push(w, myproc()->exec_cpuid_) >= 0);
gc_end_epoch(); gc_end_epoch();
return 0; return 0;
......
...@@ -287,7 +287,7 @@ initkalloc(u64 mbaddr) ...@@ -287,7 +287,7 @@ initkalloc(u64 mbaddr)
strncpy(slabmem[slab_wq][c].name, " wq", MAXNAME); strncpy(slabmem[slab_wq][c].name, " wq", MAXNAME);
slabmem[slab_wq][c].size = PGROUNDUP(wq_size()); slabmem[slab_wq][c].size = PGROUNDUP(wq_size());
slabmem[slab_wq][c].ninit = NCPU; slabmem[slab_wq][c].ninit = 2;
strncpy(slabmem[slab_userwq][c].name, " uwq", MAXNAME); strncpy(slabmem[slab_userwq][c].name, " uwq", MAXNAME);
slabmem[slab_userwq][c].size = USERWQSIZE; slabmem[slab_userwq][c].size = USERWQSIZE;
...@@ -315,7 +315,6 @@ initkalloc(u64 mbaddr) ...@@ -315,7 +315,6 @@ initkalloc(u64 mbaddr)
void void
kfree(void *v) kfree(void *v)
{ {
verifyfree((char*) v, mykmem()->size);
kfree_pool(mykmem(), (char*) v); kfree_pool(mykmem(), (char*) v);
} }
...@@ -324,22 +323,3 @@ ksfree(int slab, void *v) ...@@ -324,22 +323,3 @@ ksfree(int slab, void *v)
{ {
kfree_pool(slabmem[slab], (char*) v); kfree_pool(slabmem[slab], (char*) v);
} }
void
verifyfree(char *ptr, u64 nbytes)
{
#if VERIFYFREE
char *p = ptr;
char *e = p + nbytes;
for (; p < e; p++) {
// Search for pointers in the ptr region
u64 x = *(uptr *)p;
if ((KBASE < x && x < KBASE+(128ull<<30)) || (KCODE < x)) {
struct klockstat *kls = (struct klockstat *) x;
if (kls->magic == LOCKSTAT_MAGIC)
panic("LOCKSTAT_MAGIC %p(%lu):%p->%p",
ptr, nbytes, p, kls);
}
}
#endif
}
...@@ -117,7 +117,6 @@ kmfree(void *ap, u64 nbytes) ...@@ -117,7 +117,6 @@ kmfree(void *ap, u64 nbytes)
int b = bucket(nbytes); int b = bucket(nbytes);
struct header *h = (struct header *) ap; struct header *h = (struct header *) ap;
verifyfree((char *) ap, (1<<b));
if (ALLOC_MEMSET) if (ALLOC_MEMSET)
memset(ap, 3, (1<<b)); memset(ap, 3, (1<<b));
......
...@@ -443,7 +443,7 @@ wait(void) ...@@ -443,7 +443,7 @@ wait(void)
assert(w); assert(w);
w->rip = (void*) finishproc; w->rip = (void*) finishproc;
w->arg0 = p; w->arg0 = p;
assert(wq_pushto(w, p->run_cpuid_) >= 0); assert(wqcrit_push(w, p->run_cpuid_) >= 0);
if (!xnspid->remove(pid, &p)) if (!xnspid->remove(pid, &p))
panic("wait: ns_remove"); panic("wait: ns_remove");
......
...@@ -142,7 +142,9 @@ uwq::uwq(vmap* vmap, filetable* ftable, uwq_ipcbuf* ipc) ...@@ -142,7 +142,9 @@ uwq::uwq(vmap* vmap, filetable* ftable, uwq_ipcbuf* ipc)
ipc_->len[i].v_ = 0; ipc_->len[i].v_ = 0;
initlock(&lock_, "uwq_lock", 0); initlock(&lock_, "uwq_lock", 0);
memset(worker_, 0, sizeof(worker_));
for (int i = 0; i < NWORKERS; i++)
worker_[i].store(nullptr);
} }
uwq::~uwq(void) uwq::~uwq(void)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "wq.hh" #include "wq.hh"
static wq *wq_; static wq *wq_;
static wq *wqcrit_;
void* void*
xallocwork(unsigned long nbytes) xallocwork(unsigned long nbytes)
...@@ -33,15 +34,15 @@ wq_push(work *w) ...@@ -33,15 +34,15 @@ wq_push(work *w)
} }
int int
wq_pushto(work *w, int tcpuid) wqcrit_push(work *w, int c)
{ {
return wq_->push(w, tcpuid); return wqcrit_->push(w, c);
} }
int int
wq_trywork(void) wq_trywork(void)
{ {
return wq_->trywork(); return wqcrit_->trywork(false) || wq_->trywork(true);
} }
void void
...@@ -54,4 +55,7 @@ void ...@@ -54,4 +55,7 @@ void
initwq(void) initwq(void)
{ {
wq_ = new wq(); wq_ = new wq();
wqcrit_ = new wq();
if (wq_ == nullptr || wqcrit_ == nullptr)
panic("initwq");
} }
...@@ -50,3 +50,10 @@ wqfree(void *ptr) ...@@ -50,3 +50,10 @@ wqfree(void *ptr)
b->next = *block; b->next = *block;
*block = b; *block = b;
} }
void
wqallocinit(void)
{
for (int i = 0; i < NCPU; i++)
block[i] = nullptr;
}
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#endif #endif
#include "wq.hh" #include "wq.hh"
enum { wq_steal_others = 1 };
// //
// wq // wq
// //
...@@ -118,9 +116,6 @@ wq::pop(int c) ...@@ -118,9 +116,6 @@ wq::pop(int c)
inline work* inline work*
wq::steal(int c) wq::steal(int c)
{ {
if (!wq_steal_others && (c != mycpuid()))
return 0;
struct wqueue *q = &q_[c]; struct wqueue *q = &q_[c];
work *w; work *w;
int i; int i;
...@@ -143,7 +138,7 @@ wq::steal(int c) ...@@ -143,7 +138,7 @@ wq::steal(int c)
} }
int int
wq::trywork(void) wq::trywork(bool dosteal)
{ {
work *w; work *w;
u64 i, k; u64 i, k;
...@@ -157,6 +152,9 @@ wq::trywork(void) ...@@ -157,6 +152,9 @@ wq::trywork(void)
return 1; return 1;
} }
if (!dosteal)
return 0;
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU; u64 j = (i+k) % NCPU;
......
...@@ -83,12 +83,16 @@ xfreework(void* ptr, unsigned long nbytes) ...@@ -83,12 +83,16 @@ xfreework(void* ptr, unsigned long nbytes)
void void
initwq(void) initwq(void)
{ {
extern void wqallocinit(void);
if (pthread_key_create(&idkey, 0)) if (pthread_key_create(&idkey, 0))
die("wqarch_init: pthread_key_create"); die("wqarch_init: pthread_key_create");
int id = nextid++; int id = nextid++;
pthread_setspecific(idkey, (void*)(u64)id); pthread_setspecific(idkey, (void*)(u64)id);
wqallocinit();
wq_ = new wq(); wq_ = new wq();
if (wq_ == nullptr) if (wq_ == nullptr)
die("initwq"); die("initwq");
......
#pragma once #pragma once
#define DEBUG 0
#define NPROC 64 // maximum number of processes #define NPROC 64 // maximum number of processes
#define KSTACKSIZE 8192 // size of per-process kernel stack #define KSTACKSIZE 8192 // size of per-process kernel stack
#define NOFILE 64 // open files per process #define NOFILE 64 // open files per process
...@@ -14,13 +13,11 @@ ...@@ -14,13 +13,11 @@
#define CACHELINE 64 // cache line size #define CACHELINE 64 // cache line size
#define CPUKSTACKS (NPROC + NCPU*2) #define CPUKSTACKS (NPROC + NCPU*2)
#define QUANTUM 10 // scheduling time quantum and tick length (in msec) #define QUANTUM 10 // scheduling time quantum and tick length (in msec)
#define CILKSHIFT 4 // 2^WORKSHIFT work queue slots
#define VICTIMAGE 1000000 // cycles a proc executes before an eligible victim #define VICTIMAGE 1000000 // cycles a proc executes before an eligible victim
#define VERBOSE 0 // print kernel diagnostics #define VERBOSE 0 // print kernel diagnostics
#define SPINLOCK_DEBUG DEBUG // Debug spin locks #define SPINLOCK_DEBUG DEBUG // Debug spin locks
#define RCU_TYPE_DEBUG DEBUG #define RCU_TYPE_DEBUG DEBUG
#define LOCKSTAT DEBUG #define LOCKSTAT DEBUG
#define VERIFYFREE 0 // Unreliable, e.g. vma's vmnode pointer gets reused
#define ALLOC_MEMSET DEBUG #define ALLOC_MEMSET DEBUG
#define KSHAREDSIZE (32 << 10) #define KSHAREDSIZE (32 << 10)
#define USERWQSIZE (1 << 14) #define USERWQSIZE (1 << 14)
...@@ -28,29 +25,34 @@ ...@@ -28,29 +25,34 @@
#define WQSHIFT 7 #define WQSHIFT 7
#define CILKENABLE 0 #define CILKENABLE 0
#if defined(HW_qemu) #if defined(HW_qemu)
#define NCPU 8 // maximum number of CPUs #define NCPU 8 // maximum number of CPUs
#define MTRACE 0 #define MTRACE 0
#define PERFSIZE (16<<20ull) #define PERFSIZE (16<<20ull)
#elif defined(HW_josmp) #elif defined(HW_josmp)
#define NCPU 16 // maximum number of CPUs #define DEBUG 0
#define MTRACE 0 #define NCPU 16 // maximum number of CPUs
#define PERFSIZE (1<<20ull) #define MTRACE 0
#define PERFSIZE (1<<20ull)
#elif defined(HW_ud0) #elif defined(HW_ud0)
#define NCPU 4 // maximum number of CPUs #define NCPU 4 // maximum number of CPUs
#define MTRACE 0 #define MTRACE 0
#define PERFSIZE (512<<20ull) #define PERFSIZE (512<<20ull)
#elif defined(HW_tom) #elif defined(HW_tom)
#define NCPU 48 // maximum number of CPUs #define NCPU 48 // maximum number of CPUs
#define MTRACE 0 #define MTRACE 0
#define PERFSIZE (1<<20ull) #define PERFSIZE (1<<20ull)
#elif defined(HW_user) #elif defined(HW_user)
#define NCPU 256 #define NCPU 256
#define MTRACE 0 #define MTRACE 0
#define PERFSIZE (16<<20ull) #define PERFSIZE (16<<20ull)
#elif defined(HW_wq) #elif defined(HW_wq)
#define NCPU 2 #define NCPU 2
#define MTRACE 0 #define MTRACE 0
#define PERFSIZE (16<<20ull) #define PERFSIZE (16<<20ull)
#else #else
#error "Unknown HW" #error "Unknown HW"
#endif #endif
#ifndef DEBUG
#define DEBUG 1
#endif
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论