]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, time: refactor startNano handling
authorDmitry Vyukov <dvyukov@google.com>
Wed, 31 Oct 2018 16:27:16 +0000 (17:27 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Fri, 2 Nov 2018 12:50:03 +0000 (12:50 +0000)
Move startNano from runtime to time package.
In preparation for a subsequent change that speeds up Since and Until.
This also makes code simpler as we have less assembly as the result,
monotonic time handling is better localized in time package.
This changes values returned from nanotime on windows
(it does not account for startNano anymore), current comments state
that it's important, but it's unclear how it can be important
since no other OS does this.

Update #25729

Change-Id: I2275d57b7b5ed8fd0d53eb0f19d55a86136cc555
Reviewed-on: https://go-review.googlesource.com/c/146340
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/proc.go
src/runtime/sys_windows_386.s
src/runtime/sys_windows_amd64.s
src/runtime/sys_windows_arm.s
src/runtime/time.go
src/runtime/timeasm.go
src/runtime/timestub.go
src/time/sleep.go
src/time/time.go

index 365e516ec8a30feb2703da3d6dcbf4013343ad4f..542cf1ed70255cb0b9b14ffad09cd283369238e4 100644 (file)
@@ -157,8 +157,7 @@ func main() {
                }
        }()
 
-       // Record when the world started. Must be after runtime_init
-       // because nanotime on some platforms depends on startNano.
+       // Record when the world started.
        runtimeInitTime = nanotime()
 
        gcenable()
index babd91c9365b71ba55d254d83eb46b4832ea981d..e6d774e66f475b613baa02c05a2ec8c7af33d59a 100644 (file)
@@ -455,9 +455,7 @@ loop:
        MULL    CX
        IMULL   $100, DI
        ADDL    DI, DX
-       // wintime*100 = DX:AX, subtract startNano and return
-       SUBL    runtime·startNano+0(SB), AX
-       SBBL    runtime·startNano+4(SB), DX
+       // wintime*100 = DX:AX
        MOVL    AX, ret_lo+0(FP)
        MOVL    DX, ret_hi+4(FP)
        RET
@@ -482,9 +480,6 @@ loop:
        IMULL   $100, DI
        ADDL    DI, DX
        // w*100 = DX:AX
-       // subtract startNano and save for return
-       SUBL    runtime·startNano+0(SB), AX
-       SBBL    runtime·startNano+4(SB), DX
        MOVL    AX, mono+12(FP)
        MOVL    DX, mono+16(FP)
 
index ec49caa43e230dce3456f970509081474cc2c220..612f0a474d18f504ecba889197a0ef0669e295af 100644 (file)
@@ -486,7 +486,6 @@ loop:
        SHLQ    $32, CX
        ORQ     BX, CX
        IMULQ   $100, CX
-       SUBQ    runtime·startNano(SB), CX
        MOVQ    CX, ret+0(FP)
        RET
 useQPC:
@@ -506,7 +505,6 @@ loop:
        SHLQ    $32, AX
        ORQ     BX, AX
        IMULQ   $100, AX
-       SUBQ    runtime·startNano(SB), AX
        MOVQ    AX, mono+16(FP)
 
        MOVQ    $_SYSTEM_TIME, DI
index 409c72c5543eb39242c44bb01e942d3e117a4082..60a85b8ffb8883d99a956b698f37c68de5bc6d7d 100644 (file)
@@ -510,11 +510,7 @@ loop:
        MULLU   R0, R2, (R4, R3)    // R4:R3 = R1:R0 * R2
        MULA    R1, R2, R4, R4
 
-       // wintime*100 = R4:R3, subtract startNano and return
-       MOVW    runtime·startNano+0(SB), R0
-       MOVW    runtime·startNano+4(SB), R1
-       SUB.S   R0, R3
-       SBC     R1, R4
+       // wintime*100 = R4:R3
        MOVW    R3, ret_lo+0(FP)
        MOVW    R4, ret_hi+4(FP)
        RET
