]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use 3x fewer nanotime calls in garbage collection
authorRuss Cox <rsc@golang.org>
Wed, 9 Apr 2014 14:38:12 +0000 (10:38 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 9 Apr 2014 14:38:12 +0000 (10:38 -0400)
Cuts the number of calls from 6 to 2 in the non-debug case.

LGTM=iant
R=golang-codereviews, iant
CC=0intro, aram, golang-codereviews, khr
https://golang.org/cl/86040043

src/pkg/runtime/mgc0.c

index 24e4cf68163ad70e6c199703dc6892e5ca380fda..d3a716840dcd6e3be7ea9c24f3d0dc897341aaf9 100644 (file)
@@ -2316,13 +2316,13 @@ runtime·gc(int32 force)
        // we don't need to scan gc's internal state).  Also an
        // enabler for copyable stacks.
        for(i = 0; i < (runtime·debug.gctrace > 1 ? 2 : 1); i++) {
+               if(i > 0)
+                       a.start_time = runtime·nanotime();
                // switch to g0, call gc(&a), then switch back
                g->param = &a;
                g->status = Gwaiting;
                g->waitreason = "garbage collection";
                runtime·mcall(mgc);
-               // record a new start time in case we're going around again
-               a.start_time = runtime·nanotime();
        }
 
        // all done
@@ -2378,7 +2378,9 @@ gc(struct gc_args *args)
                itabtype = ((PtrType*)eface.type)->elem;
        }
 
-       t1 = runtime·nanotime();
+       t1 = 0;
+       if(runtime·debug.gctrace)
+               t1 = runtime·nanotime();
 
        // Sweep what is not sweeped by bgsweep.
        while(runtime·sweepone() != -1)
@@ -2393,13 +2395,17 @@ gc(struct gc_args *args)
                runtime·helpgc(work.nproc);
        }
 
-       t2 = runtime·nanotime();
+       t2 = 0;
+       if(runtime·debug.gctrace)
+               t2 = runtime·nanotime();
 
        gchelperstart();
        runtime·parfordo(work.markfor);
        scanblock(nil, true);
 
-       t3 = runtime·nanotime();
+       t3 = 0;
+       if(runtime·debug.gctrace)
+               t3 = runtime·nanotime();
 
        bufferList[m->helpgc].busy = 0;
        if(work.nproc > 1)