Bubble android client. Fork of https://git.zx2c4.com/wireguard-android/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

goruntime-boottime-over-monotonic.diff 4.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From e44f456f1d0e429e08afed64a161175ff493f3ac Mon Sep 17 00:00:00 2001
  2. From: "Jason A. Donenfeld" <Jason@zx2c4.com>
  3. Date: Wed, 27 Feb 2019 05:05:44 +0100
  4. Subject: [PATCH] runtime: use CLOCK_BOOTTIME in nanotime on Linux
  5. This makes timers account for having expired while a computer was
  6. asleep, which is quite common on mobile devices. Note that BOOTTIME is
  7. identical to MONOTONIC, except that it takes into account time spent
  8. in suspend. In Linux 4.17, the kernel will actually make MONOTONIC act
  9. like BOOTTIME anyway, so this switch will additionally unify the
  10. timer behavior across kernels.
  11. BOOTTIME was introduced into Linux 2.6.39-rc1 with 70a08cca1227d in
  12. 2011.
  13. Fixes #24595
  14. Change-Id: I7b2a6ca0c5bc5fce57ec0eeafe7b68270b429321
  15. ---
  16. src/runtime/sys_linux_386.s | 4 ++--
  17. src/runtime/sys_linux_amd64.s | 2 +-
  18. src/runtime/sys_linux_arm.s | 4 ++--
  19. src/runtime/sys_linux_arm64.s | 4 ++--
  20. src/runtime/sys_linux_mips64x.s | 2 +-
  21. src/runtime/sys_linux_mipsx.s | 2 +-
  22. src/runtime/sys_linux_ppc64x.s | 2 +-
  23. src/runtime/sys_linux_s390x.s | 2 +-
  24. 8 files changed, 11 insertions(+), 11 deletions(-)
  25. diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
  26. index 1b28098ad9..46b7071ed8 100644
  27. --- a/src/runtime/sys_linux_386.s
  28. +++ b/src/runtime/sys_linux_386.s
  29. @@ -317,13 +317,13 @@ noswitch:
  30. LEAL 8(SP), BX // &ts (struct timespec)
  31. MOVL BX, 4(SP)
  32. - MOVL $1, 0(SP) // CLOCK_MONOTONIC
  33. + MOVL $7, 0(SP) // CLOCK_BOOTTIME
  34. CALL AX
  35. JMP finish
  36. fallback:
  37. MOVL $SYS_clock_gettime, AX
  38. - MOVL $1, BX // CLOCK_MONOTONIC
  39. + MOVL $7, BX // CLOCK_BOOTTIME
  40. LEAL 8(SP), CX
  41. INVOKE_SYSCALL
  42. diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s
  43. index 58d3bc54b4..4bb9bde3d0 100644
  44. --- a/src/runtime/sys_linux_amd64.s
  45. +++ b/src/runtime/sys_linux_amd64.s
  46. @@ -293,7 +293,7 @@ noswitch:
  47. MOVQ runtime·vdsoClockgettimeSym(SB), AX
  48. CMPQ AX, $0
  49. JEQ fallback
  50. - MOVL $1, DI // CLOCK_MONOTONIC
  51. + MOVL $7, DI // CLOCK_BOOTTIME
  52. LEAQ 0(SP), SI
  53. CALL AX
  54. MOVQ 0(SP), AX // sec
  55. diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s
  56. index e103da56dc..0b872b90a6 100644
  57. --- a/src/runtime/sys_linux_arm.s
  58. +++ b/src/runtime/sys_linux_arm.s
  59. @@ -11,7 +11,7 @@
  60. #include "textflag.h"
  61. #define CLOCK_REALTIME 0
  62. -#define CLOCK_MONOTONIC 1
  63. +#define CLOCK_BOOTTIME 7
  64. // for EABI, as we don't support OABI
  65. #define SYS_BASE 0x0
  66. @@ -345,7 +345,7 @@ noswitch:
  67. SUB $24, R13 // Space for results
  68. BIC $0x7, R13 // Align for C code
  69. - MOVW $CLOCK_MONOTONIC, R0
  70. + MOVW $CLOCK_BOOTTIME, R0
  71. MOVW $8(R13), R1 // timespec
  72. MOVW runtime·vdsoClockgettimeSym(SB), R2
  73. CMP $0, R2
  74. diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s
  75. index b9588cec30..e444d50df4 100644
  76. --- a/src/runtime/sys_linux_arm64.s
  77. +++ b/src/runtime/sys_linux_arm64.s
  78. @@ -13,7 +13,7 @@
  79. #define AT_FDCWD -100
  80. #define CLOCK_REALTIME 0
  81. -#define CLOCK_MONOTONIC 1
  82. +#define CLOCK_BOOTTIME 7
  83. #define SYS_exit 93
  84. #define SYS_read 63
  85. @@ -297,7 +297,7 @@ noswitch:
  86. BIC $15, R1
  87. MOVD R1, RSP
  88. - MOVW $CLOCK_MONOTONIC, R0
  89. + MOVW $CLOCK_BOOTTIME, R0
  90. MOVD runtime·vdsoClockgettimeSym(SB), R2
  91. CBZ R2, fallback
  92. diff --git a/src/runtime/sys_linux_mips64x.s b/src/runtime/sys_linux_mips64x.s
  93. index 723cfe43d9..edd7a195eb 100644
  94. --- a/src/runtime/sys_linux_mips64x.s
  95. +++ b/src/runtime/sys_linux_mips64x.s
  96. @@ -278,7 +278,7 @@ noswitch:
  97. AND $~15, R1 // Align for C code
  98. MOVV R1, R29
  99. - MOVW $1, R4 // CLOCK_MONOTONIC
  100. + MOVW $7, R4 // CLOCK_BOOTTIME
  101. MOVV $0(R29), R5
  102. MOVV runtime·vdsoClockgettimeSym(SB), R25
  103. diff --git a/src/runtime/sys_linux_mipsx.s b/src/runtime/sys_linux_mipsx.s
  104. index 15893a7a28..f3edf9a83a 100644
  105. --- a/src/runtime/sys_linux_mipsx.s
  106. +++ b/src/runtime/sys_linux_mipsx.s
  107. @@ -235,7 +235,7 @@ TEXT runtime·walltime1(SB),NOSPLIT,$8-12
  108. RET
  109. TEXT runtime·nanotime1(SB),NOSPLIT,$8-8
  110. - MOVW $1, R4 // CLOCK_MONOTONIC
  111. + MOVW $7, R4 // CLOCK_BOOTTIME
  112. MOVW $4(R29), R5
  113. MOVW $SYS_clock_gettime, R2
  114. SYSCALL
  115. diff --git a/src/runtime/sys_linux_ppc64x.s b/src/runtime/sys_linux_ppc64x.s
  116. index 8629fe3233..2402e2623a 100644
  117. --- a/src/runtime/sys_linux_ppc64x.s
  118. +++ b/src/runtime/sys_linux_ppc64x.s
  119. @@ -233,7 +233,7 @@ fallback:
  120. JMP finish
  121. TEXT runtime·nanotime1(SB),NOSPLIT,$16
  122. - MOVD $1, R3 // CLOCK_MONOTONIC
  123. + MOVD $7, R3 // CLOCK_BOOTTIME
  124. MOVD R1, R15 // R15 is unchanged by C code
  125. MOVD g_m(g), R21 // R21 = m
  126. diff --git a/src/runtime/sys_linux_s390x.s b/src/runtime/sys_linux_s390x.s
  127. index c15a1d5364..f52c4d5098 100644
  128. --- a/src/runtime/sys_linux_s390x.s
  129. +++ b/src/runtime/sys_linux_s390x.s
  130. @@ -207,7 +207,7 @@ TEXT runtime·walltime1(SB),NOSPLIT,$16
  131. RET
  132. TEXT runtime·nanotime1(SB),NOSPLIT,$16
  133. - MOVW $1, R2 // CLOCK_MONOTONIC
  134. + MOVW $7, R2 // CLOCK_BOOTTIME
  135. MOVD $tp-16(SP), R3
  136. MOVW $SYS_clock_gettime, R1
  137. SYSCALL
  138. --
  139. 2.25.1