Skip to content

Commit cb9825e

Browse files
authored
Merge pull request #5331 from jsquyres/v3.1.x
v3.1.x: btl/tcp: use a hash map for kernel IP interface indexes
2 parents 43a8e77 + d61b6c1 commit cb9825e

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,13 +419,18 @@ 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
char str_local[128], str_remote[128];
425423

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

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

458461
/*
459462
* identify all kernel interfaces and the associated addresses of
@@ -462,17 +465,17 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
462465

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

465-
int index;
468+
uint64_t index;
466469

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

469472
mca_btl_tcp_proc_tosocks (endpoint_addr, &endpoint_addr_ss);
470473

471-
index = proc_data->peer_kindex_to_index[endpoint_addr->addr_ifkindex];
474+
rc = opal_hash_table_get_value_uint32(&proc_data->peer_kindex_to_index, endpoint_addr->addr_ifkindex, (void**) &index);
472475

473-
if(-1 == index) {
476+
if (OPAL_SUCCESS != rc) {
474477
index = proc_data->num_peer_interfaces++;
475-
proc_data->peer_kindex_to_index[endpoint_addr->addr_ifkindex] = index;
478+
opal_hash_table_set_value_uint32(&proc_data->peer_kindex_to_index, endpoint_addr->addr_ifkindex, (void*)(uintptr_t) index);
476479
if( proc_data->num_peer_interfaces == max_peer_interfaces ) {
477480
max_peer_interfaces <<= 1;
478481
peer_interfaces = (mca_btl_tcp_interface_t**)realloc( peer_interfaces,
@@ -726,6 +729,10 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
726729
free(proc_data->weights);
727730
free(proc_data->best_addr);
728731
free(proc_data->best_assignment);
732+
733+
OBJ_DESTRUCT(&_proc_data.local_kindex_to_index);
734+
OBJ_DESTRUCT(&_proc_data.peer_kindex_to_index);
735+
729736
free(a);
730737

731738
return rc;

0 commit comments

Comments
 (0)