This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR libgomp/66761 and PR libgomp/67303 (tsan warnings)
- From: "VandeVondele Joost" <joost dot vandevondele at mat dot ethz dot ch>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: "pinskia at gcc dot gnu dot org" <pinskia at gcc dot gnu dot org>, "jakub at gcc dot gnu dot org" <jakub at gcc dot gnu dot org>
- Date: Sat, 22 Aug 2015 10:36:45 +0000
- Subject: Fix PR libgomp/66761 and PR libgomp/67303 (tsan warnings)
- Authentication-results: sourceware.org; auth=none
The following fixes two warnings reported by tsan when running OMP'ed code. As suggested by Andrew Pinski in PR67303 for gomp_iter_guided_next, by employing a relaxed atomic load. The same pattern occurred a couple of more times, so fixed as well. I used the same approach for the warning in do_spin (PR66761), even though this is a different context.
Bootstrapped and regtested on x86_64-unknown-linux-gnu for trunk, and manually verified that the PR is fixed using a tsan compiled libgomp based on gcc-5.1.
OK for trunk ?
This applies without changes to the 5 branch, should I commit there as well ?
libgomp/ChangeLog:
2015-08-22 Joost VandeVondele <vondele@gnu.gcc.org>
PR libgomp/66761
PR libgomp/67303
* iter.c (gomp_iter_dynamic_next): Employ an atomic load.
(gomp_iter_guided_next): Idem.
* iter_ull.c (gomp_iter_ull_dynamic_next): Idem.
(gomp_iter_ull_guided_next): Idem.
* config/linux/wait.h (do_spin): Idem.
Index: libgomp/iter.c
===================================================================
--- libgomp/iter.c (revision 227094)
+++ libgomp/iter.c (working copy)
@@ -218,7 +218,7 @@ gomp_iter_dynamic_next (long *pstart, lo
}
}
- start = ws->next;
+ start = __atomic_load_n (&ws->next, MEMMODEL_RELAXED);
while (1)
{
long left = end - start;
@@ -301,7 +301,7 @@ gomp_iter_guided_next (long *pstart, lon
long start, end, nend, incr;
unsigned long chunk_size;
- start = ws->next;
+ start = __atomic_load_n (&ws->next, MEMMODEL_RELAXED);
end = ws->end;
incr = ws->incr;
chunk_size = ws->chunk_size;
Index: libgomp/iter_ull.c
===================================================================
--- libgomp/iter_ull.c (revision 227094)
+++ libgomp/iter_ull.c (working copy)
@@ -219,7 +219,7 @@ gomp_iter_ull_dynamic_next (gomp_ull *ps
}
}
- start = ws->next_ull;
+ start = __atomic_load_n (&ws->next_ull, MEMMODEL_RELAXED);
while (1)
{
gomp_ull left = end - start;
@@ -305,7 +305,7 @@ gomp_iter_ull_guided_next (gomp_ull *pst
gomp_ull start, end, nend, incr;
gomp_ull chunk_size;
- start = ws->next_ull;
+ start = __atomic_load_n (&ws->next_ull, MEMMODEL_RELAXED);
end = ws->end_ull;
incr = ws->incr_ull;
chunk_size = ws->chunk_size_ull;
Index: libgomp/config/linux/wait.h
===================================================================
--- libgomp/config/linux/wait.h (revision 227094)
+++ libgomp/config/linux/wait.h (working copy)
@@ -49,7 +49,8 @@ static inline int do_spin (int *addr, in
{
unsigned long long i, count = gomp_spin_count_var;
- if (__builtin_expect (gomp_managed_threads > gomp_available_cpus, 0))
+ if (__builtin_expect (__atomic_load_n (&gomp_managed_threads,
+ MEMMODEL_RELAXED) > gomp_available_cpus, 0))
count = gomp_throttled_spin_count_var;
for (i = 0; i < count; i++)
if (__builtin_expect (__atomic_load_n (addr, MEMMODEL_RELAXED) != val, 0))