提交 8a620c2e 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

wq tweak: __wq_run now inherits the frame of the thread it's running.

上级 e6668071
#include "mmu.h"
struct wqframe;
// Per-CPU state
struct cpu {
u8 id; // Local APIC ID; index into cpus[] below
int ncli; // Depth of pushcli nesting.
int intena; // Were interrupts enabled before pushcli?
......@@ -10,6 +11,7 @@ struct cpu {
struct taskstate ts; // Used by x86 to find stack for interrupt
struct context *scheduler; // swtch() here to enter scheduler
u64 last_rcu_gc_ticks;
struct wqframe *wqframe;
// Cpu-local storage variables; see below
struct cpu *cpu;
......
......@@ -18,4 +18,4 @@
#define CPUKSTACKS (NPROC + NCPU)
#define QUANTUN 10 // scheduling time quantum and tick length (in msec)
#define WQSHIFT 4 // 2^WORKSHIFT work queue slots
#define WQENABLE 0 // Enable work queue
#define WQENABLE 1 // Enable work queue
......@@ -51,7 +51,7 @@ struct wqthread {
u64 rip;
u64 arg0;
u64 arg1;
volatile u64 *ref; // pointer to parent wqframe.ref
struct wqframe *frame; // parent wqframe
__padout__;
} __mpalign__;
......@@ -75,7 +75,7 @@ wq_cur(void)
static struct wqframe *
wq_frame(void)
{
return &myproc()->wqframe;
return mycpu()->wqframe;
}
static struct wqstat *
......@@ -144,8 +144,12 @@ static void
__wq_run(struct wqthread *th)
{
void (*fn)(uptr arg0, uptr arg1) = (void*)th->rip;
struct wqframe *old = mycpu()->wqframe;
mycpu()->wqframe = th->frame;
fn(th->arg0, th->arg1);
subfetch(th->ref, 1);
mycpu()->wqframe = old;
subfetch(&th->frame->ref, 1);
kfree(th);
}
......@@ -166,7 +170,7 @@ wq_push(void *rip, u64 arg0, u64 arg1)
th->rip = (uptr) rip;
th->arg0 = arg0;
th->arg1 = arg1;
th->ref = &wq_frame()->ref;
th->frame = wq_frame();
if (__wq_push(wq_cur(), th)) {
kfree(th);
......@@ -216,6 +220,7 @@ wq_start(void)
pushcli();
if (myproc()->wqframe.ref != 0)
panic("wq_start");
mycpu()->wqframe = &myproc()->wqframe;
}
// End of the current work queue frame.
......@@ -224,7 +229,7 @@ wq_start(void)
void
wq_end(void)
{
while (myproc()->wqframe.ref != 0) {
while (wq_frame()->ref != 0) {
struct wqthread *th;
int i;
......@@ -239,6 +244,7 @@ wq_end(void)
}
}
}
mycpu()->wqframe = NULL;
popcli();
}
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论