From 3138c2108f2f5bd454a718be4020574f282173e6 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 14 Mar 2003 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2003-03-14 --- ip/iproute.c | 23 ++++++++++++++--------- port/portdat.h | 1 + port/portfns.h | 1 + port/proc.c | 27 ++++++++++++++++++++++----- port/sysproc.c | 3 +-- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index 051c3a3265264b8b21853f2546f9e486a3132524..816e6685f2993fe1be722d94b2e277256bce8b1c 100644 --- a/ip/iproute.c +++ b/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; diff --git a/port/portdat.h b/port/portdat.h index 3d0fba91213d389c54b204e809163fca241c6380..d7da58ccd9b192a3352b6be6982f68208fe6c4c4 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -658,6 +658,7 @@ struct Proc ulong basepri; /* base priority level */ uchar fixedpri; /* priority level deson't change */ int quanta; /* quanta left */ + uchar yield; /* non-zero if the process just did a sleep(0) */ ulong readytime; /* time process came ready */ ulong movetime; /* last time process switched processors */ int preempted; /* true if this process hasn't finished the interrupt diff --git a/port/portfns.h b/port/portfns.h index 1d4cc1ccfe9b2b46aec268ce6520a0191f75917b..431d410ae8c2f09e384322e62e1cb1abd8d05f68 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -366,6 +366,7 @@ void xinit(void); int xmerge(void*, void*); void* xspanalloc(ulong, int, ulong); void xsummary(void); +void yield(void); Segment* data2txt(Segment*); Segment* dupseg(Segment**, int, int); Segment* newseg(int, ulong, ulong); diff --git a/port/proc.c b/port/proc.c index 21bad1a4227e380a173571255bfa3238c9daa4e0..179c57edd81039b1bf4dfb258102e740a481ddbc 100644 --- a/port/proc.c +++ b/port/proc.c @@ -259,6 +259,21 @@ ready(Proc *p) splx(s); } +/* + * yield the processor to any other runnable process + */ +void +yield(void) +{ + if(anyready()){ + up->yield = 1; + sched(); + } +} + +/* + * pick a process to run + */ Proc* runproc(void) { @@ -282,13 +297,15 @@ 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){ + for(tp = rq->head; tp; tp = tp->rnext){ + if(tp->yield){ + tp->yield = 0; + continue; + } if(tp->mp == nil || tp->mp == MACHP(m->machno) || (!tp->wired && i > 0)) goto found; diff --git a/port/sysproc.c b/port/sysproc.c index c23d205790aa7e547b9cd81db81a0b5887efc50c..e0eee34d70e40551ce061c51452f0e9af9a309fe 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -540,8 +540,7 @@ syssleep(ulong *arg) n = arg[0]; if(n <= 0) { - up->priority = 0; - sched(); + yield(); return 0; } if(n < TK2MS(1))