Start of wq for xv6 userspace

上级 920a2be3
......@@ -23,7 +23,8 @@ UPROGS= \
preadtest \
scripttest \
ftest \
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"
// 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论