Skip to content

Commit 19e2ae2

Browse files
committed
opal/common/ucx: Switch to opal/tsd
Signed-off-by: Artem Polyakov <artpol84@gmail.com>
1 parent 7984d7d commit 19e2ae2

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

ompi/mca/osc/ucx/osc_ucx_component.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
memcpy(((char*)(_dst)) + (_off), _src, _len); \
2727
(_off) += (_len);
2828

29-
static int dbg_level = 0;
30-
3129
static int component_open(void);
3230
static int component_register(void);
3331
static int component_init(bool enable_progress_threads, bool enable_mpi_threads);

ompi/mca/osc/ucx/osc_ucx_passive_target.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
OBJ_CLASS_INSTANCE(ompi_osc_ucx_lock_t, opal_object_t, NULL, NULL);
2020

21-
static int dbg_level = 0;
22-
2321
static inline int start_shared(ompi_osc_ucx_module_t *module, int target) {
2422
uint64_t result_value = -1;
2523
uint64_t remote_addr = (module->state_addrs)[target] + OSC_UCX_STATE_LOCK_OFFSET;

opal/mca/common/ucx/common_ucx_wpool.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ opal_common_ucx_wpool_init(opal_common_ucx_wpool_t *wpool,
201201
goto err_wpool_add;
202202
}
203203

204-
pthread_key_create(&wpool->tls_key, _tlocal_cleanup);
204+
opal_tsd_key_create(&wpool->tls_key, _tlocal_cleanup);
205205

206206
return rc;
207207

@@ -229,7 +229,7 @@ void opal_common_ucx_wpool_finalize(opal_common_ucx_wpool_t *wpool)
229229

230230
/* After this have been called no thread cleanup callback
231231
* will be called */
232-
pthread_key_delete(wpool->tls_key);
232+
opal_tsd_key_delete(wpool->tls_key);
233233

234234
/* Go over remaining TLS structures and release it */
235235
OPAL_LIST_FOREACH_SAFE(tls_item, tls_next, &wpool->tls_list,
@@ -553,7 +553,7 @@ int opal_common_ucx_wpmem_create(opal_common_ucx_ctx_t *ctx,
553553

554554
/* Dont need the destructor here, will use
555555
* wpool-level destructor */
556-
pthread_key_create(&mem->mem_tls_key, NULL);
556+
opal_tsd_key_create(&mem->mem_tls_key, NULL);
557557

558558
(*mem_ptr) = mem;
559559
(*my_mem_addr) = rkey_addr;
@@ -641,7 +641,7 @@ static int _comm_ucx_wpmem_map(opal_common_ucx_wpool_t *wpool,
641641

642642
static void _common_ucx_wpmem_free(opal_common_ucx_wpmem_t *mem)
643643
{
644-
pthread_key_delete(mem->mem_tls_key);
644+
opal_tsd_key_delete(mem->mem_tls_key);
645645
free(mem->mem_addrs);
646646
free(mem->mem_displs);
647647
ucp_mem_unmap(mem->ctx->wpool->ucp_ctx, mem->memh);
@@ -714,15 +714,21 @@ static _tlocal_table_t* _common_ucx_tls_init(opal_common_ucx_wpool_t *wpool)
714714
return NULL;
715715
}
716716

717-
pthread_setspecific(wpool->tls_key, tls);
717+
opal_tsd_setspecific(wpool->tls_key, tls);
718718

719719
return tls;
720720
}
721721

722722
static inline _tlocal_table_t *
723723
_tlocal_get_tls(opal_common_ucx_wpool_t *wpool){
724-
_tlocal_table_t *tls = pthread_getspecific(wpool->tls_key);
725-
if( OPAL_UNLIKELY(NULL == tls) ) {
724+
_tlocal_table_t *tls;
725+
int rc = opal_tsd_getspecific(wpool->tls_key, (void**)&tls);
726+
727+
if (OPAL_SUCCESS != rc) {
728+
return NULL;
729+
}
730+
731+
if (OPAL_UNLIKELY(NULL == tls)) {
726732
tls = _common_ucx_tls_init(wpool);
727733
}
728734
return tls;
@@ -777,7 +783,7 @@ static void _common_ucx_tls_cleanup(_tlocal_table_t *tls)
777783
free(tls->ctx_tbl[i]);
778784
}
779785

780-
pthread_setspecific(tls->wpool->tls_key, NULL);
786+
opal_tsd_setspecific(tls->wpool->tls_key, NULL);
781787

782788
OBJ_RELEASE(tls);
783789
return;
@@ -1033,7 +1039,7 @@ static _tlocal_mem_t *_tlocal_add_mem(_tlocal_table_t *tls,
10331039
calloc(1, sizeof(*tls->mem_tbl[free_idx]->mem_tls_ptr));
10341040
tls->mem_tbl[free_idx]->mem_tls_ptr->winfo = ctx_rec->winfo;
10351041
tls->mem_tbl[free_idx]->mem_tls_ptr->rkeys = tls->mem_tbl[free_idx]->mem->rkeys;
1036-
pthread_setspecific(mem->mem_tls_key, tls->mem_tbl[free_idx]->mem_tls_ptr);
1042+
opal_tsd_setspecific(mem->mem_tls_key, tls->mem_tbl[free_idx]->mem_tls_ptr);
10371043

10381044
/* Make sure that we completed all the data structures before
10391045
* placing the item to the list

opal/mca/common/ucx/common_ucx_wpool.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include <string.h>
1010

1111
#include <ucp/api/ucp.h>
12-
#include <pthread.h>
1312

1413
#include "opal/mca/mca.h"
1514
#include "opal/util/output.h"
1615
#include "opal/runtime/opal_progress.h"
1716
#include "opal/include/opal/constants.h"
1817
#include "opal/class/opal_list.h"
18+
#include "opal/threads/tsd.h"
1919

2020
BEGIN_C_DECLS
2121

@@ -32,7 +32,7 @@ typedef struct {
3232

3333
/* Thread-local key to allow each thread to have
3434
* local information assisiated with this wpool */
35-
pthread_key_t tls_key;
35+
opal_tsd_key_t tls_key;
3636

3737
/* Bookkeeping information */
3838
opal_list_t idle_workers;
@@ -75,7 +75,7 @@ typedef struct {
7575
/* TLS item that allows each thread to
7676
* store endpoints and rkey arrays
7777
* for faster access */
78-
pthread_key_t mem_tls_key;
78+
opal_tsd_key_t mem_tls_key;
7979
} opal_common_ucx_wpmem_t;
8080

8181
typedef struct opal_common_ucx_winfo {
@@ -159,15 +159,21 @@ opal_common_ucx_tlocal_fetch(opal_common_ucx_wpmem_t *mem, int target,
159159
int rc = OPAL_SUCCESS;
160160

161161
/* First check the fast-path */
162-
fp = pthread_getspecific(mem->mem_tls_key);
162+
rc = opal_tsd_getspecific(mem->mem_tls_key, (void**)&fp);
163+
if (OPAL_SUCCESS != rc) {
164+
return rc;
165+
}
163166
expr = fp && (NULL != fp->winfo) && (fp->winfo->endpoints[target]) &&
164167
(NULL != fp->rkeys[target]);
165168
if (OPAL_UNLIKELY(!expr)) {
166169
rc = opal_common_ucx_tlocal_fetch_spath(mem, target);
167170
if (OPAL_SUCCESS != rc) {
168171
return rc;
169172
}
170-
fp = pthread_getspecific(mem->mem_tls_key);
173+
rc = opal_tsd_getspecific(mem->mem_tls_key, (void**)&fp);
174+
if (OPAL_SUCCESS != rc) {
175+
return rc;
176+
}
171177
}
172178
MCA_COMMON_UCX_ASSERT(fp && (NULL != fp->winfo) &&
173179
(fp->winfo->endpoints[target])

0 commit comments

Comments
 (0)