summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGHC GitLab CI <ghc-ci@gitlab-haskell.org>2020-09-18 13:19:34 +0000
committerBen Gamari <ben@well-typed.com>2020-12-01 12:48:54 -0500
commit0ea9a980ce452f34259880e060986b5b5a68f0eb (patch)
tree5f7b464a642fab9fa0bd062226de704783686ce7
parentf9480f502a09e8d727ae90b0614a67fd2d4ee2dd (diff)
downloadhaskell-0ea9a980ce452f34259880e060986b5b5a68f0eb.tar.gz
rts: Fix race in GC CPU time accounting
Ensure that the GC leader synchronizes with workers before calling stat_endGC.
-rw-r--r--rts/sm/GC.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index 9e94a13a7b..6d9a3e64d7 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -1300,10 +1300,13 @@ gcWorkerThread (Capability *cap)
// Wait until we're told to continue
RELEASE_SPIN_LOCK(&gct->gc_spin);
- SEQ_CST_STORE(&gct->wakeup, GC_THREAD_WAITING_TO_CONTINUE);
debugTrace(DEBUG_gc, "GC thread %d waiting to continue...",
gct->thread_index);
stat_endGCWorker (cap, gct);
+ // This must come *after* stat_endGCWorker since it serves to
+ // synchronize us with the GC leader, which will later aggregate the
+ // GC statistics.
+ SEQ_CST_STORE(&gct->wakeup, GC_THREAD_WAITING_TO_CONTINUE);
ACQUIRE_SPIN_LOCK(&gct->mut_spin);
debugTrace(DEBUG_gc, "GC thread %d on my way...", gct->thread_index);
@@ -1395,10 +1398,10 @@ wakeup_gc_threads (uint32_t me USED_IF_THREADS,
if (i == me || idle_cap[i]) continue;
inc_running();
debugTrace(DEBUG_gc, "waking up gc thread %d", i);
- if (RELAXED_LOAD(&gc_threads[i]->wakeup) != GC_THREAD_STANDING_BY)
+ if (SEQ_CST_LOAD(&gc_threads[i]->wakeup) != GC_THREAD_STANDING_BY)
barf("wakeup_gc_threads");
- RELAXED_STORE(&gc_threads[i]->wakeup, GC_THREAD_RUNNING);
+ SEQ_CST_STORE(&gc_threads[i]->wakeup, GC_THREAD_RUNNING);
ACQUIRE_SPIN_LOCK(&gc_threads[i]->mut_spin);
RELEASE_SPIN_LOCK(&gc_threads[i]->gc_spin);
}