]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make NetBSD lwp_park use monotonic time
authorChristos Zoulas <zoulasc@gmail.com>
Mon, 4 Dec 2017 01:48:45 +0000 (01:48 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 4 Dec 2017 03:29:56 +0000 (03:29 +0000)
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>
src/runtime/os_netbsd.go
src/runtime/sys_netbsd_386.s
src/runtime/sys_netbsd_amd64.s
src/runtime/sys_netbsd_arm.s

index 39e91eeffb80a85003882d5ac9f8bf166b789934..b75ec7908bd0bee504cb6dc06e8cddf70157dc5c 100644 (file)
@@ -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
                }
index d2e7aa5579b64669c4e51f3df954f54ed54d0459..4042ab4f8abd83627e9535ad251928a6fecab084 100644 (file)
@@ -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
index 1e3f7cb137cdf8bb0185a39b59d3e0f90a535047..11b9c1b417375323018ad7f1be4fd27e312a5a84 100644 (file)
@@ -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
-       SYSCALL
-       MOVL    AX, ret+32(FP)
+       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+40(FP)
        RET
 
 TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
index 47a3009a62efa5b66f56c7e837e4879f2c797515..7d2e290dd9bde3b3c6d93a54e076921079811b5e 100644 (file)
@@ -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