Add highest priority wq to the kernel.

The critical wq allows pushing to remote cores and cores never steal from the critical wq.
上级 828175bd
...@@ -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);
...@@ -84,6 +83,10 @@ private: ...@@ -84,6 +83,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;
......
...@@ -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");
......
...@@ -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");
} }
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#endif #endif
#include "wq.hh" #include "wq.hh"
enum { wq_steal_others = 1 };
// //
// wq // wq
// //
...@@ -112,9 +110,6 @@ wq::pop(int c) ...@@ -112,9 +110,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;
...@@ -137,7 +132,7 @@ wq::steal(int c) ...@@ -137,7 +132,7 @@ wq::steal(int c)
} }
int int
wq::trywork(void) wq::trywork(bool dosteal)
{ {
work *w; work *w;
u64 i, k; u64 i, k;
...@@ -151,6 +146,9 @@ wq::trywork(void) ...@@ -151,6 +146,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;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论