From: Russ Cox Date: Wed, 9 Apr 2014 14:38:12 +0000 (-0400) Subject: runtime: use 3x fewer nanotime calls in garbage collection X-Git-Tag: go1.3beta1~142 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=95ee7d6414c4a9a5da95ecb4fbefc3ac3e570d06;p=gostls13.git runtime: use 3x fewer nanotime calls in garbage collection 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 --- diff --git a/src/pkg/runtime/mgc0.c b/src/pkg/runtime/mgc0.c index 24e4cf6816..d3a716840d 100644 --- a/src/pkg/runtime/mgc0.c +++ b/src/pkg/runtime/mgc0.c @@ -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)