]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
libibverbs: fix event reporting and minor fixes
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 23 Apr 2009 19:35:20 +0000 (19:35 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 23 Apr 2009 19:35:20 +0000 (19:35 +0000)
Use the latest comp_channel changes to fix event reporting and avoid
hangs when destroying resources.  We need to track when closing
devices to make sure that events are canceled, and avoid issuing
new wait calls.

Rename windows specific calls to include 'w' after the ibv prefix to
avoid any potential future conflicts and clearly indicate to a caller
that they're using a windows only call.

Use the common ntohll definition.

Device names are changed from ibv_device_<guid> to ibv_device_X, where
X is an index (0, 1, 2, etc.).  This gives devices across the cluster
the same name, which is closer to IBAL and OFED device naming.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1@2129 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

trunk/ulp/libibverbs/examples/devinfo/SOURCES
trunk/ulp/libibverbs/examples/devinfo/devinfo.c
trunk/ulp/libibverbs/examples/srq_pingpong/SOURCES
trunk/ulp/libibverbs/include/infiniband/verbs.h
trunk/ulp/libibverbs/src/Sources
trunk/ulp/libibverbs/src/device.cpp
trunk/ulp/libibverbs/src/ibv_exports.src
trunk/ulp/libibverbs/src/ibv_main.cpp
trunk/ulp/libibverbs/src/verbs.cpp

index 007a1e102d520d90d4d407c58bec55587cc2cdd4..ac30a430c5dc0fd8c1be3db49330e78341f23ccb 100644 (file)
@@ -14,7 +14,8 @@ SOURCES =                     \
        devinfo.rc              \\r
        devinfo.c\r
        \r
-INCLUDES = ..;..\..\include;..\..\..\..\inc;..\..\..\..\inc\user;\r
+INCLUDES = ..;..\..\include;..\..\..\..\inc;..\..\..\..\inc\user;\\r
+                  ..\..\..\..\inc\user\linux;\r
 \r
 TARGETLIBS =                                           \\r
        $(SDK_LIB_PATH)\kernel32.lib    \\r
index dab22394a7d4a570972ea26dd33c488aa788cdc5..c50da422d49c8af932fe1f435080806b325e0e1f 100644 (file)
@@ -35,8 +35,8 @@
 \r
 #include "..\..\..\..\etc\user\getopt.c"\r
 #include <infiniband/verbs.h>\r
+#include <netinet/in.h>\r
 \r
-#define ntohll _byteswap_uint64\r
 static int verbose = 0;\r
 \r
 static int null_gid(union ibv_gid *gid)\r
index b1bb2979186843f38c0a454822df79133151fa6c..9e55c726b2da98bde17a7c4ad7f40b4bebaadac6 100644 (file)
@@ -11,7 +11,6 @@ USE_NATIVE_EH = 1
 USE_IOSTREAM = 1\r
 \r
 SOURCES =                      \\r
-       srq_pingpong.rc \\r
        srq_pingpong.c\r
        \r
 INCLUDES = ..;..\..\include;..\..\..\..\inc;..\..\..\..\inc\user;\r
index 68414635f34fcc24234b3337af413bb851314ce4..700259e357c7ebaa69cdae42c4bfb9b06b817bdf 100644 (file)
@@ -1117,19 +1117,19 @@ const char *ibv_event_type_str(enum ibv_event_type event);
 /*\r
  * Windows specific structures and interfaces\r
  */\r
-struct ibv_windata\r
+struct ibvw_windata\r
 {\r
        IWVProvider             *prov;\r
        COMP_MANAGER    *comp_mgr;\r
 };\r
 \r
-#define IBV_WINDATA_VERSION 1\r
+#define IBVW_WINDATA_VERSION 1\r
 \r
 __declspec(dllexport)\r
-int ibv_get_windata(struct ibv_windata *windata, int version);\r
+int ibvw_get_windata(struct ibvw_windata *windata, int version);\r
 \r
 __declspec(dllexport)\r
-void ibv_release_windata(struct ibv_windata *windata, int version);\r
+void ibvw_release_windata(struct ibvw_windata *windata, int version);\r
 \r
 #ifdef __cplusplus\r
 }\r
index ee9e40b803c8f0915172b639e924ba9a62075939..20c50ae1f824f63a7aa8ef3c6da2bf7788042e7e 100644 (file)
@@ -23,7 +23,7 @@ SOURCES = \
        device.cpp              \\r
        enum_strs.cpp\r
 \r
