Commit 1d7faf91 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: minor changes

to minimize diffs of new scheduler

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7381048
parent 4434212f
......@@ -239,6 +239,8 @@ runtime·main(void)
// by calling runtime.LockOSThread during initialization
// to preserve the lock.
runtime·lockOSThread();
if(m != &runtime·m0)
runtime·throw("runtime·main not on m0");
// From now on, newgoroutines may use non-main threads.
setmcpumax(runtime·gomaxprocs);
runtime·sched.init = true;
......@@ -672,6 +674,7 @@ runtime·gcprocs(void)
// Figure out how many CPUs to use during GC.
// Limited by gomaxprocs, number of actual CPUs, and MaxGcproc.
runtime·lock(&runtime·sched);
n = runtime·gomaxprocs;
if(n > runtime·ncpu)
n = runtime·ncpu;
......@@ -679,9 +682,26 @@ runtime·gcprocs(void)
n = MaxGcproc;
if(n > runtime·sched.mwait+1) // one M is currently running
n = runtime·sched.mwait+1;
runtime·unlock(&runtime·sched);
return n;
}
static bool
needaddgcproc(void)
{
int32 n;
runtime·lock(&runtime·sched);
n = runtime·gomaxprocs;
if(n > runtime·ncpu)
n = runtime·ncpu;
if(n > MaxGcproc)
n = MaxGcproc;
n -= runtime·sched.mwait+1; // one M is currently running
runtime·unlock(&runtime·sched);
return n > 0;
}
void
runtime·helpgc(int32 nproc)
{
......@@ -740,20 +760,14 @@ void
runtime·starttheworld(void)
{
M *mp;
int32 max;
// Figure out how many CPUs GC could possibly use.
max = runtime·gomaxprocs;
if(max > runtime·ncpu)
max = runtime·ncpu;
if(max > MaxGcproc)
max = MaxGcproc;
bool add;
add = needaddgcproc();
schedlock();
runtime·gcwaiting = 0;
setmcpumax(runtime·gomaxprocs);
matchmg();
if(runtime·gcprocs() < max && canaddmcpu()) {
if(add && canaddmcpu()) {
// If GC could have used another helper proc, start one now,
// in the hope that it will be available next time.
// It would have been even better to start it before the collection,
......@@ -1171,9 +1185,8 @@ schedule(G *gp)
if(m->profilehz != hz)
runtime·resetcpuprofiler(hz);
if(gp->sched.pc == (byte*)runtime·goexit) { // kickoff
if(gp->sched.pc == (byte*)runtime·goexit) // kickoff
runtime·gogocallfn(&gp->sched, gp->fnstart);
}
runtime·gogo(&gp->sched, 0);
}
......@@ -1646,14 +1659,25 @@ runtime·mid(uint32 ret)
void
runtime·NumGoroutine(intgo ret)
{
ret = runtime·sched.gcount;
ret = runtime·gcount();
FLUSH(&ret);
}
int32
runtime·gcount(void)
{
return runtime·sched.gcount;
G *gp;
int32 n, s;
n = 0;
runtime·lock(&runtime·sched);
for(gp = runtime·allg; gp; gp = gp->alllink) {
s = gp->status;
if(s == Grunnable || s == Grunning || s == Gsyscall || s == Gwaiting)
n++;
}
runtime·unlock(&runtime·sched);
return n;
}
int32
......@@ -1687,6 +1711,8 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp)
{
int32 n;
if(m == nil || m->mcache == nil)
return;
if(prof.fn == nil || prof.hz == 0)
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment