Skip to content

Commit 2a7e191

Browse files
committed
opal/fifo: if available use load-linked store-conditional
These instructions allow a more efficient implementation of the opal_fifo_pop_atomic function. Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent 6a19a10 commit 2a7e191

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

opal/class/opal_fifo.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo)
216216
{
217217
opal_list_item_t *item, *next;
218218

219+
#if OPAL_HAVE_ATOMIC_LLSC_PTR
220+
/* use load-linked store-conditional to avoid ABA issues */
221+
do {
222+
item = opal_atomic_ll_ptr (&fifo->opal_fifo_head.data.item);
223+
if (&fifo->opal_fifo_ghost == item) {
224+
if (&fifo->opal_fifo_ghost == fifo->opal_fifo_tail.data.item) {
225+
return NULL;
226+
}
227+
228+
/* fifo does not appear empty. wait for the fifo to be made
229+
* consistent by conflicting thread. */
230+
continue;
231+
}
232+
233+
next = (opal_list_item_t *) item->opal_list_next;
234+
if (opal_atomic_sc_ptr (&fifo->opal_fifo_head.data.item, next)) {
235+
break;
236+
}
237+
} while (1);
238+
#else
239+
/* protect against ABA issues by "locking" the head */
219240
do {
220241
if (opal_atomic_cmpset_32 ((int32_t *) &fifo->opal_fifo_head.data.counter, 0, 1)) {
221242
break;
@@ -234,6 +255,7 @@ static inline opal_list_item_t *opal_fifo_pop_atomic (opal_fifo_t *fifo)
234255

235256
next = (opal_list_item_t *) item->opal_list_next;
236257
fifo->opal_fifo_head.data.item = next;
258+
#endif
237259

238260
if (&fifo->opal_fifo_ghost == next) {
239261
if (!opal_atomic_cmpset_ptr (&fifo->opal_fifo_tail.data.item, item, &fifo->opal_fifo_ghost)) {

0 commit comments

Comments
 (0)