Browse Source

Plan 9 from Bell Labs 2003-03-18

David du Colombier 18 years ago
parent
commit
41bbf710d3

+ 7 - 7
dist/replica/plan9.db

@@ -5027,7 +5027,7 @@ sys/src/9/boot/sac.c - 664 sys sys 1015012530 802
 sys/src/9/boot/settime.c - 664 sys sys 1036813626 2473
 sys/src/9/boot/testboot.c - 664 sys sys 1039763734 496
 sys/src/9/ip - 20000000775 sys sys 1015278450 0
-sys/src/9/ip/arp.c - 664 sys sys 1047260560 10677
+sys/src/9/ip/arp.c - 664 sys sys 1047951324 10671
 sys/src/9/ip/chandial.c - 664 sys sys 1022588098 2276
 sys/src/9/ip/devip.c - 664 sys sys 1047260561 24089
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
@@ -5039,13 +5039,13 @@ sys/src/9/ip/icmp6.c - 664 sys sys 1047260563 18098
 sys/src/9/ip/igmp.c - 664 sys sys 1047260564 5190
 sys/src/9/ip/il.c - 664 sys sys 1047260564 26943
 sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
-sys/src/9/ip/ip.c - 664 sys sys 1047260565 15243
+sys/src/9/ip/ip.c - 664 sys sys 1047951326 15285
 sys/src/9/ip/ip.h - 664 sys sys 1047260722 16078
 sys/src/9/ip/ipaux.c - 664 sys sys 1022588098 12656
-sys/src/9/ip/ipifc.c - 664 sys sys 1047260565 37717
+sys/src/9/ip/ipifc.c - 664 sys sys 1047951327 37830
 sys/src/9/ip/ipmux.c - 664 sys sys 1047260566 15362
-sys/src/9/ip/iproute.c - 664 sys sys 1047260566 14689
-sys/src/9/ip/ipv6.c - 664 sys sys 1047260567 14431
+sys/src/9/ip/iproute.c - 664 sys sys 1047951327 14767
+sys/src/9/ip/ipv6.c - 664 sys sys 1047951328 14433
 sys/src/9/ip/ipv6.h - 664 sys sys 1022588099 4304
 sys/src/9/ip/loopbackmedium.c - 664 sys sys 1045063513 1651
 sys/src/9/ip/netdevmedium.c - 664 sys sys 1045063517 2675
@@ -5232,7 +5232,7 @@ sys/src/9/port/devmouse.c - 664 sys sys 1036827459 11420
 sys/src/9/port/devnmouse.c - 664 sys sys 1036812999 3738
 sys/src/9/port/devpipe.c - 664 sys sys 1032640439 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1019864265 13027
-sys/src/9/port/devproc.c - 664 sys sys 1047260622 23418
+sys/src/9/port/devproc.c - 664 sys sys 1047952847 23450
 sys/src/9/port/devrealtime.c - 664 sys sys 1044630510 15975
 sys/src/9/port/devroot.c - 664 sys sys 1042304978 3593
 sys/src/9/port/devsd.c - 664 sys sys 1026847547 28679
@@ -5272,7 +5272,7 @@ sys/src/9/port/portdat.h - 664 sys sys 1047260623 21132
 sys/src/9/port/portfns.h - 664 sys sys 1047260622 10601
 sys/src/9/port/portmkfile - 664 sys sys 1039753335 2372
 sys/src/9/port/print.c - 664 sys sys 1014931178 227
-sys/src/9/port/proc.c - 664 sys sys 1047260621 23241
+sys/src/9/port/proc.c - 664 sys sys 1047952847 24170
 sys/src/9/port/qio.c - 664 sys sys 1047260594 23281
 sys/src/9/port/qlock.c - 664 sys sys 1026847551 3246
 sys/src/9/port/rdb.c - 664 sys sys 1018721202 1698

+ 7 - 0
dist/replica/plan9.log

