This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thread-safe profiling


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]