2006-03-11 06:09:24 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2006-03-11 06:09:24 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2008-01-07 18:43:44 +03:00
|
|
|
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
|
2006-03-11 06:09:24 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
* In windows, many of the socket functions return an EWOULDBLOCK
|
|
|
|
* instead of \ things like EAGAIN, EINPROGRESS, etc. It has been
|
|
|
|
* verified that this will \ not conflict with other error codes that
|
|
|
|
* are returned by these functions \ under UNIX/Linux environments
|
|
|
|
*/
|
|
|
|
|
2005-08-02 17:20:50 +04:00
|
|
|
#include "ompi_config.h"
|
2005-08-02 18:59:50 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_UIO_H
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
2007-07-10 07:46:57 +04:00
|
|
|
#ifdef HAVE_NET_UIO_H
|
|
|
|
#include <net/uio.h>
|
|
|
|
#endif
|
2005-12-11 01:04:28 +03:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-08-02 18:59:50 +04:00
|
|
|
#include <unistd.h>
|
2005-12-11 01:04:28 +03:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
2005-08-02 18:59:50 +04:00
|
|
|
|
2006-08-15 00:14:44 +04:00
|
|
|
#include "opal/opal_socket_errno.h"
|
2005-08-02 17:20:50 +04:00
|
|
|
#include "ompi/mca/btl/base/btl_base_error.h"
|
|
|
|
#include "btl_tcp_frag.h"
|
|
|
|
#include "btl_tcp_endpoint.h"
|
2005-09-13 00:22:59 +04:00
|
|
|
#include "orte/util/proc_info.h"
|
2005-08-02 17:20:50 +04:00
|
|
|
|
|
|
|
static void mca_btl_tcp_frag_common_constructor(mca_btl_tcp_frag_t* frag)
|
|
|
|
{
|
|
|
|
frag->base.des_src = NULL;
|
|
|
|
frag->base.des_src_cnt = 0;
|
|
|
|
frag->base.des_dst = NULL;
|
|
|
|
frag->base.des_dst_cnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mca_btl_tcp_frag_eager_constructor(mca_btl_tcp_frag_t* frag)
|
|
|
|
{
|
|
|
|
frag->size = mca_btl_tcp_module.super.btl_eager_limit;
|
2006-05-25 20:57:14 +04:00
|
|
|
frag->my_list = &mca_btl_tcp_component.tcp_frag_eager;
|
2005-08-02 17:20:50 +04:00
|
|
|
mca_btl_tcp_frag_common_constructor(frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mca_btl_tcp_frag_max_constructor(mca_btl_tcp_frag_t* frag)
|
|
|
|
{
|
|
|
|
frag->size = mca_btl_tcp_module.super.btl_max_send_size;
|
2006-05-25 20:57:14 +04:00
|
|
|
frag->my_list = &mca_btl_tcp_component.tcp_frag_max;
|
2005-08-02 17:20:50 +04:00
|
|
|
mca_btl_tcp_frag_common_constructor(frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mca_btl_tcp_frag_user_constructor(mca_btl_tcp_frag_t* frag)
|
|
|
|
{
|
|
|
|
frag->size = 0;
|
2006-05-25 20:57:14 +04:00
|
|
|
frag->my_list = &mca_btl_tcp_component.tcp_frag_user;
|
2005-08-02 17:20:50 +04:00
|
|
|
mca_btl_tcp_frag_common_constructor(frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_btl_tcp_frag_t,
|
|
|
|
mca_btl_base_descriptor_t,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_btl_tcp_frag_eager_t,
|
|
|
|
mca_btl_base_descriptor_t,
|
|
|
|
mca_btl_tcp_frag_eager_constructor,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_btl_tcp_frag_max_t,
|
|
|
|
mca_btl_base_descriptor_t,
|
|
|
|
mca_btl_tcp_frag_max_constructor,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_btl_tcp_frag_user_t,
|
|
|
|
mca_btl_base_descriptor_t,
|
|
|
|
mca_btl_tcp_frag_user_constructor,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
|
|
bool mca_btl_tcp_frag_send(mca_btl_tcp_frag_t* frag, int sd)
|
|
|
|
{
|
|
|
|
int cnt=-1;
|
|
|
|
size_t i, num_vecs;
|
|
|
|
|
|
|
|
/* non-blocking write, but continue if interrupted */
|
|
|
|
while(cnt < 0) {
|
|
|
|
cnt = writev(sd, frag->iov_ptr, frag->iov_cnt);
|
|
|
|
if(cnt < 0) {
|
2006-08-15 00:14:44 +04:00
|
|
|
switch(opal_socket_errno) {
|
2005-08-02 17:20:50 +04:00
|
|
|
case EINTR:
|
|
|
|
continue;
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
return false;
|
|
|
|
case EFAULT:
|
2006-12-02 00:48:06 +03:00
|
|
|
BTL_ERROR(("mca_btl_tcp_frag_send: writev error (%p, %d)\n\t%s(%d)\n",
|
2005-08-02 17:20:50 +04:00
|
|
|
frag->iov_ptr[0].iov_base, frag->iov_ptr[0].iov_len,
|
2006-08-15 00:14:44 +04:00
|
|
|
strerror(opal_socket_errno), frag->iov_cnt));
|
2006-12-02 00:48:06 +03:00
|
|
|
mca_btl_tcp_endpoint_close(frag->endpoint);
|
|
|
|
return false;
|
2005-08-02 17:20:50 +04:00
|
|
|
default:
|
2006-12-14 21:20:43 +03:00
|
|
|
BTL_ERROR(("mca_btl_tcp_frag_send: writev failed: %s (%d)",
|
|
|
|
strerror(opal_socket_errno),
|
|
|
|
opal_socket_errno));
|
2005-08-02 17:20:50 +04:00
|
|
|
mca_btl_tcp_endpoint_close(frag->endpoint);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
|
2005-08-02 17:20:50 +04:00
|
|
|
/* if the write didn't complete - update the iovec state */
|
|
|
|
num_vecs = frag->iov_cnt;
|
|
|
|
for(i=0; i<num_vecs; i++) {
|
|
|
|
if(cnt >= (int)frag->iov_ptr->iov_len) {
|
|
|
|
cnt -= frag->iov_ptr->iov_len;
|
|
|
|
frag->iov_ptr++;
|
|
|
|
frag->iov_idx++;
|
|
|
|
frag->iov_cnt--;
|
|
|
|
} else {
|
|
|
|
frag->iov_ptr->iov_base = (ompi_iov_base_ptr_t)
|
|
|
|
(((unsigned char*)frag->iov_ptr->iov_base) + cnt);
|
|
|
|
frag->iov_ptr->iov_len -= cnt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (frag->iov_cnt == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mca_btl_tcp_frag_recv(mca_btl_tcp_frag_t* frag, int sd)
|
|
|
|
{
|
2007-04-12 08:52:29 +04:00
|
|
|
int cnt, dont_copy_data = 0;
|
2006-01-14 23:21:44 +03:00
|
|
|
size_t i, num_vecs;
|
2005-12-07 03:12:59 +03:00
|
|
|
mca_btl_base_endpoint_t* btl_endpoint = frag->endpoint;
|
|
|
|
|
|
|
|
repeat:
|
2006-01-14 23:21:44 +03:00
|
|
|
num_vecs = frag->iov_cnt;
|
2005-12-07 03:12:59 +03:00
|
|
|
#if MCA_BTL_TCP_ENDPOINT_CACHE
|
|
|
|
if( 0 != btl_endpoint->endpoint_cache_length ) {
|
2006-12-02 00:48:06 +03:00
|
|
|
size_t length;
|
|
|
|
/* It's strange at the first look but cnt have to be set to the full amount of data
|
2007-05-23 18:03:52 +04:00
|
|
|
* available. After going to advance_iov_position we will use cnt to detect if there
|
|
|
|
* is still some data pending.
|
2006-01-14 23:21:44 +03:00
|
|
|
*/
|
2006-12-02 00:48:06 +03:00
|
|
|
cnt = length = btl_endpoint->endpoint_cache_length;
|
2005-12-07 03:12:59 +03:00
|
|
|
for( i = 0; i < frag->iov_cnt; i++ ) {
|
|
|
|
if( length > frag->iov_ptr[i].iov_len )
|
2007-04-12 08:52:29 +04:00
|
|
|
length = frag->iov_ptr[i].iov_len;
|
|
|
|
if( (0 == dont_copy_data) || (length < frag->iov_ptr[i].iov_len) ) {
|
|
|
|
memcpy( frag->iov_ptr[i].iov_base, btl_endpoint->endpoint_cache_pos, length );
|
|
|
|
} else {
|
|
|
|
frag->segments[0].seg_addr.pval = btl_endpoint->endpoint_cache_pos;
|
|
|
|
frag->iov_ptr[i].iov_base = btl_endpoint->endpoint_cache_pos;
|
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
btl_endpoint->endpoint_cache_pos += length;
|
|
|
|
btl_endpoint->endpoint_cache_length -= length;
|
|
|
|
length = btl_endpoint->endpoint_cache_length;
|
2006-01-14 23:21:44 +03:00
|
|
|
if( 0 == length ) {
|
2007-05-23 18:03:52 +04:00
|
|
|
btl_endpoint->endpoint_cache_pos = btl_endpoint->endpoint_cache;
|
|
|
|
break;
|
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
}
|
|
|
|
goto advance_iov_position;
|
|
|
|
}
|
2006-01-14 23:21:44 +03:00
|
|
|
/* What's happens if all iovecs are used by the fragment ? It still work, as we reserve one
|
|
|
|
* iovec for the caching in the fragment structure (the +1).
|
|
|
|
*/
|
2007-04-12 08:52:29 +04:00
|
|
|
frag->iov_ptr[num_vecs].iov_base = btl_endpoint->endpoint_cache_pos;
|
|
|
|
frag->iov_ptr[num_vecs].iov_len =
|
|
|
|
mca_btl_tcp_component.tcp_endpoint_cache - btl_endpoint->endpoint_cache_length;
|
2005-12-07 03:12:59 +03:00
|
|
|
num_vecs++;
|
|
|
|
#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */
|
2005-11-29 20:33:01 +03:00
|
|
|
|
2005-08-02 17:20:50 +04:00
|
|
|
/* non-blocking read, but continue if interrupted */
|
2005-11-29 20:33:01 +03:00
|
|
|
cnt = -1;
|
2005-12-07 03:12:59 +03:00
|
|
|
while( cnt < 0 ) {
|
|
|
|
cnt = readv(sd, frag->iov_ptr, num_vecs);
|
2006-12-02 00:48:06 +03:00
|
|
|
if( 0 < cnt ) goto advance_iov_position;
|
|
|
|
if( cnt == 0 ) {
|
|
|
|
mca_btl_tcp_endpoint_close(btl_endpoint);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch(opal_socket_errno) {
|
|
|
|
case EINTR:
|
|
|
|
continue;
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
return false;
|
|
|
|
case EFAULT:
|
|
|
|
BTL_ERROR(("mca_btl_tcp_frag_recv: readv error (%p, %d)\n\t%s(%d)\n",
|
|
|
|
frag->iov_ptr[0].iov_base, frag->iov_ptr[0].iov_len,
|
|
|
|
strerror(opal_socket_errno), frag->iov_cnt));
|
|
|
|
mca_btl_tcp_endpoint_close(btl_endpoint);
|
|
|
|
return false;
|
|
|
|
default:
|
2006-12-14 21:20:43 +03:00
|
|
|
BTL_ERROR(("mca_btl_tcp_frag_recv: readv failed: %s (%d)",
|
|
|
|
strerror(opal_socket_errno),
|
|
|
|
opal_socket_errno));
|
2006-12-02 00:48:06 +03:00
|
|
|
mca_btl_tcp_endpoint_close(btl_endpoint);
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
};
|
2005-09-15 01:27:30 +04:00
|
|
|
|
2005-12-07 03:12:59 +03:00
|
|
|
advance_iov_position:
|
2007-04-12 08:52:29 +04:00
|
|
|
/* if the read didn't complete - update the iovec state */
|
2005-08-02 17:20:50 +04:00
|
|
|
num_vecs = frag->iov_cnt;
|
2006-01-14 23:21:44 +03:00
|
|
|
for( i = 0; i < num_vecs; i++ ) {
|
2006-12-02 00:48:06 +03:00
|
|
|
if( cnt < (int)frag->iov_ptr->iov_len ) {
|
2005-08-02 17:20:50 +04:00
|
|
|
frag->iov_ptr->iov_base = (ompi_iov_base_ptr_t)
|
|
|
|
(((unsigned char*)frag->iov_ptr->iov_base) + cnt);
|
|
|
|
frag->iov_ptr->iov_len -= cnt;
|
2006-01-14 23:21:44 +03:00
|
|
|
cnt = 0;
|
2005-08-02 17:20:50 +04:00
|
|
|
break;
|
2006-12-02 00:48:06 +03:00
|
|
|
}
|
|
|
|
cnt -= frag->iov_ptr->iov_len;
|
|
|
|
frag->iov_idx++;
|
|
|
|
frag->iov_ptr++;
|
|
|
|
frag->iov_cnt--;
|
2005-08-02 17:20:50 +04:00
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
#if MCA_BTL_TCP_ENDPOINT_CACHE
|
|
|
|
btl_endpoint->endpoint_cache_length = cnt;
|
|
|
|
#endif /* MCA_BTL_TCP_ENDPOINT_CACHE */
|
|
|
|
|
2005-08-02 17:20:50 +04:00
|
|
|
/* read header */
|
2005-08-09 18:10:17 +04:00
|
|
|
if(frag->iov_cnt == 0) {
|
2007-08-29 01:23:44 +04:00
|
|
|
if (btl_endpoint->endpoint_nbo && frag->iov_idx == 1) MCA_BTL_TCP_HDR_NTOH(frag->hdr);
|
2005-08-02 17:20:50 +04:00
|
|
|
switch(frag->hdr.type) {
|
2005-12-07 03:12:59 +03:00
|
|
|
case MCA_BTL_TCP_HDR_TYPE_SEND:
|
|
|
|
if(frag->iov_idx == 1 && frag->hdr.size) {
|
2007-01-05 01:07:37 +03:00
|
|
|
frag->segments[0].seg_addr.pval = frag+1;
|
2005-12-07 03:12:59 +03:00
|
|
|
frag->segments[0].seg_len = frag->hdr.size;
|
2007-04-12 08:52:29 +04:00
|
|
|
frag->iov[1].iov_base = (IOVBASE_TYPE*)(frag->segments[0].seg_addr.pval);
|
|
|
|
frag->iov[1].iov_len = frag->hdr.size;
|
2005-12-07 03:12:59 +03:00
|
|
|
frag->iov_cnt++;
|
2008-01-07 18:43:44 +03:00
|
|
|
#ifndef __sparc
|
|
|
|
/* The following cannot be done for sparc code
|
2007-05-08 21:17:34 +04:00
|
|
|
* because it causes alignment errors when accessing
|
|
|
|
* structures later on in the btl and pml code.
|
|
|
|
*/
|
2007-04-12 08:52:29 +04:00
|
|
|
dont_copy_data = 1;
|
2007-05-08 21:17:34 +04:00
|
|
|
#endif
|
2005-12-07 03:12:59 +03:00
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MCA_BTL_TCP_HDR_TYPE_PUT:
|
|
|
|
if(frag->iov_idx == 1) {
|
2006-08-24 20:38:08 +04:00
|
|
|
frag->iov[1].iov_base = (IOVBASE_TYPE*)frag->segments;
|
2005-12-07 03:12:59 +03:00
|
|
|
frag->iov[1].iov_len = frag->hdr.count * sizeof(mca_btl_base_segment_t);
|
|
|
|
frag->iov_cnt++;
|
|
|
|
goto repeat;
|
|
|
|
} else if (frag->iov_idx == 2) {
|
2007-04-12 08:52:29 +04:00
|
|
|
for( i = 0; i < frag->hdr.count; i++ ) {
|
2007-01-07 04:48:57 +03:00
|
|
|
frag->iov[i+2].iov_base = (IOVBASE_TYPE*)ompi_ptr_ltop(frag->segments[i].seg_addr.lval);
|
2005-12-07 03:12:59 +03:00
|
|
|
frag->iov[i+2].iov_len = frag->segments[i].seg_len;
|
2005-08-09 18:10:17 +04:00
|
|
|
}
|
2007-04-12 08:52:29 +04:00
|
|
|
frag->iov_cnt += frag->hdr.count;
|
2005-12-07 03:12:59 +03:00
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MCA_BTL_TCP_HDR_TYPE_GET:
|
|
|
|
default:
|
|
|
|
break;
|
2005-08-02 17:20:50 +04:00
|
|
|
}
|
2005-08-09 18:10:17 +04:00
|
|
|
return true;
|
2005-08-02 17:20:50 +04:00
|
|
|
}
|
2005-12-07 03:12:59 +03:00
|
|
|
return false;
|
2005-08-02 17:20:50 +04:00
|
|
|
}
|
|
|
|
|