Commit 3bd0b0a8 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: fix SetBlockProfileRate

It doughtily misses all possible corner cases.
In particular on machines with <1GHz processors,
SetBlockProfileRate(1) disables profiling.
Fixes #6114.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/12936043
parent 2eb7c6ec
......@@ -295,7 +295,17 @@ int64 runtime·blockprofilerate; // in CPU ticks
void
runtime·SetBlockProfileRate(intgo rate)
{
runtime·atomicstore64((uint64*)&runtime·blockprofilerate, rate * runtime·tickspersecond() / (1000*1000*1000));
int64 r;
if(rate <= 0)
r = 0; // disable profiling
else {
// convert ns to cycles, use float64 to prevent overflow during multiplication
r = (float64)rate*runtime·tickspersecond()/(1000*1000*1000);
if(r == 0)
r = 1;
}
runtime·atomicstore64((uint64*)&runtime·blockprofilerate, r);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment