]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make MemStats.LastGC Unix time again
authorDmitriy Vyukov <dvyukov@google.com>
Fri, 2 May 2014 16:32:42 +0000 (17:32 +0100)
committerDmitriy Vyukov <dvyukov@google.com>
Fri, 2 May 2014 16:32:42 +0000 (17:32 +0100)
The monotonic clock patch changed all runtime times
to abstract monotonic time. As the result user-visible
MemStats.LastGC become monotonic time as well.
Restore Unix time for LastGC.

This is the simplest way to expose time.now to runtime that I found.
Another option would be to change time.now to C called
int64 runtime.unixnanotime() and then express time.now in terms of it.
But this would require to introduce 2 64-bit divisions into time.now.
Another option would be to change time.now to C called
void runtime.unixnanotime1(struct {int64 sec, int32 nsec} *now)
and then express both time.now and runtime.unixnanotime in terms of it.

Fixes #7852.

LGTM=minux.ma, iant
R=minux.ma, rsc, iant
CC=golang-codereviews
https://golang.org/cl/93720045

src/pkg/runtime/asm_386.s
src/pkg/runtime/asm_amd64.s
src/pkg/runtime/asm_amd64p32.s
src/pkg/runtime/asm_arm.s
src/pkg/runtime/gc_test.go
src/pkg/runtime/mgc0.c
src/pkg/runtime/mgc0.go

index e7ea093a41def810d5f305a525d77099deb86a80..dae241a15b34e527bee2aa44cdc8c68e977ae95c 100644 (file)
@@ -2146,3 +2146,6 @@ TEXT runtime·duffcopy(SB), NOSPLIT, $0-0
        ADDL    $4,DI
        
        RET
+
+TEXT runtime·timenow(SB), NOSPLIT, $0-0
+       JMP     time·now(SB)
index eeda9aa7f446c2f521e9b48903218936cb0f417e..27abb37cdbf0b72cf74dfccf9225c3196a59132f 100644 (file)
@@ -2179,3 +2179,6 @@ TEXT runtime·duffcopy(SB), NOSPLIT, $0-0
        ADDQ    $8,DI
 
        RET
+
+TEXT runtime·timenow(SB), NOSPLIT, $0-0
+       JMP     time·now(SB)
index 47e1d52a8b61241b4a907cdcb82a856224e07cd4..775ffccf14fbd03e157071926f8c137110affa63 100644 (file)
@@ -1064,3 +1064,6 @@ TEXT bytes·Equal(SB),NOSPLIT,$0-25
 eqret:
        MOVB    AX, ret+24(FP)
        RET
+
+TEXT runtime·timenow(SB), NOSPLIT, $0-0
+       JMP     time·now(SB)
index e1464a07b2069912504f36cf61c1020c4fb3d200..c691b04a85b65d7e00be9b488a9a67258bdad7a5 100644 (file)
@@ -747,3 +747,6 @@ _sib_notfound:
        MOVW    $-1, R0
        MOVW    R0, ret+12(FP)
        RET
+
+TEXT runtime·timenow(SB), NOSPLIT, $0-0
+       B       time·now(SB)
index 75322478e47b7fbf3433185a86d666e112c37c01..58717ecf7eeb5c0790d84b10fd108754ef17c7d7 100644 (file)
@@ -9,6 +9,7 @@ import (
        "runtime"
        "runtime/debug"
        "testing"
+       "time"
 )
 
 func TestGcSys(t *testing.T) {
@@ -152,6 +153,18 @@ func TestGcRescan(t *testing.T) {
        }
 }
 
+func TestGcLastTime(t *testing.T) {
+       ms := new(runtime.MemStats)
+       t0 := time.Now().UnixNano()
+       runtime.GC()
+       t1 := time.Now().UnixNano()
+       runtime.ReadMemStats(ms)
+       last := int64(ms.LastGC)
+       if t0 > last || last > t1 {
+               t.Fatalf("bad last GC time: got %v, want [%v, %v]", last, t0, t1)
+       }
+}
+
 func BenchmarkSetTypeNoPtr1(b *testing.B) {
        type NoPtr1 struct {
                p uintptr
index 359d426fc8d4eed449ff0b6dcd1b860806db1273..70c0c933ad40619e7bafa6d62d71a817b298397a 100644 (file)
@@ -91,6 +91,8 @@ enum {
 // Initialized from $GOGC.  GOGC=off means no gc.
 static int32 gcpercent = GcpercentUnknown;
 
+void runtime·gc_unixnanotime(int64 *now);
+
 static FuncVal* poolcleanup;
 
 void
@@ -2404,7 +2406,7 @@ gc(struct gc_args *args)
        mstats.next_gc = mstats.heap_alloc+mstats.heap_alloc*gcpercent/100;
 
        t4 = runtime·nanotime();
-       mstats.last_gc = t4;
+       runtime·gc_unixnanotime((int64*)&mstats.last_gc);  // must be Unix time to make sense to user
        mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t4 - t0;
        mstats.pause_total_ns += t4 - t0;
        mstats.numgc++;
index 00b271016652b2adddbcd4030b76a3e4d48bac3e..624485d18bfc112b823ec23f0beabfb548659280 100644 (file)
@@ -18,3 +18,10 @@ func gc_g_ptr(ret *interface{}) {
 func gc_itab_ptr(ret *interface{}) {
        *ret = (*itab)(nil)
 }
+
+func timenow() (sec int64, nsec int32)
+
+func gc_unixnanotime(now *int64) {
+       sec, nsec := timenow()
+       *now = sec*1e9 + int64(nsec)
+}