提交 9fee0d5f 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

queue of children

more condition vars queue.h
上级 b025a666
......@@ -5,6 +5,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
void
......@@ -19,7 +20,7 @@ cv_sleep(struct condvar *cv, struct spinlock *lk)
// Must acquire cv_lock to avoid sleep/wakeup race
acquire(&cv->lock);
cprintf("cv_sleep: 0x%x\n", cv);
cprintf("cv_sleep: 0x%x %s\n", cv, cv->lock.name);
release(lk);
......
......@@ -11,6 +11,7 @@
#include "fs.h"
#include "file.h"
#include "mmu.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
......
......@@ -3,6 +3,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "defs.h"
#include "x86.h"
......
#include "types.h"
#include "defs.h"
#include "param.h"
#include "spinlock.h"
#include "condvar.h"
#include "fs.h"
#include "file.h"
#include "spinlock.h"
struct devsw devsw[NDEV];
struct {
......
......@@ -16,6 +16,7 @@ struct inode {
uint inum; // Inode number
int ref; // Reference count
int flags; // I_BUSY, I_VALID
struct condvar cv;
short type; // copy of disk inode
short major;
......
......@@ -17,6 +17,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "buf.h"
#include "fs.h"
......@@ -138,7 +139,11 @@ struct {
void
iinit(void)
{
int i;
initlock(&icache.lock, "icache");
for (i = 0; i < NINODE; i++) {
initlock(&icache.inode[i].cv.lock, "icache");
}
}
static struct inode* iget(uint dev, uint inum);
......@@ -246,7 +251,7 @@ ilock(struct inode *ip)
acquire(&icache.lock);
while(ip->flags & I_BUSY)
sleep(ip, &icache.lock);
cv_sleep(&ip->cv, &icache.lock);
ip->flags |= I_BUSY;
release(&icache.lock);
......@@ -275,7 +280,7 @@ iunlock(struct inode *ip)
acquire(&icache.lock);
ip->flags &= ~I_BUSY;
wakeup(ip);
cv_wakeup(&ip->cv);
release(&icache.lock);
}
......@@ -295,7 +300,7 @@ iput(struct inode *ip)
iupdate(ip);
acquire(&icache.lock);
ip->flags = 0;
wakeup(ip);
cv_wakeup(&ip->cv);
}
ip->ref--;
release(&icache.lock);
......
......@@ -6,6 +6,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
#include "traps.h"
......
......@@ -8,6 +8,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "kalloc.h"
......
......@@ -4,6 +4,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
......
......@@ -10,6 +10,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
struct cpu cpus[NCPU];
......
......@@ -4,6 +4,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "fs.h"
#include "file.h"
......
......@@ -5,6 +5,7 @@
#include "x86.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
struct ptable ptables[NCPU];
......@@ -91,7 +92,7 @@ addrun1(struct runq *rq, struct proc *p)
{
struct proc *q;
cprintf("%d: add to run %d\n", cpu->id, p->pid);
for (q = rq->runq; q != 0; q = q->runq) {
SLIST_FOREACH(q, &rq->runq, run_next) {
if (q == p) {
cprintf("allready on q\n");
p->state = RUNNABLE;
......@@ -99,8 +100,7 @@ addrun1(struct runq *rq, struct proc *p)
}
}
p->state = RUNNABLE; // race?
p->runq = rq->runq;
rq->runq = p;
SLIST_INSERT_HEAD(&rq->runq, p, run_next);
}
void
......@@ -113,23 +113,13 @@ addrun(struct proc *p)
}
static void
delrun1(struct runq *rq, struct proc *proc)
delrun1(struct runq *rq, struct proc *p)
{
struct proc *p = 0;
struct proc *n;
n = rq->runq;
while (n != 0) {
if (n == proc) {
if (p == 0) {
rq->runq = n->runq;
} else {
p->runq = n->runq;
}
n->runq = 0;
struct proc *q, *nq;
SLIST_FOREACH_SAFE(q, &rq->runq, run_next, nq) {
if (q == p) {
SLIST_REMOVE(&rq->runq, q, proc, run_next);
return;
} else {
p = n;
n = n->runq;
}
}
}
......@@ -224,10 +214,12 @@ fork(void)
if(proc->ofile[i])
np->ofile[i] = filedup(proc->ofile[i]);
np->cwd = idup(proc->cwd);
SLIST_INSERT_HEAD(&proc->childq, np, child_next); // XXX lock?
pid = np->pid;
addrun(np);
safestrcpy(np->name, proc->name, sizeof(proc->name));
return pid;
}
......@@ -293,22 +285,21 @@ exit(void)
int
wait(void)
{
struct proc *p;
struct proc *p, *np;
int havekids, pid;
int c;
cprintf("wait %d\n", proc->pid);
for(;;){
// Scan through table looking for zombie children.
havekids = 0;
for (c = 0; c < NCPU; c++) {
acquire(&ptables[c].lock); // XXX Unscalable
for(p = ptables[c].proc; p < &ptables[c].proc[NPROC]; p++){
if(p->parent != proc)
continue;
acquire(&proc->lock);
SLIST_FOREACH_SAFE(p, &proc->childq, child_next, np) {
havekids = 1;
acquire(&p->lock);
if(p->state == ZOMBIE){
// Found one.
pid = p->pid;
SLIST_REMOVE(&proc->childq, p, proc, child_next);
kfree(p->kstack);
p->kstack = 0;
freevm(p->pgdir);
......@@ -317,15 +308,13 @@ wait(void)
p->parent = 0;
p->name[0] = 0;
p->killed = 0;
release(&ptables[c].lock);
release(&p->lock);
release(&proc->lock);
return pid;
}
}
release(&ptables[c].lock);
release(&p->lock);
}
acquire(&proc->lock);
// No point waiting if we don't have any children.
if(!havekids || proc->killed){
release(&proc->lock);
......@@ -350,7 +339,7 @@ steal(void)
if (c == cpunum())
continue;
acquire(&runqs[c].lock);
for(p = runqs[c].runq; p != 0; p = p->runq) {
SLIST_FOREACH(p, &runqs[c].runq, run_next) {
if (p->state == RUNNABLE) {
cprintf("%d: steal %d from %d\n", cpunum(), p->pid, c);
delrun1(&runqs[c], p);
......@@ -386,7 +375,7 @@ scheduler(void)
// Loop over process table looking for process to run.
acquire(&runq->lock);
for(p = runq->runq; p != 0; p = p->runq) {
SLIST_FOREACH(p, &runq->runq, run_next) {
if(p->state != RUNNABLE)
continue;
......@@ -544,7 +533,7 @@ procdump(int c)
cprintf("\n");
}
cprintf("runq: ");
for (q = runqs[c].runq; q != 0; q = q->runq) {
SLIST_FOREACH(q, &runqs[c].runq, run_next) {
if(q->state >= 0 && q->state < NELEM(states) && states[q->state])
state = states[q->state];
else
......
......@@ -46,8 +46,9 @@ struct proc {
struct inode *cwd; // Current directory
char name[16]; // Process name (debugging)
struct spinlock lock;
struct proc *runq;
struct proc *childq;
SLIST_ENTRY(proc) run_next;
SLIST_HEAD(childlist, proc) childq;
SLIST_ENTRY(proc) child_next;
struct condvar cv;
};
......@@ -75,11 +76,10 @@ struct cpu {
struct runq *runq; // The per-core proc table
};
struct runq {
char name[MAXNAME];
struct spinlock lock;
struct proc *runq;
SLIST_HEAD(runlist, proc) runq;
};
struct ptable {
......
......@@ -7,6 +7,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
void
......
......@@ -4,6 +4,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
#include "syscall.h"
......
......@@ -5,6 +5,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "fs.h"
#include "file.h"
......
......@@ -5,6 +5,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
int
......
......@@ -4,6 +4,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
#include "traps.h"
......
......@@ -5,12 +5,13 @@
#include "param.h"
#include "traps.h"
#include "spinlock.h"
#include "fs.h"
#include "file.h"
#include "mmu.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "x86.h"
#include "fs.h"
#include "file.h"
#define COM1 0x3f8
......
......@@ -5,6 +5,7 @@
#include "mmu.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "elf.h"
#include "kalloc.h"
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论