2011-11-02 15:07:57 +00:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2011-10-27 20:22:46 +00:00
|
|
|
/*
|
2014-04-24 17:36:03 +00:00
|
|
|
* Copyright (c) 2011-2014 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2011-10-27 20:22:46 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(MCA_BTL_VADER_FBOX_H)
|
|
|
|
#define MCA_BTL_VADER_FBOX_H
|
|
|
|
|
|
|
|
#include "btl_vader.h"
|
|
|
|
#include "btl_vader_endpoint.h"
|
2013-07-11 20:54:12 +00:00
|
|
|
#include "btl_vader_xpmem.h"
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-07-11 20:54:12 +00:00
|
|
|
/* these hard-coded settings are based on the ideal setup for an Opteron 61xx chip and
|
|
|
|
* may need to be adjusted for other systems. adding an MCA variable is possible but
|
|
|
|
* can cost 20-40 ns on the fast path. this size is limited to 256 maximum bytes */
|
|
|
|
#define MCA_BTL_VADER_FBOX_SIZE 64
|
|
|
|
/* there should be a power of two number of fast boxes to simplify the math in the
|
|
|
|
* critical path */
|
|
|
|
#define MCA_BTL_VADER_LAST_FBOX 63
|
2014-04-24 17:36:03 +00:00
|
|
|
#define MCA_BTL_VADER_POLL_COUNT 31
|
2014-01-06 19:51:44 +00:00
|
|
|
/* two bytes are reserved for tag and size (update if the header is modified) */
|
2014-01-14 16:04:52 +00:00
|
|
|
#define MCA_BTL_VADER_FBOX_HDR_SIZE 4
|
2014-01-06 19:51:44 +00:00
|
|
|
#define MCA_BTL_VADER_FBOX_MAX_SIZE (MCA_BTL_VADER_FBOX_SIZE - MCA_BTL_VADER_FBOX_HDR_SIZE)
|
2013-07-11 20:54:12 +00:00
|
|
|
/* total size of all the fast boxes assigned to a particular peer */
|
|
|
|
#define MCA_BTL_VADER_FBOX_PEER_SIZE (MCA_BTL_VADER_FBOX_SIZE * (MCA_BTL_VADER_LAST_FBOX + 1))
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
typedef struct mca_btl_vader_fbox_t {
|
|
|
|
union {
|
|
|
|
struct {
|
2014-04-24 17:36:03 +00:00
|
|
|
uint8_t size;
|
|
|
|
uint8_t tag;
|
|
|
|
uint16_t seqn;
|
2014-01-06 19:51:44 +00:00
|
|
|
} hdr_data;
|
2014-01-14 16:04:52 +00:00
|
|
|
uint32_t ival;
|
2014-01-06 19:51:44 +00:00
|
|
|
} hdr;
|
|
|
|
|
|
|
|
uint8_t data[MCA_BTL_VADER_FBOX_MAX_SIZE];
|
|
|
|
} mca_btl_vader_fbox_t;
|
2013-07-11 20:54:12 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
#define MCA_BTL_VADER_FBOX_OUT_PTR(ep, fbox) ((ep)->fbox_out + (fbox))
|
|
|
|
#define MCA_BTL_VADER_FBOX_IN_PTR(ep, fbox) ((ep)->fbox_in + (fbox))
|
2013-07-11 20:54:12 +00:00
|
|
|
#define MCA_BTL_VADER_NEXT_FBOX(fbox) (((fbox) + 1) & MCA_BTL_VADER_LAST_FBOX)
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
static inline mca_btl_vader_fbox_t * restrict mca_btl_vader_reserve_fbox (struct mca_btl_base_endpoint_t *ep, const size_t size)
|
2011-10-27 20:22:46 +00:00
|
|
|
{
|
2013-07-11 20:54:12 +00:00
|
|
|
const int next_fbox = ep->next_fbox_out;
|
2014-01-06 19:51:44 +00:00
|
|
|
mca_btl_vader_fbox_t * restrict fbox = MCA_BTL_VADER_FBOX_OUT_PTR(ep, next_fbox);
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-04-24 17:36:03 +00:00
|
|
|
opal_atomic_mb ();
|
|
|
|
|
2012-02-22 20:53:49 +00:00
|
|
|
/* todo -- need thread locks/atomics here for the multi-threaded case */
|
2014-01-06 19:51:44 +00:00
|
|
|
if (OPAL_LIKELY(size <= MCA_BTL_VADER_FBOX_MAX_SIZE && 0 == fbox->hdr.ival)) {
|
2013-07-11 20:54:12 +00:00
|
|
|
/* mark this fast box as in use */
|
2014-01-06 19:51:44 +00:00
|
|
|
fbox->hdr.hdr_data.size = size;
|
2013-07-11 20:54:12 +00:00
|
|
|
ep->next_fbox_out = MCA_BTL_VADER_NEXT_FBOX(next_fbox);
|
2014-04-24 17:36:03 +00:00
|
|
|
opal_atomic_mb ();
|
2014-01-06 19:51:44 +00:00
|
|
|
return fbox;
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 20:54:12 +00:00
|
|
|
return NULL;
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
static inline void mca_btl_vader_fbox_send (mca_btl_vader_fbox_t * restrict fbox, unsigned char tag,
|
2014-04-24 17:36:03 +00:00
|
|
|
struct mca_btl_base_endpoint_t *endpoint)
|
2011-10-27 20:22:46 +00:00
|
|
|
{
|
|
|
|
/* ensure data writes have completed before we mark the data as available */
|
|
|
|
opal_atomic_wmb ();
|
2014-04-24 17:36:03 +00:00
|
|
|
fbox->hdr.hdr_data.seqn = endpoint->next_sequence++;
|
2014-01-06 19:51:44 +00:00
|
|
|
fbox->hdr.hdr_data.tag = tag;
|
2014-04-24 17:36:03 +00:00
|
|
|
opal_atomic_wmb ();
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mca_btl_vader_fbox_sendi (struct mca_btl_base_endpoint_t *endpoint, char tag,
|
2013-07-11 20:54:12 +00:00
|
|
|
void * restrict header, const size_t header_size,
|
|
|
|
void * restrict payload, const size_t payload_size)
|
2011-10-27 20:22:46 +00:00
|
|
|
{
|
2014-01-06 19:51:44 +00:00
|
|
|
mca_btl_vader_fbox_t * restrict fbox;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2013-03-27 22:10:02 +00:00
|
|
|
fbox = mca_btl_vader_reserve_fbox(endpoint, header_size + payload_size);
|
2012-02-23 16:29:45 +00:00
|
|
|
if (OPAL_UNLIKELY(NULL == fbox)) {
|
2011-11-02 15:07:57 +00:00
|
|
|
return 0;
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
memcpy (fbox->data, header, header_size);
|
|
|
|
if (payload) {
|
2011-11-02 15:07:57 +00:00
|
|
|
/* inline sends are typically just pml headers (due to MCA_BTL_FLAGS_SEND_INPLACE) */
|
2014-01-06 19:51:44 +00:00
|
|
|
memcpy (fbox->data + header_size, payload, payload_size);
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mark the fbox as sent */
|
2014-04-24 17:36:03 +00:00
|
|
|
mca_btl_vader_fbox_send (fbox, tag, endpoint);
|
2011-10-27 20:22:46 +00:00
|
|
|
|
|
|
|
/* send complete */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
static inline bool mca_btl_vader_check_fboxes (void)
|
2011-10-27 20:22:46 +00:00
|
|
|
{
|
2013-07-11 20:54:12 +00:00
|
|
|
const mca_btl_active_message_callback_t *reg;
|
2013-03-27 22:10:02 +00:00
|
|
|
struct mca_btl_base_endpoint_t *endpoint;
|
2014-01-06 19:51:44 +00:00
|
|
|
mca_btl_vader_fbox_t * restrict fbox;
|
|
|
|
mca_btl_base_segment_t segment;
|
|
|
|
mca_btl_base_descriptor_t desc;
|
|
|
|
bool processed = false;
|
|
|
|
int next_fbox;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
for (endpoint = mca_btl_vader_component.endpoints ; endpoint->peer_smp_rank != -1 ; ++endpoint) {
|
|
|
|
next_fbox = endpoint->next_fbox_in;
|
|
|
|
fbox = MCA_BTL_VADER_FBOX_IN_PTR(endpoint, next_fbox);
|
|
|
|
|
|
|
|
if (NULL == endpoint->fbox_in || 0 == fbox->hdr.hdr_data.tag) {
|
2011-11-02 15:07:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-07-10 16:31:15 +00:00
|
|
|
desc.des_local = &segment;
|
|
|
|
desc.des_local_count = 1;
|
2013-03-27 22:10:02 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
processed = true;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
/* process all fast-box messages */
|
2014-04-24 17:36:03 +00:00
|
|
|
for (int count = 0 ; count <= MCA_BTL_VADER_POLL_COUNT && 0 != fbox->hdr.hdr_data.tag ; ++count) {
|
|
|
|
if (OPAL_UNLIKELY(endpoint->expected_sequence != fbox->hdr.hdr_data.seqn)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
opal_atomic_mb ();
|
|
|
|
++endpoint->expected_sequence;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
reg = mca_btl_base_active_message_trigger + fbox->hdr.hdr_data.tag;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
segment.seg_addr.pval = fbox->data;
|
|
|
|
segment.seg_len = fbox->hdr.hdr_data.size;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-01-06 19:51:44 +00:00
|
|
|
reg->cbfunc(&mca_btl_vader.super, fbox->hdr.hdr_data.tag, &desc, reg->cbdata);
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-04-24 17:36:03 +00:00
|
|
|
if (segment.seg_len > MCA_BTL_VADER_FBOX_MAX_SIZE) {
|
2014-01-06 19:51:44 +00:00
|
|
|
fbox[1].hdr.ival = 0;
|
2014-04-24 17:36:03 +00:00
|
|
|
opal_atomic_mb ();
|
2013-07-11 20:54:12 +00:00
|
|
|
++next_fbox;
|
|
|
|
}
|
2014-01-06 19:51:44 +00:00
|
|
|
fbox->hdr.ival = 0;
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2013-07-11 20:54:12 +00:00
|
|
|
next_fbox = MCA_BTL_VADER_NEXT_FBOX(next_fbox);
|
2014-01-06 19:51:44 +00:00
|
|
|
fbox = (mca_btl_vader_fbox_t * restrict) MCA_BTL_VADER_FBOX_IN_PTR(endpoint, next_fbox);
|
2011-11-02 15:07:57 +00:00
|
|
|
}
|
2011-10-27 20:22:46 +00:00
|
|
|
|
2014-04-24 17:36:03 +00:00
|
|
|
opal_atomic_mb ();
|
|
|
|
|
2013-03-27 22:10:02 +00:00
|
|
|
endpoint->next_fbox_in = next_fbox;
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
2014-01-06 19:51:44 +00:00
|
|
|
|
|
|
|
return processed;
|
2011-10-27 20:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(MCA_BTL_VADER_FBOX_H) */
|