Start of some kernel code that looks for userspace work

上级 a778a729
...@@ -4,5 +4,25 @@ struct padded_length { ...@@ -4,5 +4,25 @@ struct padded_length {
}; };
#if defined (XV6_KERNEL) #if defined (XV6_KERNEL)
struct uwq_length {
uwq_length(padded_length *len) : len_(len) {}
void clear() {
for (int i = 0; i < NCPU; i++)
len_[i].v_ = 0;
}
bool haswork() {
for (int i = 0; i < NCPU; i++) {
if (len_[i].v_ > 0)
return true;
}
return false;
}
private:
padded_length* len_;
};
int uwq_trywork(void); int uwq_trywork(void);
#endif #endif
...@@ -93,10 +93,10 @@ struct vmap { ...@@ -93,10 +93,10 @@ struct vmap {
NEW_DELETE_OPS(vmap) NEW_DELETE_OPS(vmap)
uptr brk_; // Top of heap uptr brk_; // Top of heap
padded_length* const uwq_len_;
private: private:
int pagefault_wcow(vma *m); int pagefault_wcow(vma *m);
padded_length* const uwq_len_;
struct spinlock brklock_; struct spinlock brklock_;
}; };
...@@ -118,7 +118,7 @@ idleloop(void) ...@@ -118,7 +118,7 @@ idleloop(void)
idlem->heir = p; idlem->heir = p;
} }
worked = uwq_trywork(); // XXX(sbw) worked = uwq_trywork();
worked = wq_trywork(); worked = wq_trywork();
// If we are no longer the idle thread, exit // If we are no longer the idle thread, exit
......
#include "types.h" #include "types.h"
#include "amd64.h"
#include "kernel.hh" #include "kernel.hh"
#include "cpu.hh"
#include "uwq.hh" #include "uwq.hh"
#include "gc.hh"
#include "percpu.hh"
#include "spinlock.h"
#include "condvar.h"
#include "proc.hh"
#include "vm.hh"
int int
uwq_trywork(void) uwq_trywork(void)
{ {
u64 i, k;
// A "random" victim CPU
k = rdtsc();
for (i = 0; i < NCPU; i++) {
u64 j = (i+k) % NCPU;
if (j == mycpuid())
continue;
struct cpu *c = &cpus[j];
scoped_gc_epoch();
struct proc *p = c->proc;
if (p == nullptr || p->vmap == nullptr)
continue;
padded_length *len = p->vmap->uwq_len_;
if (len == nullptr)
break;
if (uwq_length(len).haswork()) {
// XXX(sbw) start a worker thread..
break;
}
}
return 0; return 0;
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "crange.hh" #include "crange.hh"
#include "cpputil.hh" #include "cpputil.hh"
#include "sperf.hh" #include "sperf.hh"
#include "uwq.hh"
enum { vm_debug = 0 }; enum { vm_debug = 0 };
...@@ -162,6 +163,8 @@ vmap::vmap() : ...@@ -162,6 +163,8 @@ vmap::vmap() :
if (uwq_len_ == nullptr) { if (uwq_len_ == nullptr) {
cprintf("vmap::vmap: userwq out of memory\n"); cprintf("vmap::vmap: userwq out of memory\n");
goto err; goto err;
} else {
uwq_length(uwq_len_).clear();
} }
if (setupuvm(pml4, kshared, (char*)uwq_len_)) { if (setupuvm(pml4, kshared, (char*)uwq_len_)) {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论