2020-12-09 13:08:45 +00:00
|
|
|
From aa85e0f90c9031ff5be32296e9fed1637a2eceae Mon Sep 17 00:00:00 2001
|
2019-02-27 05:24:56 +00:00
|
|
|
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
|
2020-12-09 13:08:45 +00:00
|
|
|
Date: Wed, 9 Dec 2020 14:07:06 +0100
|
2019-02-27 05:24:56 +00:00
|
|
|
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
|
2020-12-09 13:08:45 +00:00
|
|
|
|
|
|
|
Change-Id: Ia3282e8bd86f95ad2b76427063e60a005563f4eb
|
2019-02-27 05:24:56 +00:00
|
|
|
---
|
|
|
|
src/runtime/sys_darwin.go | 2 +-
|
|
|
|
src/runtime/sys_darwin_amd64.s | 2 +-
|
|
|
|
src/runtime/sys_darwin_arm64.s | 2 +-
|
2020-12-09 13:08:45 +00:00
|
|
|
3 files changed, 3 insertions(+), 3 deletions(-)
|
2019-02-27 05:24:56 +00:00
|
|
|
|
|
|
|
diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go
|
2020-12-09 13:08:45 +00:00
|
|
|
index 06474434c9..6f7ca37122 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin.go
|
|
|
|
+++ b/src/runtime/sys_darwin.go
|
2020-12-09 13:08:45 +00:00
|
|
|
@@ -469,7 +469,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_amd64.s b/src/runtime/sys_darwin_amd64.s
|
2020-12-09 13:08:45 +00:00
|
|
|
index 825852d673..5a8b994fb1 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_amd64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_amd64.s
|
2020-12-09 13:08:45 +00:00
|
|
|
@@ -109,7 +109,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_arm64.s b/src/runtime/sys_darwin_arm64.s
|
2020-12-09 13:08:45 +00:00
|
|
|
index 585d4f2c64..c556d88730 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_arm64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_arm64.s
|
2020-12-09 13:08:45 +00:00
|
|
|
@@ -135,7 +135,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
|
|
|
|
--
|
2020-12-09 13:08:45 +00:00
|
|
|
2.29.2
|
2019-02-27 05:24:56 +00:00
|
|
|
|