@@ -18608,3 +18608,10 @@
 1047763909 13 c 386/bin/upas/smtpd - 775 sys sys 1047763612 310609
 1047763909 14 c 386/lib/libsec.a - 664 sys sys 1047763618 642760
 1047848578 0 c 386/bin/aux/timesync - 775 sys sys 1047847239 127070
+1047952838 0 c sys/src/9/ip/arp.c - 664 sys sys 1047951324 10671
+1047952838 1 c sys/src/9/ip/ip.c - 664 sys sys 1047951326 15285
+1047952838 2 c sys/src/9/ip/ipifc.c - 664 sys sys 1047951327 37830
+1047952838 3 c sys/src/9/ip/iproute.c - 664 sys sys 1047951327 14767
+1047952838 4 c sys/src/9/ip/ipv6.c - 664 sys sys 1047951328 14433
+1047952838 5 c sys/src/9/port/devproc.c - 664 sys sys 1047952847 23450
+1047952838 6 c sys/src/9/port/proc.c - 664 sys sys 1047952847 24170

+ 5 - 4
sys/src/9/ip/arp.c

@@ -125,7 +125,7 @@ newarp6(Arp *arp, uchar *ip, Ipifc *ifc, int addrxt)
 
 	memmove(a->ip, ip, sizeof(a->ip));
 	a->utime = NOW;
-	a->ctime = a->utime;
+	a->ctime = 0;
 	a->type = m;
 
 	a->rtime = NOW + ReTransTimer;
@@ -354,14 +354,16 @@ arpenter(Fs *fs, int version, uchar *ip, uchar *mac, int n, int refresh)
 				}
 			}
 
-			a->hold = nil;
 			a->ifc = ifc;
 			a->ifcid = ifc->ifcid;
 			bp = a->hold;
 			a->hold = nil;
 			if(version == V4)
 				ip += IPv4off;
+			a->utime = NOW;
+			a->ctime = a->utime;
 			qunlock(arp);
+
 			while(bp){
 				next = bp->list;
 				if(ifc != nil){
@@ -380,8 +382,6 @@ arpenter(Fs *fs, int version, uchar *ip, uchar *mac, int n, int refresh)
 					freeb(bp);
 				bp = next;
 			}
-			a->utime = NOW;
-			a->ctime = a->utime;
 			return;
 		}
 	}
@@ -390,6 +390,7 @@ arpenter(Fs *fs, int version, uchar *ip, uchar *mac, int n, int refresh)
 		a = newarp6(arp, ip, ifc, 0);
 		a->state = AOK;
 		a->type = type;
+		a->ctime = NOW;
 		memmove(a->mac, mac, type->maclen);
 	}
 

+ 2 - 1
sys/src/9/ip/ip.c

@@ -486,7 +486,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp)
 		/* don't forward to source's network */
 		conv.r = nil;
 		r = v4lookup(f, h->dst, &conv);
-		if(r != nil && r->ifc == ifc){
+		if(r == nil || r->ifc == ifc){
 			ip->stats[OutDiscards]++;
 			freeblist(bp);
 			return;
@@ -502,6 +502,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp)
 		}
 
 		/* reassemble if the interface expects it */
