aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <zoulasc@gmail.com>2017-12-04 01:48:45 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2017-12-04 03:29:56 +0000
commit66fcf45477b5f2ee4c39214911f417480cc55f5f (patch)
tree76d32815b20c4e84b49380cbf42f71eee886a49b
parent871b79316ad7f2b10f1347f8d9077713afaff451 (diff)
downloadgo-66fcf45477b5f2ee4c39214911f417480cc55f5f.tar.xz
runtime: make NetBSD lwp_park use monotonic time
This change updates runtime.semasleep to no longer call runtime.nanotime and instead calls lwp_park with a duration to sleep relative to the monotonic clock, so the nanotime is never called. (This requires updating to a newer version of the lwp_park system call, which is safe, because Go 1.10 will require the unreleased NetBSD 8+ anyway) Additionally, this change makes the nanotime function use the monotonic clock for netbsd/arm, which was forgotten from https://golang.org/cl/81135 which updated netbsd/amd64 and netbsd/386. Because semasleep previously depended on nanotime, the past few days of netbsd have likely been unstable because lwp_park was then mixing the monotonic and wall clocks. After this CL, lwp_park no longer depends on nanotime. Original patch submitted at: https://www.netbsd.org/~christos/go-lwp-park-clock-monotonic.diff This commit message (any any mistakes therein) were written by Brad Fitzpatrick. (Brad migrated the patch to Gerrit and checked CLAs) Updates #6007 Fixes #22968 Also updates netbsd/arm to use monotonic time for Change-Id: If77ef7dc610b3025831d84cdfadfbbba2c52acb2 Reviewed-on: https://go-review.googlesource.com/81715 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/runtime/os_netbsd.go8
-rw-r--r--src/runtime/sys_netbsd_386.s4
-rw-r--r--src/runtime/sys_netbsd_amd64.s14
-rw-r--r--src/runtime/sys_netbsd_arm.s20
4 files changed, 27 insertions, 19 deletions
diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go
index 39e91eeffb..b75ec7908b 100644
--- a/src/runtime/os_netbsd.go
+++ b/src/runtime/os_netbsd.go
@@ -58,7 +58,7 @@ func getcontext(ctxt unsafe.Pointer)
func lwp_create(ctxt unsafe.Pointer, flags uintptr, lwpid unsafe.Pointer) int32
//go:noescape
-func lwp_park(abstime *timespec, unpark int32, hint, unparkhint unsafe.Pointer) int32
+func lwp_park(clockid, flags int32, ts *timespec, unpark int32, hint, unparkhint unsafe.Pointer) int32
//go:noescape
func lwp_unpark(lwp int32, hint unsafe.Pointer) int32
@@ -76,6 +76,9 @@ const (
_CLOCK_VIRTUAL = 1
_CLOCK_PROF = 2
_CLOCK_MONOTONIC = 3
+
+ _TIMER_RELTIME = 0
+ _TIMER_ABSTIME = 1
)
var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}}
@@ -122,7 +125,6 @@ func semasleep(ns int64) int32 {
if ns >= 0 {
var ts timespec
var nsec int32
- ns += nanotime()
ts.set_sec(timediv(ns, 1000000000, &nsec))
ts.set_nsec(nsec)
tsp = &ts
@@ -138,7 +140,7 @@ func semasleep(ns int64) int32 {
}
// Sleep until unparked by semawakeup or timeout.
- ret := lwp_park(tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
+ ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
if ret == _ETIMEDOUT {
return -1
}
diff --git a/src/runtime/sys_netbsd_386.s b/src/runtime/sys_netbsd_386.s
index d2e7aa5579..4042ab4f8a 100644
--- a/src/runtime/sys_netbsd_386.s
+++ b/src/runtime/sys_netbsd_386.s
@@ -346,9 +346,9 @@ TEXT runtime·osyield(SB),NOSPLIT,$-4
RET
TEXT runtime·lwp_park(SB),NOSPLIT,$-4
- MOVL $434, AX // sys__lwp_park
+ MOVL $478, AX // sys__lwp_park
INT $0x80
- MOVL AX, ret+16(FP)
+ MOVL AX, ret+24(FP)
RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
diff --git a/src/runtime/sys_netbsd_amd64.s b/src/runtime/sys_netbsd_amd64.s
index 1e3f7cb137..11b9c1b417 100644
--- a/src/runtime/sys_netbsd_amd64.s
+++ b/src/runtime/sys_netbsd_amd64.s
@@ -48,13 +48,15 @@ TEXT runtime·osyield(SB),NOSPLIT,$0
RET
TEXT runtime·lwp_park(SB),NOSPLIT,$0
- MOVQ abstime+0(FP), DI // arg 1 - abstime
- MOVL unpark+8(FP), SI // arg 2 - unpark
- MOVQ hint+16(FP), DX // arg 3 - hint
- MOVQ unparkhint+24(FP), R10 // arg 4 - unparkhint
- MOVL $434, AX // sys__lwp_park
+ MOVL clockid+0(FP), DI // arg 1 - clockid
+ MOVL flags+4(FP), SI // arg 2 - flags
+ MOVQ ts+8(FP), DX // arg 3 - ts
+ MOVL unpark+16(FP), R10 // arg 4 - unpark
+ MOVQ hint+24(FP), R8 // arg 5 - hint
+ MOVQ unparkhint+32(FP), R9 // arg 6 - unparkhint
+ MOVL $478, AX // sys__lwp_park
SYSCALL
- MOVL AX, ret+32(FP)
+ MOVL AX, ret+40(FP)
RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
diff --git a/src/runtime/sys_netbsd_arm.s b/src/runtime/sys_netbsd_arm.s
index 47a3009a62..7d2e290dd9 100644
--- a/src/runtime/sys_netbsd_arm.s
+++ b/src/runtime/sys_netbsd_arm.s
@@ -80,13 +80,17 @@ TEXT runtime·osyield(SB),NOSPLIT,$0
SWI $0xa0015e // sys_sched_yield
RET
-TEXT runtime·lwp_park(SB),NOSPLIT,$0
- MOVW abstime+0(FP), R0 // arg 1 - abstime
- MOVW unpark+4(FP), R1 // arg 2 - unpark
- MOVW hint+8(FP), R2 // arg 3 - hint
- MOVW unparkhint+12(FP), R3 // arg 4 - unparkhint
- SWI $0xa001b2 // sys__lwp_park
- MOVW R0, ret+16(FP)
+TEXT runtime·lwp_park(SB),NOSPLIT,$8
+ MOVW clockid+0(FP), R0 // arg 1 - clock_id
+ MOVW flags+4(FP), R1 // arg 2 - flags
+ MOVW ts+8(FP), R2 // arg 3 - ts
+ MOVW unpark+12(FP), R3 // arg 4 - unpark
+ MOVW hint+16(FP), R4 // arg 5 - hint
+ MOVW R4, 4(R13)
+ MOVW unparkhint+20(FP), R5 // arg 6 - unparkhint
+ MOVW R5, 8(R13)
+ SWI $0xa001de // sys__lwp_park
+ MOVW R0, ret+24(FP)
RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
@@ -164,7 +168,7 @@ TEXT runtime·walltime(SB), NOSPLIT, $32
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), NOSPLIT, $32
- MOVW $0, R0 // CLOCK_REALTIME
+ MOVW $3, R0 // CLOCK_MONOTONIC
MOVW $8(R13), R1
SWI $0xa001ab // clock_gettime