from cinap theres a bug in devproc again. the fd is not bounds checked for the "close fd" procctl command and the "closefiles" command misses the last fd as it iterates from: fd=0 to maxfd-1 and not to maxfd in procctlclosefiles() Reference: /n/atom/patch/applied/procfdclose Date: Mon May 26 22:24:55 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/port/proc.c Mon May 26 22:24:36 2014 +++ /sys/src/nix/port/proc.c Mon May 26 22:24:39 2014 @@ -71,7 +71,7 @@ color = machcolor(mp); if(color < 0){ - iprint("cpu%d: unknown color\n", mp->machno); + iprint("mach%d: unknown color\n", mp->machno); color = 0; } mp->sch = &run[color%Nsched]; @@ -156,7 +156,7 @@ p = &dummy; if(p < up->kstack + 4*KiB || p > up->kstack + KSTACK) - panic("cpu%d: up->stack bounds %s:%s %#p %#p", + panic("mach%d: up->stack bounds %s:%s %#p %#p", m->machno, up->text, statename[up->state], p, up->kstack); } @@ -172,7 +172,7 @@ sch = m->sch; if(m->ilockdepth) - panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p", + panic("mach%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p", m->machno, m->ilockdepth, up? up->lastilock: nil, @@ -256,7 +256,7 @@ /* unless preempted, get to run for at least 100ms */ if(anyhigher() - || (!m->proc->fixedpri && tickscmp(m->ticks, m->schedticks) > 0 && anyready())){ + || (!m->proc->fixedpri && tickscmp(m->ticks, m->schedticks) >= 0 && anyready())){ m->readied = nil; /* avoid cooperative scheduling */ m->proc->delaysched++; } @@ -475,7 +475,8 @@ * BUG: if schedready is called to rebalance the scheduler, * for another core, then this is wrong. */ - if(up != p && (p->wired == nil || p->wired->machno == m->machno)) +// if(up != p && (p->wired == nil || p->wired->machno == m->machno)) + if(m->proc != p && (p->wired == nil || p->wired->machno == m->machno)) m->readied = p; /* group scheduling */ updatecpu(p); @@ -604,7 +605,7 @@ continue; for(rq = &sch->runq[Nrq-1]; rq >= sch->runq; rq--){ for(p = rq->head; p != nil; p = p->rnext) - if(!p->wired && p->priority < PriKproc) + if(p->wired == nil && p->priority < PriKproc) break; if(p != nil && dequeueproc(sch, rq, p) != nil) return p; @@ -620,7 +621,7 @@ * avoid serious unfairness. this is architecture sensitive. */ // Migratedelay = 250*1000, /* 250 µs */ - Migratedelay = 10*1000*1000, /* 10 ms */ + Migratedelay = 50*1000*1000, /* 50 ms */ }; /* @@ -632,13 +633,13 @@ Schedq *rq; Sched *sch; Proc *p; - uvlong start, now; + uvlong start, now, delay; int i; start = perfticks(); sch = m->sch; /* cooperative scheduling until the clock ticks */ - if((p=m->readied) != nil && procsaved(p) && p->state==Ready + if((p=m->readied) != nil && procsaved(p) && p->state == Ready && sch->runq[Nrq-1].head == nil && sch->runq[Nrq-2].head == nil && (p->wired == nil || p->wired->machno == m->machno)){ sch->skipscheds++; @@ -655,6 +656,7 @@ * time around the loop affinity goes down. */ spllo(); + delay = ns2fastticks(Migratedelay); for(i = 0;; i++){ /* * find the highest priority target process that this @@ -663,7 +665,7 @@ for(rq = &sch->runq[Nrq-1]; rq >= sch->runq; rq--){ for(p = rq->head; p != nil; p = p->rnext){ if(p->mp == nil || p->mp == m - || p->wired == nil && (i>0 || fastticks2ns(fastticks(nil) - p->readytime) >= Migratedelay)) + || (p->wired == nil || p->wired->machno == m->machno) && (i>0 || fastticks(nil) - p->readytime >= delay)) goto found; } } @@ -674,8 +676,10 @@ goto stolen; spllo(); - while(sch->runvec == 0) - monmwait((int*)&sch->runvec, 0); + /* highly contended; delays in the µs */ +// high power, high performance, low latency if(m->machno>0) + while(monmwait((int*)&sch->runvec, 0) == 0) + ; /* remember how much time we're here */ now = perfticks(); @@ -1178,8 +1182,9 @@ iprint(" %s=%d", up->text, up->nfullq); free(up->syscalltrace); up->syscalltrace = nil; - up->alarm = 0; + if(up->alarm != 0) + procalarm(0); if(up->tt) timerdel(up); if(up->trace) @@ -1373,8 +1378,8 @@ s = p->psstate; if(s == nil) s = statename[p->state]; - print("%3d:%10s pc %#p dbgpc %#p %8s (%s) ut %ld st %ld bss %#p qpc %#p nl %d nd %ud lpc %#p pri %ud\n", - p->pid, p->text, p->pc, dbgpc(p), s, statename[p->state], + print("%3d:%10s m %d pc %#p dbgpc %#p %8s (%s) ut %ld st %ld bss %#p qpc %#p nl %d nd %ud lpc %#p pri %ud\n", + p->pid, p->text, p->mach? p->mach->machno: -1, p->pc, dbgpc(p), s, statename[p->state], p->time[0], p->time[1], bss, p->qpc, p->nlocks, p->delaysched, lockgetpc(p->lastlock), p->priority); } @@ -1385,7 +1390,7 @@ int i; Proc *p; - if(up) + if(up != nil) print("up %d\n", up->pid); else print("no current process\n"); @@ -1495,7 +1500,7 @@ p->notified = 0; p->lastnote = up->lastnote; p->notify = up->notify; - p->ureg = 0; + p->ureg = nil; p->dbgreg = 0; procpriority(p, PriKproc, 0); --- /sys/src/9/port/proc.c Mon May 26 22:24:43 2014 +++ /sys/src/9/port/proc.c Mon May 26 22:24:45 2014 @@ -5,6 +5,7 @@ #include "fns.h" #include "../port/error.h" #include "../port/edf.h" +#include "errstr.h" #include int schedgain = 30; /* units in seconds */ @@ -265,8 +266,7 @@ void updatecpu(Proc *p) { - int n, t, ocpu; - int D = schedgain*HZ*Scaling; + int D, n, t, ocpu; if(p->edf) return; @@ -277,6 +277,7 @@ if(n == 0) return; + D = schedgain*HZ*Scaling; if(n > D) n = D; @@ -619,7 +620,7 @@ p->procctl = Proc_tracesyscall; else p->procctl = 0; - p->syscalltrace = 0; + p->syscalltrace = nil; p->notepending = 0; p->nnote = 0; p->ureg = 0; @@ -647,8 +648,8 @@ p->kstack = smalloc(KSTACK); /* sched params */ - p->mp = 0; - p->wired = 0; + p->mp = nil; + p->wired = nil; procpriority(p, PriNormal, 0); p->cpu = 0; p->lastupdate = MACHP(0)->ticks*Scaling; @@ -1242,7 +1243,7 @@ void dumpaproc(Proc *p) { - ulong bss; + uintptr bss; char *s; if(p == 0) @@ -1437,8 +1438,6 @@ } } -#include "errstr.h" - void error(char *err) { @@ -1471,7 +1470,7 @@ { int i; Segment *s; - ulong l, max; + uintptr l, max; Proc *p, *ep, *kp; max = 0;