+if(r->ifc == nil) panic("nil route rfc");
 		if(r->ifc->reassemble){
 			frag = nhgets(h->frag);
 			if(frag) {

+ 9 - 0
sys/src/9/ip/ipifc.c

@@ -305,10 +305,19 @@ ipifckick(void *x)
 		return;
 
 	ifc = (Ipifc*)c->ptcl;
+	if(!canrlock(ifc)){
+		freeb(bp);
+		return;
+	}
+	if(waserror()){
+		runlock(ifc);
+		nexterror();
+	}
 	if(ifc->m == nil || ifc->m->pktin == nil)
 		freeb(bp);
 	else
 		(*ifc->m->pktin)(c->p->f, ifc, bp);
+	runlock(ifc);
 }
 
 /*

+ 14 - 9
sys/src/9/ip/iproute.c

@@ -487,8 +487,9 @@ v4lookup(Fs *f, uchar *a, Conv *c)
 	Route *p, *q;
 	ulong la;
 	uchar gate[IPaddrlen];
+	Ipifc *ifc;
 
-	if(c != nil && c->r != nil && c->rgen == v4routegeneration)
+	if(c != nil && c->r != nil && c->r->ifc != nil && c->rgen == v4routegeneration)
 		return c->r;
 
 	la = nhgetl(a);
@@ -509,11 +510,13 @@ v4lookup(Fs *f, uchar *a, Conv *c)
 			memmove(gate, v4prefix, IPv4off);
 		} else
 			v4tov6(gate, q->v4.gate);
-		q->ifc = findipifc(f, gate, q->type);
-		if(q->ifc == nil)
+		ifc = findipifc(f, gate, q->type);
+		if(ifc == nil)
 			return nil;
-		q->ifcid = q->ifc->ifcid;
+		q->ifc = ifc;
+		q->ifcid = ifc->ifcid;
 	}
+
 	if(c != nil){
 		c->r = q;
 		c->rgen = v4routegeneration;
@@ -530,6 +533,7 @@ v6lookup(Fs *f, uchar *a, Conv *c)
 	int h;
 	ulong x, y;
 	uchar gate[IPaddrlen];
+	Ipifc *ifc;
 
 	if(memcmp(a, v4prefix, IPv4off) == 0){
 		q = v4lookup(f, a+IPv4off, c);
@@ -537,7 +541,7 @@ v6lookup(Fs *f, uchar *a, Conv *c)
 			return q;
 	}
 
-	if(c != nil && c->r != nil && c->rgen == v6routegeneration)
+	if(c != nil && c->r != nil && c->r->ifc != nil && c->rgen == v6routegeneration)
 		return c->r;
 
 	for(h = 0; h < IPllen; h++)
@@ -576,12 +580,13 @@ next:		;
 		if(q->type & Rifc) {
 			for(h = 0; h < IPllen; h++)
 				hnputl(gate+4*h, q->v6.address[h]);
-			q->ifc = findipifc(f, gate, q->type);
+			ifc = findipifc(f, gate, q->type);
 		} else
-			q->ifc = findipifc(f, q->v6.gate, q->type);
-		if(q->ifc == nil)
+			ifc = findipifc(f, q->v6.gate, q->type);
+		if(ifc == nil)
 			return nil;
-		q->ifcid = q->ifc->ifcid;
+		q->ifc = ifc;
+		q->ifcid = ifc->ifcid;
 	}
 	if(c != nil){
 		c->r = q;

+ 1 - 1
sys/src/9/ip/ipv6.c

@@ -173,7 +173,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Conv *c)
 	}
 
 	if(len >= IP_MAX){
-		print("len > IP_MAX, free\n");
+//		print("len > IP_MAX, free\n");
 		ip->stats[OutDiscards]++;
 		netlog(f, Logip, "exceeded ip max size %I\n", eh->dst);
 		goto free;

+ 3 - 2
sys/src/9/port/devproc.c

@@ -1147,9 +1147,10 @@ procctlreq(Proc *p, char *va, int n)
 		procpriority(p, pri, 0);
 		break;
 	case CMfixedpri:
-		if(!iseve())
+		pri = atoi(cb->f[1]);
+		if(pri > PriNormal && !iseve())
 			error(Eperm);
-		procpriority(p, atoi(cb->f[1]), 1);
+		procpriority(p, pri, 1);
 		break;
 	case CMprivate:
 		p->privatemem = 1;

+ 103 - 41
sys/src/9/port/proc.c

@@ -259,11 +259,101 @@ ready(Proc *p)
 	splx(s);
 }
 
+/*
+ *  remove a process from a scheduling queue (called splhi)
+ */
+static Proc*
+dequeueproc(Schedq *rq, Proc *tp)
+{
+	Proc *l, *p;
+
+	if(!canlock(runq))
+		return nil;
+
+	/*
+	 *  the queue may have changed before we locked runq,
+	 *  refind the target process.
+	 */
+	l = 0;
+	for(p = rq->head; p; p = p->rnext){
+		if(p == tp)
+			break;
+		l = p;
+	}
+
+	/*
+	 *  p->mach==0 only when process state is saved
+	 */
+	if(p == 0 || p->mach){
+		unlock(runq);
+		return nil;
+	}
+	if(p->rnext == 0)
+		rq->tail = l;
+	if(l)
+		l->rnext = p->rnext;
+	else
+		rq->head = p->rnext;
+	if(rq->head == nil)
+		runvec &= ~(1<<(rq-runq));
+	rq->n--;
+	nrdy--;
+	if(p->state != Ready)
+		print("dequeueproc %s %lud %s\n", p->text, p->pid, statename[p->state]);
+
+	unlock(runq);
+	return p;
+}
+
+/*
+ *  yield the processor and drop our priority
+ */
+void
+yield(void)
+{
+	if(anyready()){
+		up->quanta = 0;	/* act like you used them all up */
+		sched();
+	}
+}
+
+/*
+ *  move up any process waiting more than its quanta
+ */
+static void
+rebalance(void)
+{
+	Schedq *rq;
+	Proc *p;
+
+	for(rq = runq; rq < &runq[Nrq]; rq++){
+		p = rq->head;
+		if(p == nil)
+			continue;
+		if(p->mp != MACHP(m->machno))
+			continue;
+		if(p->priority == p->basepri)
+			continue;
+		if(m->ticks - p->readytime < quanta[p->priority]/4)
+			continue;
+		splhi();
+		p = dequeueproc(rq, p);
+		spllo();
+		if(p == nil)
+			continue;
+		p->quanta = quanta[p->priority];	/* act like we used none */
+		ready(p);
+	}
+}
+
+/*
+ *  pick a process to run
+ */
 Proc*
 runproc(void)
 {
 	Schedq *rq;
-	Proc *p, *l, *tp;
+	Proc *p;
 	ulong start, now;
 	int i;
 
@@ -272,6 +362,11 @@ runproc(void)
 	if ((p = edf->edfrunproc()) != nil)
 		return p;
 
+	if(m->fairness++ == 10){
+		m->fairness = 0;
+		rebalance();
+	}
+
 loop:
 	/*
 	 *  find a process that last ran on this processor (affinity),
@@ -282,15 +377,13 @@ loop:
 	for(i = 0;; i++){
 		/*
 		 *  find the highest priority target process that this
-		 *  processor can run given affinity constraints
+		 *  processor can run given affinity constraints.
+		 *
 		 */
 		for(rq = &runq[Nrq-1]; rq >= runq; rq--){
-			tp = rq->head;
-			if(tp == 0)
-				continue;
-			for(; tp; tp = tp->rnext){
-				if(tp->mp == nil || tp->mp == MACHP(m->machno)
-				|| (!tp->wired && i > 0))
+			for(p = rq->head; p; p = p->rnext){
+				if(p->mp == nil || p->mp == MACHP(m->machno)
+				|| (!p->wired && i > 0))
 					goto found;
 			}
 		}
@@ -306,41 +399,10 @@ loop:
 
 found:
 	splhi();
-	if(!canlock(runq))
+	p = dequeueproc(rq, p);
+	if(p == nil)
 		goto loop;
 
-	/*
-	 *  the queue may have changed before we locked runq,
-	 *  refind the target process.
-	 */
-	l = 0;
-	for(p = rq->head; p; p = p->rnext){
-		if(p == tp)
-			break;
-		l = p;
-	}
-
-	/*
-	 *  p->mach==0 only when process state is saved
-	 */
-	if(p == 0 || p->mach){
-		unlock(runq);
-		goto loop;
-	}
-	if(p->rnext == 0)
-		rq->tail = l;
-	if(l)
-		l->rnext = p->rnext;
-	else
-		rq->head = p->rnext;
-	if(rq->head == nil)
-		runvec &= ~(1<<(rq-runq));
-	rq->n--;
-	nrdy--;
-	if(p->state != Ready)
-		print("runproc %s %lud %s\n", p->text, p->pid, statename[p->state]);
-	unlock(runq);
-
 	p->state = Scheding;
 	p->mp = MACHP(m->machno);