From 658d19a53f26865549653fb16f80a47ae552b4f0 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Wed, 31 Jul 2013 20:09:03 +0400 Subject: [PATCH] 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 --- src/pkg/runtime/proc.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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); -- 2.48.1