Try using percpu in idle.cc

上级 ddfb7b66
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "sched.hh" #include "sched.hh"
#include "percpu.hh" #include "percpu.hh"
// XXX(sbw) these should be padded out
struct idle : public pad { struct idle : public pad {
struct proc *cur; struct proc *cur;
struct proc *heir; struct proc *heir;
...@@ -18,22 +17,13 @@ struct idle : public pad { ...@@ -18,22 +17,13 @@ struct idle : public pad {
static percpu<idle> idlem; static percpu<idle> idlem;
struct proc * idlep[NCPU] __mpalign__;
struct heir {
struct proc *proc;
__padout__;
} __mpalign__;
struct heir heir[NCPU] __mpalign__;
void idleloop(void); void idleloop(void);
struct proc * struct proc *
idleproc(void) idleproc(void)
{ {
assert(mycpu()->ncli > 0); assert(mycpu()->ncli > 0);
return idlep[mycpu()->id]; return idlem->cur;
} }
void void
...@@ -48,18 +38,16 @@ void ...@@ -48,18 +38,16 @@ void
idlebequeath(void) idlebequeath(void)
{ {
// Only the current idle thread may call this function // Only the current idle thread may call this function
struct heir *h;
assert(mycpu()->ncli > 0); assert(mycpu()->ncli > 0);
assert(myproc() == idlep[mycpu()->id]); assert(myproc() == idlem->cur);
h = &heir[mycpu()->id]; assert(idlem->heir != nullptr);
assert(h->proc != nullptr);
idlep[mycpu()->id] = h->proc; idlem->cur = idlem->heir;
acquire(&h->proc->lock); acquire(&idlem->heir->lock);
h->proc->set_state(RUNNABLE); idlem->heir->set_state(RUNNABLE);
release(&h->proc->lock); release(&idlem->heir->lock);
} }
...@@ -68,7 +56,7 @@ idleheir(void *x) ...@@ -68,7 +56,7 @@ idleheir(void *x)
{ {
post_swtch(); post_swtch();
heir[mycpu()->id].proc = nullptr; idlem->heir = nullptr;
idleloop(); idleloop();
} }
...@@ -91,10 +79,6 @@ finishzombies(void) ...@@ -91,10 +79,6 @@ finishzombies(void)
void void
idleloop(void) idleloop(void)
{ {
struct heir *h;
h = &heir[mycpu()->id];
// Test the work queue // Test the work queue
//extern void testwq(void); //extern void testwq(void);
//testwq(); //testwq();
...@@ -120,7 +104,7 @@ idleloop(void) ...@@ -120,7 +104,7 @@ idleloop(void)
assert(mycpu()->ncli == 0); assert(mycpu()->ncli == 0);
// If we don't have an heir, try to allocate one // If we don't have an heir, try to allocate one
if (h->proc == nullptr) { if (idlem->heir == nullptr) {
struct proc *p; struct proc *p;
p = allocproc(); p = allocproc();
if (p == nullptr) if (p == nullptr)
...@@ -130,12 +114,12 @@ idleloop(void) ...@@ -130,12 +114,12 @@ idleloop(void)
p->cpu_pin = 1; p->cpu_pin = 1;
p->context->rip = (u64)idleheir; p->context->rip = (u64)idleheir;
p->cwd = nullptr; p->cwd = nullptr;
h->proc = p; idlem->heir = p;
} }
worked = wq_trywork(); worked = wq_trywork();
// If we are no longer the idle thread, exit // If we are no longer the idle thread, exit
if (worked && idlep[mycpu()->id] != myproc()) if (worked && idlem->cur != myproc())
exit(); exit();
} while(worked); } while(worked);
sti(); sti();
...@@ -157,5 +141,5 @@ initidle(void) ...@@ -157,5 +141,5 @@ initidle(void)
mycpu()->proc = p; mycpu()->proc = p;
myproc()->cpuid = cpunum(); myproc()->cpuid = cpunum();
myproc()->cpu_pin = 1; myproc()->cpu_pin = 1;
idlep[cpunum()] = p; idlem->cur = p;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论