diff options
author | Christos Zoulas <christos@zoulas.com> | 2017-12-04 23:50:19 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-12-05 00:08:51 +0000 |
commit | 2ff2eab0d240ec4ccfbc05f17afa8d99c6fbed61 (patch) | |
tree | 335ba081b54a8cdbd445e7ccc9d9fbd96c287cf8 /src/runtime/os_netbsd.go | |
parent | 9d70b3ae04316c5753435dddee54fe7373502e09 (diff) | |
download | go-2ff2eab0d240ec4ccfbc05f17afa8d99c6fbed61.tar.gz go-2ff2eab0d240ec4ccfbc05f17afa8d99c6fbed61.zip |
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/os_netbsd.go')
-rw-r--r-- | src/runtime/os_netbsd.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go index b75ec7908b..3778969318 100644 --- a/src/runtime/os_netbsd.go +++ b/src/runtime/os_netbsd.go @@ -122,8 +122,8 @@ func semasleep(ns int64) int32 { // Compute sleep deadline. var tsp *timespec + var ts timespec if ns >= 0 { - var ts timespec var nsec int32 ts.set_sec(timediv(ns, 1000000000, &nsec)) ts.set_nsec(nsec) @@ -143,6 +143,15 @@ func semasleep(ns int64) int32 { ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil) if ret == _ETIMEDOUT { return -1 + } else if ret == _EINTR && ns >= 0 { + // Avoid sleeping forever if we keep getting + // interrupted (for example by the profiling + // timer). It would be if tsp upon return had the + // remaining time to sleep, but this is good enough. + var nsec int32 + ns /= 2 + ts.set_sec(timediv(ns, 1000000000, &nsec)) + ts.set_nsec(nsec) } } } |