2021-03-08 19:29:12 +00:00
|
|
|
From 516dc0c15ff1ab781e0677606b5be72919251b3e 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
|
2021-03-08 19:29:12 +00:00
|
|
|
index 4a3f2fc453..4a69403b32 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin.go
|
|
|
|
+++ b/src/runtime/sys_darwin.go
|
2021-03-08 19:29:12 +00:00
|
|
|
@@ -440,7 +440,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"
|
2021-03-08 19:29:12 +00:00
|
|
|
//go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib"
|
2019-02-27 05:24:56 +00:00
|
|
|
//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
|
2021-03-08 19:29:12 +00:00
|
|
|
index 630fb5df64..4499c88802 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_amd64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_amd64.s
|
2021-03-08 19:29:12 +00:00
|
|
|
@@ -114,7 +114,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
|
2021-03-08 19:29:12 +00:00
|
|
|
index 96d2ed1076..f046545395 100644
|
2019-02-27 05:24:56 +00:00
|
|
|
--- a/src/runtime/sys_darwin_arm64.s
|
|
|
|
+++ b/src/runtime/sys_darwin_arm64.s
|
2021-03-08 19:29:12 +00:00
|
|
|
@@ -143,7 +143,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
|
|
|
|
--
|
2021-03-08 19:29:12 +00:00
|
|
|
2.30.1
|
2019-02-27 05:24:56 +00:00
|
|
|
|