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

Simplify code of garbage collection functions.



The original code of going over all issued operation lists
and cleaning up operations is gross, this patches simplifies
the related code.
Signed-off-by: Pavan Balaji's avatarPavan Balaji <balaji@anl.gov>
parent 74c2007f
......@@ -358,96 +358,79 @@ static inline int MPIDI_CH3I_RMA_Cleanup_ops_target(MPID_Win * win_ptr, MPIDI_RM
target->issued_dt_op_list_head == NULL)
goto cleanup_target;
if (target->issued_read_op_list_head != NULL) {
op_list_head = &(target->issued_read_op_list_head);
op_list_tail = &(target->issued_read_op_list_tail);
read_flag = 1;
}
else if (target->issued_write_op_list_head != NULL) {
op_list_head = &(target->issued_write_op_list_head);
op_list_tail = &(target->issued_write_op_list_tail);
write_flag = 1;
}
else if (target->issued_dt_op_list_head != NULL) {
op_list_head = &(target->issued_dt_op_list_head);
op_list_tail = &(target->issued_dt_op_list_tail);
}
else {
/* only pending op list is not NULL, nothing we can do here. */
goto fn_exit;
}
/* go over issued_read_op_list, issued_write_op_list,
* issued_dt_op_list, start from issued_read_op_list. */
op_list_head = &(target->issued_read_op_list_head);
op_list_tail = &(target->issued_read_op_list_tail);
read_flag = 1;
curr_op = *op_list_head;
while (curr_op != NULL) {
for (i = 0; i < curr_op->reqs_size; i++) {
if (curr_op->reqs[i] == NULL)
continue;
while (1) {
if (curr_op != NULL) {
for (i = 0; i < curr_op->reqs_size; i++) {
if (curr_op->reqs[i] == NULL)
continue;
if (MPID_Request_is_complete(curr_op->reqs[i])) {
/* If there's an error, return it */
mpi_errno = curr_op->reqs[i]->status.MPI_ERROR;
MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**ch3|rma_msg");
/* No errors, free the request */
MPID_Request_release(curr_op->reqs[i]);
curr_op->reqs[i] = NULL;
win_ptr->active_req_cnt--;
}
else
break;
}
if (MPID_Request_is_complete(curr_op->reqs[i])) {
/* If there's an error, return it */
mpi_errno = curr_op->reqs[i]->status.MPI_ERROR;
MPIU_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER, "**ch3|rma_msg");
if (i == curr_op->reqs_size) {
/* Release user request */
if (curr_op->ureq) {
/* User request must be completed by progress engine */
MPIU_Assert(MPID_Request_is_complete(curr_op->ureq));
/* No errors, free the request */
MPID_Request_release(curr_op->reqs[i]);
/* Release the ch3 ref */
MPID_Request_release(curr_op->ureq);
}
curr_op->reqs[i] = NULL;
/* free request array in op struct */
MPIU_Free(curr_op->reqs);
curr_op->reqs = NULL;
curr_op->reqs_size = 0;
win_ptr->active_req_cnt--;
/* dequeue the operation and free it */
MPL_LL_DELETE(*op_list_head, *op_list_tail, curr_op);
MPIDI_CH3I_Win_op_free(win_ptr, curr_op);
}
else
break;
}
if (i == curr_op->reqs_size) {
/* Release user request */
if (curr_op->ureq) {
/* User request must be completed by progress engine */
MPIU_Assert(MPID_Request_is_complete(curr_op->ureq));
/* Release the ch3 ref */
MPID_Request_release(curr_op->ureq);
else {
/* current op ptr reaches NULL, move on to the next list */
if (read_flag == 1) {
read_flag = 0;
op_list_head = &(target->issued_write_op_list_head);
op_list_tail = &(target->issued_write_op_list_tail);
write_flag = 1;
}
/* free request array in op struct */
MPIU_Free(curr_op->reqs);
curr_op->reqs = NULL;
curr_op->reqs_size = 0;
/* dequeue the operation and free it */
MPL_LL_DELETE(*op_list_head, *op_list_tail, curr_op);
MPIDI_CH3I_Win_op_free(win_ptr, curr_op);
if (*op_list_head == NULL) {
if (read_flag == 1) {
read_flag = 0;
if (target->issued_write_op_list_head != NULL) {
op_list_head = &(target->issued_write_op_list_head);
op_list_tail = &(target->issued_write_op_list_tail);
write_flag = 1;
}
else if (target->issued_dt_op_list_head != NULL) {
op_list_head = &(target->issued_dt_op_list_head);
op_list_tail = &(target->issued_dt_op_list_tail);
}
else
break;
}
else if (write_flag == 1) {
write_flag = 0;
if (target->issued_dt_op_list_head != NULL) {
op_list_head = &(target->issued_dt_op_list_head);
op_list_tail = &(target->issued_dt_op_list_tail);
}
else
break;
}
else if (write_flag == 1) {
write_flag = 0;
op_list_head = &(target->issued_dt_op_list_head);
op_list_tail = &(target->issued_dt_op_list_tail);
}
else {
/* we reach the tail of the last operation list (dt_op_list),
* break out. */
break;
}
/* next op */
curr_op = *op_list_head;
}
else
break;
/* next op */
curr_op = *op_list_head;
}
cleanup_target:
......
......@@ -574,42 +574,43 @@ int MPIDI_CH3I_RMA_Free_ops_before_completion(MPID_Win * win_ptr)
* must do a Win_flush instead. */
curr_target->sync.upgrade_flush_local = 1;
if (curr_target->issued_read_op_list_head != NULL) {
op_list_head = &curr_target->issued_read_op_list_head;
op_list_tail = &curr_target->issued_read_op_list_tail;
read_flag = 1;
}
else {
op_list_head = &curr_target->issued_write_op_list_head;
op_list_tail = &curr_target->issued_write_op_list_tail;
}
op_list_head = &curr_target->issued_read_op_list_head;
op_list_tail = &curr_target->issued_read_op_list_tail;
read_flag = 1;
curr_op = *op_list_head;
/* free all ops in the list since we do not need to maintain them anymore */
for (curr_op = *op_list_head; curr_op != NULL;) {
if (curr_op->reqs_size > 0) {
MPIU_Assert(curr_op->reqs != NULL);
for (i = 0; i < curr_op->reqs_size; i++) {
if (curr_op->reqs[i] != NULL) {
MPID_Request_release(curr_op->reqs[i]);
curr_op->reqs[i] = NULL;
win_ptr->active_req_cnt--;
while (1) {
if (curr_op != NULL) {
if (curr_op->reqs_size > 0) {
MPIU_Assert(curr_op->reqs != NULL);
for (i = 0; i < curr_op->reqs_size; i++) {
if (curr_op->reqs[i] != NULL) {
MPID_Request_release(curr_op->reqs[i]);
curr_op->reqs[i] = NULL;
win_ptr->active_req_cnt--;
}
}
}
/* free req array in this op */
MPIU_Free(curr_op->reqs);
curr_op->reqs = NULL;
curr_op->reqs_size = 0;
/* free req array in this op */
MPIU_Free(curr_op->reqs);
curr_op->reqs = NULL;
curr_op->reqs_size = 0;
}
MPL_LL_DELETE(*op_list_head, *op_list_tail, curr_op);
MPIDI_CH3I_Win_op_free(win_ptr, curr_op);
}
MPL_LL_DELETE(*op_list_head, *op_list_tail, curr_op);
MPIDI_CH3I_Win_op_free(win_ptr, curr_op);
if (*op_list_head == NULL) {
else {
if (read_flag == 1) {
op_list_head = &curr_target->issued_write_op_list_head;
op_list_head = &curr_target->issued_write_op_list_tail;
read_flag = 0;
}
else {
/* we reach the tail of write_op_list, break out. */
break;
}
}
curr_op = *op_list_head;
}
......
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