kernel: tsemacquire() use MACHP(0)->ticks for time delta

we might wake up on a different cpu after the sleep so
delta from machX->ticks - machY->ticks can become negative
giving spurious timeouts. to avoid this always use the
same mach 0 tick counter for the delta.
This commit is contained in:
cinap_lenrek 2016-09-07 23:36:04 +02:00
parent bfd8098b8d
commit 1848f4e946

View file

@ -1126,7 +1126,7 @@ static int
tsemacquire(Segment *s, long *addr, ulong ms) tsemacquire(Segment *s, long *addr, ulong ms)
{ {
int acquired, timedout; int acquired, timedout;
ulong t, elms; ulong t;
Sema phore; Sema phore;
if(canacquire(addr)) if(canacquire(addr))
@ -1144,15 +1144,15 @@ tsemacquire(Segment *s, long *addr, ulong ms)
} }
if(waserror()) if(waserror())
break; break;
t = m->ticks; t = MACHP(0)->ticks;
tsleep(&phore, semawoke, &phore, ms); tsleep(&phore, semawoke, &phore, ms);
elms = TK2MS(m->ticks - t); t = TK2MS(MACHP(0)->ticks - t);
poperror(); poperror();
if(elms >= ms){ if(t >= ms){
timedout = 1; timedout = 1;
break; break;
} }
ms -= elms; ms -= t;
} }
semdequeue(s, &phore); semdequeue(s, &phore);
coherence(); /* not strictly necessary due to lock in semdequeue */ coherence(); /* not strictly necessary due to lock in semdequeue */