From 1848f4e946c6a5d625c23f9c6a3ad7480816585a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 7 Sep 2016 23:36:04 +0200 Subject: 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. --- sys/src/9/port/sysproc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c index 6cc23c265..46f8f536f 100644 --- a/sys/src/9/port/sysproc.c +++ b/sys/src/9/port/sysproc.c @@ -1126,7 +1126,7 @@ static int tsemacquire(Segment *s, long *addr, ulong ms) { int acquired, timedout; - ulong t, elms; + ulong t; Sema phore; if(canacquire(addr)) @@ -1144,15 +1144,15 @@ tsemacquire(Segment *s, long *addr, ulong ms) } 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 */ -- cgit v1.2.3