]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make nanotime use monotonic clock in Solaris
authorJerrin Shaji George <jerrinsg@gmail.com>
Mon, 7 Oct 2019 19:27:33 +0000 (12:27 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 11 Oct 2019 20:01:28 +0000 (20:01 +0000)
nanotime() currently uses the REALTIME clock to get the elapsed
time in Solaris. This commit changes it to use the MONOTONIC clock
instead, similar to how it's done in Linux and other OSs. Also changed
nanotime() and walltime() to call clock_gettime() library function
directly from Go code rather than from assembly.

Fixes #33674

Change-Id: Ie4a687b17d2140998ecd97af6ce048c86cf5fc02
Reviewed-on: https://go-review.googlesource.com/c/go/+/199502
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
src/runtime/os3_solaris.go
src/runtime/sys_solaris_amd64.s
src/runtime/timestub2.go

index afda44295b236822331f1aa02f65aac0e3a52d44..cdec190de52abfe3270440bb3d5c003b0917a633 100644 (file)
@@ -393,11 +393,16 @@ func munmap(addr unsafe.Pointer, n uintptr) {
        sysvicall2(&libc_munmap, uintptr(addr), uintptr(n))
 }
 
-func nanotime2()
+const (
+       _CLOCK_REALTIME  = 3
+       _CLOCK_MONOTONIC = 4
+)
 
 //go:nosplit
 func nanotime1() int64 {
-       return int64(sysvicall0((*libcFunc)(unsafe.Pointer(funcPC(nanotime2)))))
+       var ts mts
+       sysvicall2(&libc_clock_gettime, _CLOCK_MONOTONIC, uintptr(unsafe.Pointer(&ts)))
+       return ts.tv_sec*1e9 + ts.tv_nsec
 }
 
 //go:nosplit
@@ -498,6 +503,12 @@ func usleep(µs uint32) {
        usleep1(µs)
 }
 
+func walltime1() (sec int64, nsec int32) {
+       var ts mts
+       sysvicall2(&libc_clock_gettime, _CLOCK_REALTIME, uintptr(unsafe.Pointer(&ts)))
+       return ts.tv_sec, int32(ts.tv_nsec)
+}
+
 //go:nosplit
 func write1(fd uintptr, buf unsafe.Pointer, nbyte int32) int32 {
        return int32(sysvicall3(&libc_write, uintptr(fd), uintptr(buf), uintptr(nbyte)))
index bd5f7736adc6ad8f9a4d2c616f8a2bca6972d78d..05fd187517ee19144109f41df1116704c592f01d 100644 (file)
@@ -29,26 +29,6 @@ TEXT runtime·miniterrno(SB),NOSPLIT,$0
        MOVQ    AX,     (m_mOS+mOS_perrno)(BX)
        RET
 
-// int64 runtime·nanotime2(void);
-//
-// clock_gettime(3c) wrapper because Timespec is too large for
-// runtime·nanotime stack.
-//
-// Called using runtime·sysvicall6 from os_solaris.c:/nanotime.
-// NOT USING GO CALLING CONVENTION.
-TEXT runtime·nanotime2(SB),NOSPLIT,$0
-       // need space for the timespec argument.
-       SUBQ    $64, SP // 16 bytes will do, but who knows in the future?
-       MOVQ    $3, DI  // CLOCK_REALTIME from <sys/time_impl.h>
-       MOVQ    SP, SI
-       LEAQ    libc_clock_gettime(SB), AX
-       CALL    AX
-       MOVQ    (SP), AX        // tv_sec from struct timespec
-       IMULQ   $1000000000, AX // multiply into nanoseconds
-       ADDQ    8(SP), AX       // tv_nsec, offset should be stable.
-       ADDQ    $64, SP
-       RET
-
 // pipe(3c) wrapper that returns fds in AX, DX.
 // NOT USING GO CALLING CONVENTION.
 TEXT runtime·pipe1(SB),NOSPLIT,$0
@@ -338,23 +318,3 @@ TEXT runtime·osyield1(SB),NOSPLIT,$0
        LEAQ    libc_sched_yield(SB), AX
        CALL    AX
        RET
-
-// func walltime1() (sec int64, nsec int32)
-TEXT runtime·walltime1(SB),NOSPLIT,$8-12
-       CALL    runtime·nanotime1(SB)
-       MOVQ    0(SP), AX
-
-       // generated code for
-       //      func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
-       // adapted to reduce duplication
-       MOVQ    AX, CX
-       MOVQ    $1360296554856532783, AX
-       MULQ    CX
-       ADDQ    CX, DX
-       RCRQ    $1, DX
-       SHRQ    $29, DX
-       MOVQ    DX, sec+0(FP)
-       IMULQ   $1000000000, DX
-       SUBQ    DX, CX
-       MOVL    CX, nsec+8(FP)
-       RET
index 95ec99e7dcc07f92fb55d6288efd985fbd0516e5..6d73aabc3507b9c5cb4fa1de9dcae688cfca630e 100644 (file)
@@ -6,6 +6,7 @@
 // +build !windows
 // +build !freebsd
 // +build !aix
+// +build !solaris
 
 package runtime