[Openmp-commits] [openmp] [OpenMP] Use a memory fence before incrementing the dispatch buffer index (PR #87995)

Xing Xue via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 8 07:11:19 PDT 2024


https://github.com/xingxue-ibm created https://github.com/llvm/llvm-project/pull/87995

This patch uses a memory fence in function `__kmp_dispatch_next()` to flush pending memory write invalidates before incrementing the `volatile` variable `buffer_index` to fix intermittent time-outs of OpenMP runtime LIT test cases `env/kmp_set_dispatch_buf.c` and `worksharing/for/kmp_set_dispatch_buf.c`, noting that the same is needed for incrementing `buffer_index` in function `__kmpc_next_section()` (line 2600 of `kmp_dispatch.cpp`).

>From 01b00f0d4dbdb60405a7c66874d6d010b1003fc7 Mon Sep 17 00:00:00 2001
From: Xing Xue <xingxue at outlook.com>
Date: Mon, 8 Apr 2024 09:32:38 -0400
Subject: [PATCH] Use a memory fence before incrementing the dispatch buffer
 index.

---
 openmp/runtime/src/kmp_dispatch.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/openmp/runtime/src/kmp_dispatch.cpp b/openmp/runtime/src/kmp_dispatch.cpp
index ac85b2b3f2fcd4..fc333765118179 100644
--- a/openmp/runtime/src/kmp_dispatch.cpp
+++ b/openmp/runtime/src/kmp_dispatch.cpp
@@ -2397,6 +2397,8 @@ static int __kmp_dispatch_next(ident_t *loc, int gtid, kmp_int32 *p_last,
           sh->u.s.ordered_iteration = 0;
         }
 
+        KMP_MB(); /* Flush all pending memory write invalidates.  */
+
         sh->buffer_index += __kmp_dispatch_num_buffers;
         KD_TRACE(100, ("__kmp_dispatch_next: T#%d change buffer_index:%d\n",
                        gtid, sh->buffer_index));



More information about the Openmp-commits mailing list