1
0
mirror of https://github.com/golang/go synced 2024-11-26 13:38:20 -07:00

runtime: use clock_gettime instead of gettimeofday on darwin

clock_gettime has higher resolution than gettimeofday and is available
since macOS 10.12. Go 1.15 already requires at least macOS 10.12 and
thus clock_gettime can be used unconditionally (also see
https://golang.org/doc/go1.15#darwin)

Fixes #25633

Change-Id: I46305387212735e5d3a13e5f02ec90f3e6d546a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/270918
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Tobias Klauser 2020-11-18 11:08:43 +01:00 committed by Tobias Klauser
parent ee1b51294a
commit ae76f6e962
3 changed files with 13 additions and 9 deletions

View File

@ -303,9 +303,9 @@ func nanotime_trampoline()
//go:nosplit //go:nosplit
//go:cgo_unsafe_args //go:cgo_unsafe_args
func walltime1() (int64, int32) { func walltime1() (int64, int32) {
var t timeval var t timespec
libcCall(unsafe.Pointer(funcPC(walltime_trampoline)), unsafe.Pointer(&t)) libcCall(unsafe.Pointer(funcPC(walltime_trampoline)), unsafe.Pointer(&t))
return int64(t.tv_sec), 1000 * t.tv_usec return t.tv_sec, int32(t.tv_nsec)
} }
func walltime_trampoline() func walltime_trampoline()
@ -470,7 +470,7 @@ func setNonblock(fd int32) {
//go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_gettimeofday gettimeofday "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib" //go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib"

View File

@ -10,6 +10,8 @@
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#define CLOCK_REALTIME 0
// Exit the entire program (like C exit) // Exit the entire program (like C exit)
TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 TEXT runtime·exit_trampoline(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
@ -137,9 +139,9 @@ initialized:
TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0 TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0
PUSHQ BP // make a frame; keep stack aligned PUSHQ BP // make a frame; keep stack aligned
MOVQ SP, BP MOVQ SP, BP
// DI already has *timeval MOVQ DI, SI // arg 2 timespec
XORL SI, SI // no timezone needed MOVL $CLOCK_REALTIME, DI // arg 1 clock_id
CALL libc_gettimeofday(SB) CALL libc_clock_gettime(SB)
POPQ BP POPQ BP
RET RET

View File

@ -10,6 +10,8 @@
#include "go_tls.h" #include "go_tls.h"
#include "textflag.h" #include "textflag.h"
#define CLOCK_REALTIME 0
TEXT notok<>(SB),NOSPLIT,$0 TEXT notok<>(SB),NOSPLIT,$0
MOVD $0, R8 MOVD $0, R8
MOVD R8, (R8) MOVD R8, (R8)
@ -126,9 +128,9 @@ TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
RET RET
TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0 TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0
// R0 already has *timeval MOVD R0, R1 // arg 2 timespec
MOVD $0, R1 // no timezone needed MOVW $CLOCK_REALTIME, R0 // arg 1 clock_id
BL libc_gettimeofday(SB) BL libc_clock_gettime(SB)
RET RET
GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size) GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)