Skip to content

RTS: Zero gc_cpu_start and gc_cpu_end after accounting

Matthew Pickering requested to merge wip/gc-stats-times into master

When passed a combination of -N and -qn options the cpu time for garbage collection was being vastly overcounted because the counters were not being zeroed appropiately.

When -qn1 is passed, only 1 of the N avaiable GC threads is chosen to perform work, the rest are idle. At the end of the GC period, stat_endGC traverses all the GC threads and adds up the elapsed time from each of them. For threads which didn't participate in this GC, the value of the cpu time should be zero, but before this patch, the counters were not zeroed and hence we would count the same elapsed time on many subsequent iterations (until the thread participated in a GC again).

The most direct way to zero these fields is to do so immediately after the value is added into the global counter, after which point they are never used again.

We also tried another approach where we would zero the counter in yieldCapability but there are some (undiagnosed) siations where a capbility would not pass through yieldCapability before the GC ended and the same double counting problem would occur.

Fixes #21082 (closed)

Merge request reports