btl_tcp_component.c
来自「MPI stands for the Message Passing Inter」· C语言 代码 · 共 642 行 · 第 1/2 页
C
642 行
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University * 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. * $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 */#include "ompi_config.h"#include "opal/opal_socket_errno.h"#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <string.h>#include <fcntl.h>#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_SOCKET_H#include <sys/socket.h>#endif#ifdef HAVE_NETINET_IN_H#include <netinet/in.h>#endif#ifdef HAVE_ARPA_INET_H#include <arpa/inet.h>#endif#include "ompi/constants.h"#include "opal/event/event.h"#include "opal/util/if.h"#include "opal/util/argv.h"#include "opal/util/output.h"#include "orte/mca/oob/base/base.h"#include "orte/mca/ns/ns_types.h"#include "ompi/mca/pml/pml.h"#include "ompi/mca/btl/btl.h"#include "opal/mca/base/mca_base_param.h"#include "ompi/mca/pml/base/pml_base_module_exchange.h"#include "orte/mca/errmgr/errmgr.h"#include "ompi/mca/mpool/base/base.h" #include "ompi/mca/btl/base/btl_base_error.h"#include "btl_tcp.h"#include "btl_tcp_addr.h"#include "btl_tcp_proc.h"#include "btl_tcp_frag.h"#include "btl_tcp_endpoint.h" #include "ompi/mca/btl/base/base.h" #include "ompi/datatype/convertor.h" mca_btl_tcp_component_t mca_btl_tcp_component = { { /* First, the mca_base_component_t struct containing meta information about the component itself */ { /* Indicate that we are a pml v1.0.0 component (which also implies a specific MCA version) */ MCA_BTL_BASE_VERSION_1_0_1, "tcp", /* MCA component name */ 1, /* MCA component major version */ 0, /* MCA component minor version */ 0, /* MCA component release version */ mca_btl_tcp_component_open, /* component open */ mca_btl_tcp_component_close /* component close */ }, /* Next the MCA v1.0.0 component meta data */ { /* Whether the component is checkpointable or not */ false }, mca_btl_tcp_component_init, NULL, }};/* * utility routines for parameter registration */static inline char* mca_btl_tcp_param_register_string( const char* param_name, const char* default_value){ char *param_value; int id = mca_base_param_register_string("btl","tcp",param_name,NULL,default_value); mca_base_param_lookup_string(id, ¶m_value); return param_value;}static inline int mca_btl_tcp_param_register_int( const char* param_name, int default_value){ int id = mca_base_param_register_int("btl","tcp",param_name,NULL,default_value); int param_value = default_value; mca_base_param_lookup_int(id,¶m_value); return param_value;}/* * Data structure for accepting connections. */struct mca_btl_tcp_event_t { opal_list_item_t item; opal_event_t event;};typedef struct mca_btl_tcp_event_t mca_btl_tcp_event_t;static void mca_btl_tcp_event_construct(mca_btl_tcp_event_t* event){ OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); opal_list_append(&mca_btl_tcp_component.tcp_events, &event->item); OPAL_THREAD_UNLOCK(&mca_btl_tcp_component.tcp_lock);}static void mca_btl_tcp_event_destruct(mca_btl_tcp_event_t* event){ OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); opal_list_remove_item(&mca_btl_tcp_component.tcp_events, &event->item); OPAL_THREAD_UNLOCK(&mca_btl_tcp_component.tcp_lock);}OBJ_CLASS_INSTANCE( mca_btl_tcp_event_t, opal_list_item_t, mca_btl_tcp_event_construct, mca_btl_tcp_event_destruct);/* * functions for receiving event callbacks */static void mca_btl_tcp_component_recv_handler(int, short, void*);/* * Called by MCA framework to open the component, registers * component parameters. */int mca_btl_tcp_component_open(void){#ifdef __WINDOWS__ WSADATA win_sock_data; if (WSAStartup(MAKEWORD(2,2), &win_sock_data) != 0) { BTL_ERROR(("failed to initialise windows sockets:%d", WSAGetLastError())); return OMPI_ERROR; }#endif /* initialize state */ mca_btl_tcp_component.tcp_listen_sd = -1; mca_btl_tcp_component.tcp_num_btls=0; mca_btl_tcp_component.tcp_btls=NULL; /* initialize objects */ OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_lock, opal_mutex_t); OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_procs, opal_hash_table_t); OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_events, opal_list_t); OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_frag_eager, ompi_free_list_t); OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_frag_max, ompi_free_list_t); OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_frag_user, ompi_free_list_t); opal_hash_table_init(&mca_btl_tcp_component.tcp_procs, 256); /* register TCP component parameters */ mca_btl_tcp_component.tcp_if_include = mca_btl_tcp_param_register_string("if_include", ""); mca_btl_tcp_component.tcp_if_exclude = mca_btl_tcp_param_register_string("if_exclude", "lo"); mca_btl_tcp_component.tcp_free_list_num = mca_btl_tcp_param_register_int ("free_list_num", 8); mca_btl_tcp_component.tcp_free_list_max = mca_btl_tcp_param_register_int ("free_list_max", -1); mca_btl_tcp_component.tcp_free_list_inc = mca_btl_tcp_param_register_int ("free_list_inc", 32); mca_btl_tcp_component.tcp_sndbuf = mca_btl_tcp_param_register_int ("sndbuf", 128*1024); mca_btl_tcp_component.tcp_rcvbuf = mca_btl_tcp_param_register_int ("rcvbuf", 128*1024); mca_btl_tcp_component.tcp_endpoint_cache = mca_btl_tcp_param_register_int ("endpoint_cache", 30*1024); mca_btl_tcp_module.super.btl_exclusivity = mca_btl_tcp_param_register_int ("exclusivity", MCA_BTL_EXCLUSIVITY_LOW); mca_btl_tcp_module.super.btl_eager_limit = mca_btl_tcp_param_register_int ("eager_limit", 64*1024); mca_btl_tcp_module.super.btl_min_send_size = mca_btl_tcp_param_register_int ("min_send_size", 64*1024); mca_btl_tcp_module.super.btl_max_send_size = mca_btl_tcp_param_register_int ("max_send_size", 128*1024); mca_btl_tcp_module.super.btl_min_rdma_size = mca_btl_tcp_param_register_int("min_rdma_size", 128*1024); mca_btl_tcp_module.super.btl_max_rdma_size = mca_btl_tcp_param_register_int("max_rdma_size", INT_MAX); mca_btl_tcp_module.super.btl_flags = mca_btl_tcp_param_register_int("flags", MCA_BTL_FLAGS_PUT | MCA_BTL_FLAGS_SEND_INPLACE | MCA_BTL_FLAGS_NEED_CSUM | MCA_BTL_FLAGS_NEED_ACK | MCA_BTL_FLAGS_FAKE_RDMA); return OMPI_SUCCESS;}/* * module cleanup - sanity checking of queue lengths */int mca_btl_tcp_component_close(void){ opal_list_item_t* item; if(NULL != mca_btl_tcp_component.tcp_if_include) free(mca_btl_tcp_component.tcp_if_include); if(NULL != mca_btl_tcp_component.tcp_if_exclude) free(mca_btl_tcp_component.tcp_if_exclude); if (NULL != mca_btl_tcp_component.tcp_btls) free(mca_btl_tcp_component.tcp_btls); if (mca_btl_tcp_component.tcp_listen_sd >= 0) { opal_event_del(&mca_btl_tcp_component.tcp_recv_event); CLOSE_THE_SOCKET(mca_btl_tcp_component.tcp_listen_sd); mca_btl_tcp_component.tcp_listen_sd = -1; } /* cleanup any pending events */ OPAL_THREAD_LOCK(&mca_btl_tcp_component.tcp_lock); for(item = opal_list_remove_first(&mca_btl_tcp_component.tcp_events); item != NULL; item = opal_list_remove_first(&mca_btl_tcp_component.tcp_events)) { mca_btl_tcp_event_t* event = (mca_btl_tcp_event_t*)item; opal_event_del(&event->event); OBJ_RELEASE(event); } OPAL_THREAD_UNLOCK(&mca_btl_tcp_component.tcp_lock); /* release resources */ OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_procs); OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_events); OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_frag_eager); OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_frag_max); OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_frag_user); OBJ_DESTRUCT(&mca_btl_tcp_component.tcp_lock);#ifdef __WINDOWS__ WSACleanup();#endif return OMPI_SUCCESS;}/* * Create a btl instance and add to modules list. */static int mca_btl_tcp_create(int if_index, const char* if_name){ struct mca_btl_tcp_module_t* btl = (struct mca_btl_tcp_module_t *)malloc(sizeof(mca_btl_tcp_module_t)); char param[256]; if(NULL == btl) return OMPI_ERR_OUT_OF_RESOURCE; memcpy(btl, &mca_btl_tcp_module, sizeof(mca_btl_tcp_module)); OBJ_CONSTRUCT(&btl->tcp_endpoints, opal_list_t); mca_btl_tcp_component.tcp_btls[mca_btl_tcp_component.tcp_num_btls++] = btl; /* initialize the btl */ btl->tcp_ifindex = if_index;#if MCA_BTL_TCP_STATISTICS btl->tcp_bytes_recv = 0; btl->tcp_bytes_sent = 0; btl->tcp_send_handler = 0;#endif opal_ifindextoaddr(if_index, (struct sockaddr*)&btl->tcp_ifaddr, sizeof(btl->tcp_ifaddr)); opal_ifindextomask(if_index, (struct sockaddr*)&btl->tcp_ifmask, sizeof(btl->tcp_ifmask)); /* allow user to specify interface bandwidth */ sprintf(param, "bandwidth_%s", if_name); btl->super.btl_bandwidth = mca_btl_tcp_param_register_int(param, 0); /* allow user to override/specify latency ranking */ sprintf(param, "latency_%s", if_name); btl->super.btl_latency = mca_btl_tcp_param_register_int(param, 0);#if 0 && OMPI_ENABLE_DEBUG BTL_OUTPUT(("interface: %s bandwidth %d latency %d", if_name, btl->super.btl_bandwidth, btl->super.btl_latency));#endif return OMPI_SUCCESS;}/* * Create a TCP BTL instance for either:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?