Thread-safe profiling

Michael Matz matz@suse.de
Thu Mar 15 16:11:00 GMT 2007


Hi,

On Thu, 15 Mar 2007, Ian Lance Taylor wrote:

> > Trying to imagine what random user would find more discourgrating - ie 
> > longer train runs (still probably quite shorter than in ICC) or weird 
> > looking mismatches and/or wrong resulting profile, I guess the former 
> > is lesser evil and easier to analyze.
> 
> It seems to me that the alternative to thread-safe profiling should just 
> be that some nodes are undercounted, when two threads try to update the 
> count simultaneously.

That is, what happens most of the time.  Except for some counter types, 
e.g. the one_value counter:

static inline void
__gcov_one_value_profiler_body (gcov_type *counters, gcov_type value)
{
  if (value == counters[0])
    counters[1]++;
  else if (counters[1] == 0)
    {
      counters[1] = 1;
      counters[0] = value;
    }
  else
    counters[1]--;
  counters[2]++;
}

Here, if multiple threads want to touch the same counter with different 
'value' arguments, it might happen that the first get's still into the 
second if body (setting counter[1] to 1, and counters[0] to the value) and 
all other threads get into the counters[1]-- operation.  In that case you 
might end up with negative (or better: very large positive) values in 
there, which I think are wildly wrong.

> It shouldn't be wildly wrong, just slightly wrong.


Ciao,
Michael.



More information about the Gcc-patches mailing list