From d324f2143b2b7dade319ce70261f3441041710e9 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 30 Sep 2011 09:40:01 -0400 Subject: runtime: parallelize garbage collector mark + sweep Running test/garbage/parser.out. On a 4-core Lenovo X201s (Linux): 31.12u 0.60s 31.74r 1 cpu, no atomics 32.27u 0.58s 32.86r 1 cpu, atomic instructions 33.04u 0.83s 27.47r 2 cpu On a 16-core Xeon (Linux): 33.08u 0.65s 33.80r 1 cpu, no atomics 34.87u 1.12s 29.60r 2 cpu 36.00u 1.87s 28.43r 3 cpu 36.46u 2.34s 27.10r 4 cpu 38.28u 3.85s 26.92r 5 cpu 37.72u 5.25s 26.73r 6 cpu 39.63u 7.11s 26.95r 7 cpu 39.67u 8.10s 26.68r 8 cpu On a 2-core MacBook Pro Core 2 Duo 2.26 (circa 2009, MacBookPro5,5): 39.43u 1.45s 41.27r 1 cpu, no atomics 43.98u 2.95s 38.69r 2 cpu On a 2-core Mac Mini Core 2 Duo 1.83 (circa 2008; Macmini2,1): 48.81u 2.12s 51.76r 1 cpu, no atomics 57.15u 4.72s 51.54r 2 cpu The handoff algorithm is really only good for two cores. Beyond that we will need to so something more sophisticated, like have each core hand off to the next one, around a circle. Even so, the code is a good checkpoint; for now we'll limit the number of gc procs to at most 2. R=dvyukov CC=golang-dev https://golang.org/cl/4641082 --- src/pkg/runtime/linux/thread.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/pkg/runtime/linux/thread.c') diff --git a/src/pkg/runtime/linux/thread.c b/src/pkg/runtime/linux/thread.c index 4878a00f25..bf3b0947d6 100644 --- a/src/pkg/runtime/linux/thread.c +++ b/src/pkg/runtime/linux/thread.c @@ -8,7 +8,6 @@ #include "stack.h" extern SigTab runtime·sigtab[]; -static int32 proccount; int32 runtime·open(uint8*, int32, int32); int32 runtime·close(int32); @@ -136,13 +135,10 @@ futexlock(Lock *l) // its wakeup call. wait = v; - if(proccount == 0) - proccount = getproccount(); - // On uniprocessor's, no point spinning. // On multiprocessors, spin for ACTIVE_SPIN attempts. spin = 0; - if(proccount > 1) + if(runtime·ncpu > 1) spin = ACTIVE_SPIN; for(;;) { @@ -276,6 +272,7 @@ runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void)) void runtime·osinit(void) { + runtime·ncpu = getproccount(); } void -- cgit v1.3