wq nits

上级 cfd454fc
...@@ -109,10 +109,18 @@ wq_push2(void (*fn)(struct work*, void*, void*), void *a0, void *a1) ...@@ -109,10 +109,18 @@ wq_push2(void (*fn)(struct work*, void*, void*), void *a0, void *a1)
return 0; return 0;
} }
static struct work * static void
__wq_run(struct work *w)
{
void (*fn)(struct work*, void*, void*, void*, void*, void*) =
(void(*)(work*,void*,void*,void*,void*,void*))w->rip;
fn(w, w->arg0, w->arg1, w->arg2, w->arg3, w->arg4);
freework(w);
}
static inline struct work *
__wq_pop(int c) __wq_pop(int c)
{ {
// Called with cli
struct wqueue *wq = &queue[c]; struct wqueue *wq = &queue[c];
struct work *w; struct work *w;
int i; int i;
...@@ -136,10 +144,9 @@ __wq_pop(int c) ...@@ -136,10 +144,9 @@ __wq_pop(int c)
return w; return w;
} }
static struct work * static inline struct work *
__wq_steal(int c) __wq_steal(int c)
{ {
// Called with cli
struct wqueue *wq = &queue[c]; struct wqueue *wq = &queue[c];
struct work *w; struct work *w;
int i; int i;
...@@ -160,42 +167,34 @@ __wq_steal(int c) ...@@ -160,42 +167,34 @@ __wq_steal(int c)
return w; return w;
} }
static void
__wq_run(struct work *w)
{
void (*fn)(struct work*, void*, void*, void*, void*, void*) =
(void(*)(work*,void*,void*,void*,void*,void*))w->rip;
fn(w, w->arg0, w->arg1, w->arg2, w->arg3, w->arg4);
freework(w);
}
int int
wq_trywork(void) wq_trywork(void)
{ {
struct work *w; struct work *w;
int i; int i, k;
// A "random" victim CPU
k = rdtsc();
//pushcli();
w = __wq_pop(mycpu()->id); w = __wq_pop(mycpu()->id);
if (w != nullptr) { if (w != nullptr) {
__wq_run(w); __wq_run(w);
//popcli();
return 1; return 1;
} }
// XXX(sbw) should be random
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++) {
if (i == mycpu()->id) int j = (i+k) % NCPU;
if (j == mycpu()->id)
continue; continue;
w = __wq_steal(i); w = __wq_steal(j);
if (w != nullptr) { if (w != nullptr) {
__wq_run(w); __wq_run(w);
//popcli();
return 1; return 1;
} }
} }
//popcli();
return 0; return 0;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论