x

上级 286cbb04
#pragma once
#include "wqtypes.hh"
#include "percpu.hh"
class work;
int wq_trywork(void);
......@@ -38,6 +41,45 @@ struct wframe {
volatile int v_;
};
#define NSLOTS (1 << WQSHIFT)
class wq {
public:
wq();
int push(work *w, int tcpuid);
int trywork();
void dump();
static void* operator new(unsigned long);
private:
work *steal(int c);
work *pop(int c);
void inclen(int c);
void declen(int c);
struct wqueue {
work *w[NSLOTS];
volatile int head __mpalign__;
volatile int tail;
wqlock_t lock;
};
struct stat {
u64 push;
u64 full;
u64 pop;
u64 steal;
};
percpu<wqueue> q_;
percpu<stat> stat_;
#if defined(XV6_USER)
uwq_ipcbuf* ipc_;
#endif
};
#if defined(LINUX)
#include <stdlib.h>
#include <assert.h>
......
#include "types.h"
#include "wqtypes.hh"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"
typedef struct spinlock wqlock_t;
static inline void*
allocwq(unsigned long nbytes)
......@@ -38,9 +35,4 @@ wqlock_init(wqlock_t *lock)
initlock(lock, "wq lock", LOCKSTAT_WQ);
}
static inline void
wqarch_init(void)
{
}
#define xprintf cprintf
#pragma once
#if defined (LINUX)
typedef pthread_spinlock_t wqlock_t;
#elif defined(XV6_KERNEL)
#include "types.h"
#include "spinlock.h"
typedef struct spinlock wqlock_t;
#else
#include "uspinlock.h"
typedef struct uspinlock wqlock_t;
#endif
......@@ -2,7 +2,6 @@
#include "uspinlock.h"
#include "amd64.h"
#include "user.h"
#include "wq.hh"
#include "pthread.h"
#include "memlayout.h"
#include "uwq.hh"
......@@ -12,15 +11,7 @@
typedef struct uspinlock wqlock_t;
static pthread_key_t idkey;
static std::atomic<int> nextid;
static volatile int exiting;
int
mycpuid(void)
{
return (int)(u64)pthread_getspecific(idkey);
}
int mycpuid(void);
static inline void*
allocwq(unsigned long nbytes)
......@@ -64,34 +55,6 @@ wqlock_init(wqlock_t *lock)
initlock(lock);
}
extern "C" long wqwait(void);
static void __attribute__((used))
initworker(void)
{
int id;
forkt_setup(0);
id = nextid++;
if (id >= NCPU)
die("initworker: to man IDs");
pthread_setspecific(idkey, (void*)(u64)id);
while (1) {
if (!wq_trywork())
assert(wqwait() == 0);
}
}
DEFINE_XV6_ADDRNOTE(xnote, XV6_ADDR_ID_WQ, &initworker);
static inline void
wqarch_init(void)
{
if (pthread_key_create(&idkey, 0))
die("wqarch_init: pthread_key_create");
int id = nextid++;
pthread_setspecific(idkey, (void*)(u64)id);
}
#define xprintf printf
#define pushcli()
#define popcli()
......
......@@ -47,7 +47,8 @@ OBJS = \
trap.o \
uaccess.o \
trapasm.o \
wq.o \
wqkern.o \
wqlib.o \
script.o \
zalloc.o \
incbin.o
......
#include "types.h"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"
static wq *wq_;
size_t
wq_size(void)
{
return sizeof(wq);
}
int
wq_push(work *w)
{
return wq_->push(w, mycpuid());
}
int
wq_pushto(work *w, int tcpuid)
{
return wq_->push(w, tcpuid);
}
int
wq_trywork(void)
{
return wq_->trywork();
}
void
wq_dump(void)
{
return wq_->dump();
}
void
initwq(void)
{
wq_ = new wq();
}
......@@ -2,7 +2,7 @@ $(O)/lib/%.o: CFLAGS:=$(CFLAGS) -DXV6_USER
$(O)/lib/%.o: CXXFLAGS:=$(CXXFLAGS) -DXV6_USER
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o fmt.o stream.o ipc.o \
threads.o crt.o wq.o perf.o wqalloc.o
threads.o crt.o wqlib.o wquser.o perf.o wqalloc.o
ULIB := $(addprefix $(O)/lib/, $(ULIB))
.PRECIOUS: $(O)/lib/%.o
......
......@@ -5,49 +5,11 @@
#else
#include "wquser.hh"
#endif
#include "percpu.hh"
#define NSLOTS (1 << WQSHIFT)
#include "wq.hh"
enum { wq_steal_others = 1 };
class wq {
public:
wq();
int push(work *w, int tcpuid);
int trywork();
void dump();
static void* operator new(unsigned long);
private:
work *steal(int c);
work *pop(int c);
void inclen(int c);
void declen(int c);
struct wqueue {
work *w[NSLOTS];
volatile int head __mpalign__;
volatile int tail;
wqlock_t lock;
};
struct stat {
u64 push;
u64 full;
u64 pop;
u64 steal;
};
percpu<wqueue> q_;
percpu<stat> stat_;
#if defined(XV6_USER)
uwq_ipcbuf* ipc_;
#endif
};
#if 0
static wq *wq_;
size_t
......@@ -86,6 +48,8 @@ initwq(void)
wq_ = new wq();
wqarch_init();
}
#endif
//
// wq
......
#include "types.h"
#include "user.h"
#include "uwq.hh"
#include "wq.hh"
#include "atomic.hh"
#include "pthread.h"
#include "elf.hh"
static pthread_key_t idkey;
static std::atomic<int> nextid;
static wq *wq_;
extern "C" long wqwait(void);
static void __attribute__((used))
initworker(void)
{
int id;
forkt_setup(0);
id = nextid++;
if (id >= NCPU)
die("initworker: to man IDs");
pthread_setspecific(idkey, (void*)(u64)id);
while (1) {
if (!wq_trywork())
assert(wqwait() == 0);
}
}
DEFINE_XV6_ADDRNOTE(xnote, XV6_ADDR_ID_WQ, &initworker);
static inline void
wqarch_init(void)
{
if (pthread_key_create(&idkey, 0))
die("wqarch_init: pthread_key_create");
int id = nextid++;
pthread_setspecific(idkey, (void*)(u64)id);
}
int
mycpuid(void)
{
return (int)(u64)pthread_getspecific(idkey);
}
size_t
wq_size(void)
{
return sizeof(wq);
}
int
wq_push(work *w)
{
return wq_->push(w, mycpuid());
}
int
wq_pushto(work *w, int tcpuid)
{
return wq_->push(w, tcpuid);
}
int
wq_trywork(void)
{
return wq_->trywork();
}
void
wq_dump(void)
{
return wq_->dump();
}
void
initwq(void)
{
wq_ = new wq();
wqarch_init();
}
#pragma once
#define DEBUG 1
#define DEBUG 0
#define NPROC 64 // maximum number of processes
#define KSTACKSIZE 8192 // size of per-process kernel stack
#define NOFILE 64 // open files per process
......
......@@ -9,8 +9,6 @@
static __thread int myid_;
typedef pthread_spinlock_t wqlock_t;
int
mycpuid(void)
{
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论