2019-09-19 05:26:57 +00:00
|
|
|
From 04f5695b83cd221e99e9fa6171b57e45177d5ad3 Mon Sep 17 00:00:00 2001
|
2019-02-27 05:24:56 +00:00
|
|
|
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
|
|
|
|
Date: Wed, 27 Feb 2019 05:33:01 +0100
|
|
|
|
Subject: [PATCH] runtime: use libc_mach_continuous_time in nanotime on Darwin
|
|
|
|
|
|
|
|
This makes timers account for having expired while a computer was
|
|
|
|
asleep, which is quite common on mobile devices. Note that
|
|
|
|
continuous_time absolute_time, except that it takes into account
|
|
|
|
time spent in suspend.
|
|
|
|
|
|
|
|
Fixes #24595
|
|
|
|
---
|
|
|
|
src/runtime/sys_darwin.go | 2 +-
|
|
|
|
src/runtime/sys_darwin_386.s | 2 +-
|
|
|
|
src/runtime/sys_darwin_amd64.s | 2 +-
|
|
|
|
src/runtime/sys_darwin_arm.s | 2 +-
|
|
|
|
src/runtime/sys_darwin_arm64.s | 2 +-
|
|
|
|
5 files changed, 5 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go
|
2019-09-19 05:26:57 +00:00
|
|
|
index 376f76dbc5..a0677a83f6 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin.go
|
|
|
|
+++ b/src/runtime/sys_darwin.go
|
2019-09-19 05:26:57 +00:00
|
|
|
@@ -431,7 +431,7 @@ func setNonblock(fd int32) {
|
2019-02-27 05:24:56 +00:00
|
|
|
//go:cgo_import_dynamic libc_usleep usleep "/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_continuous_time mach_continuous_time "/usr/lib/libSystem.B.dylib"
|
|
|
|
//go:cgo_import_dynamic libc_gettimeofday gettimeofday "/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"
|
|
|
|
diff --git a/src/runtime/sys_darwin_386.s b/src/runtime/sys_darwin_386.s
|
2019-09-19 05:26:57 +00:00
|
|
|
index e653c54f61..5a43fcbdc1 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_386.s
|
|
|
|
+++ b/src/runtime/sys_darwin_386.s
|
2019-09-19 05:26:57 +00:00
|
|
|
@@ -199,7 +199,7 @@ TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
|
2018-11-01 22:39:06 +00:00
|
|
|
PUSHL BP
|
|
|
|
MOVL SP, BP
|
|
|
|
SUBL $8+(machTimebaseInfo__size+15)/16*16, SP
|
|
|
|
- CALL libc_mach_absolute_time(SB)
|
|
|
|
+ CALL libc_mach_continuous_time(SB)
|
|
|
|
MOVL 16+(machTimebaseInfo__size+15)/16*16(SP), CX
|
|
|
|
MOVL AX, 0(CX)
|
|
|
|
MOVL DX, 4(CX)
|
2019-02-27 05:24:56 +00:00
|
|
|
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
|
2019-09-19 05:26:57 +00:00
|
|
|
index 87c8db8c82..f962f24339 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_amd64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_amd64.s
|
2019-09-19 05:26:57 +00:00
|
|
|
@@ -97,7 +97,7 @@ TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
|
2018-11-01 22:39:06 +00:00
|
|
|
PUSHQ BP
|
|
|
|
MOVQ SP, BP
|
|
|
|
MOVQ DI, BX
|
|
|
|
- CALL libc_mach_absolute_time(SB)
|
|
|
|
+ CALL libc_mach_continuous_time(SB)
|
|
|
|
MOVQ AX, 0(BX)
|
|
|
|
MOVL timebase<>+machTimebaseInfo_numer(SB), SI
|
|
|
|
MOVL timebase<>+machTimebaseInfo_denom(SB), DI // atomic read
|
2019-02-27 05:24:56 +00:00
|
|
|
diff --git a/src/runtime/sys_darwin_arm.s b/src/runtime/sys_darwin_arm.s
|
2019-09-19 05:26:57 +00:00
|
|
|
index 996f8028a3..5bd34b51be 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_arm.s
|
|
|
|
+++ b/src/runtime/sys_darwin_arm.s
|
2019-09-19 05:26:57 +00:00
|
|
|
@@ -126,7 +126,7 @@ GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
|
2018-11-01 22:39:06 +00:00
|
|
|
|
|
|
|
TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
|
|
|
|
MOVW R0, R8
|
|
|
|
- BL libc_mach_absolute_time(SB)
|
|
|
|
+ BL libc_mach_continuous_time(SB)
|
|
|
|
MOVW R0, 0(R8)
|
|
|
|
MOVW R1, 4(R8)
|
|
|
|
MOVW timebase<>+machTimebaseInfo_numer(SB), R6
|
2019-02-27 05:24:56 +00:00
|
|
|
diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s
|
2019-09-19 05:26:57 +00:00
|
|
|
index ac3ca74f63..5e91540f94 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_arm64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_arm64.s
|
2019-09-19 05:26:57 +00:00
|
|
|
@@ -121,7 +121,7 @@ GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
|
2018-11-01 22:39:06 +00:00
|
|
|
|
2019-02-27 05:24:56 +00:00
|
|
|
TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$40
|
|
|
|
MOVD R0, R19
|
|
|
|
- BL libc_mach_absolute_time(SB)
|
|
|
|
+ BL libc_mach_continuous_time(SB)
|
|
|
|
MOVD R0, 0(R19)
|
|
|
|
MOVW timebase<>+machTimebaseInfo_numer(SB), R20
|
|
|
|
MOVD $timebase<>+machTimebaseInfo_denom(SB), R21
|
|
|
|
--
|
2019-09-19 05:26:57 +00:00
|
|
|
2.23.0
|
2019-02-27 05:24:56 +00:00
|
|
|
|