Skip to content

Commit cbfc9a3

Browse files
author
Tomislav Janjusic
committed
opal/mca/common/ucx: Use new TSD api
Co-authored-by: Artem Y. Polyakov <artemp@mellanox.com> Signed-off-by: Tomislav Janjusic <tomislavj@mellanox.com>
1 parent 72296e1 commit cbfc9a3

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

ompi/mca/osc/ucx/osc_ucx_component.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ int ompi_osc_ucx_free(struct ompi_win_t *win) {
695695

696696
opal_common_ucx_wpctx_release(module->ctx);
697697

698-
if (module->disp_units)
698+
if (module->disp_units) {
699699
free(module->disp_units);
700+
}
700701
ompi_comm_free(&module->comm);
701702

702703
free(module);

opal/mca/common/ucx/common_ucx_wpool.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ __thread int initialized = 0;
3333
static _ctx_record_t *
3434
_tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx);
3535
static inline _ctx_record_t *
36-
_tlocal_get_ctx_rec(opal_tsd_key_t tls_key);
36+
_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key);
3737
static void _tlocal_ctx_rec_cleanup(_ctx_record_t *ctx_rec);
3838
static void _tlocal_mem_rec_cleanup(_mem_record_t *mem_rec);
3939
static void _ctx_rec_destructor(void *arg);
@@ -399,7 +399,8 @@ opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size,
399399
goto error;
400400
}
401401

402-
opal_tsd_key_create(&ctx->tls_key, _ctx_rec_destructor);
402+
OBJ_CONSTRUCT(&ctx->tls_key, opal_tsd_tracked_key_t);
403+
opal_tsd_tracked_key_set_destructor(&ctx->tls_key, _ctx_rec_destructor);
403404

404405
(*ctx_ptr) = ctx;
405406
return ret;
@@ -414,16 +415,16 @@ opal_common_ucx_wpctx_create(opal_common_ucx_wpool_t *wpool, int comm_size,
414415
OPAL_DECLSPEC void
415416
opal_common_ucx_wpctx_release(opal_common_ucx_ctx_t *ctx)
416417
{
417-
_ctx_record_t *ctx_rec = NULL;
418+
_ctx_record_t *ctx_rec = NULL, *next;
418419

419420
/* Application is expected to guarantee that no operation
420421
* is performed on the context that is being released */
421422

422423
/* destroy key so that other threads don't invoke destructors */
423-
opal_tsd_key_delete(ctx->tls_key);
424+
OBJ_DESTRUCT(&ctx->tls_key);
424425

425426
/* loop through list of records */
426-
OPAL_LIST_FOREACH(ctx_rec, &ctx->ctx_records, _ctx_record_t) {
427+
OPAL_LIST_FOREACH_SAFE(ctx_rec, next, &ctx->ctx_records, _ctx_record_t) {
427428
_tlocal_ctx_rec_cleanup(ctx_rec);
428429
}
429430

@@ -493,7 +494,8 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx,
493494
goto error_rkey_pack;
494495
}
495496

496-
opal_tsd_key_create(&mem->tls_key, _mem_rec_destructor);
497+
OBJ_CONSTRUCT(&mem->tls_key, opal_tsd_tracked_key_t);
498+
opal_tsd_tracked_key_set_destructor(&mem->tls_key, _mem_rec_destructor);
497499

498500
(*mem_ptr) = mem;
499501
(*my_mem_addr) = rkey_addr;
@@ -560,12 +562,12 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool,
560562

561563
void opal_common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem)
562564
{
563-
_mem_record_t *mem_rec = NULL;
564-
565-
opal_tsd_key_delete(mem->tls_key);
565+
_mem_record_t *mem_rec = NULL, *next;
566566

567+
OBJ_DESTRUCT(&mem->tls_key);
568+
567569
/* Loop through list of records */
568-
OPAL_LIST_FOREACH(mem_rec, &mem->mem_records, _mem_record_t) {
570+
OPAL_LIST_FOREACH_SAFE(mem_rec, next, &mem->mem_records, _mem_record_t) {
569571
_tlocal_mem_rec_cleanup(mem_rec);
570572
}
571573

@@ -581,9 +583,9 @@ void opal_common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem)
581583
}
582584

583585
static inline _ctx_record_t *
584-
_tlocal_get_ctx_rec(opal_tsd_key_t tls_key){
586+
_tlocal_get_ctx_rec(opal_tsd_tracked_key_t tls_key){
585587
_ctx_record_t *ctx_rec = NULL;
586-
int rc = opal_tsd_getspecific(tls_key, (void**)&ctx_rec);
588+
int rc = opal_tsd_tracked_key_get(&tls_key, (void**)&ctx_rec);
587589

588590
if (OPAL_SUCCESS != rc) {
589591
return NULL;
@@ -657,7 +659,7 @@ _tlocal_add_ctx_rec(opal_common_ucx_ctx_t *ctx)
657659
opal_mutex_unlock(&ctx->mutex);
658660

659661
/* Add tls reference to record */
660-
rc = opal_tsd_setspecific(ctx->tls_key, ctx_rec);
662+
rc = opal_tsd_tracked_key_set(&ctx->tls_key, ctx_rec);
661663
if (OPAL_SUCCESS != rc) {
662664
OBJ_RELEASE(ctx_rec);
663665
return NULL;
@@ -743,7 +745,7 @@ static _mem_record_t *_tlocal_add_mem_rec(opal_common_ucx_wpmem_t *mem, _ctx_rec
743745

744746
opal_atomic_wmb();
745747

746-
rc = opal_tsd_setspecific(mem->tls_key, mem_rec);
748+
rc = opal_tsd_tracked_key_set(&mem->tls_key, mem_rec);
747749
if (OPAL_SUCCESS != rc) {
748750
return NULL;
749751
}

opal/mca/common/ucx/common_ucx_wpool.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ typedef struct {
7373

7474
/* Thread-local key to allow each thread to have
7575
* local information associated with this wpctx */
76-
opal_tsd_key_t tls_key;
76+
opal_tsd_tracked_key_t tls_key;
7777

7878
/* UCX addressing information */
7979
char *recv_worker_addrs;
@@ -107,7 +107,7 @@ typedef struct {
107107
/* TLS item that allows each thread to
108108
* store endpoints and rkey arrays
109109
* for faster access */
110-
opal_tsd_key_t tls_key;
110+
opal_tsd_tracked_key_t tls_key;
111111
} opal_common_ucx_wpmem_t;
112112

113113
typedef struct __winfo_list_item_t _winfo_list_item_t;
@@ -220,7 +220,7 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target,
220220
int rc = OPAL_SUCCESS;
221221

222222
/* First check the fast-path */
223-
rc = opal_tsd_getspecific(mem->tls_key, (void**)&mem_rec);
223+
rc = opal_tsd_tracked_key_get(&mem->tls_key, (void**)&mem_rec);
224224
if (OPAL_SUCCESS != rc) {
225225
return rc;
226226
}
@@ -231,7 +231,7 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target,
231231
if (OPAL_SUCCESS != rc) {
232232
return rc;
233233
}
234-
rc = opal_tsd_getspecific(mem->tls_key, (void**)&mem_rec);
234+
rc = opal_tsd_tracked_key_get(&mem->tls_key, (void**)&mem_rec);
235235
if (OPAL_SUCCESS != rc) {
236236
return rc;
237237
}

0 commit comments

Comments
 (0)