aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHector Chu <hectorchu@gmail.com>2011-10-25 08:35:20 +0100
committerHector Chu <hectorchu@gmail.com>2011-10-25 08:35:20 +0100
commit2572ca2ff2cda56a3fb1732a4b628fc7b85ea798 (patch)
tree16af1c7fe6af77a54916aa324db34b470307bcb4
parentd72267ae23380cdec4fd84a66058772ae7f84da6 (diff)
downloadgo-2572ca2ff2cda56a3fb1732a4b628fc7b85ea798.tar.gz
go-2572ca2ff2cda56a3fb1732a4b628fc7b85ea798.zip
runtime: include bootstrap m in mcpu accounting
R=rsc, dvyukov CC=golang-dev https://golang.org/cl/5307052
-rw-r--r--src/pkg/runtime/proc.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c
index 468960d177..3408c06f69 100644
--- a/src/pkg/runtime/proc.c
+++ b/src/pkg/runtime/proc.c
@@ -128,6 +128,8 @@ Sched runtime·sched;
int32 runtime·gomaxprocs;
bool runtime·singleproc;
+static bool canaddmcpu(void);
+
// An m that is waiting for notewakeup(&m->havenextg). This may
// only be accessed while the scheduler lock is held. This is used to
// minimize the number of times we call notewakeup while the scheduler
@@ -202,6 +204,10 @@ runtime·schedinit(void)
setmcpumax(runtime·gomaxprocs);
runtime·singleproc = runtime·gomaxprocs == 1;
+ canaddmcpu(); // mcpu++ to account for bootstrap m
+ m->helpgc = 1; // flag to tell schedule() to mcpu--
+ runtime·sched.grunning++;
+
mstats.enablegc = 1;
m->nomemprof--;
}
@@ -811,6 +817,7 @@ schedule(G *gp)
readylocked(gp);
}
} else if(m->helpgc) {
+ // Bootstrap m or new m started by starttheworld.
// atomic { mcpu-- }
v = runtime·xadd(&runtime·sched.atomic, -1<<mcpuShift);
if(atomic_mcpu(v) > maxgomaxprocs)
@@ -818,6 +825,10 @@ schedule(G *gp)
// Compensate for increment in starttheworld().
runtime·sched.grunning--;
m->helpgc = 0;
+ } else if(m->nextg != nil) {
+ // New m started by matchmg.
+ } else {
+ runtime·throw("invalid m state in scheduler");
}
// Find (or wait for) g to run. Unlocks runtime·sched.