Skip to content

Commit

Permalink
osc/rdma: use pointer to btl to replace btl_index in peer
Browse files Browse the repository at this point in the history
Currently, each peer keep a state_btl_index and a data_btl_index.
The btl_index is used to retrive btl used for data transfer and
state updating, by calling function mpi_osc_rdma_selected_btl().

This patch simplify the code by directly storing the pointer to
the btl inside peer, thus bypassing the call to
mpi_osc_rdma_selected_btl().

The function mpi_osc_rdma_selected_btl() is then removed.

Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
wzamazon committed Sep 27, 2021
1 parent 3c0ae03 commit 6c4cb75
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 62 deletions.
5 changes: 0 additions & 5 deletions ompi/mca/osc/rdma/osc_rdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,6 @@ static inline bool ompi_osc_rdma_oor (int rc)
return (OPAL_SUCCESS != rc && (OPAL_ERR_OUT_OF_RESOURCE == rc || OPAL_ERR_TEMP_OUT_OF_RESOURCE == rc));
}

__opal_attribute_always_inline__
static inline mca_btl_base_module_t *ompi_osc_rdma_selected_btl (ompi_osc_rdma_module_t *module, uint8_t btl_index) {
return module->selected_btls[btl_index];
}

__opal_attribute_always_inline__
static inline void ompi_osc_rdma_selected_btl_insert (ompi_osc_rdma_module_t *module, struct mca_btl_base_module_t *btl, uint8_t btl_index) {
if(btl_index == module->selected_btls_size) {
Expand Down
22 changes: 11 additions & 11 deletions ompi/mca/osc/rdma/osc_rdma_accumulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int ompi_osc_rdma_fetch_and_op_atomic (ompi_osc_rdma_sync_t *sync, const
mca_btl_base_registration_handle_t *target_handle, ompi_op_t *op, ompi_osc_rdma_request_t *req)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *selected_btl = peer->data_btl;
int32_t atomic_flags = selected_btl->btl_atomic_flags;
int btl_op, flags;
int64_t origin;
Expand All @@ -176,7 +176,7 @@ static int ompi_osc_rdma_fetch_and_op_atomic (ompi_osc_rdma_sync_t *sync, const

origin = (8 == extent) ? ((int64_t *) origin_addr)[0] : ((int32_t *) origin_addr)[0];

return ompi_osc_rdma_btl_fop (module, peer->data_btl_index, peer->data_endpoint, target_address, target_handle, btl_op, origin, flags,
return ompi_osc_rdma_btl_fop (module, peer->data_btl, peer->data_endpoint, target_address, target_handle, btl_op, origin, flags,
result_addr, true, NULL, NULL, NULL);
}

Expand All @@ -198,7 +198,7 @@ static int ompi_osc_rdma_fetch_and_op_cas (ompi_osc_rdma_sync_t *sync, const voi

OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "initiating fetch-and-op using compare-and-swap");

ret = ompi_osc_get_data_blocking (module, peer->data_btl_index, peer->data_endpoint, address, target_handle, &old_value, 8);
ret = ompi_osc_get_data_blocking (module, peer->data_btl, peer->data_endpoint, address, target_handle, &old_value, 8);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
}
Expand All @@ -213,7 +213,7 @@ static int ompi_osc_rdma_fetch_and_op_cas (ompi_osc_rdma_sync_t *sync, const voi
ompi_op_reduce (op, (void *) ((intptr_t) origin_addr + dt->super.true_lb), (void*)((intptr_t) &new_value + offset), 1, dt);
}

ret = ompi_osc_rdma_btl_cswap (module, peer->data_btl_index, peer->data_endpoint, address, target_handle,
ret = ompi_osc_rdma_btl_cswap (module, peer->data_btl, peer->data_endpoint, address, target_handle,
old_value, new_value, 0, (int64_t*)&new_value);
if (OPAL_SUCCESS != ret || new_value == old_value) {
break;
Expand All @@ -234,7 +234,7 @@ static int ompi_osc_rdma_acc_single_atomic (ompi_osc_rdma_sync_t *sync, const vo
ompi_op_t *op, ompi_osc_rdma_request_t *req)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *selected_btl = peer->data_btl;
int32_t atomic_flags = selected_btl->btl_atomic_flags;
int btl_op, flags;
int64_t origin;
Expand Down Expand Up @@ -262,7 +262,7 @@ static int ompi_osc_rdma_acc_single_atomic (ompi_osc_rdma_sync_t *sync, const vo
*((int64_t *) origin_addr));

/* if we locked the peer its best to wait for completion before returning */
return ompi_osc_rdma_btl_op (module, peer->data_btl_index, peer->data_endpoint, target_address, target_handle, btl_op, origin,
return ompi_osc_rdma_btl_op (module, peer->data_btl, peer->data_endpoint, target_address, target_handle, btl_op, origin,
flags, true, NULL, NULL, NULL);
}

Expand Down Expand Up @@ -375,7 +375,7 @@ static inline int ompi_osc_rdma_gacc_contig (ompi_osc_rdma_sync_t *sync, const v
/* set up the request */
request->to_free = ptr;

ret = ompi_osc_get_data_blocking (module, peer->data_btl_index, peer->data_endpoint,
ret = ompi_osc_get_data_blocking (module, peer->data_btl, peer->data_endpoint,
target_address, target_handle, ptr, len);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
Expand Down Expand Up @@ -661,7 +661,7 @@ static inline int ompi_osc_rdma_cas_atomic (ompi_osc_rdma_sync_t *sync, const vo
bool lock_acquired)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
int32_t atomic_flags = btl->btl_atomic_flags;
const size_t size = datatype->super.size;
int64_t compare, source;
Expand All @@ -679,7 +679,7 @@ static inline int ompi_osc_rdma_cas_atomic (ompi_osc_rdma_sync_t *sync, const vo
OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "initiating compare-and-swap using %d-bit btl atomics. compare: 0x%"
PRIx64 ", origin: 0x%" PRIx64, (int) size * 8, *((int64_t *) compare_addr), *((int64_t *) source_addr));

ret = ompi_osc_rdma_btl_cswap (module, peer->data_btl_index, peer->data_endpoint, target_address, target_handle,
ret = ompi_osc_rdma_btl_cswap (module, peer->data_btl, peer->data_endpoint, target_address, target_handle,
compare, source, flags, result_addr);
if (OPAL_LIKELY(OMPI_SUCCESS == ret)) {
ompi_osc_rdma_peer_accumulate_cleanup (module, peer, lock_acquired);
Expand Down Expand Up @@ -715,7 +715,7 @@ static inline int cas_rdma (ompi_osc_rdma_sync_t *sync, const void *source_addr,
mca_btl_base_registration_handle_t *target_handle, bool lock_acquired)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
unsigned long len = datatype->super.size;
mca_btl_base_registration_handle_t *local_handle = NULL;
ompi_osc_rdma_frag_t *frag = NULL;
Expand All @@ -728,7 +728,7 @@ static inline int cas_rdma (ompi_osc_rdma_sync_t *sync, const void *source_addr,
", sync %p", len, target_address, (void *) sync);

OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "RDMA compare-and-swap initiating blocking btl get...");
ret = ompi_osc_get_data_blocking (module, peer->data_btl_index, peer->data_endpoint, target_address,
ret = ompi_osc_get_data_blocking (module, peer->data_btl, peer->data_endpoint, target_address,
target_handle, result_addr, len);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
return ret;
Expand Down
14 changes: 7 additions & 7 deletions ompi/mca/osc/rdma/osc_rdma_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ static void ompi_osc_get_data_complete (struct mca_btl_base_module_t *btl, struc
((bool *) context)[0] = true;
}

int ompi_osc_get_data_blocking (ompi_osc_rdma_module_t *module, uint8_t btl_index,
int ompi_osc_get_data_blocking (ompi_osc_rdma_module_t *module,
struct mca_btl_base_module_t *btl,
struct mca_btl_base_endpoint_t *endpoint, uint64_t source_address,
mca_btl_base_registration_handle_t *source_handle, void *data, size_t len)
{
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, btl_index);
const size_t btl_alignment_mask = ALIGNMENT_MASK(btl->btl_get_alignment);
mca_btl_base_registration_handle_t *local_handle = NULL;
ompi_osc_rdma_frag_t *frag = NULL;
Expand Down Expand Up @@ -444,7 +444,7 @@ static int ompi_osc_rdma_put_real (ompi_osc_rdma_sync_t *sync, ompi_osc_rdma_pee
mca_btl_base_registration_handle_t *local_handle, size_t size,
mca_btl_base_rdma_completion_fn_t cb, void *context, void *cbdata) {
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
int ret;

OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_TRACE, "initiating btl put of %lu bytes to remote address %" PRIx64 ", sync "
Expand Down Expand Up @@ -481,7 +481,7 @@ int ompi_osc_rdma_put_contig (ompi_osc_rdma_sync_t *sync, ompi_osc_rdma_peer_t *
ompi_osc_rdma_request_t *request)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
mca_btl_base_registration_handle_t *local_handle = NULL;
mca_btl_base_rdma_completion_fn_t cbfunc = NULL;
ompi_osc_rdma_frag_t *frag = NULL;
Expand Down Expand Up @@ -600,7 +600,7 @@ static int ompi_osc_rdma_get_contig (ompi_osc_rdma_sync_t *sync, ompi_osc_rdma_p
ompi_osc_rdma_request_t *request)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
const size_t btl_alignment_mask = ALIGNMENT_MASK(btl->btl_get_alignment);
mca_btl_base_registration_handle_t *local_handle = NULL;
ompi_osc_rdma_frag_t *frag = NULL;
Expand Down Expand Up @@ -736,7 +736,7 @@ static inline int ompi_osc_rdma_put_w_req (ompi_osc_rdma_sync_t *sync, const voi
ompi_datatype_t *target_datatype, ompi_osc_rdma_request_t *request)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
mca_btl_base_registration_handle_t *target_handle;
uint64_t target_address;
int ret;
Expand Down Expand Up @@ -779,7 +779,7 @@ static inline int ompi_osc_rdma_get_w_req (ompi_osc_rdma_sync_t *sync, void *ori
ompi_datatype_t *source_datatype, ompi_osc_rdma_request_t *request)
{
ompi_osc_rdma_module_t *module = sync->module;
mca_btl_base_module_t *btl = ompi_osc_rdma_selected_btl (module, peer->data_btl_index);
mca_btl_base_module_t *btl = peer->data_btl;
mca_btl_base_registration_handle_t *source_handle;
uint64_t source_address;
ptrdiff_t source_span, source_lb;
Expand Down
4 changes: 3 additions & 1 deletion ompi/mca/osc/rdma/osc_rdma_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ int ompi_osc_rdma_rget (void *origin_addr, int origin_count, ompi_datatype_t *or
* @brief read data from a remote memory region (blocking)
*
* @param[in] module osc rdma module
* @param[in] btl btl module
* @param[in] endpoint btl endpoint
* @param[in] source_address remote address to read from
* @param[in] source_handle btl registration handle for remote region (must be valid for the entire region)
Expand All @@ -113,7 +114,8 @@ int ompi_osc_rdma_rget (void *origin_addr, int origin_count, ompi_datatype_t *or
* data that is stored on the remote peer. The peer object does not have to be fully initialized to
* work. Only the btl endpoint is needed.
*/
int ompi_osc_get_data_blocking (ompi_osc_rdma_module_t *module, uint8_t btl_index,
int ompi_osc_get_data_blocking (ompi_osc_rdma_module_t *module,
struct mca_btl_base_module_t *btl,
struct mca_btl_base_endpoint_t *endpoint, uint64_t source_address,
mca_btl_base_registration_handle_t *source_handle,
void *data, size_t len);
Expand Down
10 changes: 5 additions & 5 deletions ompi/mca/osc/rdma/osc_rdma_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static int allocate_state_single (ompi_osc_rdma_module_t *module, void **base, s
} else {
/* use my endpoint handle to modify the peer's state */
my_peer->state_handle = module->state_handle;
my_peer->state_btl_index = my_peer->data_btl_index;
my_peer->state_btl = my_peer->data_btl;
my_peer->state_endpoint = my_peer->data_endpoint;
}

Expand Down Expand Up @@ -845,17 +845,17 @@ static int allocate_state_shared (ompi_osc_rdma_module_t *module, void **base, s
peer->state = (osc_rdma_counter_t) ((uintptr_t) state_region->base + state_base + module->state_size * i);
if (i==0) {
peer->state_endpoint = peer->data_endpoint;
peer->state_btl_index = peer->data_btl_index;
peer->state_btl = peer->data_btl;
} else {
peer->state_endpoint = local_leader->state_endpoint;
peer->state_btl_index = local_leader->state_btl_index;
peer->state_btl = local_leader->state_btl;
}
} else {
assert (!module->use_memory_registration);
assert (NULL != module->peer_state_array);
peer->state = (osc_rdma_counter_t)module->peer_state_array[peer_rank];
peer->state_endpoint = peer->data_endpoint;
peer->state_btl_index = peer->data_btl_index;
peer->state_btl = peer->data_btl;
}
}

Expand All @@ -867,7 +867,7 @@ static int allocate_state_shared (ompi_osc_rdma_module_t *module, void **base, s
!module->use_cpu_atomics && temp[i].size && i > 0) {
/* use the local leader's endpoint */
peer->data_endpoint = local_leader->data_endpoint;
peer->data_btl_index = local_leader->data_btl_index;
peer->data_btl = local_leader->data_btl;
}

ompi_osc_module_add_peer (module, peer);
Expand Down
4 changes: 2 additions & 2 deletions ompi/mca/osc/rdma/osc_rdma_dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int ompi_osc_rdma_refresh_dynamic_region (ompi_osc_rdma_module_t *module,
osc_rdma_counter_t remote_value;

source_address = (uint64_t)(intptr_t) peer->super.state + offsetof (ompi_osc_rdma_state_t, region_count);
ret = ompi_osc_get_data_blocking (module, peer->super.state_btl_index, peer->super.state_endpoint,
ret = ompi_osc_get_data_blocking (module, peer->super.state_btl, peer->super.state_endpoint,
source_address, peer->super.state_handle, &remote_value,
sizeof (remote_value));
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
Expand Down Expand Up @@ -433,7 +433,7 @@ static int ompi_osc_rdma_refresh_dynamic_region (ompi_osc_rdma_module_t *module,
OMPI_OSC_RDMA_LOCK_EXCLUSIVE);

source_address = (uint64_t)(intptr_t) peer->super.state + offsetof (ompi_osc_rdma_state_t, regions);
ret = ompi_osc_get_data_blocking (module, peer->super.state_btl_index, peer->super.state_endpoint,
ret = ompi_osc_get_data_blocking (module, peer->super.state_btl, peer->super.state_endpoint,
source_address, peer->super.state_handle, peer->regions, region_len);
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
OPAL_THREAD_UNLOCK(&module->lock);
Expand Down
20 changes: 10 additions & 10 deletions ompi/mca/osc/rdma/osc_rdma_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ void ompi_osc_rdma_atomic_complete (mca_btl_base_module_t *btl, struct mca_btl_b
void *context, void *data, int status);

__opal_attribute_always_inline__
static inline int ompi_osc_rdma_btl_fop (ompi_osc_rdma_module_t *module, uint8_t btl_index,
static inline int ompi_osc_rdma_btl_fop (ompi_osc_rdma_module_t *module,
struct mca_btl_base_module_t *selected_btl,
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
mca_btl_base_registration_handle_t *address_handle, int op,
int64_t operand, int flags, int64_t *result, const bool wait_for_completion,
ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
{
ompi_osc_rdma_pending_op_t *pending_op;
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
int ret = OPAL_ERROR;

pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
Expand Down Expand Up @@ -110,23 +110,23 @@ static inline int ompi_osc_rdma_lock_btl_fop (ompi_osc_rdma_module_t *module, om
int op, ompi_osc_rdma_lock_t operand, ompi_osc_rdma_lock_t *result,
const bool wait_for_completion)
{
return ompi_osc_rdma_btl_fop (module, peer->state_btl_index, peer->state_endpoint, address, peer->state_handle, op,
return ompi_osc_rdma_btl_fop (module, peer->state_btl, peer->state_endpoint, address, peer->state_handle, op,
operand, 0, result, wait_for_completion, NULL, NULL, NULL);
}

__opal_attribute_always_inline__
static inline int ompi_osc_rdma_btl_op (ompi_osc_rdma_module_t *module, uint8_t btl_index,
static inline int ompi_osc_rdma_btl_op (ompi_osc_rdma_module_t *module,
struct mca_btl_base_module_t *selected_btl,
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
mca_btl_base_registration_handle_t *address_handle,
int op, int64_t operand, int flags, const bool wait_for_completion,
ompi_osc_rdma_pending_op_cb_fn_t cbfunc, void *cbdata, void *cbcontext)
{
ompi_osc_rdma_pending_op_t *pending_op;
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
int ret;

if (!(selected_btl->btl_flags & MCA_BTL_FLAGS_ATOMIC_OPS)) {
return ompi_osc_rdma_btl_fop (module, btl_index, endpoint, address, address_handle, op, operand, flags,
return ompi_osc_rdma_btl_fop (module, selected_btl, endpoint, address, address_handle, op, operand, flags,
NULL, wait_for_completion, cbfunc, cbdata, cbcontext);
}

Expand Down Expand Up @@ -181,18 +181,18 @@ __opal_attribute_always_inline__
static inline int ompi_osc_rdma_lock_btl_op (ompi_osc_rdma_module_t *module, ompi_osc_rdma_peer_t *peer, uint64_t address,
int op, ompi_osc_rdma_lock_t operand, const bool wait_for_completion)
{
return ompi_osc_rdma_btl_op (module, peer->state_btl_index, peer->state_endpoint, address, peer->state_handle, op,
return ompi_osc_rdma_btl_op (module, peer->state_btl, peer->state_endpoint, address, peer->state_handle, op,
operand, 0, wait_for_completion, NULL, NULL, NULL);
}

__opal_attribute_always_inline__
static inline int ompi_osc_rdma_btl_cswap (ompi_osc_rdma_module_t *module, uint8_t btl_index,
static inline int ompi_osc_rdma_btl_cswap (ompi_osc_rdma_module_t *module,
struct mca_btl_base_module_t *selected_btl,
struct mca_btl_base_endpoint_t *endpoint, uint64_t address,
mca_btl_base_registration_handle_t *address_handle,
int64_t compare, int64_t value, int flags, int64_t *result)
{
ompi_osc_rdma_pending_op_t *pending_op;
mca_btl_base_module_t *selected_btl = ompi_osc_rdma_selected_btl (module, btl_index);
int ret;

pending_op = OBJ_NEW(ompi_osc_rdma_pending_op_t);
Expand Down Expand Up @@ -244,7 +244,7 @@ __opal_attribute_always_inline__
static inline int ompi_osc_rdma_lock_btl_cswap (ompi_osc_rdma_module_t *module, ompi_osc_rdma_peer_t *peer, uint64_t address,
ompi_osc_rdma_lock_t compare, ompi_osc_rdma_lock_t value, ompi_osc_rdma_lock_t *result)
{
return ompi_osc_rdma_btl_cswap (module, peer->state_btl_index, peer->state_endpoint, address, peer->state_handle, compare, value,
return ompi_osc_rdma_btl_cswap (module, peer->state_btl, peer->state_endpoint, address, peer->state_handle, compare, value,
0, result);
}

Expand Down
Loading

0 comments on commit 6c4cb75

Please sign in to comment.