Commit 66fcf454 authored by Christos Zoulas's avatar Christos Zoulas Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 871b7931
...@@ -58,7 +58,7 @@ func getcontext(ctxt unsafe.Pointer) ...@@ -58,7 +58,7 @@ func getcontext(ctxt unsafe.Pointer)
func lwp_create(ctxt unsafe.Pointer, flags uintptr, lwpid unsafe.Pointer) int32 func lwp_create(ctxt unsafe.Pointer, flags uintptr, lwpid unsafe.Pointer) int32
//go:noescape //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 //go:noescape
func lwp_unpark(lwp int32, hint unsafe.Pointer) int32 func lwp_unpark(lwp int32, hint unsafe.Pointer) int32
...@@ -76,6 +76,9 @@ const ( ...@@ -76,6 +76,9 @@ const (
_CLOCK_VIRTUAL = 1 _CLOCK_VIRTUAL = 1
_CLOCK_PROF = 2 _CLOCK_PROF = 2
_CLOCK_MONOTONIC = 3 _CLOCK_MONOTONIC = 3
_TIMER_RELTIME = 0
_TIMER_ABSTIME = 1
) )
var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}} var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}}
...@@ -122,7 +125,6 @@ func semasleep(ns int64) int32 { ...@@ -122,7 +125,6 @@ func semasleep(ns int64) int32 {
if ns >= 0 { if ns >= 0 {
var ts timespec var ts timespec
var nsec int32 var nsec int32
ns += nanotime()
ts.set_sec(timediv(ns, 1000000000, &nsec)) ts.set_sec(timediv(ns, 1000000000, &nsec))
ts.set_nsec(nsec) ts.set_nsec(nsec)
tsp = &ts tsp = &ts
...@@ -138,7 +140,7 @@ func semasleep(ns int64) int32 { ...@@ -138,7 +140,7 @@ func semasleep(ns int64) int32 {
} }
// Sleep until unparked by semawakeup or timeout. // 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 { if ret == _ETIMEDOUT {
return -1 return -1
} }
......
...@@ -346,9 +346,9 @@ TEXT runtime·osyield(SB),NOSPLIT,$-4 ...@@ -346,9 +346,9 @@ TEXT runtime·osyield(SB),NOSPLIT,$-4
RET RET
TEXT runtime·lwp_park(SB),NOSPLIT,$-4 TEXT runtime·lwp_park(SB),NOSPLIT,$-4
MOVL $434, AX // sys__lwp_park MOVL $478, AX // sys__lwp_park
INT $0x80 INT $0x80
MOVL AX, ret+16(FP) MOVL AX, ret+24(FP)
RET RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4 TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
......
...@@ -48,13 +48,15 @@ TEXT runtime·osyield(SB),NOSPLIT,$0 ...@@ -48,13 +48,15 @@ TEXT runtime·osyield(SB),NOSPLIT,$0
RET RET
TEXT runtime·lwp_park(SB),NOSPLIT,$0 TEXT runtime·lwp_park(SB),NOSPLIT,$0
MOVQ abstime+0(FP), DI // arg 1 - abstime MOVL clockid+0(FP), DI // arg 1 - clockid
MOVL unpark+8(FP), SI // arg 2 - unpark MOVL flags+4(FP), SI // arg 2 - flags
MOVQ hint+16(FP), DX // arg 3 - hint MOVQ ts+8(FP), DX // arg 3 - ts
MOVQ unparkhint+24(FP), R10 // arg 4 - unparkhint MOVL unpark+16(FP), R10 // arg 4 - unpark
MOVL $434, AX // sys__lwp_park MOVQ hint+24(FP), R8 // arg 5 - hint
SYSCALL MOVQ unparkhint+32(FP), R9 // arg 6 - unparkhint
MOVL AX, ret+32(FP) MOVL $478, AX // sys__lwp_park
SYSCALL
MOVL AX, ret+40(FP)
RET RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$0 TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
......
...@@ -80,13 +80,17 @@ TEXT runtime·osyield(SB),NOSPLIT,$0 ...@@ -80,13 +80,17 @@ TEXT runtime·osyield(SB),NOSPLIT,$0
SWI $0xa0015e // sys_sched_yield SWI $0xa0015e // sys_sched_yield
RET RET
TEXT runtime·lwp_park(SB),NOSPLIT,$0 TEXT runtime·lwp_park(SB),NOSPLIT,$8
MOVW abstime+0(FP), R0 // arg 1 - abstime MOVW clockid+0(FP), R0 // arg 1 - clock_id
MOVW unpark+4(FP), R1 // arg 2 - unpark MOVW flags+4(FP), R1 // arg 2 - flags
MOVW hint+8(FP), R2 // arg 3 - hint MOVW ts+8(FP), R2 // arg 3 - ts
MOVW unparkhint+12(FP), R3 // arg 4 - unparkhint MOVW unpark+12(FP), R3 // arg 4 - unpark
SWI $0xa001b2 // sys__lwp_park MOVW hint+16(FP), R4 // arg 5 - hint
MOVW R0, ret+16(FP) 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 RET
TEXT runtime·lwp_unpark(SB),NOSPLIT,$0 TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
...@@ -164,7 +168,7 @@ TEXT runtime·walltime(SB), NOSPLIT, $32 ...@@ -164,7 +168,7 @@ TEXT runtime·walltime(SB), NOSPLIT, $32
// int64 nanotime(void) so really // int64 nanotime(void) so really
// void nanotime(int64 *nsec) // void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), NOSPLIT, $32 TEXT runtime·nanotime(SB), NOSPLIT, $32
MOVW $0, R0 // CLOCK_REALTIME MOVW $3, R0 // CLOCK_MONOTONIC
MOVW $8(R13), R1 MOVW $8(R13), R1
SWI $0xa001ab // clock_gettime SWI $0xa001ab // clock_gettime
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment