2004-01-29 01:52:51 +03:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-29 01:52:51 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-08-16 05:13:25 +04:00
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
2004-03-26 17:15:20 +03:00
|
|
|
#include <string.h>
|
2004-08-16 05:13:25 +04:00
|
|
|
|
|
|
|
#include "include/sys/atomic.h"
|
2004-10-25 23:55:04 +04:00
|
|
|
#include "class/ompi_proc_table.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mca/base/mca_base_module_exchange.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "mca/ns/ns_types.h"
|
2004-01-29 01:52:51 +03:00
|
|
|
#include "ptl_tcp.h"
|
|
|
|
#include "ptl_tcp_addr.h"
|
|
|
|
#include "ptl_tcp_peer.h"
|
|
|
|
#include "ptl_tcp_proc.h"
|
|
|
|
|
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
static void mca_ptl_tcp_proc_construct(mca_ptl_tcp_proc_t* proc);
|
|
|
|
static void mca_ptl_tcp_proc_destruct(mca_ptl_tcp_proc_t* proc);
|
2004-10-25 23:55:04 +04:00
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_ptl_tcp_proc_t,
|
|
|
|
ompi_list_item_t,
|
|
|
|
mca_ptl_tcp_proc_construct,
|
|
|
|
mca_ptl_tcp_proc_destruct
|
|
|
|
);
|
2004-01-29 01:52:51 +03:00
|
|
|
|
|
|
|
|
2004-06-04 02:13:01 +04:00
|
|
|
/**
|
|
|
|
* Initialize tcp proc instance
|
|
|
|
*/
|
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
void mca_ptl_tcp_proc_construct(mca_ptl_tcp_proc_t* proc)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
proc->proc_ompi = 0;
|
2004-01-29 01:52:51 +03:00
|
|
|
proc->proc_addrs = 0;
|
|
|
|
proc->proc_addr_count = 0;
|
|
|
|
proc->proc_peers = 0;
|
|
|
|
proc->proc_peer_count = 0;
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&proc->proc_lock, ompi_mutex_t);
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-04 02:13:01 +04:00
|
|
|
/*
|
|
|
|
* Cleanup tcp proc instance
|
|
|
|
*/
|
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
void mca_ptl_tcp_proc_destruct(mca_ptl_tcp_proc_t* proc)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
|
|
|
/* remove from list of all proc instances */
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_THREAD_LOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-10-25 23:55:04 +04:00
|
|
|
ompi_hash_table_remove_proc(&mca_ptl_tcp_component.tcp_procs, &proc->proc_name);
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
|
|
|
|
/* release resources */
|
|
|
|
if(NULL != proc->proc_peers)
|
2004-02-10 03:09:36 +03:00
|
|
|
free(proc->proc_peers);
|
2004-12-07 21:14:55 +03:00
|
|
|
OBJ_DESTRUCT(&proc->proc_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a TCP process structure. There is a one-to-one correspondence
|
2004-06-07 19:33:53 +04:00
|
|
|
* between a ompi_proc_t and a mca_ptl_tcp_proc_t instance. We cache additional
|
2004-01-29 01:52:51 +03:00
|
|
|
* data (specifically the list of mca_ptl_tcp_peer_t instances, and publiched
|
|
|
|
* addresses) associated w/ a given destination on this datastructure.
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
mca_ptl_tcp_proc_t* mca_ptl_tcp_proc_create(ompi_proc_t* ompi_proc)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
|
|
|
int rc;
|
2004-07-01 18:49:54 +04:00
|
|
|
size_t size;
|
2004-10-25 23:55:04 +04:00
|
|
|
mca_ptl_tcp_proc_t* ptl_proc;
|
|
|
|
|
|
|
|
OMPI_THREAD_LOCK(&mca_ptl_tcp_component.tcp_lock);
|
|
|
|
ptl_proc = (mca_ptl_tcp_proc_t*)ompi_hash_table_get_proc(
|
|
|
|
&mca_ptl_tcp_component.tcp_procs, &ompi_proc->proc_name);
|
|
|
|
if(NULL != ptl_proc) {
|
|
|
|
OMPI_THREAD_UNLOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
return ptl_proc;
|
2004-10-25 23:55:04 +04:00
|
|
|
}
|
2004-01-29 01:52:51 +03:00
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
ptl_proc = OBJ_NEW(mca_ptl_tcp_proc_t);
|
2004-10-25 23:55:04 +04:00
|
|
|
if(NULL == ptl_proc)
|
|
|
|
return NULL;
|
2004-06-07 19:33:53 +04:00
|
|
|
ptl_proc->proc_ompi = ompi_proc;
|
2004-10-25 23:55:04 +04:00
|
|
|
ptl_proc->proc_name = ompi_proc->proc_name;
|
2004-01-29 01:52:51 +03:00
|
|
|
|
2004-10-25 23:55:04 +04:00
|
|
|
/* add to hash table of all proc instance */
|
|
|
|
ompi_hash_table_set_proc(
|
|
|
|
&mca_ptl_tcp_component.tcp_procs,
|
|
|
|
&ptl_proc->proc_name,
|
|
|
|
ptl_proc);
|
|
|
|
OMPI_THREAD_UNLOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
|
|
|
|
/* lookup tcp parameters exported by this proc */
|
2005-04-10 04:26:35 +04:00
|
|
|
rc = mca_base_modex_recv( &mca_ptl_tcp_component.super.ptlm_version,
|
|
|
|
ompi_proc,
|
|
|
|
(void**)&ptl_proc->proc_addrs,
|
|
|
|
&size);
|
2004-06-07 19:33:53 +04:00
|
|
|
if(rc != OMPI_SUCCESS) {
|
|
|
|
ompi_output(0, "mca_ptl_tcp_proc_create: mca_base_modex_recv: failed with return value=%d", rc);
|
2004-01-29 01:52:51 +03:00
|
|
|
OBJ_RELEASE(ptl_proc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-03 19:44:41 +03:00
|
|
|
if(0 != (size % sizeof(mca_ptl_tcp_addr_t))) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_output(0, "mca_ptl_tcp_proc_create: mca_base_modex_recv: invalid size %d\n", size);
|
2004-01-29 01:52:51 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-03 19:44:41 +03:00
|
|
|
ptl_proc->proc_addr_count = size / sizeof(mca_ptl_tcp_addr_t);
|
2004-01-29 01:52:51 +03:00
|
|
|
|
|
|
|
/* allocate space for peer array - one for each exported address */
|
2004-02-05 03:50:37 +03:00
|
|
|
ptl_proc->proc_peers = (mca_ptl_base_peer_t**)
|
2004-02-10 03:09:36 +03:00
|
|
|
malloc(ptl_proc->proc_addr_count * sizeof(mca_ptl_base_peer_t*));
|
2004-01-29 01:52:51 +03:00
|
|
|
if(NULL == ptl_proc->proc_peers) {
|
|
|
|
OBJ_RELEASE(ptl_proc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-02 04:24:22 +04:00
|
|
|
if(NULL == mca_ptl_tcp_component.tcp_local && ompi_proc == ompi_proc_local())
|
|
|
|
mca_ptl_tcp_component.tcp_local = ptl_proc;
|
2004-01-29 01:52:51 +03:00
|
|
|
return ptl_proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for an existing TCP process instance based on the globally unique
|
|
|
|
* process identifier.
|
|
|
|
*/
|
2005-03-14 23:57:21 +03:00
|
|
|
mca_ptl_tcp_proc_t* mca_ptl_tcp_proc_lookup(const orte_process_name_t *name)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
2004-10-25 23:55:04 +04:00
|
|
|
mca_ptl_tcp_proc_t* proc;
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_THREAD_LOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-10-25 23:55:04 +04:00
|
|
|
proc = (mca_ptl_tcp_proc_t*)ompi_hash_table_get_proc(
|
|
|
|
&mca_ptl_tcp_component.tcp_procs, name);
|
2004-08-02 04:24:22 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&mca_ptl_tcp_component.tcp_lock);
|
2004-10-25 23:55:04 +04:00
|
|
|
return proc;
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
|
2005-04-10 04:26:35 +04:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2004-01-29 01:52:51 +03:00
|
|
|
/*
|
|
|
|
* Note that this routine must be called with the lock on the process already
|
|
|
|
* held. Insert a ptl instance into the proc array and assign it an address.
|
|
|
|
*/
|
2004-02-05 03:50:37 +03:00
|
|
|
int mca_ptl_tcp_proc_insert(mca_ptl_tcp_proc_t* ptl_proc, mca_ptl_base_peer_t* ptl_peer)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
2004-08-02 04:24:22 +04:00
|
|
|
struct mca_ptl_tcp_module_t *ptl_tcp = ptl_peer->peer_ptl;
|
2004-01-29 01:52:51 +03:00
|
|
|
size_t i;
|
2005-04-10 04:26:35 +04:00
|
|
|
unsigned long net1;
|
2004-01-29 01:52:51 +03:00
|
|
|
|
|
|
|
/* insert into peer array */
|
|
|
|
ptl_peer->peer_proc = ptl_proc;
|
|
|
|
ptl_proc->proc_peers[ptl_proc->proc_peer_count++] = ptl_peer;
|
2004-10-25 23:55:04 +04:00
|
|
|
|
2005-04-10 04:26:35 +04:00
|
|
|
net1 = ptl_tcp->ptl_ifaddr.sin_addr.s_addr & ptl_tcp->ptl_ifmask.sin_addr.s_addr;
|
2004-01-29 01:52:51 +03:00
|
|
|
/*
|
|
|
|
* Look through the proc instance for an address that is on the
|
|
|
|
* directly attached network. If we don't find one, pick the first
|
|
|
|
* unused address.
|
|
|
|
*/
|
|
|
|
for(i=0; i<ptl_proc->proc_addr_count; i++) {
|
|
|
|
mca_ptl_tcp_addr_t* peer_addr = ptl_proc->proc_addrs + i;
|
|
|
|
unsigned long net2 = peer_addr->addr_inet.s_addr & ptl_tcp->ptl_ifmask.sin_addr.s_addr;
|
|
|
|
if(peer_addr->addr_inuse != 0)
|
|
|
|
continue;
|
|
|
|
if(net1 == net2) {
|
|
|
|
ptl_peer->peer_addr = peer_addr;
|
|
|
|
break;
|
|
|
|
} else if(ptl_peer->peer_addr != 0)
|
|
|
|
ptl_peer->peer_addr = peer_addr;
|
|
|
|
}
|
2005-02-10 03:03:37 +03:00
|
|
|
/* Make sure there is a common interface */
|
|
|
|
if( NULL != ptl_peer->peer_addr ) {
|
|
|
|
ptl_peer->peer_addr->addr_inuse++;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
return OMPI_ERR_UNREACH;
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a peer from the proc array and indicate the address is
|
|
|
|
* no longer in use.
|
|
|
|
*/
|
|
|
|
|
2004-02-05 03:50:37 +03:00
|
|
|
int mca_ptl_tcp_proc_remove(mca_ptl_tcp_proc_t* ptl_proc, mca_ptl_base_peer_t* ptl_peer)
|
2004-01-29 01:52:51 +03:00
|
|
|
{
|
|
|
|
size_t i;
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_LOCK(&ptl_proc->proc_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
for(i=0; i<ptl_proc->proc_peer_count; i++) {
|
|
|
|
if(ptl_proc->proc_peers[i] == ptl_peer) {
|
2004-08-12 17:23:57 +04:00
|
|
|
memmove(ptl_proc->proc_peers+i, ptl_proc->proc_peers+i+1,
|
|
|
|
(ptl_proc->proc_peer_count-i-1)*sizeof(mca_ptl_base_peer_t*));
|
2004-12-06 23:53:22 +03:00
|
|
|
if(--ptl_proc->proc_peer_count == 0) {
|
2004-12-07 21:14:55 +03:00
|
|
|
OMPI_THREAD_UNLOCK(&ptl_proc->proc_lock);
|
2004-12-06 23:53:22 +03:00
|
|
|
OBJ_RELEASE(ptl_proc);
|
2004-12-07 21:14:55 +03:00
|
|
|
return OMPI_SUCCESS;
|
2004-12-06 23:53:22 +03:00
|
|
|
}
|
2004-08-11 20:56:45 +04:00
|
|
|
ptl_peer->peer_addr->addr_inuse--;
|
|
|
|
break;
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
}
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ptl_proc->proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loop through all available PTLs for one matching the source address
|
|
|
|
* of the request.
|
|
|
|
*/
|
|
|
|
bool mca_ptl_tcp_proc_accept(mca_ptl_tcp_proc_t* ptl_proc, struct sockaddr_in* addr, int sd)
|
|
|
|
{
|
|
|
|
size_t i;
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_LOCK(&ptl_proc->proc_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
for(i=0; i<ptl_proc->proc_peer_count; i++) {
|
2004-02-05 03:50:37 +03:00
|
|
|
mca_ptl_base_peer_t* ptl_peer = ptl_proc->proc_peers[i];
|
2004-04-12 19:39:15 +04:00
|
|
|
if(mca_ptl_tcp_peer_accept(ptl_peer, addr, sd)) {
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ptl_proc->proc_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
return true;
|
2004-04-12 19:39:15 +04:00
|
|
|
}
|
2004-01-29 01:52:51 +03:00
|
|
|
}
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ptl_proc->proc_lock);
|
2004-01-29 01:52:51 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|