提交 cb928e7a 创建 作者: Robert Morris's avatar Robert Morris

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

Conflicts: bin/Makefrag
......@@ -24,7 +24,8 @@ UPROGS= \
scripttest \
ftest \
wqsh \
perf
perf \
xls
# pdu
# pls
......
......@@ -21,6 +21,7 @@
#include "fs.h"
#include "lib.h"
#include "dirit.hh"
#include "wq.hh"
#define ST_SIZE(st) (st).size
#define ST_TYPE(st) (st).type
#define ST_INO(st) (st).ino
......
......@@ -17,3 +17,9 @@ release(struct uspinlock *lk)
{
xchg32(&lk->locked, 0);
}
static int inline
tryacquire(struct uspinlock *lk)
{
return xchg32(&lk->locked, 1) == 0;
}
......@@ -38,7 +38,8 @@ struct cwork : public work {
#define xmalloc(n) kmalloc(n)
#define xfree(p, sz) kmfree(p, sz)
#else
#warning "Unknown wq implementation"
#define xmalloc(n) malloc(n)
#define xfree(p, sz) free(p)
#endif
#include "wqfor.hh"
struct forframe
{
forframe(int v) : v_(v) {}
int inc() { return __sync_add_and_fetch(&v_, 1); }
int dec() { return __sync_sub_and_fetch(&v_, 1); }
bool zero() volatile { return v_ == 0; };
volatile int v_;
};
template <typename IT, typename BODY>
struct forwork : public work {
typedef std::atomic<int> forframe;
forwork(IT &it, bool (*cond)(IT &it), BODY &body, forframe &frame)
: it_(it), cond_(cond), body_(body), frame_(frame) {}
......@@ -10,11 +17,11 @@ struct forwork : public work {
++it_;
if (cond_(it_)) {
forwork<IT, BODY> *w = new forwork<IT, BODY>(it_, cond_, body_, frame_);
++frame_;
frame_.inc();
wq_push(w);
}
body_(v);
--frame_;
frame_.dec();
delete this;
}
......@@ -37,7 +44,7 @@ template <typename IT, typename BODY>
static inline void
wq_for(IT &init, bool (*cond)(IT &it), BODY body)
{
typename forwork<IT, BODY>::forframe frame(0);
forframe frame(0);
// XXX(sbw) should be able to coarsen loop
......@@ -45,11 +52,11 @@ wq_for(IT &init, bool (*cond)(IT &it), BODY body)
++init;
if (cond(init)) {
forwork<IT, BODY> *w = new forwork<IT, BODY>(init, cond, body, frame);
++frame;
frame.inc();
wq_push(w);
}
body(v);
while (frame != 0)
while (!frame.zero())
wq_trywork();
}
// XXX(sbw)
#include "types.h"
#include "uspinlock.h"
#include "amd64.h"
#include "user.h"
#include "wq.hh"
#include "pthread.h"
typedef struct uspinlock wqlock_t;
static pthread_key_t idkey;
int
mycpuid(void)
{
return (int)(u64)pthread_getspecific(idkey);
}
static inline void*
allocwq(void)
{
return malloc(WQSIZE);
}
static inline void
wqlock_acquire(wqlock_t *lock)
{
acquire(lock);
}
static inline int
wqlock_tryacquire(wqlock_t *lock)
{
return tryacquire(lock);
}
static inline void
wqlock_release(wqlock_t *lock)
{
release(lock);
}
static inline void
wqlock_init(wqlock_t *lock)
{
lock->locked = 0;
}
static void
setaffinity(int c)
{
// XXX(sbw)
}
static void*
workerth(void *x)
{
u64 c = (u64)x;
setaffinity(c);
pthread_setspecific(idkey, (void*)c);
while (1)
wq_trywork();
return 0;
}
static inline void
wqarch_init(void)
{
pthread_t th;
int r;
if (pthread_key_create(&idkey, 0))
die("wqarch_init: pthread_key_create");
pthread_setspecific(idkey, 0);
setaffinity(0);
for (int i = 1; i < NCPU; i++) {
r = pthread_create(&th, 0, workerth, (void*)(u64)i);
if (r < 0)
die("wqarch_init: pthread_create");
}
}
#define xprintf printf
#define pushcli()
#define popcli()
......@@ -2,7 +2,7 @@ $(O)/lib/%.o: CFLAGS:=$(CFLAGS)
$(O)/lib/%.o: CXXFLAGS:=$(CXXFLAGS)
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o fmt.o stream.o ipc.o \
threads.o crt.o
threads.o crt.o wq.o
ULIB := $(addprefix $(O)/lib/, $(ULIB))
.PRECIOUS: $(O)/lib/%.o
......
......@@ -2,6 +2,7 @@
.align 8
.globl _start
_start:
call usetup
pop %rdi
mov %rsp, %rsi
call main
......
......@@ -150,3 +150,15 @@ open(const char *path, int omode)
{
return openat(AT_FDCWD, path, omode);
}
extern void __cxa_pure_virtual(void);
void __cxa_pure_virtual(void)
{
die("__cxa_pure_virtual");
}
void
usetup(void)
{
forkt_setup(getpid());
}
#if defined(LINUX)
#include "user/wqlinux.hh"
#include "percpu.hh"
#elif defined(XV6_KERNEL)
#include "wqkernel.hh"
#include "percpu.hh"
#else
#warning "Unknown wq implementation"
#include "wquser.hh"
#endif
#include "percpu.hh"
#define NSLOTS (1 << WQSHIFT)
......
......@@ -84,7 +84,5 @@ wqarch_init(void)
}
#define xprintf printf
#define xmalloc(n) malloc(n)
#define xfree(p, sz) free(p)
#define pushcli()
#define popcli()
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论