Skip to content

Commit 2ff2eab

Browse files
zoulascbradfitz
authored andcommitted
runtime: fix NetBSD CPU spin in lwp_park when CPU profiling is active
Fixes #22981 Change-Id: I449eb7b5e022401e80a3ab138063e2f4499fbdf8 Reviewed-on: https://go-review.googlesource.com/81855 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9d70b3a commit 2ff2eab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/runtime/os_netbsd.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func semasleep(ns int64) int32 {
122122

123123
// Compute sleep deadline.
124124
var tsp *timespec
125+
var ts timespec
125126
if ns >= 0 {
126-
var ts timespec
127127
var nsec int32
128128
ts.set_sec(timediv(ns, 1000000000, &nsec))
129129
ts.set_nsec(nsec)
@@ -143,6 +143,15 @@ func semasleep(ns int64) int32 {
143143
ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
144144
if ret == _ETIMEDOUT {
145145
return -1
146+
} else if ret == _EINTR && ns >= 0 {
147+
// Avoid sleeping forever if we keep getting
148+
// interrupted (for example by the profiling
149+
// timer). It would be if tsp upon return had the
150+
// remaining time to sleep, but this is good enough.
151+
var nsec int32
152+
ns /= 2
153+
ts.set_sec(timediv(ns, 1000000000, &nsec))
154+
ts.set_nsec(nsec)
146155
}
147156
}
148157
}

0 commit comments

Comments
 (0)