[WSD] Minimize allocations of CQ threads.
[mirror/winof/.git] / ulp / wsd / user / ibsp_iblow.c
index 3dc8e13..de059b9 100644 (file)
@@ -622,6 +622,9 @@ ib_alloc_cq_tinfo(
                cq_tinfo->list_item.p_prev = &cq_tinfo->list_item;\r
        }\r
 \r
                cq_tinfo->list_item.p_prev = &cq_tinfo->list_item;\r
        }\r
 \r
+       /* We will be assigned to a QP - set the QP count. */\r
+       cq_tinfo->qp_count = 1;\r
+\r
        /* Upon allocation, the new CQ becomes the primary. */\r
        hca->cq_tinfo = cq_tinfo;\r
 \r
        /* Upon allocation, the new CQ becomes the primary. */\r
        hca->cq_tinfo = cq_tinfo;\r
 \r
@@ -733,7 +736,7 @@ static struct cq_thread_info *
 ib_acquire_cq_tinfo(\r
                                        struct ibsp_hca                         *hca )\r
 {\r
 ib_acquire_cq_tinfo(\r
                                        struct ibsp_hca                         *hca )\r
 {\r
-       struct cq_thread_info   *cq_tinfo = NULL;\r
+       struct cq_thread_info   *cq_tinfo = NULL, *cq_end;\r
        uint32_t                                cqe_size;\r
        ib_api_status_t                 status;\r
 \r
        uint32_t                                cqe_size;\r
        ib_api_status_t                 status;\r
 \r
@@ -745,56 +748,49 @@ ib_acquire_cq_tinfo(
        {\r
                cq_tinfo = ib_alloc_cq_tinfo( hca );\r
                if( !cq_tinfo )\r
        {\r
                cq_tinfo = ib_alloc_cq_tinfo( hca );\r
                if( !cq_tinfo )\r
-               {\r
-                       IBSP_ERROR_EXIT( ("ib_alloc_cq_tinfo() failed\n") );\r
-                       cl_spinlock_release( &hca->cq_lock );\r
-                       return (NULL);\r
-               }\r
+                       IBSP_ERROR( ("ib_alloc_cq_tinfo() failed\n") );\r
+               cl_spinlock_release( &hca->cq_lock );\r
+               IBSP_EXIT( IBSP_DBG_HW );\r
+               return cq_tinfo;\r
        }\r
        }\r
-       else\r
-       {\r
-               cq_tinfo = hca->cq_tinfo;\r
-       }\r
-\r
-       CL_ASSERT( cq_tinfo != NULL );\r
 \r
 \r
+       cq_tinfo = hca->cq_tinfo;\r
+       cq_end = cq_tinfo;\r
        cqe_size = (cq_tinfo->qp_count + 1) * IB_CQ_SIZE;\r
 \r
        cqe_size = (cq_tinfo->qp_count + 1) * IB_CQ_SIZE;\r
 \r
-       if( cq_tinfo->cqe_size < cqe_size )\r
+       do\r
        {\r
        {\r
-               status = ib_modify_cq( cq_tinfo->cq, &cqe_size );\r
-               switch( status )\r
+               if( cq_tinfo->cqe_size >= cqe_size )\r
                {\r
                {\r
-               case IB_INVALID_CQ_SIZE:\r
-               case IB_UNSUPPORTED:\r
-                       cq_tinfo = ib_alloc_cq_tinfo( hca );\r
-                       if( !cq_tinfo )\r
-                               break;\r
-\r
                        cq_tinfo->qp_count++;\r
                        cq_tinfo->qp_count++;\r
-                       break;\r
+                       cl_spinlock_release( &hca->cq_lock );\r
+                       IBSP_EXIT( IBSP_DBG_HW );\r
+                       return (cq_tinfo);\r
+               }\r
 \r
 \r
+               status = ib_modify_cq( cq_tinfo->cq, &cqe_size );\r
+               switch( status )\r
+               {\r
                case IB_SUCCESS:\r
                        cq_tinfo->cqe_size = cqe_size;\r
                case IB_SUCCESS:\r
                        cq_tinfo->cqe_size = cqe_size;\r
-\r
                        cq_tinfo->qp_count++;\r
                        cq_tinfo->qp_count++;\r
-\r
-                       fzprint(("%s():%d:0x%x:0x%x: New cq size=%d.\n",\r
-                                        __FUNCTION__,\r
-                                        __LINE__, GetCurrentProcessId(),\r
-                                        GetCurrentThreadId(), cq_tinfo->cqe_size));\r
                        break;\r
 \r
                default:\r
                        IBSP_ERROR_EXIT(\r
                                ("ib_modify_cq() returned %s\n", ib_get_err_str(status)) );\r
                        break;\r
 \r
                default:\r
                        IBSP_ERROR_EXIT(\r
                                ("ib_modify_cq() returned %s\n", ib_get_err_str(status)) );\r
-                       cq_tinfo = NULL;\r
+               case IB_INVALID_CQ_SIZE:\r
+               case IB_UNSUPPORTED:\r
+                       cq_tinfo = PARENT_STRUCT(\r
+                               cl_qlist_next( &cq_tinfo->list_item ), struct cq_thread_info,\r
+                               list_item );\r
+                       cqe_size = (cq_tinfo->qp_count + 1) * IB_CQ_SIZE;\r
                }\r
                }\r
-       }\r
-       else\r
-       {\r
-               cq_tinfo->qp_count++;\r
-       }\r
+\r
+       } while( cq_tinfo != cq_end );\r
+\r
+       if( cq_tinfo == cq_end )\r
+               cq_tinfo = ib_alloc_cq_tinfo( hca );\r
 \r
        cl_spinlock_release( &hca->cq_lock );\r
        IBSP_EXIT( IBSP_DBG_HW );\r
 \r
        cl_spinlock_release( &hca->cq_lock );\r
        IBSP_EXIT( IBSP_DBG_HW );\r