M carrera/dat.h => carrera/dat.h +4 -1
@@ 12,6 12,7 @@ typedef struct Notsave Notsave;
typedef struct PMMU PMMU;
typedef struct Softtlb Softtlb;
typedef struct Ureg Ureg;
+typedef struct Proc Proc;
/*
* parameters for sysproc.c
@@ 26,7 27,9 @@ struct Lock
ulong key; /* semaphore (non-zero = locked) */
ulong sr;
ulong pc;
- ulong pid;
+ Proc *p;
+ ushort pri;
+ ushort isilock;
};
struct Label
M ip/ip.c => ip/ip.c +1 -1
@@ 182,11 182,11 @@ ipoput(Fs *f, Block *bp, int gating, int ttl)
eh->ttl = ttl;
}
+ rlock(ifc);
if(waserror()){
runlock(ifc);
nexterror();
}
- rlock(ifc);
if(ifc->m == nil)
goto raise;
M ip/udp.c => ip/udp.c +1 -1
@@ 327,7 327,7 @@ udpiput(Proto *udp, uchar *ia, Block *bp)
if(ipforme(f, laddr) == Runi)
v6tov4(bp->rp+IPv4addrlen, laddr);
else
- memmove(bp->rp+IPv4addrlen, ia, IPv4addrlen);
+ v6tov4(bp->rp+IPv4addrlen, ia);
hnputs(bp->rp + 2*IPv4addrlen, rport);
hnputs(bp->rp + 2*IPv4addrlen + 2, lport);
break;
M pc/dat.h => pc/dat.h +4 -1
@@ 15,6 15,7 @@ typedef struct Page Page;
typedef struct PMMU PMMU;
typedef struct Segdesc Segdesc;
typedef struct Ureg Ureg;
+typedef struct Proc Proc;
/*
* parameters for sysproc.c
@@ 26,7 27,9 @@ struct Lock
ulong key;
ulong sr;
ulong pc;
- ulong pid;
+ Proc *p;
+ ushort pri;
+ ushort isilock;
};
struct Label
M port/portdat.h => port/portdat.h +0 -1
@@ 610,7 610,6 @@ struct Proc
ulong art; /* avg # ticks used since last blocked */
ulong movetime; /* last time process switched processors */
ulong readytime; /* time process went ready */
- ulong lockpri; /* priority of process holding lock we're trying for */
int preempted; /* true if this process hasn't finished the interrupt
* that last preempted it
*/
M port/proc.c => port/proc.c +0 -5
@@ 157,10 157,6 @@ ready(Proc *p)
if(pri < PriNormal && p->basepri > PriNormal)
pri = PriNormal;
- /* hack for livelocks due to priority */
- if(p->lockpri)
- pri = 0;
-
p->priority = pri;
rq = &runq[p->priority];
@@ 327,7 323,6 @@ newproc(void)
p->wired = 0;
p->ureg = 0;
p->error[0] = '\0';
- p->lockpri = 0;
memset(p->seg, 0, sizeof p->seg);
p->pid = incref(&pidalloc);
p->noteid = incref(¬eidalloc);
M port/taslock.c => port/taslock.c +48 -20
@@ 9,43 9,56 @@ void
lockloop(Lock *l, ulong pc)
{
print("lock loop key 0x%lux pc 0x%lux held by pc 0x%lux proc %d\n",
- l->key, pc, l->pc, l->pid);
+ l->key, pc, l->pc, l->p ? l->p->pid : 0);
dumpaproc(up);
- /* lower priority till we get the lock */
- if(up && up->state == Running && islo()){
- up->lockpri = 1;
+ if(up && up->state == Running && islo())
sched();
- }
}
void
lock(Lock *l)
{
int i;
- ulong pc, pid;
+ ulong pc;
pc = getcallerpc(l);
- pid = up ? up->pid : 0;
if(tas(&l->key) == 0){
l->pc = pc;
- l->pid = pid;
+ l->p = up;
+ l->isilock = 0;
+ if(up){
+ l->pri = up->priority;
+ up->priority = PriLock;
+ }
return;
}
for(;;){
i = 0;
- while(l->key)
- if(i++ > 100000000){
- i = 0;
- lockloop(l, pc);
+ while(l->key){
+ if(conf.nmach < 2){
+ if(i++ > 1000){
+ i = 0;
+ lockloop(l, pc);
+ }
+ sched();
+ } else {
+ if(i++ > 100000000){
+ i = 0;
+ lockloop(l, pc);
+ }
}
+ }
if(tas(&l->key) == 0){
l->pc = pc;
- l->pid = pid;
- if(up)
- up->lockpri = 0;
+ l->p = up;
+ l->isilock = 0;
+ if(up){
+ l->pri = up->priority;
+ up->priority = PriLock;
+ }
return;
}
}
@@ 55,16 68,16 @@ void
ilock(Lock *l)
{
ulong x;
- ulong pc, pid;
+ ulong pc;
pc = getcallerpc(l);
- pid = up ? up->pid : 0;
x = splhi();
if(tas(&l->key) == 0){
l->sr = x;
l->pc = pc;
- l->pid = pid;
+ l->p = up;
+ l->isilock = 1;
return;
}
@@ 79,7 92,8 @@ ilock(Lock *l)
if(tas(&l->key) == 0){
l->sr = x;
l->pc = pc;
- l->pid = pid;
+ l->p = up;
+ l->isilock = 1;
return;
}
}
@@ 92,17 106,29 @@ canlock(Lock *l)
return 0;
l->pc = getcallerpc(l);
- l->pid = up ? up->pid : 0;
+ l->p = up;
+ l->isilock = 0;
+ if(up){
+ l->pri = up->priority;
+ up->priority = PriLock;
+ }
return 1;
}
void
unlock(Lock *l)
{
+ int p;
+
+ p = l->pri;
if(l->key == 0)
print("unlock: not locked: pc %uX\n", getcallerpc(l));
+ if(l->isilock)
+ print("iunlock of lock: pc %lux, held by %lux\n", getcallerpc(l), l->pc);
l->pc = 0;
l->key = 0;
+ if(up && p < up->priority)
+ up->priority = p;
coherence();
}
@@ 113,6 139,8 @@ iunlock(Lock *l)
if(l->key == 0)
print("iunlock: not locked: pc %uX\n", getcallerpc(l));
+ if(!l->isilock)
+ print("unlock of ilock: pc %lux, held by %lux\n", getcallerpc(l), l->pc);
sr = l->sr;
l->pc = 0;