Commit a36fd9dd authored by Xin Zhao's avatar Xin Zhao Committed by Pavan Balaji
Browse files

Code refactoring: setting ureq after issuing op in a function.



After (1) issuing an op (no LOCK flag), or (2) issuing an op
(with LOCK flag) and receiving an ACK that LOCK is granted or
queued, we should set the user request (ureq) to be completed.
This patch wraps up the work of setting ureq into a function,
and call that function after (1) and (2) happens.
Signed-off-by: Pavan Balaji's avatarPavan Balaji <balaji@anl.gov>
parent fd92b7bc
......@@ -840,4 +840,65 @@ static inline int issue_rma_op(MPIDI_RMA_Op_t * op_ptr, MPID_Win * win_ptr,
/* --END ERROR HANDLING-- */
}
#undef FUNCNAME
#define FUNCNAME set_user_req_after_issuing_op
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
static inline int set_user_req_after_issuing_op(MPIDI_RMA_Op_t * op)
{
int mpi_errno = MPI_SUCCESS;
MPIDI_STATE_DECL(MPID_STATE_SET_USER_REQ_AFTER_ISSUING_OP);
MPIDI_RMA_FUNC_ENTER(MPID_STATE_SET_USER_REQ_AFTER_ISSUING_OP);
if (op->ureq == NULL)
goto fn_exit;
if (!op->request) {
/* Sending is completed immediately, complete user request
* and release ch3 ref. */
/* Complete user request and release the ch3 ref */
MPID_Request_set_completed(op->ureq);
MPID_Request_release(op->ureq);
}
else {
/* Sending is not completed immediately. */
/* Setup user request info in order to be completed following send request. */
/* Increase ref for completion handler */
MPIU_Object_add_ref(op->ureq);
op->request->dev.request_handle = op->ureq->handle;
/* Setup user request completion handler.
*
* The handler is triggered when send request is completed at
* following places:
* - progress engine: complete PUT/ACC req.
* - GET/GET_ACC packet handler: complete GET/GET_ACC reqs.
*
* We always set OnFinal which should be called when sending or
* receiving the last segment. However, short put/acc ops are
* issued in one packet and the lower layer only check OnDataAvail
* so we have to set OnDataAvail as well.
*
* Note that a noncontig send also uses OnDataAvail to loop all
* segments but it must be changed to OnFinal when sending the
* last segment, so it is also correct for us.
*
* TODO: implement stack for overriding functions*/
if (op->request->dev.OnDataAvail == NULL) {
op->request->dev.OnDataAvail = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
op->request->dev.OnFinal = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
fn_exit:
MPIDI_RMA_FUNC_EXIT(MPID_STATE_SET_USER_REQ_AFTER_ISSUING_OP);
return mpi_errno;
fn_fail:
goto fn_exit;
}
#endif /* MPID_RMA_ISSUE_H_INCLUDED */
......@@ -601,13 +601,13 @@ static inline int adjust_op_piggybacked_with_lock(MPID_Win * win_ptr,
if (flags & MPIDI_CH3_PKT_FLAG_RMA_LOCK_GRANTED ||
flags & MPIDI_CH3_PKT_FLAG_RMA_LOCK_QUEUED_DATA_QUEUED) {
if (!op->request) {
if (op->ureq) {
/* Complete user request and release the ch3 ref */
MPID_Request_set_completed(op->ureq);
MPID_Request_release(op->ureq);
}
if (op->ureq != NULL) {
mpi_errno = set_user_req_after_issuing_op(op);
if (mpi_errno != MPI_SUCCESS)
MPIU_ERR_POP(mpi_errno);
}
if (!op->request) {
MPIDI_CH3I_RMA_Ops_free_elem(win_ptr, &(target->pending_op_list),
&(target->pending_op_list_tail), op);
}
......@@ -629,23 +629,6 @@ static inline int adjust_op_piggybacked_with_lock(MPID_Win * win_ptr,
MPIDI_CH3I_RMA_Ops_append(&(target->read_op_list),
&(target->read_op_list_tail), op);
}
if (op->ureq) {
if (MPID_Request_is_complete(op->request)) {
/* Complete user request, let cleanup function to release
* ch3 ref */
MPID_Request_set_completed(op->ureq);
}
else {
/* Increase ref for completion handler */
MPIU_Object_add_ref(op->ureq);
op->request->dev.request_handle = op->ureq->handle;
if (op->request->dev.OnDataAvail == NULL) {
op->request->dev.OnDataAvail = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
op->request->dev.OnFinal = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
}
}
}
else if (flags & MPIDI_CH3_PKT_FLAG_RMA_LOCK_QUEUED_DATA_DISCARDED ||
......
......@@ -390,13 +390,13 @@ static inline int issue_ops_target(MPID_Win * win_ptr, MPIDI_RMA_Target_t * targ
break;
}
if (!curr_op->request) {
if (curr_op->ureq) {
/* Complete user request and release the ch3 ref */
MPID_Request_set_completed(curr_op->ureq);
MPID_Request_release(curr_op->ureq);
}
if (curr_op->ureq != NULL) {
mpi_errno = set_user_req_after_issuing_op(curr_op);
if (mpi_errno != MPI_SUCCESS)
MPIU_ERR_POP(mpi_errno);
}
if (!curr_op->request) {
/* Sending is completed immediately. */
MPIDI_CH3I_RMA_Ops_free_elem(win_ptr, &(target->pending_op_list),
&(target->pending_op_list_tail), curr_op);
......@@ -421,35 +421,6 @@ static inline int issue_ops_target(MPID_Win * win_ptr, MPIDI_RMA_Target_t * targ
MPIDI_CH3I_RMA_Ops_append(&(target->read_op_list),
&(target->read_op_list_tail), curr_op);
}
/* Setup user request info in order to be completed following send request. */
if (curr_op->ureq) {
/* Increase ref for completion handler */
MPIU_Object_add_ref(curr_op->ureq);
curr_op->request->dev.request_handle = curr_op->ureq->handle;
/* Setup user request completion handler.
*
* The handler is triggered when send request is completed at
* following places:
* - progress engine: complete PUT/ACC req.
* - GET/GET_ACC packet handler: complete GET/GET_ACC reqs.
*
* We always set OnFinal which should be called when sending or
* receiving the last segment. However, short put/acc ops are
* issued in one packet and the lower layer only check OnDataAvail
* so we have to set OnDataAvail as well.
*
* Note that a noncontig send also uses OnDataAvail to loop all
* segments but it must be changed to OnFinal when sending the
* last segment, so it is also correct for us.
*
* TODO: implement stack for overriding functions*/
if (curr_op->request->dev.OnDataAvail == NULL) {
curr_op->request->dev.OnDataAvail = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
curr_op->request->dev.OnFinal = MPIDI_CH3_ReqHandler_ReqOpsComplete;
}
}
curr_op = target->next_op_to_issue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment