]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Fix up struct gomp_work_share handling [PR102838]
authorTobias Burnus <tobias@codesourcery.com>
Wed, 20 Oct 2021 08:33:40 +0000 (10:33 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 20 Oct 2021 08:33:40 +0000 (10:33 +0200)
commit5fd5e23b2cb4cfc2a455ab2e55f2a84346a192a8
treeab8bbf64bff65b003158a05fdbdb7fcba6dd1504
parente60643bfd7e63a3a853839c667c5fce348b6deb9
openmp: Fix up struct gomp_work_share handling [PR102838]

If GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is not defined, the intent was to
treat the split of the structure between first cacheline (64 bytes)
as mostly write-once, use afterwards and second cacheline as rw just
as an optimization.  But as has been reported, with vectorization enabled
at -O2 it can now result in aligned vector 16-byte or larger stores.
When not having posix_memalign/aligned_alloc/memalign or other similar API,
alloc.c emulates it but it needs to allocate extra memory for the dynamic
realignment.
So, for the GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC not defined case, this patch
stops using aligned (64) attribute in the middle of the structure and instead
inserts padding that puts the second half of the structure at offset 64 bytes.

And when GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is defined, usually it was allocated
as aligned, but for the orphaned case it could still be allocated just with
gomp_malloc without guaranteed proper alignment.

2021-10-20  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/102838
* libgomp.h (struct gomp_work_share_1st_cacheline): New type.
(struct gomp_work_share): Only use aligned(64) attribute if
GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is defined, otherwise just
add padding before lock to ensure lock is at offset 64 bytes
into the structure.
(gomp_workshare_struct_check1, gomp_workshare_struct_check2):
New poor man's static assertions.
* work.c (gomp_work_share_start): Use gomp_aligned_alloc instead of
gomp_malloc if GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC.

(cherry picked from commit c7abdf46fb7ac9a0c37f120feff3fcc3a752584f)
libgomp/ChangeLog.omp
libgomp/libgomp.h
libgomp/work.c