ref: 1848f4e946c6a5d625c23f9c6a3ad7480816585a
parent: bfd8098b8de4c9dfbd5def087b92b09dfc97b41c
author: cinap_lenrek <[email protected]>
date: Wed Sep 7 19:36:04 EDT 2016
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.
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -1126,7 +1126,7 @@
tsemacquire(Segment *s, long *addr, ulong ms)
{
int acquired, timedout;
- ulong t, elms;
+ ulong t;
Sema phore;
if(canacquire(addr))
@@ -1144,15 +1144,15 @@
}
if(waserror())
break;
- t = m->ticks;
+ t = MACHP(0)->ticks;
tsleep(&phore, semawoke, &phore, ms);
- elms = TK2MS(m->ticks - t);
+ t = TK2MS(MACHP(0)->ticks - t);
poperror();
- if(elms >= ms){
+ if(t >= ms){
timedout = 1;
break;
}
- ms -= elms;
+ ms -= t;
}
semdequeue(s, &phore);
coherence(); /* not strictly necessary due to lock in semdequeue */