2011-11-02 15:07:57 +00:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2011-10-20 21:39:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2009 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2006-2007 Voltaire. All rights reserved.
|
|
|
|
* Copyright (c) 2009-2010 Cisco Systems, Inc. All rights reserved.
|
2014-01-29 18:35:47 +00:00
|
|
|
* Copyright (c) 2010-2014 Los Alamos National Security, LLC.
|
2011-10-20 21:39:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
#ifndef MCA_BTL_VADER_FIFO_H
|
|
|
|
#define MCA_BTL_VADER_FIFO_H
|
|
|
|
|
|
|
|
#include "btl_vader.h"
|
|
|
|
#include "btl_vader_endpoint.h"
|
|
|
|
#include "btl_vader_frag.h"
|
|
|
|
|
2014-01-29 18:35:47 +00:00
|
|
|
#if OPAL_HAVE_ATOMIC_MATH_64
|
|
|
|
#define vader_item_cmpset(x, y, z) opal_atomic_cmpset_64((volatile int64_t *)(x), (int64_t)(y), (int64_t)(z))
|
|
|
|
#define vader_item_swap(x, y) opal_atomic_swap_64((volatile int64_t *)(x), (int64_t)(y))
|
|
|
|
#else
|
|
|
|
#define vader_item_cmpset(x, y, z) opal_atomic_cmpset_32((volatile int32_t *)(x), (int32_t)(y), (int32_t)(z))
|
|
|
|
#define vader_item_swap(x, y) opal_atomic_swap_32((volatile int32_t *)(x), (int32_t)(y))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VADER_FIFO_FREE ((intptr_t)-2)
|
2012-02-22 18:32:40 +00:00
|
|
|
|
2011-10-20 21:39:44 +00:00
|
|
|
/*
|
|
|
|
* Shared Memory FIFOs
|
|
|
|
*
|
|
|
|
* The FIFO is implemented as a linked list of frag headers. The fifo has multiple
|
|
|
|
* producers and a single consumer (in the single thread case) so the tail needs
|
|
|
|
* to be modified by an atomic or protected by a atomic lock.
|
|
|
|
*
|
|
|
|
* Since the frags live in shared memory that is mapped differently into
|
|
|
|
* each address space, the head and tail pointers are relative (each process must
|
|
|
|
* add its own offset).
|
|
|
|
*
|
|
|
|
* We introduce some padding at the end of the structure but it is probably unnecessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* lock free fifo */
|
2012-03-15 20:12:59 +00:00
|
|
|
typedef struct vader_fifo_t {
|
2014-01-29 18:35:47 +00:00
|
|
|
volatile intptr_t fifo_head;
|
|
|
|
volatile intptr_t fifo_tail;
|
2012-03-15 20:12:59 +00:00
|
|
|
} vader_fifo_t;
|
2011-10-20 21:39:44 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
/* large enough to ensure the fifo is on its own cache line */
|
|
|
|
#define MCA_BTL_VADER_FIFO_SIZE 128
|
2013-07-11 20:54:12 +00:00
|
|
|
|
2012-02-22 18:32:40 +00:00
|
|
|
static inline mca_btl_vader_hdr_t *vader_fifo_read (vader_fifo_t *fifo)
|
2011-10-20 21:39:44 +00:00
|
|
|
{
|
|
|
|
mca_btl_vader_hdr_t *hdr;
|
2014-01-29 18:35:47 +00:00
|
|
|
intptr_t value;
|
2011-10-20 21:39:44 +00:00
|
|
|
|
|
|
|
opal_atomic_rmb ();
|
|
|
|
|
2014-01-29 18:35:47 +00:00
|
|
|
value = vader_item_swap (&fifo->fifo_head, VADER_FIFO_FREE);
|
2011-10-20 21:39:44 +00:00
|
|
|
if (VADER_FIFO_FREE == value) {
|
2011-11-02 15:07:57 +00:00
|
|
|
/* fifo is empty or we lost the race with another thread */
|
2012-02-22 18:32:40 +00:00
|
|
|
return NULL;
|
2011-10-20 21:39:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 22:10:02 +00:00
|
|
|
hdr = (mca_btl_vader_hdr_t *) relative2virtual (value);
|
|
|
|
|
|
|
|
assert (hdr->next != value);
|
2011-10-20 21:39:44 +00:00
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(VADER_FIFO_FREE == hdr->next)) {
|
2012-03-15 20:12:59 +00:00
|
|
|
opal_atomic_rmb();
|
|
|
|
|
2014-01-29 18:35:47 +00:00
|
|
|
if (!vader_item_cmpset (&fifo->fifo_tail, value, VADER_FIFO_FREE)) {
|
2011-11-02 15:07:57 +00:00
|
|
|
while (VADER_FIFO_FREE == hdr->next) {
|
|
|
|
opal_atomic_rmb ();
|
|
|
|
}
|
2011-10-20 21:39:44 +00:00
|
|
|
|
2011-11-02 15:07:57 +00:00
|
|
|
fifo->fifo_head = hdr->next;
|
|
|
|
}
|
2011-10-20 21:39:44 +00:00
|
|
|
} else {
|
2011-11-02 15:07:57 +00:00
|
|
|
fifo->fifo_head = hdr->next;
|
2011-10-20 21:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opal_atomic_wmb ();
|
|
|
|
|
2012-02-22 18:32:40 +00:00
|
|
|
return hdr;
|
2011-10-20 21:39:44 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
static inline int vader_fifo_init (vader_fifo_t *fifo)
|
|
|
|
{
|
|
|
|
fifo->fifo_head = fifo->fifo_tail = VADER_FIFO_FREE;
|
|
|
|
mca_btl_vader_component.my_fifo = fifo;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-01-29 18:35:47 +00:00
|
|
|
static inline void vader_fifo_write (vader_fifo_t *fifo, intptr_t value)
|
2014-01-06 19:51:44 +00:00
|
|
|
{
|
2014-01-29 18:35:47 +00:00
|
|
|
intptr_t prev;
|
2014-01-06 19:51:44 +00:00
|
|
|
|
|
|
|
opal_atomic_wmb ();
|
2014-01-29 18:35:47 +00:00
|
|
|
prev = vader_item_swap (&fifo->fifo_tail, value);
|
2014-01-06 19:51:44 +00:00
|
|
|
opal_atomic_rmb ();
|
|
|
|
|
|
|
|
assert (prev != value);
|
|
|
|
|
|
|
|
if (OPAL_LIKELY(VADER_FIFO_FREE != prev)) {
|
|
|
|
mca_btl_vader_hdr_t *hdr = (mca_btl_vader_hdr_t *) relative2virtual (prev);
|
|
|
|
hdr->next = value;
|
|
|
|
} else {
|
|
|
|
fifo->fifo_head = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
opal_atomic_wmb ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write a frag (relative to this process' base) to another rank's fifo */
|
|
|
|
static inline void vader_fifo_write_ep (mca_btl_vader_hdr_t *hdr, struct mca_btl_base_endpoint_t *ep)
|
|
|
|
{
|
|
|
|
hdr->next = VADER_FIFO_FREE;
|
|
|
|
vader_fifo_write (ep->fifo, virtual2relative ((char *) hdr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write a frag (relative to the remote process' base) to the remote fifo. note the remote peer must own hdr */
|
|
|
|
static inline void vader_fifo_write_back (mca_btl_vader_hdr_t *hdr, struct mca_btl_base_endpoint_t *ep)
|
|
|
|
{
|
|
|
|
hdr->next = VADER_FIFO_FREE;
|
|
|
|
vader_fifo_write(ep->fifo, virtual2relativepeer (ep, (char *) hdr));
|
|
|
|
}
|
|
|
|
|
2011-10-20 21:39:44 +00:00
|
|
|
#endif /* MCA_BTL_VADER_FIFO_H */
|