Skip to content

Commit 6f0a7a2

Browse files
author
Sergey Oblomov
committed
OSC/UCX: opal progress register/unregister optimization
Signed-off-by: Sergey Oblomov <sergeyo@mellanox.com>
1 parent 55b934b commit 6f0a7a2

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

ompi/mca/osc/ucx/osc_ucx_component.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ static int component_register(void) {
110110
}
111111

112112
static int progress_callback(void) {
113-
if ((mca_osc_ucx_component.ucp_worker != NULL) &&
114-
mca_osc_ucx_component.num_modules) {
115-
ucp_worker_progress(mca_osc_ucx_component.ucp_worker);
116-
}
113+
ucp_worker_progress(mca_osc_ucx_component.ucp_worker);
117114
return 0;
118115
}
119116

@@ -140,7 +137,6 @@ static int component_finalize(void) {
140137
assert(mca_osc_ucx_component.num_incomplete_req_ops == 0);
141138
if (mca_osc_ucx_component.env_initialized == true) {
142139
OBJ_DESTRUCT(&mca_osc_ucx_component.requests);
143-
opal_progress_unregister(progress_callback);
144140
ucp_cleanup(mca_osc_ucx_component.ucp_context);
145141
mca_osc_ucx_component.env_initialized = false;
146142
}
@@ -250,7 +246,7 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
250246
ucs_status_t status;
251247
int i, comm_size = ompi_comm_size(comm);
252248
int is_eps_ready;
253-
bool progress_registered = false, eps_created = false, env_initialized = false;
249+
bool eps_created = false, env_initialized = false;
254250
ucp_address_t *my_addr = NULL;
255251
size_t my_addr_len;
256252
char *recv_buf = NULL;
@@ -327,13 +323,6 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
327323
goto error_nomem;
328324
}
329325

330-
ret = opal_progress_register(progress_callback);
331-
progress_registered = true;
332-
if (OMPI_SUCCESS != ret) {
333-
OSC_UCX_VERBOSE(1, "opal_progress_register failed: %d", ret);
334-
goto error;
335-
}
336-
337326
/* query UCP worker attributes */
338327
worker_attr.field_mask = UCP_WORKER_ATTR_FIELD_THREAD_MODE;
339328
status = ucp_worker_query(mca_osc_ucx_component.ucp_worker, &worker_attr);
@@ -617,6 +606,14 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
617606
goto error;
618607
}
619608

609+
OSC_UCX_ASSERT(mca_osc_ucx_component.num_modules > 0);
610+
if (1 == mca_osc_ucx_component.num_modules) {
611+
ret = opal_progress_register(progress_callback);
612+
if (OMPI_SUCCESS != ret) {
613+
OSC_UCX_VERBOSE(1, "opal_progress_register failed: %d", ret);
614+
goto error;
615+
}
616+
}
620617
return ret;
621618

622619
error:
@@ -644,9 +641,17 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
644641
ucp_ep_destroy(ep);
645642
}
646643
}
647-
if (progress_registered) opal_progress_unregister(progress_callback);
648-
if (module) free(module);
649-
mca_osc_ucx_component.num_modules--;
644+
if (module) {
645+
free(module);
646+
mca_osc_ucx_component.num_modules--;
647+
OSC_UCX_ASSERT(mca_osc_ucx_component.num_modules >= 0);
648+
if (0 == mca_osc_ucx_component.num_modules) {
649+
ret = opal_progress_unregister(progress_callback);
650+
if (OMPI_SUCCESS != ret) {
651+
OSC_UCX_VERBOSE(1, "opal_progress_unregister failed: %d", ret);
652+
}
653+
}
654+
}
650655

651656
error_nomem:
652657
if (env_initialized == true) {
@@ -815,6 +820,13 @@ int ompi_osc_ucx_free(struct ompi_win_t *win) {
815820

816821
free(module);
817822
mca_osc_ucx_component.num_modules--;
823+
OSC_UCX_ASSERT(mca_osc_ucx_component.num_modules >= 0);
824+
if (0 == mca_osc_ucx_component.num_modules) {
825+
ret = opal_progress_unregister(progress_callback);
826+
if (OMPI_SUCCESS != ret) {
827+
OSC_UCX_VERBOSE(1, "opal_progress_unregister failed: %d", ret);
828+
}
829+
}
818830

819831
return ret;
820832
}

0 commit comments

Comments
 (0)