From e43320ddc3a316e3410d6dde56062cf8968ea284 Mon Sep 17 00:00:00 2001
From: Nathan Hjelm <hjelmn@lanl.gov>
Date: Tue, 2 Oct 2018 15:52:45 -0600
Subject: [PATCH 38/52] btl/vader: ensure the fast box tag is always read first
On some platfoms reading a 64-bit value is non-atomic and it is
possible that the two 32-bit values are read in the wrong order. To
ensure the tag is always read first this commit reads the tag before
reading the full 64-bit value.
Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
(cherry picked from commit 66a7dc4c72cb25df67e7f872bee7a20b5fa9c763)
---
opal/mca/btl/vader/btl_vader_fbox.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/opal/mca/btl/vader/btl_vader_fbox.h b/opal/mca/btl/vader/btl_vader_fbox.h
index df1fb92..6df9a2d 100644
--- a/opal/mca/btl/vader/btl_vader_fbox.h
+++ b/opal/mca/btl/vader/btl_vader_fbox.h
@@ -56,6 +56,16 @@ static inline void mca_btl_vader_fbox_set_header (mca_btl_vader_fbox_hdr_t *hdr,
hdr->data.tag = tag;
}
+static inline mca_btl_vader_fbox_hdr_t mca_btl_vader_fbox_read_header (mca_btl_vader_fbox_hdr_t *hdr)
+{
+ mca_btl_vader_fbox_hdr_t tmp;
+ uint16_t tag = hdr->data.tag;
+ opal_atomic_rmb ();
+ tmp.ival = hdr->ival;
+ tmp.data.tag = tag;
+ return tmp;
+}
+
/* attempt to reserve a contiguous segment from the remote ep */
static inline bool mca_btl_vader_fbox_sendi (mca_btl_base_endpoint_t *ep, unsigned char tag,
void * restrict header, const size_t header_size,
@@ -175,7 +185,7 @@ static inline bool mca_btl_vader_check_fboxes (void)
int poll_count;
for (poll_count = 0 ; poll_count <= MCA_BTL_VADER_POLL_COUNT ; ++poll_count) {
- const mca_btl_vader_fbox_hdr_t hdr = {.ival = MCA_BTL_VADER_FBOX_HDR(ep->fbox_in.buffer + start)->ival};
+ const mca_btl_vader_fbox_hdr_t hdr = mca_btl_vader_fbox_read_header (MCA_BTL_VADER_FBOX_HDR(ep->fbox_in.buffer + start));
/* check for a valid tag a sequence number */
if (0 == hdr.data.tag || hdr.data.seq != ep->fbox_in.seq) {
--
1.8.3.1