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