summaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-04 23:14:21 -0400
committerRuss Cox <rsc@golang.org>2014-09-04 23:14:21 -0400
commit1dba806d6a948976a2ecdb08a7c4839ff0a42766 (patch)
tree3ac8590a990be7b044213b95e3a40334745ad04e /src/pkg
parent566ae3b86ade8318c926b72d7c77bbbd975aa4bc (diff)
downloadgo-1dba806d6a948976a2ecdb08a7c4839ff0a42766.tar.gz
runtime: use cas loop to coordinate with sigprof
sigprof and setcpuprofilerate coordinate the enabling/disabling of the handler using a Mutex. This has always been a bit dodgy: setcpuprofilerate must be careful to turn off signals before acquiring the lock to avoid a deadlock. Now the lock implementations use onM, and onM isn't okay on the signal stack. We know how to make it okay, but it's more work than is probably worth doing. Since this is super-dodgy anyway, replace the lock with a simple cas loop. It is only contended if setcpuprofilerate is being called, and that doesn't happen frequently enough to care about the raw speed or about using futexes/semaphores. TBR to fix freebsd/amd64 and dragonfly/amd64 builds. Happy to make changes in a follow-up CL. TBR=dvyukov CC=golang-codereviews https://codereview.appspot.com/141080044
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/runtime/proc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c
index 3c5e244a9..56c35c5a4 100644
--- a/src/pkg/runtime/proc.c
+++ b/src/pkg/runtime/proc.c
@@ -2630,7 +2630,7 @@ runtime·badreflectcall(void) // called from assembly
}
static struct {
- Mutex lock;
+ uint32 lock;
int32 hz;
} prof;
@@ -2774,10 +2774,12 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
}
if(prof.hz != 0) {
- runtime·lock(&prof.lock);
+ // Simple cas-lock to coordinate with setcpuprofilerate.
+ while(!runtime·cas(&prof.lock, 0, 1))
+ runtime·osyield();
if(prof.hz != 0)
runtime·cpuproftick(stk, n);
- runtime·unlock(&prof.lock);
+ runtime·atomicstore(&prof.lock, 0);
}
mp->mallocing--;
}
@@ -2804,9 +2806,11 @@ runtime·setcpuprofilerate_m(void)
// it would deadlock.
runtime·resetcpuprofiler(0);
- runtime·lock(&prof.lock);
+ while(!runtime·cas(&prof.lock, 0, 1))
+ runtime·osyield();
prof.hz = hz;
- runtime·unlock(&prof.lock);
+ runtime·atomicstore(&prof.lock, 0);
+
runtime·lock(&runtime·sched.lock);
runtime·sched.profilehz = hz;
runtime·unlock(&runtime·sched.lock);