-INCLUDES = ..\include;..\..\..\inc;..\..\..\inc\user;\r
+INCLUDES = ..\include;..\..\..\inc;..\..\..\inc\user;..\..\..\inc\user\linux;\r
 \r
 USER_C_FLAGS = $(USER_C_FLAGS) -DEXPORT_IBV_SYMBOLS\r
 \r
index 58a2ec5366395829f37a9445a143eb60e4605ea3..143f8b33156142897ea2af2b4d0477dd448462e7 100644 (file)
 #include <infiniband/verbs.h>\r
 #include <rdma/winverbs.h>\r
 #include "..\..\..\etc\user\comp_channel.cpp"\r
+#include "..\..\..\etc\user\dlist.c"\r
 \r
+CRITICAL_SECTION lock;\r
 IWVProvider *prov;\r
 COMP_MANAGER comp_mgr;\r
+static DWORD ref;\r
 \r
 struct verbs_device\r
 {\r
@@ -54,31 +57,59 @@ struct verbs_context
 {\r
        struct ibv_context      context;\r
        struct verbs_device     device;\r
+       uint8_t                         closing;\r
        struct verbs_port       *port;\r
        verbs_port                      *event_port;\r
 };\r
 \r
-static int ibv_init(void)\r
+static int ibv_acquire(void)\r
 {\r
        HRESULT hr;\r
 \r
-       if (prov == NULL) {\r
+       EnterCriticalSection(&lock);\r
+       if (ref++ == 0) {\r
                hr = WvGetObject(IID_IWVProvider, (LPVOID*) &prov);\r
                if (FAILED(hr)) {\r
-                       return -1;\r
+                       goto err1;\r
+               }\r
+               hr = CompManagerOpen(&comp_mgr);\r
+               if (FAILED(hr)) {\r
+                       goto err2;\r
+               }\r
+               hr = CompManagerMonitor(&comp_mgr, prov->GetFileHandle(), 0);\r
+               if (FAILED(hr)) {\r
+                       goto err3;\r
                }\r
-               CompManagerOpen(&comp_mgr);\r
-               CompManagerMonitor(&comp_mgr, prov->GetFileHandle(), 0);\r
        }\r
+       LeaveCriticalSection(&lock);\r
        return 0;\r
+\r
+err3:\r
+       CompManagerClose(&comp_mgr);\r
+err2:\r
+       prov->Release();\r
+err1:\r
+       ref--;\r
+       LeaveCriticalSection(&lock);\r
+       return hr;\r
+}\r
+\r
+static void ibv_release(void)\r
+{\r
+       EnterCriticalSection(&lock);\r
+       if (--ref == 0) {\r
+               CompManagerClose(&comp_mgr);\r
+               prov->Release();\r
+       }\r
+       LeaveCriticalSection(&lock);\r
 }\r
 \r
 __declspec(dllexport)\r
-int ibv_get_windata(struct ibv_windata *windata, int version)\r
+int ibvw_get_windata(struct ibvw_windata *windata, int version)\r
 {\r
        int ret;\r
 \r
-       if (version != IBV_WINDATA_VERSION || ibv_init()) {\r
+       if (version != IBVW_WINDATA_VERSION || ibv_acquire()) {\r
                return -1;\r
        }\r
 \r
@@ -89,9 +120,9 @@ int ibv_get_windata(struct ibv_windata *windata, int version)
 }\r
 \r
 __declspec(dllexport)\r
-void ibv_release_windata(struct ibv_windata *windata, int version)\r
+void ibvw_release_windata(struct ibvw_windata *windata, int version)\r
 {\r
-       windata->prov->Release();\r
+       ibv_release();\r
 }\r
 \r
 __declspec(dllexport)\r
@@ -104,7 +135,7 @@ struct ibv_device **ibv_get_device_list(int *num)
        SIZE_T size, cnt;\r
        HRESULT hr;\r
 \r
-       if (ibv_init()) {\r
+       if (ibv_acquire()) {\r
                goto err1;\r
        }\r
 \r
@@ -142,7 +173,7 @@ struct ibv_device **ibv_get_device_list(int *num)
                        goto err3;\r
                }\r
 \r
-               sprintf(dev_array[cnt].device.name, "ibv_device_0x%I64x", guid[cnt]);\r
+               sprintf(dev_array[cnt].device.name, "ibv_device%d", cnt);\r
                dev_array[cnt].device.node_type = IBV_NODE_UNKNOWN;\r
                dev_array[cnt].device.transport_type = (ibv_transport_type) attr.DeviceType;\r
                dev_array[cnt].guid = guid[cnt];\r
@@ -166,6 +197,7 @@ err1:
 __declspec(dllexport)\r
 void ibv_free_device_list(struct ibv_device **list)\r
 {\r
+       ibv_release();\r
        delete CONTAINING_RECORD(list[0], struct verbs_device, device);\r
        delete list;\r
 }\r
@@ -195,8 +227,12 @@ struct ibv_context *ibv_open_device(struct ibv_device *device)
        if (vcontext == NULL) {\r
                return NULL;\r
        }\r
+\r
+       ibv_acquire();\r
        memcpy(&vcontext->device, vdev, sizeof(struct verbs_device));\r
+       vcontext->context.device = &vcontext->device.device;\r
        vcontext->event_port = NULL;\r
+       vcontext->closing = 0;\r
        CompChannelInit(&comp_mgr, &vcontext->context.channel, INFINITE);\r
 \r
        vcontext->port = new struct verbs_port[vdev->phys_port_cnt];\r
@@ -213,6 +249,7 @@ struct ibv_context *ibv_open_device(struct ibv_device *device)
                vcontext->port[i].port_num = (uint8_t) i + 1;\r
                vcontext->port[i].event_flag = 0;\r
                CompEntryInit(&vcontext->context.channel, &vcontext->port[i].comp_entry);\r
+               vcontext->port[i].comp_entry.Busy = 1;\r
                vcontext->context.cmd_if->Notify(vcontext->port[i].port_num,\r
                                                                                 &vcontext->port[i].comp_entry.Overlap,\r
                                                                                 &vcontext->port[i].event_flag);\r
@@ -224,6 +261,7 @@ err2:
        delete vcontext->port;\r
 err1:\r
        delete vcontext;\r
+       ibv_release();\r
        return NULL;\r
 }\r
 \r
@@ -234,13 +272,15 @@ int ibv_close_device(struct ibv_context *context)
        int i;\r
 \r
        vcontext = CONTAINING_RECORD(context, struct verbs_context, context);\r
+       vcontext->closing = 1;\r
        context->cmd_if->CancelOverlappedRequests();\r
 \r
        for (i = 0; i < vcontext->device.phys_port_cnt; i++) {\r
-               CompChannelRemoveEntry(&context->channel, &vcontext->port[i].comp_entry);\r
+               CompEntryCancel(&vcontext->port[i].comp_entry);\r
        }\r
 \r
        context->cmd_if->Release();\r
+       ibv_release();\r
        delete vcontext->port;\r
        delete vcontext;\r
        return 0;\r
@@ -289,7 +329,8 @@ static int ibv_report_port_event(struct verbs_context *vcontext,
                ret = -1;\r
        }\r
        \r
-       if (port->event_flag == 0) {\r
+       if (port->event_flag == 0 && !vcontext->closing) {\r
+               port->comp_entry.Busy = 1;\r
                vcontext->context.cmd_if->Notify(vcontext->event_port->port_num,\r
                                                                                 &port->comp_entry.Overlap,\r
                                                                                 &port->event_flag);\r
index 63f274eaee2da2f16e327e917d2c78fcb175a16e..67707a55834d5defbd2ce9321ee7e2debd563c42 100644 (file)
@@ -51,6 +51,6 @@ ibv_detach_mcast
 ibv_node_type_str\r
 ibv_port_state_str\r
 ibv_event_type_str\r
-ibv_get_windata\r
-ibv_release_windata\r
+ibvw_get_windata\r
+ibvw_release_windata\r
 #endif\r
index f57d13cfa94b36f6f767b0db7a4a7b741c2ad05a..bfa00d7fe49328689de1458b8d41c34689692d69 100644 (file)
 \r
 #include <windows.h>\r
 \r
+extern CRITICAL_SECTION lock;\r
+\r
 BOOLEAN WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
 {\r
        UNREFERENCED_PARAMETER(hInstance);\r
        UNREFERENCED_PARAMETER(dwReason);\r
        UNREFERENCED_PARAMETER(lpReserved);\r
 \r
+       InitializeCriticalSection(&lock);\r
        return TRUE;\r
 }\r
index ca80d1aa27d67621bf122ce1e846fb805811efcd..fd9f318a05fef793dfd510fbd42c50cd19a30226 100644 (file)
 #include <windows.h>\r
 #include <winsock2.h>\r
 #include <stdio.h>\r
+#include <netinet/in.h>\r
 \r
 #include <infiniband/verbs.h>\r
 #include <comp_channel.h>\r
 #include "ibverbs.h"\r
 \r
+\r
 __declspec(dllexport)\r
 int ibv_rate_to_mult(enum ibv_rate rate)\r
 {\r
@@ -296,6 +298,7 @@ struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
                delete mr;\r
                return NULL;\r
        }\r
+       mr->rkey = ntohl(mr->rkey);\r
        return mr;\r
 }\r
 \r
@@ -383,13 +386,16 @@ int ibv_req_notify_cq(struct ibv_cq *cq, int solicited_only)
 {\r
        HRESULT hr;\r
 \r
-       hr = cq->handle->Notify(solicited_only ? WvCqSolicited : WvCqNextCompletion,\r
-                                                       &cq->comp_entry.Overlap);\r
-       if (SUCCEEDED(hr) || hr == WV_IO_PENDING) {\r
-               return 0;\r
+       if (InterlockedCompareExchange(&cq->comp_entry.Busy, 1, 0) == 0) {\r
+               hr = cq->handle->Notify(solicited_only ? WvCqSolicited : WvCqNextCompletion,\r
+                                                               &cq->comp_entry.Overlap);\r
+               if (SUCCEEDED(hr) || hr == WV_IO_PENDING) {\r
+                       hr = 0;\r
+               }\r
        } else {\r
-               return hr;\r
+               hr = 0;\r
        }\r
+       return hr;\r
 }\r
 \r
 __declspec(dllexport)\r
@@ -410,11 +416,9 @@ __declspec(dllexport)
 int ibv_destroy_cq(struct ibv_cq *cq)\r
 {\r
        cq->handle->CancelOverlappedRequests();\r
-\r
        if (cq->channel != NULL) {\r
-               CompChannelRemoveEntry(&cq->channel->comp_channel, &cq->comp_entry);\r
+               CompEntryCancel(&cq->comp_entry);\r
        }\r
-\r
        cq->handle->Release();\r
        delete cq;\r
        return 0;\r
@@ -729,21 +733,29 @@ int ibv_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
                        cur_wr->opcode = (ibv_wr_opcode) (cur_wr->opcode & ~0x80000000);\r
                        cur_wr->send_flags = (ibv_send_flags) (cur_wr->send_flags | WV_SEND_IMMEDIATE);\r
                }\r
+\r
+               if (cur_wr->opcode != 0) {\r
+                       cur_wr->wr.rdma.rkey = htonl(cur_wr->wr.rdma.rkey);\r
+               }\r
        }\r
 \r
        hr = qp->handle->PostSend((WV_SEND_REQUEST *) wr, (WV_SEND_REQUEST **) bad_wr);\r
 \r
        for (cur_wr = wr; cur_wr != NULL; cur_wr = cur_wr->next) {\r
-               if (qp->qp_type == IBV_QPT_UD) {\r
-                       cur_wr->wr.ud.ah = ah;\r
-                       cur_wr->wr.ud.remote_qkey = ntohl(cur_wr->wr.ud.remote_qkey);\r
-                       cur_wr->wr.ud.remote_qpn = ntohl(cur_wr->wr.ud.remote_qpn);\r
+               if (cur_wr->opcode != 0) {\r
+                       cur_wr->wr.rdma.rkey = ntohl(cur_wr->wr.rdma.rkey);\r
                }\r
 \r
                if ((cur_wr->send_flags & WV_SEND_IMMEDIATE) != 0) {\r
                        cur_wr->send_flags = (ibv_send_flags) (cur_wr->send_flags & ~WV_SEND_IMMEDIATE);\r
                        cur_wr->opcode = (ibv_wr_opcode) (cur_wr->opcode | 0x80000000);\r
                }\r
+\r
+               if (qp->qp_type == IBV_QPT_UD) {\r
+                       cur_wr->wr.ud.ah = ah;\r
+                       cur_wr->wr.ud.remote_qkey = ntohl(cur_wr->wr.ud.remote_qkey);\r
+                       cur_wr->wr.ud.remote_qpn = ntohl(cur_wr->wr.ud.remote_qpn);\r
+               }\r
        }\r
 \r
        return hr;\r