x

上级 286cbb04
#pragma once #pragma once
#include "wqtypes.hh"
#include "percpu.hh"
class work; class work;
int wq_trywork(void); int wq_trywork(void);
...@@ -38,6 +41,45 @@ struct wframe { ...@@ -38,6 +41,45 @@ struct wframe {
volatile int v_; 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) #if defined(LINUX)
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
......
#include "types.h" #include "wqtypes.hh"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "amd64.h" #include "amd64.h"
#include "cpu.hh" #include "cpu.hh"
#include "kalloc.hh" #include "kalloc.hh"
#include "wq.hh"
typedef struct spinlock wqlock_t;
static inline void* static inline void*
allocwq(unsigned long nbytes) allocwq(unsigned long nbytes)
...@@ -38,9 +35,4 @@ wqlock_init(wqlock_t *lock) ...@@ -38,9 +35,4 @@ wqlock_init(wqlock_t *lock)
initlock(lock, "wq lock", LOCKSTAT_WQ); initlock(lock, "wq lock", LOCKSTAT_WQ);
} }
static inline void
wqarch_init(void)
{
}
#define xprintf cprintf #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 @@ ...@@ -2,7 +2,6 @@
#include "uspinlock.h" #include "uspinlock.h"
#include "amd64.h" #include "amd64.h"
#include "user.h" #include "user.h"
#include "wq.hh"
#include "pthread.h" #include "pthread.h"
#include "memlayout.h" #include "memlayout.h"
#include "uwq.hh" #include "uwq.hh"
...@@ -12,15 +11,7 @@ ...@@ -12,15 +11,7 @@
typedef struct uspinlock wqlock_t; typedef struct uspinlock wqlock_t;
static pthread_key_t idkey; int mycpuid(void);
static std::atomic<int> nextid;
static volatile int exiting;
int
mycpuid(void)
{
return (int)(u64)pthread_getspecific(idkey);
}
static inline void* static inline void*
allocwq(unsigned long nbytes) allocwq(unsigned long nbytes)
...@@ -64,34 +55,6 @@ wqlock_init(wqlock_t *lock) ...@@ -64,34 +55,6 @@ wqlock_init(wqlock_t *lock)
initlock(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 xprintf printf
#define pushcli() #define pushcli()
#define popcli() #define popcli()
......
...@@ -47,7 +47,8 @@ OBJS = \ ...@@ -47,7 +47,8 @@ OBJS = \
trap.o \ trap.o \
uaccess.o \ uaccess.o \
trapasm.o \ trapasm.o \
wq.o \ wqkern.o \
wqlib.o \
script.o \ script.o \
zalloc.o \ zalloc.o \
incbin.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 ...@@ -2,7 +2,7 @@ $(O)/lib/%.o: CFLAGS:=$(CFLAGS) -DXV6_USER
$(O)/lib/%.o: CXXFLAGS:=$(CXXFLAGS) -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 \ 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)) ULIB := $(addprefix $(O)/lib/, $(ULIB))
.PRECIOUS: $(O)/lib/%.o .PRECIOUS: $(O)/lib/%.o
......
...@@ -5,49 +5,11 @@ ...@@ -5,49 +5,11 @@
#else #else
#include "wquser.hh" #include "wquser.hh"
#endif #endif
#include "percpu.hh" #include "wq.hh"
#define NSLOTS (1 << WQSHIFT)
enum { wq_steal_others = 1 }; enum { wq_steal_others = 1 };
class wq { #if 0
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
};
static wq *wq_; static wq *wq_;
size_t size_t
...@@ -86,6 +48,8 @@ initwq(void) ...@@ -86,6 +48,8 @@ initwq(void)
wq_ = new wq(); wq_ = new wq();
wqarch_init(); wqarch_init();
} }
#endif
// //
// wq // 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 #pragma once
#define DEBUG 1 #define DEBUG 0
#define NPROC 64 // maximum number of processes #define NPROC 64 // maximum number of processes
#define KSTACKSIZE 8192 // size of per-process kernel stack #define KSTACKSIZE 8192 // size of per-process kernel stack
#define NOFILE 64 // open files per process #define NOFILE 64 // open files per process
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
static __thread int myid_; static __thread int myid_;
typedef pthread_spinlock_t wqlock_t;
int int
mycpuid(void) mycpuid(void)
{ {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论