diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-06-25 14:50:10 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-08-19 03:49:06 +0000 |
commit | bd519d0c8734c3e30cb1a8b8217dd9934cd61e25 (patch) | |
tree | d90268bb3f95512ba2039deeea6a2c0b53a9f1de /src/runtime/signal_unix.go | |
parent | 31da1d993a498acefcf3dd5fdfbefa8eec132791 (diff) | |
download | go-bd519d0c8734c3e30cb1a8b8217dd9934cd61e25.tar.gz go-bd519d0c8734c3e30cb1a8b8217dd9934cd61e25.zip |
runtime: don't call setitimer for each thread
Previously, on Unix systems, when the profiler was enabled or disabled,
we called setitimer once per thread. With this change we instead call
it once per process.
Change-Id: I90f0189b562e11232816390dc7d55ed154bd836d
Reviewed-on: https://go-review.googlesource.com/c/go/+/240003
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/signal_unix.go')
-rw-r--r-- | src/runtime/signal_unix.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 6a11c91fb9..064a0ea100 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -272,6 +272,12 @@ func setProcessCPUProfiler(hz int32) { atomic.Storeuintptr(&fwdSig[_SIGPROF], getsig(_SIGPROF)) setsig(_SIGPROF, funcPC(sighandler)) } + + var it itimerval + it.it_interval.tv_sec = 0 + it.it_interval.set_usec(1000000 / hz) + it.it_value = it.it_interval + setitimer(_ITIMER_PROF, &it, nil) } else { // If the Go signal handler should be disabled by default, // switch back to the signal handler that was installed @@ -296,23 +302,16 @@ func setProcessCPUProfiler(hz int32) { setsig(_SIGPROF, h) } } + + setitimer(_ITIMER_PROF, &itimerval{}, nil) } } // setThreadCPUProfiler makes any thread-specific changes required to // implement profiling at a rate of hz. +// No changes required on Unix systems. func setThreadCPUProfiler(hz int32) { - var it itimerval - if hz == 0 { - setitimer(_ITIMER_PROF, &it, nil) - } else { - it.it_interval.tv_sec = 0 - it.it_interval.set_usec(1000000 / hz) - it.it_value = it.it_interval - setitimer(_ITIMER_PROF, &it, nil) - } - _g_ := getg() - _g_.m.profilehz = hz + getg().m.profilehz = hz } func sigpipe() { |