Commit f195ae94 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: remove old preemption checks

runtime.gcwaiting checks are not needed anymore

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12934043
parent 67c79da8
...@@ -169,9 +169,6 @@ runtime·chansend(ChanType *t, Hchan *c, byte *ep, bool *pres, void *pc) ...@@ -169,9 +169,6 @@ runtime·chansend(ChanType *t, Hchan *c, byte *ep, bool *pres, void *pc)
return; // not reached return; // not reached
} }
if(runtime·gcwaiting)
runtime·gosched();
if(debug) { if(debug) {
runtime·printf("chansend: chan=%p; elem=", c); runtime·printf("chansend: chan=%p; elem=", c);
c->elemalg->print(c->elemsize, ep); c->elemalg->print(c->elemsize, ep);
...@@ -295,9 +292,6 @@ runtime·chanrecv(ChanType *t, Hchan* c, byte *ep, bool *selected, bool *receive ...@@ -295,9 +292,6 @@ runtime·chanrecv(ChanType *t, Hchan* c, byte *ep, bool *selected, bool *receive
G *gp; G *gp;
int64 t0; int64 t0;
if(runtime·gcwaiting)
runtime·gosched();
if(debug) if(debug)
runtime·printf("chanrecv: chan=%p\n", c); runtime·printf("chanrecv: chan=%p\n", c);
...@@ -860,8 +854,6 @@ selectgo(Select **selp) ...@@ -860,8 +854,6 @@ selectgo(Select **selp)
void *pc; void *pc;
sel = *selp; sel = *selp;
if(runtime·gcwaiting)
runtime·gosched();
if(debug) if(debug)
runtime·printf("select: sel=%p\n", sel); runtime·printf("select: sel=%p\n", sel);
...@@ -1260,9 +1252,6 @@ closechan(Hchan *c, void *pc) ...@@ -1260,9 +1252,6 @@ closechan(Hchan *c, void *pc)
if(c == nil) if(c == nil)
runtime·panicstring("close of nil channel"); runtime·panicstring("close of nil channel");
if(runtime·gcwaiting)
runtime·gosched();
runtime·lock(c); runtime·lock(c);
if(c->closed) { if(c->closed) {
runtime·unlock(c); runtime·unlock(c);
......
...@@ -1167,9 +1167,6 @@ runtime·mapaccess(MapType *t, Hmap *h, byte *ak, byte *av, bool *pres) ...@@ -1167,9 +1167,6 @@ runtime·mapaccess(MapType *t, Hmap *h, byte *ak, byte *av, bool *pres)
return; return;
} }
if(runtime·gcwaiting)
runtime·gosched();
res = hash_lookup(t, h, &ak); res = hash_lookup(t, h, &ak);
if(res != nil) { if(res != nil) {
...@@ -1277,9 +1274,6 @@ runtime·mapassign(MapType *t, Hmap *h, byte *ak, byte *av) ...@@ -1277,9 +1274,6 @@ runtime·mapassign(MapType *t, Hmap *h, byte *ak, byte *av)
if(h == nil) if(h == nil)
runtime·panicstring("assignment to entry in nil map"); runtime·panicstring("assignment to entry in nil map");
if(runtime·gcwaiting)
runtime·gosched();
if(av == nil) { if(av == nil) {
hash_remove(t, h, ak); hash_remove(t, h, ak);
} else { } else {
...@@ -1424,8 +1418,6 @@ runtime·mapiternext(struct hash_iter *it) ...@@ -1424,8 +1418,6 @@ runtime·mapiternext(struct hash_iter *it)
{ {
if(raceenabled) if(raceenabled)
runtime·racereadpc(it->h, runtime·getcallerpc(&it), runtime·mapiternext); runtime·racereadpc(it->h, runtime·getcallerpc(&it), runtime·mapiternext);
if(runtime·gcwaiting)
runtime·gosched();
hash_next(it); hash_next(it);
if(debug) { if(debug) {
......
...@@ -41,8 +41,6 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) ...@@ -41,8 +41,6 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag)
MSpan *s; MSpan *s;
MLink *v; MLink *v;
if(runtime·gcwaiting && g != m->g0 && m->locks == 0 && !(flag & FlagNoInvokeGC))
runtime·gosched();
if(size == 0) { if(size == 0) {
// All 0-length allocations use this pointer. // All 0-length allocations use this pointer.
// The language does not require the allocations to // The language does not require the allocations to
......
...@@ -46,6 +46,7 @@ struct Sched { ...@@ -46,6 +46,7 @@ struct Sched {
Lock gflock; Lock gflock;
G* gfree; G* gfree;
uint32 gcwaiting; // gc is waiting to run
int32 stopwait; int32 stopwait;
Note stopnote; Note stopnote;
uint32 sysmonwait; uint32 sysmonwait;
...@@ -63,7 +64,6 @@ Sched runtime·sched; ...@@ -63,7 +64,6 @@ Sched runtime·sched;
int32 runtime·gomaxprocs; int32 runtime·gomaxprocs;
uint32 runtime·needextram; uint32 runtime·needextram;
bool runtime·iscgo; bool runtime·iscgo;
uint32 runtime·gcwaiting;
M runtime·m0; M runtime·m0;
G runtime·g0; // idle goroutine for m0 G runtime·g0; // idle goroutine for m0
G* runtime·allg; G* runtime·allg;
...@@ -391,7 +391,7 @@ runtime·freezetheworld(void) ...@@ -391,7 +391,7 @@ runtime·freezetheworld(void)
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
// this should tell the scheduler to not start any new goroutines // this should tell the scheduler to not start any new goroutines
runtime·sched.stopwait = 0x7fffffff; runtime·sched.stopwait = 0x7fffffff;
runtime·atomicstore((uint32*)&runtime·gcwaiting, 1); runtime·atomicstore((uint32*)&runtime·sched.gcwaiting, 1);
// this should stop running goroutines // this should stop running goroutines
if(!preemptall()) if(!preemptall())
break; // no running goroutines break; // no running goroutines
...@@ -413,7 +413,7 @@ runtime·stoptheworld(void) ...@@ -413,7 +413,7 @@ runtime·stoptheworld(void)
runtime·lock(&runtime·sched); runtime·lock(&runtime·sched);
runtime·sched.stopwait = runtime·gomaxprocs; runtime·sched.stopwait = runtime·gomaxprocs;
runtime·atomicstore((uint32*)&runtime·gcwaiting, 1); runtime·atomicstore((uint32*)&runtime·sched.gcwaiting, 1);
preemptall(); preemptall();
// stop current P // stop current P
m->p->status = Pgcstop; m->p->status = Pgcstop;
...@@ -477,7 +477,7 @@ runtime·starttheworld(void) ...@@ -477,7 +477,7 @@ runtime·starttheworld(void)
newprocs = 0; newprocs = 0;
} else } else
procresize(runtime·gomaxprocs); procresize(runtime·gomaxprocs);
runtime·gcwaiting = 0; runtime·sched.gcwaiting = 0;
p1 = nil; p1 = nil;
while(p = pidleget()) { while(p = pidleget()) {
...@@ -971,7 +971,7 @@ handoffp(P *p) ...@@ -971,7 +971,7 @@ handoffp(P *p)
return; return;
} }
runtime·lock(&runtime·sched); runtime·lock(&runtime·sched);
if(runtime·gcwaiting) { if(runtime·sched.gcwaiting) {
p->status = Pgcstop; p->status = Pgcstop;
if(--runtime·sched.stopwait == 0) if(--runtime·sched.stopwait == 0)
runtime·notewakeup(&runtime·sched.stopnote); runtime·notewakeup(&runtime·sched.stopnote);
...@@ -1056,7 +1056,7 @@ gcstopm(void) ...@@ -1056,7 +1056,7 @@ gcstopm(void)
{ {
P *p; P *p;
if(!runtime·gcwaiting) if(!runtime·sched.gcwaiting)
runtime·throw("gcstopm: not waiting for gc"); runtime·throw("gcstopm: not waiting for gc");
if(m->spinning) { if(m->spinning) {
m->spinning = false; m->spinning = false;
...@@ -1107,7 +1107,7 @@ findrunnable(void) ...@@ -1107,7 +1107,7 @@ findrunnable(void)
int32 i; int32 i;
top: top:
if(runtime·gcwaiting) { if(runtime·sched.gcwaiting) {
gcstopm(); gcstopm();
goto top; goto top;
} }
...@@ -1141,7 +1141,7 @@ top: ...@@ -1141,7 +1141,7 @@ top:
} }
// random steal from other P's // random steal from other P's
for(i = 0; i < 2*runtime·gomaxprocs; i++) { for(i = 0; i < 2*runtime·gomaxprocs; i++) {
if(runtime·gcwaiting) if(runtime·sched.gcwaiting)
goto top; goto top;
p = runtime·allp[runtime·fastrand1()%runtime·gomaxprocs]; p = runtime·allp[runtime·fastrand1()%runtime·gomaxprocs];
if(p == m->p) if(p == m->p)
...@@ -1154,7 +1154,7 @@ top: ...@@ -1154,7 +1154,7 @@ top:
stop: stop:
// return P and block // return P and block
runtime·lock(&runtime·sched); runtime·lock(&runtime·sched);
if(runtime·gcwaiting) { if(runtime·sched.gcwaiting) {
runtime·unlock(&runtime·sched); runtime·unlock(&runtime·sched);
goto top; goto top;
} }
...@@ -1263,7 +1263,7 @@ schedule(void) ...@@ -1263,7 +1263,7 @@ schedule(void)
runtime·throw("schedule: holding locks"); runtime·throw("schedule: holding locks");
top: top:
if(runtime·gcwaiting) { if(runtime·sched.gcwaiting) {
gcstopm(); gcstopm();
goto top; goto top;
} }
...@@ -1442,7 +1442,7 @@ void ...@@ -1442,7 +1442,7 @@ void
m->mcache = nil; m->mcache = nil;
m->p->m = nil; m->p->m = nil;
runtime·atomicstore(&m->p->status, Psyscall); runtime·atomicstore(&m->p->status, Psyscall);
if(runtime·gcwaiting) { if(runtime·sched.gcwaiting) {
runtime·lock(&runtime·sched); runtime·lock(&runtime·sched);
if (runtime·sched.stopwait > 0 && runtime·cas(&m->p->status, Psyscall, Pgcstop)) { if (runtime·sched.stopwait > 0 && runtime·cas(&m->p->status, Psyscall, Pgcstop)) {
if(--runtime·sched.stopwait == 0) if(--runtime·sched.stopwait == 0)
...@@ -2251,9 +2251,9 @@ sysmon(void) ...@@ -2251,9 +2251,9 @@ sysmon(void)
delay = 10*1000; delay = 10*1000;
runtime·usleep(delay); runtime·usleep(delay);
if(runtime·debug.schedtrace <= 0 && if(runtime·debug.schedtrace <= 0 &&
(runtime·gcwaiting || runtime·atomicload(&runtime·sched.npidle) == runtime·gomaxprocs)) { // TODO: fast atomic (runtime·sched.gcwaiting || runtime·atomicload(&runtime·sched.npidle) == runtime·gomaxprocs)) { // TODO: fast atomic
runtime·lock(&runtime·sched); runtime·lock(&runtime·sched);
if(runtime·atomicload(&runtime·gcwaiting) || runtime·atomicload(&runtime·sched.npidle) == runtime·gomaxprocs) { if(runtime·atomicload(&runtime·sched.gcwaiting) || runtime·atomicload(&runtime·sched.npidle) == runtime·gomaxprocs) {
runtime·atomicstore(&runtime·sched.sysmonwait, 1); runtime·atomicstore(&runtime·sched.sysmonwait, 1);
runtime·unlock(&runtime·sched); runtime·unlock(&runtime·sched);
runtime·notesleep(&runtime·sched.sysmonnote); runtime·notesleep(&runtime·sched.sysmonnote);
...@@ -2427,7 +2427,7 @@ runtime·schedtrace(bool detailed) ...@@ -2427,7 +2427,7 @@ runtime·schedtrace(bool detailed)
runtime·sched.nmidle, runtime·sched.runqsize); runtime·sched.nmidle, runtime·sched.runqsize);
if(detailed) { if(detailed) {
runtime·printf(" gcwaiting=%d nmidlelocked=%d nmspinning=%d stopwait=%d sysmonwait=%d\n", runtime·printf(" gcwaiting=%d nmidlelocked=%d nmspinning=%d stopwait=%d sysmonwait=%d\n",
runtime·gcwaiting, runtime·sched.nmidlelocked, runtime·sched.nmspinning, runtime·sched.gcwaiting, runtime·sched.nmidlelocked, runtime·sched.nmspinning,
runtime·sched.stopwait, runtime·sched.sysmonwait); runtime·sched.stopwait, runtime·sched.sysmonwait);
} }
// We must be careful while reading data from P's, M's and G's. // We must be careful while reading data from P's, M's and G's.
......
...@@ -704,7 +704,6 @@ extern P** runtime·allp; ...@@ -704,7 +704,6 @@ extern P** runtime·allp;
extern int32 runtime·gomaxprocs; extern int32 runtime·gomaxprocs;
extern uint32 runtime·needextram; extern uint32 runtime·needextram;
extern uint32 runtime·panicking; extern uint32 runtime·panicking;
extern uint32 runtime·gcwaiting; // gc is waiting to run
extern int8* runtime·goos; extern int8* runtime·goos;
extern int32 runtime·ncpu; extern int32 runtime·ncpu;
extern bool runtime·iscgo; extern bool runtime·iscgo;
......
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