From: Sean Hefty Date: Fri, 10 Apr 2009 15:07:18 +0000 (-0700) Subject: Convert the openib_cma provider to common code between linux and windows. X-Git-Tag: dapl-2.0.18-1~24 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=a8582be0e1fc89e856f1d0b43a3c1b271295a352;p=~ardavis%2Fdapl.git Convert the openib_cma provider to common code between linux and windows. Signed-off-by: Sean Hefty --- diff --git a/Makefile.am b/Makefile.am index 721996f..a9e0fec 100755 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,8 @@ dapl_udapl_libdaplofa_la_CFLAGS = $(AM_CFLAGS) -D_GNU_SOURCE $(OSFLAGS) $(XFLAGS -DOPENIB -DCQ_WAIT_OBJECT \ -I$(srcdir)/dat/include/ -I$(srcdir)/dapl/include/ \ -I$(srcdir)/dapl/common -I$(srcdir)/dapl/udapl/linux \ - -I$(srcdir)/dapl/openib_cma + -I$(srcdir)/dapl/openib_cma \ + -I$(srcdir)/dapl/openib_cma/linux dapl_udapl_libdaploscm_la_CFLAGS = $(AM_CFLAGS) -D_GNU_SOURCE $(OSFLAGS) $(XFLAGS) \ -DOPENIB -DCQ_WAIT_OBJECT \ diff --git a/dapl/dirs b/dapl/dirs index 6fb48fa..713ed74 100644 --- a/dapl/dirs +++ b/dapl/dirs @@ -1 +1 @@ -DIRS = ibal ibal-scm +DIRS = ibal ibal-scm openib_scm openib_cma diff --git a/dapl/openib_cma/SOURCES b/dapl/openib_cma/SOURCES new file mode 100644 index 0000000..29e836e --- /dev/null +++ b/dapl/openib_cma/SOURCES @@ -0,0 +1,56 @@ +!if $(FREEBUILD) +TARGETNAME=dapl2-ofa-cma +!else +TARGETNAME=dapl2-ofa-cmad +!endif + +TARGETPATH = ..\..\..\..\bin\user\obj$(BUILD_ALT_DIR) +TARGETTYPE = DYNLINK +DLLENTRY = _DllMainCRTStartup + +!if $(_NT_TOOLS_VERSION) == 0x700 +DLLDEF=$O\udapl_ofa_cma_exports.def +!else +DLLDEF=$(OBJ_PATH)\$O\udapl_ofa_cma_exports.def +!endif + +USE_MSVCRT = 1 + +SOURCES = \ + udapl.rc \ + ..\dapl_common_src.c \ + ..\dapl_udapl_src.c \ + dapl_ib_cq.c \ + dapl_ib_extensions.c \ + dapl_ib_mem.c \ + dapl_ib_qp.c \ + dapl_ib_util.c \ + dapl_ib_cm.c + +INCLUDES = ..\include;..\common;windows;..\..\dat\include;\ + ..\..\dat\udat\windows;..\udapl\windows;\ + ..\..\..\..\inc;..\..\..\..\inc\user;..\..\..\libibverbs\include;\ + ..\..\..\librdmacm\include + +DAPL_OPTS = -DEXPORT_DAPL_SYMBOLS -DDAT_EXTENSIONS -DOPENIB + +USER_C_FLAGS = $(USER_C_FLAGS) $(DAPL_OPTS) + +!if !$(FREEBUILD) +USER_C_FLAGS = $(USER_C_FLAGS) -DDAPL_DBG +!endif + +TARGETLIBS= \ + $(SDK_LIB_PATH)\kernel32.lib \ + $(SDK_LIB_PATH)\ws2_32.lib \ +!if $(FREEBUILD) + $(TARGETPATH)\*\dat2.lib \ + $(TARGETPATH)\*\libibverbs.lib \ + $(TARGETPATH)\*\librdmacm.lib +!else + $(TARGETPATH)\*\dat2d.lib \ + $(TARGETPATH)\*\libibverbsd.lib \ + $(TARGETPATH)\*\librdmacmd.lib +!endif + +MSC_WARNING_LEVEL = /W1 /wd4113 /Wp64 diff --git a/dapl/openib_cma/dapl_ib_cm.c b/dapl/openib_cma/dapl_ib_cm.c index de35eba..1b4145e 100755 --- a/dapl/openib_cma/dapl_ib_cm.c +++ b/dapl/openib_cma/dapl_ib_cm.c @@ -46,11 +46,7 @@ #include "dapl_name_service.h" #include "dapl_ib_util.h" #include "dapl_vendor.h" -#include -#include -#include -#include -#include +#include "dapl_osd.h" extern struct rdma_event_channel *g_cm_events; @@ -64,12 +60,6 @@ static void dapli_cm_passive_cb(struct dapl_cm_id *conn, static void dapli_addr_resolve(struct dapl_cm_id *conn); static void dapli_route_resolve(struct dapl_cm_id *conn); -#if __BYTE_ORDER == __LITTLE_ENDIAN -static inline uint64_t cpu_to_be64(uint64_t x) { return bswap_64(x); } -#elif __BYTE_ORDER == __BIG_ENDIAN -static inline uint64_t cpu_to_be64(uint64_t x) { return x; } -#endif - /* cma requires 16 bit SID, in network order */ #define IB_PORT_MOD 32001 #define IB_PORT_BASE (65535 - IB_PORT_MOD) @@ -131,16 +121,16 @@ static void dapli_route_resolve(struct dapl_cm_id *conn) dapl_dbg_log(DAPL_DBG_TYPE_CM, " route_resolve: SRC GID subnet %016llx id %016llx\n", (unsigned long long) - cpu_to_be64(ibaddr->sgid.global.subnet_prefix), + ntohll(ibaddr->sgid.global.subnet_prefix), (unsigned long long) - cpu_to_be64(ibaddr->sgid.global.interface_id)); + ntohll(ibaddr->sgid.global.interface_id)); dapl_dbg_log(DAPL_DBG_TYPE_CM, " route_resolve: DST GID subnet %016llx id %016llx\n", (unsigned long long) - cpu_to_be64(ibaddr->dgid.global.subnet_prefix), + ntohll(ibaddr->dgid.global.subnet_prefix), (unsigned long long) - cpu_to_be64(ibaddr->dgid.global.interface_id)); + ntohll(ibaddr->dgid.global.interface_id)); dapl_dbg_log(DAPL_DBG_TYPE_CM, " route_resolve: cm_id %p pdata %p plen %d rr %d ind %d\n", @@ -904,15 +894,16 @@ dapls_ib_reject_connection( IN DAT_COUNT private_data_size, IN const DAT_PVOID private_data) { - int ret; + int ret; int offset = sizeof(struct dapl_pdata_hdr); - struct dapl_pdata_hdr pdata_hdr = { - .version = htonl( + struct dapl_pdata_hdr pdata_hdr; + + memset(&pdata_hdr, 0, sizeof pdata_hdr); + pdata_hdr.version = htonl( (DAT_VERSION_MAJOR << 24) | (DAT_VERSION_MINOR << 16) | (VN_PROVIDER_MAJOR << 8 ) | - (VN_PROVIDER_MINOR)) - }; + (VN_PROVIDER_MINOR)); dapl_dbg_log(DAPL_DBG_TYPE_CM, " reject: handle %p reason %x, ver=%x, data %p, sz=%d\n", diff --git a/dapl/openib_cma/dapl_ib_cq.c b/dapl/openib_cma/dapl_ib_cq.c index 742c247..59ad65e 100755 --- a/dapl/openib_cma/dapl_ib_cq.c +++ b/dapl/openib_cma/dapl_ib_cq.c @@ -35,12 +35,12 @@ * **********************************************************************/ +#include "openib_osd.h" #include "dapl.h" #include "dapl_adapter_util.h" #include "dapl_lmr_util.h" #include "dapl_evd_util.h" #include "dapl_ring_buffer_util.h" -#include /* One CQ event channel per HCA */ void dapli_cq_event_cb(struct _ib_hca_transport *hca) @@ -48,17 +48,11 @@ void dapli_cq_event_cb(struct _ib_hca_transport *hca) /* check all comp events on this device */ struct dapl_evd *evd_ptr = NULL; struct ibv_cq *ibv_cq = NULL; - struct pollfd cq_fd = { - .fd = hca->ib_cq->fd, - .events = POLLIN, - .revents = 0 - }; dapl_dbg_log(DAPL_DBG_TYPE_UTIL," dapli_cq_event_cb(%p)\n", hca); - if ((poll(&cq_fd, 1, 0) == 1) && - (!ibv_get_cq_event(hca->ib_cq, - &ibv_cq, (void*)&evd_ptr))) { + if (!ibv_get_cq_event(hca->ib_cq, + &ibv_cq, (void*)&evd_ptr)) { if (DAPL_BAD_HANDLE(evd_ptr, DAPL_MAGIC_EVD)) { ibv_ack_cq_events(ibv_cq, 1); @@ -222,11 +216,11 @@ dapls_ib_cq_alloc(IN DAPL_IA *ia_ptr, IN DAPL_EVD *evd_ptr, IN DAT_COUNT *cqlen ) { + struct ibv_comp_channel *channel = ia_ptr->hca_ptr->ib_trans.ib_cq; + dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "dapls_ib_cq_alloc: evd %p cqlen=%d \n", evd_ptr, *cqlen); - struct ibv_comp_channel *channel = ia_ptr->hca_ptr->ib_trans.ib_cq; - #ifdef CQ_WAIT_OBJECT if (evd_ptr->cq_wait_obj_handle) channel = evd_ptr->cq_wait_obj_handle->events; diff --git a/dapl/openib_cma/dapl_ib_dto.h b/dapl/openib_cma/dapl_ib_dto.h index eba19b7..feaba6e 100644 --- a/dapl/openib_cma/dapl_ib_dto.h +++ b/dapl/openib_cma/dapl_ib_dto.h @@ -147,12 +147,6 @@ dapls_ib_post_send ( IN const DAT_RMR_TRIPLET *remote_iov, IN DAT_COMPLETION_FLAGS completion_flags) { - dapl_dbg_log(DAPL_DBG_TYPE_EP, - " post_snd: ep %p op %d ck %p sgs", - "%d l_iov %p r_iov %p f %d\n", - ep_ptr, op_type, cookie, segments, local_iov, - remote_iov, completion_flags); - ib_data_segment_t ds_array[DEFAULT_DS_ENTRIES]; ib_data_segment_t *ds_array_p, *ds_array_start_p = NULL; struct ibv_send_wr wr; @@ -162,6 +156,12 @@ dapls_ib_post_send ( DAT_COUNT i, total_len; int ret; + dapl_dbg_log(DAPL_DBG_TYPE_EP, + " post_snd: ep %p op %d ck %p sgs", + "%d l_iov %p r_iov %p f %d\n", + ep_ptr, op_type, cookie, segments, local_iov, + remote_iov, completion_flags); + dapl_dbg_log(DAPL_DBG_TYPE_EP, " post_snd: ep %p cookie %p segs %d l_iov %p\n", ep_ptr, cookie, segments, local_iov); @@ -319,12 +319,6 @@ dapls_ib_post_ext_send ( IN DAT_UINT64 swap, IN DAT_COMPLETION_FLAGS completion_flags) { - dapl_dbg_log(DAPL_DBG_TYPE_EP, - " post_snd: ep %p op %d ck %p sgs", - "%d l_iov %p r_iov %p f %d\n", - ep_ptr, op_type, cookie, segments, local_iov, - remote_iov, completion_flags); - ib_data_segment_t ds_array[DEFAULT_DS_ENTRIES]; ib_data_segment_t *ds_array_p, *ds_array_start_p = NULL; struct ibv_send_wr wr; @@ -332,6 +326,12 @@ dapls_ib_post_ext_send ( DAT_COUNT i, total_len; int ret; + dapl_dbg_log(DAPL_DBG_TYPE_EP, + " post_snd: ep %p op %d ck %p sgs", + "%d l_iov %p r_iov %p f %d\n", + ep_ptr, op_type, cookie, segments, local_iov, + remote_iov, completion_flags); + dapl_dbg_log(DAPL_DBG_TYPE_EP, " post_snd: ep %p cookie %p segs %d l_iov %p\n", ep_ptr, cookie, segments, local_iov); diff --git a/dapl/openib_cma/dapl_ib_mem.c b/dapl/openib_cma/dapl_ib_mem.c index 126777d..62e1cde 100755 --- a/dapl/openib_cma/dapl_ib_mem.c +++ b/dapl/openib_cma/dapl_ib_mem.c @@ -35,13 +35,6 @@ * **********************************************************************/ -#include /* for IOCTL's */ -#include /* for socket(2) and related bits and pieces */ -#include /* for socket(2) */ -#include /* for struct ifreq */ -#include /* for ARPHRD_ETHER */ -#include /* for _SC_CLK_TCK */ - #include "dapl.h" #include "dapl_adapter_util.h" #include "dapl_lmr_util.h" @@ -212,10 +205,9 @@ dapls_ib_mr_register(IN DAPL_IA *ia_ptr, lmr->param.registered_address = (DAT_VADDR)(uintptr_t)virt_addr; dapl_dbg_log(DAPL_DBG_TYPE_UTIL, - " mr_register: mr=%p addr=%p h %x pd %p ctx %p " + " mr_register: mr=%p addr=%p pd %p ctx %p " "lkey=0x%x rkey=0x%x priv=%x\n", lmr->mr_handle, lmr->mr_handle->addr, - lmr->mr_handle->handle, lmr->mr_handle->pd, lmr->mr_handle->context, lmr->mr_handle->lkey, lmr->mr_handle->rkey, length, dapls_convert_privileges(privileges)); diff --git a/dapl/openib_cma/dapl_ib_util.c b/dapl/openib_cma/dapl_ib_util.c index c5641f0..5ffe4c7 100755 --- a/dapl/openib_cma/dapl_ib_util.c +++ b/dapl/openib_cma/dapl_ib_util.c @@ -39,31 +39,78 @@ static const char rcsid[] = "$Id: $"; #endif +#include "openib_osd.h" #include "dapl.h" #include "dapl_adapter_util.h" #include "dapl_ib_util.h" +#include "dapl_osd.h" #include -#include -#include -#include - -#include /* for IOCTL's */ -#include /* for socket(2) and related bits and pieces */ -#include /* for socket(2) */ -#include /* for struct ifreq */ -#include /* for ARPHRD_INFINIBAND */ -#include /* for inet_ntoa */ int g_dapl_loopback_connection = 0; -int g_ib_pipe[2]; struct rdma_event_channel *g_cm_events = NULL; ib_thread_state_t g_ib_thread_state = 0; DAPL_OS_THREAD g_ib_thread; DAPL_OS_LOCK g_hca_lock; struct dapl_llist_entry *g_hca_list; +#if defined(_WIN64) || defined(_WIN32) +#include "..\..\..\..\..\etc\user\comp_channel.cpp" +#include "..\..\..\..\..\etc\user\dlist.c" + +#define getipaddr_netdev(x,y,z) -1 +struct ibvw_windata windata; + +static int dapls_os_init(void) +{ + return ibvw_get_windata(&windata, IBVW_WINDATA_VERSION); +} + +static void dapls_os_release(void) +{ + if (windata.comp_mgr) + ibvw_release_windata(&windata, IBVW_WINDATA_VERSION); + windata.comp_mgr = NULL; +} + +static int dapls_config_comp_channel(struct ibv_comp_channel *channel) +{ + channel->comp_channel.Milliseconds = 0; + return 0; +} + +static int dapls_config_cm_channel(struct rdma_event_channel *channel) +{ + channel->channel.Milliseconds = 0; + return 0; +} + +static int dapls_config_verbs(struct ibv_context *verbs) +{ + verbs->channel.Milliseconds = 0; + return 0; +} + +static int dapls_thread_signal(void) +{ + CompManagerCancel(windata.comp_mgr); + return 0; +} +#else // _WIN64 || WIN32 +int g_ib_pipe[2]; + +static int dapls_os_init(void) +{ + /* create pipe for waking up work thread */ + return pipe(g_ib_pipe); +} + +static void dapls_os_release(void) +{ + /* close pipe? */ +} + /* Get IP address using network device name */ static int getipaddr_netdev(char *name, char *addr, int addr_len) { @@ -103,6 +150,42 @@ bail: return ret; } +static int dapls_config_fd(int fd) +{ + int opts; + + opts = fcntl(fd, F_GETFL); + if (opts < 0 || fcntl(fd, F_SETFL, opts | O_NONBLOCK) < 0) { + dapl_log(DAPL_DBG_TYPE_ERR, + " dapls_config_fd: fcntl on fd %d ERR %d %s\n", + fd, opts, strerror(errno)); + return errno; + } + + return 0; +} + +static int dapls_config_comp_channel(struct ibv_comp_channel *channel) +{ + return dapls_config_fd(channel->fd); +} + +static int dapls_config_cm_channel(struct rdma_event_channel *channel) +{ + return dapls_config_fd(channel->fd); +} + +static int dapls_config_verbs(struct ibv_context *verbs) +{ + return dapls_config_fd(verbs->async_fd); +} + +static int dapls_thread_signal(void) +{ + return write(g_ib_pipe[1], "w", sizeof "w"); +} +#endif + /* Get IP address using network name, address, or device name */ static int getipaddr(char *name, char *addr, int len) { @@ -164,8 +247,7 @@ int32_t dapls_ib_init(void) /* initialize hca list for CQ events */ dapl_llist_init_head(&g_hca_list); - /* create pipe for waking up work thread */ - if (pipe(g_ib_pipe)) + if (dapls_os_init()) return 1; return 0; @@ -177,6 +259,7 @@ int32_t dapls_ib_release(void) dapli_ib_thread_destroy(); if (g_cm_events != NULL) rdma_destroy_event_channel(g_cm_events); + dapls_os_release(); return 0; } @@ -199,7 +282,6 @@ int32_t dapls_ib_release(void) */ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) { - long opts; struct rdma_cm_id *cm_id = NULL; union ibv_gid *gid; int ret; @@ -222,8 +304,7 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) dapl_os_unlock(&g_hca_lock); dapl_dbg_log (DAPL_DBG_TYPE_UTIL, - " open_hca: RDMA channel created(%p,%d)\n", - g_cm_events, g_cm_events->fd); + " open_hca: RDMA channel created (%p)\n", g_cm_events); dat_status = dapli_ib_thread_init(); if (dat_status != DAT_SUCCESS) @@ -256,6 +337,7 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) /* keep reference to IB device and cm_id */ hca_ptr->ib_trans.cm_id = cm_id; hca_ptr->ib_hca_handle = cm_id->verbs; + dapls_config_verbs(cm_id->verbs); hca_ptr->port_num = cm_id->port_num; gid = &cm_id->route.addr.addr.ibaddr.sgid; @@ -263,8 +345,8 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) DAPL_DBG_TYPE_UTIL, " open_hca: ctx=%p port=%d GID subnet %016llx id %016llx\n", cm_id->verbs,cm_id->port_num, - (unsigned long long)bswap_64(gid->global.subnet_prefix), - (unsigned long long)bswap_64(gid->global.interface_id)); + (unsigned long long)ntohll(gid->global.subnet_prefix), + (unsigned long long)ntohll(gid->global.interface_id)); /* set inline max with env or default, get local lid and gid 0 */ if (hca_ptr->ib_hca_handle->device->transport_type @@ -294,20 +376,12 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) strerror(errno)); goto bail; } - dapl_dbg_log (DAPL_DBG_TYPE_UTIL, - " open_hca: CQ channel created(fd=%d)\n", - hca_ptr->ib_trans.ib_cq->fd); + dapl_dbg_log (DAPL_DBG_TYPE_UTIL, " open_hca: CQ channel created\n"); - opts = fcntl(hca_ptr->ib_trans.ib_cq->fd, F_GETFL); /* uCQ */ - if (opts < 0 || fcntl(hca_ptr->ib_trans.ib_cq->fd, - F_SETFL, opts | O_NONBLOCK) < 0) { - dapl_log(DAPL_DBG_TYPE_ERR, - " open_hca: fcntl on ib_cq->fd %d ERR %d %s\n", - hca_ptr->ib_trans.ib_cq->fd, opts, - strerror(errno)); + if (dapls_config_comp_channel(hca_ptr->ib_trans.ib_cq)) { goto bail; } - + /* * Put new hca_transport on list for async and CQ event processing * Wakeup work thread to add to polling list @@ -317,7 +391,7 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_NAME hca_name, IN DAPL_HCA *hca_ptr) dapl_llist_add_tail(&g_hca_list, (DAPL_LLIST_ENTRY*)&hca_ptr->ib_trans.entry, &hca_ptr->ib_trans.entry); - if (write(g_ib_pipe[1], "w", sizeof "w") == -1) + if (dapls_thread_signal() == -1) dapl_log(DAPL_DBG_TYPE_UTIL, " open_hca: thread wakeup error = %s\n", strerror(errno)); @@ -387,23 +461,20 @@ DAT_RETURN dapls_ib_close_hca(IN DAPL_HCA *hca_ptr) * Wakeup work thread to remove from polling list */ hca_ptr->ib_trans.destroy = 1; - if (write(g_ib_pipe[1], "w", sizeof "w") == -1) + if (dapls_thread_signal() == -1) dapl_log(DAPL_DBG_TYPE_UTIL, " destroy: thread wakeup error = %s\n", strerror(errno)); /* wait for thread to remove HCA references */ while (hca_ptr->ib_trans.destroy != 2) { - struct timespec sleep, remain; - sleep.tv_sec = 0; - sleep.tv_nsec = 10000000; /* 10 ms */ - if (write(g_ib_pipe[1], "w", sizeof "w") == -1) + if (dapls_thread_signal() == -1) dapl_log(DAPL_DBG_TYPE_UTIL, " destroy: thread wakeup error = %s\n", strerror(errno)); dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread_destroy: wait on hca %p destroy\n"); - nanosleep (&sleep, &remain); + dapl_os_sleep_usec(10000); } bail: return (DAT_SUCCESS); @@ -624,11 +695,10 @@ DAT_RETURN dapls_ib_setup_async_callback(IN DAPL_IA *ia_ptr, DAT_RETURN dapli_ib_thread_init(void) { - long opts; DAT_RETURN dat_status; dapl_dbg_log(DAPL_DBG_TYPE_UTIL, - " ib_thread_init(%d)\n", getpid()); + " ib_thread_init(%d)\n", dapl_os_getpid()); dapl_os_lock(&g_hca_lock); if (g_ib_thread_state != IB_THREAD_INIT) { @@ -637,9 +707,7 @@ DAT_RETURN dapli_ib_thread_init(void) } /* uCMA events non-blocking */ - opts = fcntl(g_cm_events->fd, F_GETFL); /* uCMA */ - if (opts < 0 || fcntl(g_cm_events->fd, - F_SETFL, opts | O_NONBLOCK) < 0) { + if (dapls_config_cm_channel(g_cm_events)) { dapl_os_unlock(&g_hca_lock); return(dapl_convert_errno(errno, "create_thread ERR: cm_fd")); } @@ -657,19 +725,16 @@ DAT_RETURN dapli_ib_thread_init(void) /* wait for thread to start */ dapl_os_lock(&g_hca_lock); while (g_ib_thread_state != IB_THREAD_RUN) { - struct timespec sleep, remain; - sleep.tv_sec = 0; - sleep.tv_nsec = 2000000; /* 2 ms */ dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread_init: waiting for ib_thread\n"); dapl_os_unlock(&g_hca_lock); - nanosleep (&sleep, &remain); + dapl_os_sleep_usec(2000); dapl_os_lock(&g_hca_lock); } dapl_os_unlock(&g_hca_lock); dapl_dbg_log(DAPL_DBG_TYPE_UTIL, - " ib_thread_init(%d) exit\n",getpid()); + " ib_thread_init(%d) exit\n",dapl_os_getpid()); return DAT_SUCCESS; } @@ -679,7 +744,7 @@ void dapli_ib_thread_destroy(void) int retries = 10; dapl_dbg_log(DAPL_DBG_TYPE_UTIL, - " ib_thread_destroy(%d)\n", getpid()); + " ib_thread_destroy(%d)\n", dapl_os_getpid()); /* * wait for async thread to terminate. * pthread_join would be the correct method @@ -692,22 +757,19 @@ void dapli_ib_thread_destroy(void) goto bail; g_ib_thread_state = IB_THREAD_CANCEL; - if (write(g_ib_pipe[1], "w", sizeof "w") == -1) + if (dapls_thread_signal() == -1) dapl_log(DAPL_DBG_TYPE_UTIL, " destroy: thread wakeup error = %s\n", strerror(errno)); while ((g_ib_thread_state != IB_THREAD_EXIT) && (retries--)) { - struct timespec sleep, remain; - sleep.tv_sec = 0; - sleep.tv_nsec = 2000000; /* 2 ms */ dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread_destroy: waiting for ib_thread\n"); - if (write(g_ib_pipe[1], "w", sizeof "w") == -1) + if (dapls_thread_signal() == -1) dapl_log(DAPL_DBG_TYPE_UTIL, " destroy: thread wakeup error = %s\n", strerror(errno)); dapl_os_unlock( &g_hca_lock ); - nanosleep(&sleep, &remain); + dapl_os_sleep_usec(2000); dapl_os_lock( &g_hca_lock ); } @@ -715,25 +777,19 @@ bail: dapl_os_unlock( &g_hca_lock ); dapl_dbg_log(DAPL_DBG_TYPE_UTIL, - " ib_thread_destroy(%d) exit\n",getpid()); + " ib_thread_destroy(%d) exit\n",dapl_os_getpid()); } void dapli_async_event_cb(struct _ib_hca_transport *hca) { struct ibv_async_event event; - struct pollfd async_fd = { - .fd = hca->cm_id->verbs->async_fd, - .events = POLLIN, - .revents = 0 - }; dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " async_event(%p)\n",hca); if (hca->destroy) return; - if ((poll(&async_fd, 1, 0)==1) && - (!ibv_get_async_event(hca->cm_id->verbs, &event))) { + if (!ibv_get_async_event(hca->cm_id->verbs, &event)) { switch (event.event_type) { case IBV_EVENT_CQ_ERR: @@ -826,6 +882,62 @@ void dapli_async_event_cb(struct _ib_hca_transport *hca) } } +#if defined(_WIN64) || defined(_WIN32) +/* work thread for uAT, uCM, CQ, and async events */ +void dapli_thread(void *arg) +{ + struct _ib_hca_transport *hca; + struct _ib_hca_transport *uhca[8]; + COMP_CHANNEL *channel; + int ret, idx, cnt; + + dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread(%d,0x%x): ENTER: \n", + dapl_os_getpid(), g_ib_thread); + + dapl_os_lock(&g_hca_lock); + for (g_ib_thread_state = IB_THREAD_RUN; + g_ib_thread_state == IB_THREAD_RUN; dapl_os_lock(&g_hca_lock)) { + + idx = 0; + hca = dapl_llist_is_empty(&g_hca_list) ? NULL : + dapl_llist_peek_head(&g_hca_list); + + while (hca) { + uhca[idx++] = hca; + hca = dapl_llist_next_entry(&g_hca_list, + (DAPL_LLIST_ENTRY *) &hca->entry); + } + cnt = idx; + + dapl_os_unlock(&g_hca_lock); + ret = CompManagerPoll(windata.comp_mgr, INFINITE, &channel); + + dapl_dbg_log(DAPL_DBG_TYPE_UTIL, + " ib_thread(%d) poll_event 0x%x\n", + dapl_os_getpid(), ret); + + dapli_cma_event_cb(); + + /* check and process CQ and ASYNC events, per device */ + for (idx = 0; idx < cnt; idx++) { + if (uhca[idx]->destroy == 1) { + dapl_os_lock(&g_hca_lock); + dapl_llist_remove_entry(&g_hca_list, + (DAPL_LLIST_ENTRY*) &uhca[idx]->entry); + dapl_os_unlock(&g_hca_lock); + uhca[idx]->destroy = 2; + } else { + dapli_cq_event_cb(uhca[idx]); + dapli_async_event_cb(uhca[idx]); + } + } + } + + dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread(%d) EXIT\n", dapl_os_getpid()); + g_ib_thread_state = IB_THREAD_EXIT; + dapl_os_unlock(&g_hca_lock); +} +#else // _WIN64 || WIN32 /* work thread for uAT, uCM, CQ, and async events */ void dapli_thread(void *arg) { @@ -837,7 +949,7 @@ void dapli_thread(void *arg) dapl_dbg_log (DAPL_DBG_TYPE_UTIL, " ib_thread(%d,0x%x): ENTER: pipe %d ucma %d\n", - getpid(), g_ib_thread, g_ib_pipe[0], g_cm_events->fd); + dapl_os_getpid(), g_ib_thread, g_ib_pipe[0], g_cm_events->fd); /* Poll across pipe, CM, AT never changes */ dapl_os_lock( &g_hca_lock ); @@ -878,7 +990,7 @@ void dapli_thread(void *arg) dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread(%d) poll_fd: hca[%d]=%p, async=%d" " pipe=%d cm=%d cq=d\n", - getpid(), hca, ufds[idx-1].fd, + dapl_os_getpid(), hca, ufds[idx-1].fd, ufds[0].fd, ufds[1].fd, ufds[idx].fd); hca = dapl_llist_next_entry( @@ -893,7 +1005,7 @@ void dapli_thread(void *arg) if (ret <= 0) { dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread(%d): ERR %s poll\n", - getpid(),strerror(errno)); + dapl_os_getpid(),strerror(errno)); dapl_os_lock(&g_hca_lock); continue; } @@ -901,7 +1013,7 @@ void dapli_thread(void *arg) dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " ib_thread(%d) poll_event: " " async=0x%x pipe=0x%x cm=0x%x cq=0x%x\n", - getpid(), ufds[idx-1].revents, ufds[0].revents, + dapl_os_getpid(), ufds[idx-1].revents, ufds[0].revents, ufds[1].revents, ufds[idx].revents); /* uCMA events */ @@ -939,10 +1051,11 @@ void dapli_thread(void *arg) dapl_os_lock(&g_hca_lock); } - dapl_dbg_log(DAPL_DBG_TYPE_UTIL," ib_thread(%d) EXIT\n",getpid()); + dapl_dbg_log(DAPL_DBG_TYPE_UTIL," ib_thread(%d) EXIT\n",dapl_os_getpid()); g_ib_thread_state = IB_THREAD_EXIT; dapl_os_unlock(&g_hca_lock); } +#endif /* * dapls_set_provider_specific_attr diff --git a/dapl/openib_cma/dapl_ib_util.h b/dapl/openib_cma/dapl_ib_util.h index 1e13db9..93635ef 100755 --- a/dapl/openib_cma/dapl_ib_util.h +++ b/dapl/openib_cma/dapl_ib_util.h @@ -38,8 +38,8 @@ #ifndef _DAPL_IB_UTIL_H_ #define _DAPL_IB_UTIL_H_ +#include "openib_osd.h" #include -#include #include /* Typedefs to map common DAPL provider types to IB verbs */ @@ -294,33 +294,24 @@ dapl_convert_errno( IN int err, IN const char *str ) { if (!err) return DAT_SUCCESS; - if ((err != EAGAIN) && (err != ETIME) && - (err != ETIMEDOUT) && (err != EINTR)) - dapl_log (DAPL_DBG_TYPE_ERR," %s %s\n", str, strerror(err)); +#if DAPL_DBG + if ((err != EAGAIN) && (err != ETIMEDOUT)) + dapl_dbg_log (DAPL_DBG_TYPE_ERR," %s %s\n", str, strerror(err)); +#endif switch( err ) { case EOVERFLOW : return DAT_LENGTH_ERROR; case EACCES : return DAT_PRIVILEGES_VIOLATION; - case ENXIO : - case ERANGE : case EPERM : return DAT_PROTECTION_VIOLATION; - case EINVAL : - case EBADF : - case ENOENT : - case ENOTSOCK : return DAT_INVALID_HANDLE; + case EINVAL : return DAT_INVALID_HANDLE; case EISCONN : return DAT_INVALID_STATE | DAT_INVALID_STATE_EP_CONNECTED; case ECONNREFUSED : return DAT_INVALID_STATE | DAT_INVALID_STATE_EP_NOTREADY; - case ETIME : case ETIMEDOUT : return DAT_TIMEOUT_EXPIRED; case ENETUNREACH: return DAT_INVALID_ADDRESS | DAT_INVALID_ADDRESS_UNREACHABLE; - case EBUSY : return DAT_PROVIDER_IN_USE; - case EADDRINUSE : return DAT_CONN_QUAL_IN_USE; + case EADDRINUSE : return DAT_CONN_QUAL_IN_USE; case EALREADY : return DAT_INVALID_STATE | DAT_INVALID_STATE_EP_ACTCONNPENDING; - case ENOSPC : - case ENOMEM : - case E2BIG : - case EDQUOT : return DAT_INSUFFICIENT_RESOURCES; + case ENOMEM : return DAT_INSUFFICIENT_RESOURCES; case EAGAIN : return DAT_QUEUE_EMPTY; case EINTR : return DAT_INTERRUPTED_CALL; case EAFNOSUPPORT : return DAT_INVALID_ADDRESS | DAT_INVALID_ADDRESS_MALFORMED; diff --git a/dapl/openib_cma/libdaplcma.map b/dapl/openib_cma/libdaplcma.map new file mode 100644 index 0000000..de06305 --- /dev/null +++ b/dapl/openib_cma/libdaplcma.map @@ -0,0 +1,7 @@ +DAPL_CMA_2.0 { + global: + dat_provider_fini; + dat_provider_init; + dapl_extensions; + local: *; +}; diff --git a/dapl/openib_cma/linux/openib_osd.h b/dapl/openib_cma/linux/openib_osd.h new file mode 100644 index 0000000..309972f --- /dev/null +++ b/dapl/openib_cma/linux/openib_osd.h @@ -0,0 +1,15 @@ +#ifndef OPENIB_OSD_H +#define OPENIB_OSD_H + +#include +#include + +#if __BYTE_ORDER == __BIG_ENDIAN +#define htonll(x) (x) +#define ntohll(x) (x) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll(x) bswap_64(x) +#define ntohll(x) bswap_64(x) +#endif + +#endif // OPENIB_OSD_H diff --git a/dapl/openib_cma/makefile b/dapl/openib_cma/makefile new file mode 100644 index 0000000..a0c0627 --- /dev/null +++ b/dapl/openib_cma/makefile @@ -0,0 +1,7 @@ +# +# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source +# file to this component. This file merely indirects to the real make file +# that is shared by all the driver components of the OpenIB Windows project. +# + +!INCLUDE ..\..\..\..\inc\openib.def diff --git a/dapl/openib_cma/udapl.rc b/dapl/openib_cma/udapl.rc new file mode 100644 index 0000000..c053329 --- /dev/null +++ b/dapl/openib_cma/udapl.rc @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2007, 2009 Intel Corporation. All rights reserved. + * + * This software is available to you under the OpenIB.org BSD license + * below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * $Id$ + */ + + +#include + +#define VER_FILETYPE VFT_DLL +#define VER_FILESUBTYPE VFT2_UNKNOWN + +#if DBG +#define VER_FILEDESCRIPTION_STR "Direct Access Provider Library v2.0 (OFA rdma-cm) (Debug)" +#define VER_INTERNALNAME_STR "dapl2-ofa-cmad.dll" +#define VER_ORIGINALFILENAME_STR "dapl2-ofa-cmad.dll" +#else +#define VER_FILEDESCRIPTION_STR "Direct Access Provider Library v2.0 (OFA rdma-cm)" +#define VER_INTERNALNAME_STR "dapl2-ofa-cma.dll" +#define VER_ORIGINALFILENAME_STR "dapl2-ofa-cma.dll" +#endif + +#include diff --git a/dapl/openib_cma/udapl_ofa_cma_exports.src b/dapl/openib_cma/udapl_ofa_cma_exports.src new file mode 100644 index 0000000..32e74d2 --- /dev/null +++ b/dapl/openib_cma/udapl_ofa_cma_exports.src @@ -0,0 +1,14 @@ +#if DBG +LIBRARY dapl2-ofa-cmad.dll +#else +LIBRARY dapl2-ofa-cma.dll +#endif + + +EXPORTS +dat_provider_init +dat_provider_fini +#ifdef DAT_EXTENSIONS +dapl_extensions +#endif + diff --git a/dapl/openib_cma/windows/openib_osd.h b/dapl/openib_cma/windows/openib_osd.h new file mode 100644 index 0000000..d008fc0 --- /dev/null +++ b/dapl/openib_cma/windows/openib_osd.h @@ -0,0 +1,5 @@ +#include +#include + +#define ntohll _byteswap_uint64 +#define htonll _byteswap_uint64