]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: do not park sysmon thread if any goroutines are running
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 31 Jul 2013 16:09:03 +0000 (20:09 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 31 Jul 2013 16:09:03 +0000 (20:09 +0400)
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

src/pkg/runtime/proc.c

index c4b8c025173b26a3dfdfa3758a8ca4328f336148..c3af1efaf309197a86bb50080da55b1b943ee705 100644 (file)
@@ -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);