From: Dmitriy Vyukov Date: Wed, 31 Jul 2013 16:09:03 +0000 (+0400) Subject: runtime: do not park sysmon thread if any goroutines are running X-Git-Tag: go1.2rc2~866 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=658d19a53f26865549653fb16f80a47ae552b4f0;p=gostls13.git runtime: do not park sysmon thread if any goroutines are running Sysmon thread parks if no goroutines are running (runtime.sched.npidle == runtime.gomaxprocs). Currently it's unparked when a goroutine enters syscall, it was enough to retake P's from blocking syscalls. But it's not enough for reliable goroutine preemption. We need to ensure that sysmon runs if any goroutines are running. R=rsc CC=golang-dev https://golang.org/cl/12176043 --- diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index c4b8c02517..c3af1efaf3 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -1536,6 +1536,10 @@ exitsyscallfast(void) if(runtime·sched.pidle) { runtime·lock(&runtime·sched); p = pidleget(); + if(p && runtime·atomicload(&runtime·sched.sysmonwait)) { + runtime·atomicstore(&runtime·sched.sysmonwait, 0); + runtime·notewakeup(&runtime·sched.sysmonnote); + } runtime·unlock(&runtime·sched); if(p) { acquirep(p); @@ -1559,6 +1563,10 @@ exitsyscall0(G *gp) p = pidleget(); if(p == nil) globrunqput(gp); + else if(runtime·atomicload(&runtime·sched.sysmonwait)) { + runtime·atomicstore(&runtime·sched.sysmonwait, 0); + runtime·notewakeup(&runtime·sched.sysmonnote); + } runtime·unlock(&runtime·sched); if(p) { acquirep(p);