Add a uwq member to cpu and only write to it when necessary

上级 e38988a8
...@@ -7,6 +7,8 @@ using std::atomic; ...@@ -7,6 +7,8 @@ using std::atomic;
extern atomic<u64> tlbflush_req; extern atomic<u64> tlbflush_req;
class uwq;
// Per-CPU state // Per-CPU state
struct cpu { struct cpu {
cpuid_t id; // Index into cpus[] below cpuid_t id; // Index into cpus[] below
...@@ -20,6 +22,7 @@ struct cpu { ...@@ -20,6 +22,7 @@ struct cpu {
atomic<u64> tlbflush_done; // last tlb flush req done on this cpu atomic<u64> tlbflush_done; // last tlb flush req done on this cpu
struct proc *prev; // The previously-running process struct proc *prev; // The previously-running process
uwq* uwq __mpalign__; // Current userspace wq (might be nullptr)
hwid_t hwid __mpalign__; // Local APIC ID, accessed by other CPUs hwid_t hwid __mpalign__; // Local APIC ID, accessed by other CPUs
// Cpu-local storage variables; see below // Cpu-local storage variables; see below
......
...@@ -291,6 +291,9 @@ sched(void) ...@@ -291,6 +291,9 @@ sched(void)
mycpu()->proc = next; mycpu()->proc = next;
mycpu()->prev = prev; mycpu()->prev = prev;
if (mycpu()->uwq != nullptr || next->uwq != nullptr)
mycpu()->uwq = next->uwq;
if (prev->get_state() == ZOMBIE) if (prev->get_state() == ZOMBIE)
mtstop(prev); mtstop(prev);
else else
......
...@@ -31,14 +31,11 @@ uwq_trywork(void) ...@@ -31,14 +31,11 @@ uwq_trywork(void)
continue; continue;
struct cpu *c = &cpus[j]; struct cpu *c = &cpus[j];
// The gc_epoch is for p and uwq // The gc_epoch is for uwq
scoped_gc_epoch xgc(); scoped_gc_epoch xgc();
barrier(); barrier();
struct proc *p = c->proc; uwq* uwq = c->uwq;
if (p == nullptr)
continue;
uwq* uwq = p->uwq;
if (uwq == nullptr) if (uwq == nullptr)
continue; continue;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论