@@ -540,11 +536,7 @@ loop:
        MULLU   R0, R2, (R4, R3)    // R4:R3 = R1:R0 * R2
        MULA    R1, R2, R4, R4
 
-       // wintime*100 = R4:R3, subtract startNano and return
-       MOVW    runtime·startNano+0(SB), R0
-       MOVW    runtime·startNano+4(SB), R1
-       SUB.S   R0, R3
-       SBC     R1, R4
+       // wintime*100 = R4:R3
        MOVW    R3, mono+12(FP)
        MOVW    R4, mono+16(FP)
 
index 88fd319a90ba0a1ce4920455afd8df0f867e60b5..b345ed4e02390fa159d7cb1ee44aa31fa6bef257 100644 (file)
@@ -470,11 +470,3 @@ func poll_runtimeNano() int64 {
 func time_runtimeNano() int64 {
        return nanotime()
 }
-
-// Monotonic times are reported as offsets from startNano.
-// We initialize startNano to nanotime() - 1 so that on systems where
-// monotonic time resolution is fairly low (e.g. Windows 2008
-// which appears to have a default resolution of 15ms),
-// we avoid ever reporting a nanotime of 0.
-// (Callers may want to use 0 as "time not set".)
-var startNano int64 = nanotime() - 1
index 5af920c18c0487ad1f3b1930f6fe62290a3e90b8..82cf63edffd46374ab639c7f38b2c41bc66b6646 100644 (file)
@@ -3,8 +3,6 @@
 // license that can be found in the LICENSE file.
 
 // Declarations for operating systems implementing time.now directly in assembly.
-// Those systems are also expected to have nanotime subtract startNano,
-// so that time.now and nanotime return the same monotonic clock readings.
 
 // +build windows
 
index f9230da69f92a9ec40c44f9f16b3d828dda2c3a9..459bf8e5435b063b9ba7ebe0485b44720f109866 100644 (file)
@@ -14,5 +14,5 @@ import _ "unsafe" // for go:linkname
 //go:linkname time_now time.now
 func time_now() (sec int64, nsec int32, mono int64) {
        sec, nsec = walltime()
-       return sec, nsec, nanotime() - startNano
+       return sec, nsec, nanotime()
 }
index b8c81b437c0c63265c66349a24d8a7ddae6995fd..10edf6fe0e0dd70ef866fe99e2f0bf98d3912ac1 100644 (file)
@@ -8,9 +8,6 @@ package time
 // A negative or zero duration causes Sleep to return immediately.
 func Sleep(d Duration)
 
-// runtimeNano returns the current value of the runtime clock in nanoseconds.
-func runtimeNano() int64
-
 // Interface to timers implemented in package runtime.
 // Must be in sync with ../runtime/time.go:/^type timer
 type runtimeTimer struct {
index f2da32dbadc8fc5a572e7462293c0757f94d1c48..144f2fe73df2bec4c7aabd76d875e57a09bc5e92 100644 (file)
@@ -1050,9 +1050,21 @@ func daysIn(m Month, year int) int {
 // Provided by package runtime.
 func now() (sec int64, nsec int32, mono int64)
 
+// runtimeNano returns the current value of the runtime clock in nanoseconds.
+func runtimeNano() int64
+
+// Monotonic times are reported as offsets from startNano.
+// We initialize startNano to runtimeNano() - 1 so that on systems where
+// monotonic time resolution is fairly low (e.g. Windows 2008
+// which appears to have a default resolution of 15ms),
+// we avoid ever reporting a monotonic time of 0.
+// (Callers may want to use 0 as "time not set".)
+var startNano int64 = runtimeNano() - 1
+
 // Now returns the current local time.
 func Now() Time {
        sec, nsec, mono := now()
+       mono -= startNano
        sec += unixToInternal - minWall
        if uint64(sec)>>33 != 0 {
                return Time{uint64(nsec), sec + minWall, Local}