Commit 4bb35606 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

rportals code refactoring.



1. Moved op management to a different file.

2. Move rptl_info to an extern, so it can be shared by multiple files.

3. Separate out rptl initialization routines.
Signed-off-by: Kenneth Raffenetti's avatarKen Raffenetti <raffenet@mcs.anl.gov>
parent 88d34091
......@@ -16,7 +16,9 @@ mpi_core_sources += \
src/mpid/ch3/channels/nemesis/netmod/portals4/ptl_nm.c \
src/mpid/ch3/channels/nemesis/netmod/portals4/ptl_send.c \
src/mpid/ch3/channels/nemesis/netmod/portals4/ptl_lmt.c \
src/mpid/ch3/channels/nemesis/netmod/portals4/rptl.c
src/mpid/ch3/channels/nemesis/netmod/portals4/rptl.c \
src/mpid/ch3/channels/nemesis/netmod/portals4/rptl_init.c \
src/mpid/ch3/channels/nemesis/netmod/portals4/rptl_op.c
noinst_HEADERS += \
src/mpid/ch3/channels/nemesis/netmod/portals4/ptl_impl.h \
......
......@@ -60,15 +60,7 @@
#define IDS_ARE_EQUAL(t1, t2) \
(t1.phys.nid == t2.phys.nid && t1.phys.pid == t2.phys.pid)
static struct {
struct rptl *rptl_list;
struct rptl_target *target_list;
int world_size;
uint64_t origin_events_left;
int (*get_target_info) (int rank, ptl_process_t * id, ptl_pt_index_t local_data_pt,
ptl_pt_index_t * target_data_pt, ptl_pt_index_t * target_control_pt);
} rptl_info;
struct rptl_info rptl_info;
#undef FUNCNAME
......@@ -118,292 +110,6 @@ static int find_target(ptl_process_t id, struct rptl_target **target)
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_init
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_init(int world_size, uint64_t max_origin_events,
int (*get_target_info) (int rank, ptl_process_t * id,
ptl_pt_index_t local_data_pt,
ptl_pt_index_t * target_data_pt,
ptl_pt_index_t * target_control_pt))
{
int ret = PTL_OK;
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
rptl_info.rptl_list = NULL;
rptl_info.target_list = NULL;
rptl_info.world_size = world_size;
rptl_info.origin_events_left = max_origin_events;
rptl_info.get_target_info = get_target_info;
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_drain_eq
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_drain_eq(int eq_count, ptl_handle_eq_t *eq)
{
int ret = PTL_OK;
ptl_event_t event;
struct rptl_op_pool_segment *op_segment;
int i;
struct rptl_target *target, *t;
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
for (target = rptl_info.target_list; target; target = target->next) {
while (target->control_op_list || target->data_op_list) {
for (i = 0; i < eq_count; i++) {
/* read and ignore all events */
ret = MPID_nem_ptl_rptl_eqget(eq[i], &event);
if (ret == PTL_EQ_EMPTY)
ret = PTL_OK;
RPTLU_ERR_POP(ret, "Error calling MPID_nem_ptl_rptl_eqget\n");
}
}
}
for (target = rptl_info.target_list; target;) {
assert(target->data_op_list == NULL);
assert(target->control_op_list == NULL);
while (target->op_segment_list) {
op_segment = target->op_segment_list;
MPL_DL_DELETE(target->op_segment_list, op_segment);
MPIU_Free(op_segment);
}
t = target->next;
MPIU_Free(target);
target = t;
}
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME post_empty_buffer
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
static inline int post_empty_buffer(ptl_handle_ni_t ni_handle, ptl_pt_index_t pt,
ptl_handle_me_t * me_handle)
{
int ret;
ptl_me_t me;
ptl_process_t id;
MPIDI_STATE_DECL(MPID_STATE_POST_EMPTY_BUFFER);
MPIDI_FUNC_ENTER(MPID_STATE_POST_EMPTY_BUFFER);
id.phys.nid = PTL_NID_ANY;
id.phys.pid = PTL_PID_ANY;
me.start = NULL;
me.length = 0;
me.ct_handle = PTL_CT_NONE;
me.uid = PTL_UID_ANY;
me.options = (PTL_ME_OP_PUT | PTL_ME_OP_GET | PTL_ME_USE_ONCE | PTL_ME_IS_ACCESSIBLE |
PTL_ME_EVENT_LINK_DISABLE | PTL_ME_EVENT_UNLINK_DISABLE);
me.match_id = id;
me.match_bits = 0;
me.ignore_bits = 0;
me.min_free = 0;
ret = PtlMEAppend(ni_handle, pt, &me, PTL_PRIORITY_LIST, NULL, me_handle);
RPTLU_ERR_POP(ret, "Error appending empty buffer to priority list\n");
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_POST_EMPTY_BUFFER);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_ptinit
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_ptinit(ptl_handle_ni_t ni_handle, ptl_handle_eq_t eq_handle, ptl_pt_index_t data_pt,
ptl_pt_index_t control_pt)
{
int ret = PTL_OK;
struct rptl *rptl;
int mpi_errno = MPI_SUCCESS;
int i;
ptl_md_t md;
MPIU_CHKPMEM_DECL(2);
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_PTINIT);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_PTINIT);
/* setup the parts of rptls that can be done before world size or
* target information */
MPIU_CHKPMEM_MALLOC(rptl, struct rptl *, sizeof(struct rptl), mpi_errno, "rptl");
MPL_DL_APPEND(rptl_info.rptl_list, rptl);
rptl->local_state = RPTL_LOCAL_STATE_ACTIVE;
rptl->pause_ack_counter = 0;
rptl->data.ob_max_count = 0;
rptl->data.ob_curr_count = 0;
rptl->data.pt = data_pt;
rptl->control.pt = control_pt;
rptl->ni = ni_handle;
rptl->eq = eq_handle;
md.start = 0;
md.length = (ptl_size_t) (-1);
md.options = 0x0;
md.eq_handle = rptl->eq;
md.ct_handle = PTL_CT_NONE;
ret = PtlMDBind(rptl->ni, &md, &rptl->md);
RPTLU_ERR_POP(ret, "Error binding new global MD\n");
/* post world_size number of empty buffers on the control portal */
if (rptl->control.pt != PTL_PT_ANY) {
MPIU_CHKPMEM_MALLOC(rptl->control.me, ptl_handle_me_t *,
2 * rptl_info.world_size * sizeof(ptl_handle_me_t), mpi_errno,
"rptl target info");
for (i = 0; i < 2 * rptl_info.world_size; i++) {
ret = post_empty_buffer(rptl->ni, rptl->control.pt, &rptl->control.me[i]);
RPTLU_ERR_POP(ret, "Error in post_empty_buffer\n");
}
rptl->control.me_idx = 0;
}
fn_exit:
MPIU_CHKPMEM_COMMIT();
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_PTINIT);
return ret;
fn_fail:
if (mpi_errno)
ret = PTL_FAIL;
MPIU_CHKPMEM_REAP();
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_ptfini
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_ptfini(ptl_pt_index_t pt_index)
{
int i;
int ret = PTL_OK;
struct rptl *rptl;
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_PTFINI);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_PTFINI);
/* find the right rptl */
for (rptl = rptl_info.rptl_list; rptl && rptl->data.pt != pt_index; rptl = rptl->next);
assert(rptl);
/* free control portals that were created */
if (rptl->control.pt != PTL_PT_ANY) {
for (i = 0; i < rptl_info.world_size * 2; i++) {
ret = PtlMEUnlink(rptl->control.me[i]);
RPTLU_ERR_POP(ret, "Error unlinking control buffers\n");
}
MPIU_Free(rptl->control.me);
}
MPL_DL_DELETE(rptl_info.rptl_list, rptl);
MPIU_Free(rptl);
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_PTFINI);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME alloc_op
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
static int alloc_op(struct rptl_op **op, struct rptl_target *target)
{
int ret = PTL_OK;
struct rptl_op_pool_segment *op_segment;
int mpi_errno = MPI_SUCCESS;
int i;
MPIU_CHKPMEM_DECL(1);
MPIDI_STATE_DECL(MPID_STATE_ALLOC_OP);
MPIDI_FUNC_ENTER(MPID_STATE_ALLOC_OP);
assert(target);
if (target->op_pool == NULL) {
MPIU_CHKPMEM_MALLOC(op_segment, struct rptl_op_pool_segment *, sizeof(struct rptl_op_pool_segment),
mpi_errno, "op pool segment");
MPL_DL_APPEND(target->op_segment_list, op_segment);
for (i = 0; i < RPTL_OP_POOL_SEGMENT_COUNT; i++)
MPL_DL_APPEND(target->op_pool, &op_segment->op[i]);
}
*op = target->op_pool;
MPL_DL_DELETE(target->op_pool, *op);
fn_exit:
MPIU_CHKPMEM_COMMIT();
MPIDI_FUNC_EXIT(MPID_STATE_ALLOC_OP);
return ret;
fn_fail:
if (mpi_errno)
ret = PTL_FAIL;
MPIU_CHKPMEM_REAP();
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME free_op
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
static void free_op(struct rptl_op *op)
{
MPIDI_STATE_DECL(MPID_STATE_FREE_OP);
MPIDI_FUNC_ENTER(MPID_STATE_FREE_OP);
MPL_DL_APPEND(op->target->op_pool, op);
MPIDI_FUNC_EXIT(MPID_STATE_FREE_OP);
}
static int rptl_put(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size_t length,
ptl_ack_req_t ack_req, ptl_process_t target_id, ptl_pt_index_t pt_index,
ptl_match_bits_t match_bits, ptl_size_t remote_offset, void *user_ptr,
......@@ -620,7 +326,7 @@ static int rptl_put(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size
ret = find_target(target_id, &target);
RPTLU_ERR_POP(ret, "error finding target structure\n");
ret = alloc_op(&op, target);
ret = rptli_op_alloc(&op, target);
RPTLU_ERR_POP(ret, "error allocating op\n");
op->op_type = RPTL_OP_PUT;
......@@ -694,7 +400,7 @@ int MPID_nem_ptl_rptl_get(ptl_handle_md_t md_handle, ptl_size_t local_offset, pt
ret = find_target(target_id, &target);
RPTLU_ERR_POP(ret, "error finding target structure\n");
ret = alloc_op(&op, target);
ret = rptli_op_alloc(&op, target);
RPTLU_ERR_POP(ret, "error allocating op\n");
op->op_type = RPTL_OP_GET;
......@@ -942,7 +648,7 @@ static int retrieve_event(ptl_event_t * event)
event->user_ptr = op->u.put.user_ptr;
MPL_DL_DELETE(target->data_op_list, op);
free_op(op);
rptli_op_free(op);
have_event = 1;
goto fn_exit;
......@@ -1048,11 +754,11 @@ int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event)
ret = PTL_EQ_EMPTY;
/* the message came in on the control PT, repost it */
tmp_ret = post_empty_buffer(rptl->ni, rptl->control.pt,
tmp_ret = rptli_post_control_buffer(rptl->ni, rptl->control.pt,
&rptl->control.me[rptl->control.me_idx]);
if (tmp_ret) {
ret = tmp_ret;
RPTLU_ERR_POP(ret, "Error returned from post_empty_buffer\n");
RPTLU_ERR_POP(ret, "Error returned from rptli_post_control_buffer\n");
}
rptl->control.me_idx++;
if (rptl->control.me_idx >= 2 * rptl_info.world_size)
......@@ -1141,7 +847,7 @@ int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event)
/* GET operations only go into the data op list */
MPL_DL_DELETE(op->target->data_op_list, op);
free_op(op);
rptli_op_free(op);
}
else if (event->type == PTL_EVENT_SEND && op->u.put.ack) {
......@@ -1158,7 +864,7 @@ int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event)
if (op->u.put.pt_type == RPTL_PT_CONTROL) {
MPIU_Free(op->u.put.ack);
MPL_DL_DELETE(op->target->control_op_list, op);
free_op(op);
rptli_op_free(op);
ret = PTL_EQ_EMPTY;
}
}
......@@ -1177,7 +883,7 @@ int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event)
if (op->u.put.pt_type == RPTL_PT_CONTROL) {
MPIU_Free(op->u.put.send);
MPL_DL_DELETE(op->target->control_op_list, op);
free_op(op);
rptli_op_free(op);
ret = PTL_EQ_EMPTY;
}
......@@ -1193,7 +899,7 @@ int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event)
/* we should be in the data op list */
MPL_DL_DELETE(op->target->data_op_list, op);
free_op(op);
rptli_op_free(op);
}
}
......
......@@ -160,28 +160,44 @@ struct rptl_target {
struct rptl_target *prev;
};
struct rptl_info {
struct rptl *rptl_list;
struct rptl_target *target_list;
int world_size;
uint64_t origin_events_left;
int (*get_target_info) (int rank, ptl_process_t * id, ptl_pt_index_t local_data_pt,
ptl_pt_index_t * target_data_pt, ptl_pt_index_t * target_control_pt);
};
extern struct rptl_info rptl_info;
/* initialization */
int MPID_nem_ptl_rptl_init(int world_size, uint64_t max_origin_events,
int (*get_target_info) (int rank, ptl_process_t * id,
ptl_pt_index_t local_data_pt,
ptl_pt_index_t * target_data_pt,
ptl_pt_index_t * target_control_pt));
int MPID_nem_ptl_rptl_drain_eq(int eq_count, ptl_handle_eq_t *eq);
int MPID_nem_ptl_rptl_ptinit(ptl_handle_ni_t ni_handle, ptl_handle_eq_t eq_handle, ptl_pt_index_t data_pt,
ptl_pt_index_t control_pt);
int MPID_nem_ptl_rptl_ptfini(ptl_pt_index_t pt_index);
int rptli_post_control_buffer(ptl_handle_ni_t ni_handle, ptl_pt_index_t pt,
ptl_handle_me_t * me_handle);
/* op management */
int rptli_op_alloc(struct rptl_op **op, struct rptl_target *target);
void rptli_op_free(struct rptl_op *op);
/* communication */
int MPID_nem_ptl_rptl_put(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size_t length,
ptl_ack_req_t ack_req, ptl_process_t target_id, ptl_pt_index_t pt_index,
ptl_match_bits_t match_bits, ptl_size_t remote_offset, void *user_ptr,
ptl_hdr_data_t hdr_data);
int MPID_nem_ptl_rptl_get(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size_t length,
ptl_process_t target_id, ptl_pt_index_t pt_index,
ptl_match_bits_t match_bits, ptl_size_t remote_offset, void *user_ptr);
int MPID_nem_ptl_rptl_eqget(ptl_handle_eq_t eq_handle, ptl_event_t * event);
#endif /* RPTL_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
* (C) 2014 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#include "ptl_impl.h"
#include "rptl.h"
#undef FUNCNAME
#define FUNCNAME rptli_post_control_buffer
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int rptli_post_control_buffer(ptl_handle_ni_t ni_handle, ptl_pt_index_t pt,
ptl_handle_me_t * me_handle)
{
int ret;
ptl_me_t me;
ptl_process_t id;
MPIDI_STATE_DECL(MPID_STATE_RPTLI_POST_CONTROL_BUFFER);
MPIDI_FUNC_ENTER(MPID_STATE_RPTLI_POST_CONTROL_BUFFER);
id.phys.nid = PTL_NID_ANY;
id.phys.pid = PTL_PID_ANY;
me.start = NULL;
me.length = 0;
me.ct_handle = PTL_CT_NONE;
me.uid = PTL_UID_ANY;
me.options = (PTL_ME_OP_PUT | PTL_ME_OP_GET | PTL_ME_USE_ONCE | PTL_ME_IS_ACCESSIBLE |
PTL_ME_EVENT_LINK_DISABLE | PTL_ME_EVENT_UNLINK_DISABLE);
me.match_id = id;
me.match_bits = 0;
me.ignore_bits = 0;
me.min_free = 0;
ret = PtlMEAppend(ni_handle, pt, &me, PTL_PRIORITY_LIST, NULL, me_handle);
RPTLU_ERR_POP(ret, "Error appending empty buffer to priority list\n");
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_RPTLI_POST_CONTROL_BUFFER);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_init
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_init(int world_size, uint64_t max_origin_events,
int (*get_target_info) (int rank, ptl_process_t * id,
ptl_pt_index_t local_data_pt,
ptl_pt_index_t * target_data_pt,
ptl_pt_index_t * target_control_pt))
{
int ret = PTL_OK;
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
rptl_info.rptl_list = NULL;
rptl_info.target_list = NULL;
rptl_info.world_size = world_size;
rptl_info.origin_events_left = max_origin_events;
rptl_info.get_target_info = get_target_info;
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_INIT);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_drain_eq
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_drain_eq(int eq_count, ptl_handle_eq_t *eq)
{
int ret = PTL_OK;
ptl_event_t event;
struct rptl_op_pool_segment *op_segment;
int i;
struct rptl_target *target, *t;
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
for (target = rptl_info.target_list; target; target = target->next) {
while (target->control_op_list || target->data_op_list) {
for (i = 0; i < eq_count; i++) {
/* read and ignore all events */
ret = MPID_nem_ptl_rptl_eqget(eq[i], &event);
if (ret == PTL_EQ_EMPTY)
ret = PTL_OK;
RPTLU_ERR_POP(ret, "Error calling MPID_nem_ptl_rptl_eqget\n");
}
}
}
for (target = rptl_info.target_list; target;) {
assert(target->data_op_list == NULL);
assert(target->control_op_list == NULL);
while (target->op_segment_list) {
op_segment = target->op_segment_list;
MPL_DL_DELETE(target->op_segment_list, op_segment);
MPIU_Free(op_segment);
}
t = target->next;
MPIU_Free(target);
target = t;
}
fn_exit:
MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_FINALIZE);
return ret;
fn_fail:
goto fn_exit;
}
#undef FUNCNAME
#define FUNCNAME MPID_nem_ptl_rptl_ptinit
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
int MPID_nem_ptl_rptl_ptinit(ptl_handle_ni_t ni_handle, ptl_handle_eq_t eq_handle, ptl_pt_index_t data_pt,
ptl_pt_index_t control_pt)
{
int ret = PTL_OK;
struct rptl *rptl;
int mpi_errno = MPI_SUCCESS;
int i;
ptl_md_t md;
MPIU_CHKPMEM_DECL(2);
MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_PTINIT);
MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_PTINIT);
/* setup the parts of rptls that can be done before world size or
* target information */
MPIU_CHKPMEM_MALLOC(rptl, struct rptl *, sizeof(struct rptl), mpi_errno, "rptl");
MPL_DL_APPEND(rptl_info.rptl_list, rptl);