Skip to content

Commit de1a5ee

Browse files
authored
Merge pull request #5330 from jsquyres/pr/v3.0.x/btl-tcp-use-opal-hash-map-for-kindex
v3.0.x: btl/tcp: use a hash map for kernel IP interface indexes
2 parents da52fb1 + fedb139 commit de1a5ee

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

opal/mca/btl/tcp/btl_tcp_proc.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ static void mca_btl_tcp_proc_destruct(mca_btl_tcp_proc_t* proc);
5151

5252
struct mca_btl_tcp_proc_data_t {
5353
mca_btl_tcp_interface_t** local_interfaces;
54-
int local_kindex_to_index[MAX_KERNEL_INTERFACE_INDEX];
54+
opal_hash_table_t local_kindex_to_index;
5555
size_t num_local_interfaces, max_local_interfaces;
5656
size_t num_peer_interfaces;
57-
int peer_kindex_to_index[MAX_KERNEL_INTERFACE_INDEX];
57+
opal_hash_table_t peer_kindex_to_index;
5858
unsigned int *best_assignment;
5959
int max_assignment_weight;
6060
int max_assignment_cardinality;
@@ -280,8 +280,6 @@ static mca_btl_tcp_interface_t** mca_btl_tcp_retrieve_local_interfaces(mca_btl_t
280280
if( NULL == proc_data->local_interfaces )
281281
return NULL;
282282

283-
memset(proc_data->local_kindex_to_index, -1, sizeof(int)*MAX_KERNEL_INTERFACE_INDEX);
284-
285283
/* Collect up the list of included and excluded interfaces, if any */
286284
include = opal_argv_split(mca_btl_tcp_component.tcp_if_include,',');
287285
exclude = opal_argv_split(mca_btl_tcp_component.tcp_if_exclude,',');
@@ -291,7 +289,8 @@ static mca_btl_tcp_interface_t** mca_btl_tcp_retrieve_local_interfaces(mca_btl_t
291289
* the local node
292290
*/
293291
for( idx = opal_ifbegin(); idx >= 0; idx = opal_ifnext (idx) ) {
294-
int kindex, index;
292+
int kindex;
293+
uint64_t index;
295294
bool skip = false;
296295

297296
opal_ifindextoaddr (idx, (struct sockaddr*) &local_addr, sizeof (local_addr));
@@ -340,12 +339,12 @@ static mca_btl_tcp_interface_t** mca_btl_tcp_retrieve_local_interfaces(mca_btl_t
340339
}
341340

342341
kindex = opal_ifindextokindex(idx);
343-
index = proc_data->local_kindex_to_index[kindex];
342+
int rc = opal_hash_table_get_value_uint32(&proc_data->local_kindex_to_index, kindex, (void**) &index);
344343

345344
/* create entry for this kernel index previously not seen */
346-
if(-1 == index) {
345+
if (OPAL_SUCCESS != rc) {
347346
index = proc_data->num_local_interfaces++;
348-
proc_data->local_kindex_to_index[kindex] = index;
347+
opal_hash_table_set_value_uint32(&proc_data->local_kindex_to_index, kindex, (void*)(uintptr_t) index);
349348

350349
if( proc_data->num_local_interfaces == proc_data->max_local_interfaces ) {
351350
proc_data->max_local_interfaces <<= 1;
@@ -359,7 +358,7 @@ static mca_btl_tcp_interface_t** mca_btl_tcp_retrieve_local_interfaces(mca_btl_t
359358
mca_btl_tcp_initialise_interface(proc_data->local_interfaces[index], kindex, index);
360359
}
361360

362-
local_interface = proc_data->local_interfaces[proc_data->local_kindex_to_index[kindex]];
361+
local_interface = proc_data->local_interfaces[index];
363362
switch(local_addr.ss_family) {
364363
case AF_INET:
365364
/* if AF is disabled, skip it completely */
@@ -420,12 +419,17 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
420419
mca_btl_tcp_interface_t** peer_interfaces;
421420
mca_btl_tcp_proc_data_t _proc_data, *proc_data=&_proc_data;
422421
size_t max_peer_interfaces;
423-
memset(proc_data, 0, sizeof(mca_btl_tcp_proc_data_t));
424422

425423
if (NULL == (proc_hostname = opal_get_proc_hostname(btl_proc->proc_opal))) {
426424
return OPAL_ERR_UNREACH;
427425
}
428426

427+
memset(proc_data, 0, sizeof(mca_btl_tcp_proc_data_t));
428+
OBJ_CONSTRUCT(&_proc_data.local_kindex_to_index, opal_hash_table_t);
429+
opal_hash_table_init(&_proc_data.local_kindex_to_index, 8);
430+
OBJ_CONSTRUCT(&_proc_data.peer_kindex_to_index, opal_hash_table_t);
431+
opal_hash_table_init(&_proc_data.peer_kindex_to_index, 8);
432+
429433
#ifndef WORDS_BIGENDIAN
430434
/* if we are little endian and our peer is not so lucky, then we
431435
need to put all information sent to him in big endian (aka
@@ -452,7 +456,6 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
452456
peer_interfaces = (mca_btl_tcp_interface_t**)calloc( max_peer_interfaces, sizeof(mca_btl_tcp_interface_t*) );
453457
assert(NULL != peer_interfaces);
454458
proc_data->num_peer_interfaces = 0;
455-
memset(proc_data->peer_kindex_to_index, -1, sizeof(int)*MAX_KERNEL_INTERFACE_INDEX);
456459

457460
/*
458461
* identify all kernel interfaces and the associated addresses of
@@ -461,17 +464,17 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
461464

462465
for( i = 0; i < btl_proc->proc_addr_count; i++ ) {
463466

464-
int index;
467+
uint64_t index;
465468

466469
mca_btl_tcp_addr_t* endpoint_addr = btl_proc->proc_addrs + i;
467470

468471
mca_btl_tcp_proc_tosocks (endpoint_addr, &endpoint_addr_ss);
469472

470-
index = proc_data->peer_kindex_to_index[endpoint_addr->addr_ifkindex];
473+
rc = opal_hash_table_get_value_uint32(&proc_data->peer_kindex_to_index, endpoint_addr->addr_ifkindex, (void**) &index);
471474

472-
if(-1 == index) {
475+
if (OPAL_SUCCESS != rc) {
473476
index = proc_data->num_peer_interfaces++;
474-
proc_data->peer_kindex_to_index[endpoint_addr->addr_ifkindex] = index;
477+
opal_hash_table_set_value_uint32(&proc_data->peer_kindex_to_index, endpoint_addr->addr_ifkindex, (void*)(uintptr_t) index);
475478
if( proc_data->num_peer_interfaces == max_peer_interfaces ) {
476479
max_peer_interfaces <<= 1;
477480
peer_interfaces = (mca_btl_tcp_interface_t**)realloc( peer_interfaces,
@@ -692,6 +695,10 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
692695
free(proc_data->weights);
693696
free(proc_data->best_addr);
694697
free(proc_data->best_assignment);
698+
699+
OBJ_DESTRUCT(&_proc_data.local_kindex_to_index);
700+
OBJ_DESTRUCT(&_proc_data.peer_kindex_to_index);
701+
695702
free(a);
696703

697704
return rc;

0 commit comments

Comments
 (0)