From 42f0ac1c5a4c120e358c28353d11b30db6c35562 Mon Sep 17 00:00:00 2001 From: tzachid Date: Mon, 21 Nov 2005 12:17:02 +0000 Subject: [PATCH] Credits are being implemented for send. (Rev 110,111) git-svn-id: svn://openib.tc.cornell.edu/gen1@169 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/ulp/sdp/kernel/SdpBufferPool.cpp | 25 ++++++--------- trunk/ulp/sdp/kernel/SdpBufferPool.h | 15 +++++++-- trunk/ulp/sdp/kernel/SdpGenUtils.cpp | 5 +++ trunk/ulp/sdp/kernel/SdpGenUtils.h | 2 ++ trunk/ulp/sdp/kernel/SdpRecvPool.cpp | 42 ++++++++++++++++++-------- trunk/ulp/sdp/kernel/SdpRecvPool.h | 3 -- trunk/ulp/sdp/kernel/SdpSocket.cpp | 20 ++++++------ trunk/ulp/sdp/kernel/SdpSocket.h | 9 ++++-- 8 files changed, 75 insertions(+), 46 deletions(-) diff --git a/trunk/ulp/sdp/kernel/SdpBufferPool.cpp b/trunk/ulp/sdp/kernel/SdpBufferPool.cpp index 5524e4de..41255872 100644 --- a/trunk/ulp/sdp/kernel/SdpBufferPool.cpp +++ b/trunk/ulp/sdp/kernel/SdpBufferPool.cpp @@ -189,21 +189,12 @@ BufferPool::AddBufferToQueuedList(BufferDescriptor *pBufferDescriptor) NTSTATUS rc = STATUS_SUCCESS; - if ((m_CurrentlySentBuffers < m_MaxConcurrentSends) && - (m_QueuedPackets.Size() == 0 )){ - // we can send right away (no need to wait for anything) - rc = SendBuffer(pBufferDescriptor); - if (!NT_SUCCESS(rc)) { - SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("SendBuffer failed rc = 0x%x\n", rc )); - m_FreePackets.InsertTailList(&pBufferDescriptor->BuffersList); - goto Cleanup; - } - // We have finished our job + m_QueuedPackets.InsertTailList(&pBufferDescriptor->BuffersList); + rc = SendBuffersIfCan(); + if (!NT_SUCCESS(rc)) { + SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("SendBuffersIfCan failed rc = 0x%x\n", rc )); goto Cleanup; - } else { - // we put the buffer in the queued list - m_QueuedPackets.InsertTailList(&pBufferDescriptor->BuffersList); - } + } Cleanup: return rc; @@ -264,7 +255,8 @@ BufferPool::SendBuffersIfCan() NTSTATUS rc = STATUS_SUCCESS; while ((m_QueuedPackets.Size() > 0) && - (m_CurrentlySentBuffers < m_MaxConcurrentSends)) { + (m_CurrentlySentBuffers < m_MaxConcurrentSends) && + (m_rRecvBuf > 2)) { // we can now send the next buffer LIST_ENTRY *item = m_QueuedPackets.RemoveHeadList(); BufferDescriptor *pBufferDescriptor = CONTAINING_RECORD(item, BufferDescriptor , BuffersList); @@ -319,7 +311,7 @@ BufferPool::SendBuffer(BufferDescriptor *pBufferDescriptor) pHeader->recv_bufs = m_pSdpSocket->m_RecvBufferPool.GetCurrentlyPostedRecievedBuffers(); //?????recv_bufs = conn->l_advt_bf; pHeader->size = pBufferDescriptor->DataSize + sizeof msg_hdr_bsdh; - pHeader->seq_num = GetSendSeq(); + pHeader->seq_num = GetAndIncreaseSendSeq(); pHeader->seq_ack = m_pSdpSocket->m_RecvBufferPool.GetRecvSeq();//????conn->advt_seq; m_AdvtSeq = pHeader->seq_ack;// Currently only for debug pHeader->mid = SDP_MID_DATA; @@ -350,6 +342,7 @@ BufferPool::SendBuffer(BufferDescriptor *pBufferDescriptor) goto Cleanup; } m_CurrentlySentBuffers ++; + m_rRecvBuf--; Cleanup: return rc; diff --git a/trunk/ulp/sdp/kernel/SdpBufferPool.h b/trunk/ulp/sdp/kernel/SdpBufferPool.h index 28ed8db3..bf668386 100644 --- a/trunk/ulp/sdp/kernel/SdpBufferPool.h +++ b/trunk/ulp/sdp/kernel/SdpBufferPool.h @@ -136,10 +136,18 @@ public: VOID ShutDown(); - uint32_t GetSendSeq() {return m_SendSeq++;} + uint32_t GetSendSeq() {return m_SendSeq;} + uint32_t GetAndIncreaseSendSeq() {return m_SendSeq++;} uint32_t GetAdvtSeq() {return m_AdvtSeq;} - + VOID SetRemoteRecvBuf (uint16_t rRecvBuf) { + if (m_rRecvBuf == 2) { + SDP_PRINT(SDP_ALL, SDP_BUFFER_POOL,("m_rRecvBuf = %d, it is being set to %d seqnum = %d\n", m_rRecvBuf, rRecvBuf, m_SendSeq)); + } + m_rRecvBuf = rRecvBuf; + } + + private: @@ -172,7 +180,8 @@ private: bool m_ClientWaiting; uint32_t m_SendSeq; //sequence number of last message sent (send_seq in linux) - uint32_t m_AdvtSeq; // sequence number of last message acknowledged (advt_seq in linux) + uint32_t m_AdvtSeq; // sequence number of last message acknowledged (advt_seq in linux) + uint16_t m_rRecvBuf; // number of recv buffers remote currently has (r_recv_bf in linux) SdpSocket *m_pSdpSocket; diff --git a/trunk/ulp/sdp/kernel/SdpGenUtils.cpp b/trunk/ulp/sdp/kernel/SdpGenUtils.cpp index db4eb659..5f246978 100644 --- a/trunk/ulp/sdp/kernel/SdpGenUtils.cpp +++ b/trunk/ulp/sdp/kernel/SdpGenUtils.cpp @@ -136,6 +136,11 @@ VOID UpdateRc(NTSTATUS *rc, NTSTATUS rc1) } } +int abs(int i){ + if (i > 0) return i; + return -i; +} + void* __cdecl operator new(size_t n ) throw() { return ExAllocatePoolWithTag(NonPagedPool , n, GLOBAL_ALLOCATION_TAG); } diff --git a/trunk/ulp/sdp/kernel/SdpGenUtils.h b/trunk/ulp/sdp/kernel/SdpGenUtils.h index e810afdc..497b8059 100644 --- a/trunk/ulp/sdp/kernel/SdpGenUtils.h +++ b/trunk/ulp/sdp/kernel/SdpGenUtils.h @@ -70,6 +70,8 @@ CopyToUser( VOID UpdateRc(NTSTATUS *rc, NTSTATUS rc1); +int abs(int i); + // This error codes are taken from winsock2.h (the file can not) // be included from user mode diff --git a/trunk/ulp/sdp/kernel/SdpRecvPool.cpp b/trunk/ulp/sdp/kernel/SdpRecvPool.cpp index 2cdf2e8f..1781d355 100644 --- a/trunk/ulp/sdp/kernel/SdpRecvPool.cpp +++ b/trunk/ulp/sdp/kernel/SdpRecvPool.cpp @@ -1,5 +1,4 @@ /* Copyright mellanox */ -#pragma warning(disable: 4244 ) #include "preCompile.h" @@ -34,9 +33,7 @@ RecvPool::Init( m_qp = qp; ASSERT(lkey != NULL); m_lkey = lkey; -#if DBG m_pSdpSocket = pSdpSocket; -#endif return STATUS_SUCCESS; } @@ -66,19 +63,40 @@ RecvPool::RecievedBuffer(BufferDescriptor *pBufferDescriptor, bool error) pBufferDescriptor->DataSize = pHeader->size - sizeof msg_hdr_bsdh; m_RecvSeq = pHeader->seq_num; - - m_FullPackets.InsertTailList(&pBufferDescriptor->BuffersList); - ASSERT(m_FullPackets.Size() <= m_MaxBuffers); - // we need to notify the client that is waiting - if (m_ClientWaiting) { - KeSetEvent( &m_WaitingClients, IO_NO_INCREMENT, FALSE ); - m_ClientWaiting = false; + // Start processing the different messages: + // No metter what the message type is, we can update our credits + + uint16_t rRecvBuf = + pHeader->recv_bufs - + abs ( + (int)m_pSdpSocket->m_SendBufferPool.GetSendSeq()- + (int)pHeader->seq_ack); + m_pSdpSocket->m_SendBufferPool.SetRemoteRecvBuf(rRecvBuf); + + + if(pHeader->size > sizeof msg_hdr_bsdh) { + m_FullPackets.InsertTailList(&pBufferDescriptor->BuffersList); + ASSERT(m_FullPackets.Size() <= m_MaxBuffers); + + // we need to notify the client that is waiting + if (m_ClientWaiting) { + KeSetEvent( &m_WaitingClients, IO_NO_INCREMENT, FALSE ); + m_ClientWaiting = false; + } + } else { + // This is an empty buffer + ASSERT(pHeader->size == sizeof msg_hdr_bsdh); + m_FreePackets.InsertTailList(&pBufferDescriptor->BuffersList); } // ???? Handle state changes here ???? - //???? we will also have to wake up the clients of the send ??????? - + // Wake up the clients of the send (new credits were added) + rc = m_pSdpSocket->m_SendBufferPool.SendBuffersIfCan(); + if (!NT_SUCCESS(rc)) { + SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("SendBuffersIfCan failed rc = 0x%x\n", rc )); + goto Cleanup; + } m_CurrentlyPostedRecievedBuffers--; ASSERT(m_CurrentlyPostedRecievedBuffers >= 0); diff --git a/trunk/ulp/sdp/kernel/SdpRecvPool.h b/trunk/ulp/sdp/kernel/SdpRecvPool.h index 68ac1833..4e86b027 100644 --- a/trunk/ulp/sdp/kernel/SdpRecvPool.h +++ b/trunk/ulp/sdp/kernel/SdpRecvPool.h @@ -71,10 +71,7 @@ private: uint32_t m_RecvSeq; // sequence number of last message received (recv_seq) - -#if DBG SdpSocket *m_pSdpSocket; -#endif //DBG VOID AssertLocked(); diff --git a/trunk/ulp/sdp/kernel/SdpSocket.cpp b/trunk/ulp/sdp/kernel/SdpSocket.cpp index af8adbb1..6add3c1e 100644 --- a/trunk/ulp/sdp/kernel/SdpSocket.cpp +++ b/trunk/ulp/sdp/kernel/SdpSocket.cpp @@ -546,6 +546,7 @@ NTSTATUS SdpSocket::CmSendRTU() SDP_PRINT(SDP_ERR, SDP_SOCKET, ("m_RecvBufferPool.Init failed rc = 0x%x\n", rc )); goto Cleanup; } + m_SendBufferPool.SetRemoteRecvBuf(m_hello_ack.bsdh.recv_bufs); #if 0 /* @@ -669,19 +670,19 @@ SdpSocket::recv_cb() } ib_api_status_t ib_status; - ib_wc_t wc[QP_ATTRIB_RQ_DEPTH], *p_free, *p_wc1; + ib_wc_t *p_free, *p_wc1; uint32_t pkt_cnt, recv_cnt = 0; size_t i; BufferDescriptor *pBufferDescriptor = NULL; for( i = 0; i < QP_ATTRIB_RQ_DEPTH; i++ ) - wc[i].p_next = &wc[i + 1]; - wc[QP_ATTRIB_RQ_DEPTH - 1].p_next = NULL; + m_RecvComplitionWC[i].p_next = &m_RecvComplitionWC[i + 1]; + m_RecvComplitionWC[QP_ATTRIB_RQ_DEPTH - 1].p_next = NULL; do { /* If we get here, then the list of WCs is intact. */ - p_free = wc; + p_free = m_RecvComplitionWC; ib_status = ib_poll_cq( m_rcq, &p_free, &p_wc1 ); if( (ib_status != IB_SUCCESS) && (ib_status != IB_NOT_FOUND) ) { @@ -792,24 +793,23 @@ static NTSTATUS __recv_cb2(SdpSocket * pSdpSocket) return pSdpSocket->recv_cb(); } - NTSTATUS SdpSocket::send_cb() { SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("called this =0x%x\n", this)); NTSTATUS rc = STATUS_SUCCESS; ib_api_status_t ib_status; - ib_wc_t wc[QP_ATTRIB_SQ_DEPTH], *p_wc, *p_free; + ib_wc_t *p_wc, *p_free; size_t i; BufferDescriptor *pBufferDescriptor = NULL; for( i = 0; i < QP_ATTRIB_SQ_DEPTH; i++ ) { - wc[i].p_next = &wc[i + 1]; + m_SendComplitionWC[i].p_next = &m_SendComplitionWC[i + 1]; } - wc[QP_ATTRIB_SQ_DEPTH - 1].p_next = NULL; + m_SendComplitionWC[QP_ATTRIB_SQ_DEPTH - 1].p_next = NULL; do { - p_free = wc; + p_free = m_SendComplitionWC; ib_status = ib_poll_cq( m_scq, &p_free, &p_wc ); ASSERT( ib_status == IB_SUCCESS || ib_status == IB_NOT_FOUND); if (ib_status == IB_NOT_FOUND) { @@ -1065,7 +1065,7 @@ VOID SdpSocket::CreateHelloHeader( hello_msg->bsdh.flags = SDP_MSG_FLAG_NON_FLAG; hello_msg->bsdh.mid = SDP_MID_HELLO; hello_msg->bsdh.size = sizeof(struct sdp_msg_hello); - hello_msg->bsdh.seq_num = m_SendBufferPool.GetSendSeq();//conn->send_seq; ??? + hello_msg->bsdh.seq_num = m_SendBufferPool.GetAndIncreaseSendSeq();//conn->send_seq; ??? hello_msg->bsdh.seq_ack = m_RecvBufferPool.GetRecvSeq();//conn->advt_seq; ??? hello_msg->hh.max_adv = QP_ATTRIB_RQ_DEPTH;// ??? conn->l_max_adv; diff --git a/trunk/ulp/sdp/kernel/SdpSocket.h b/trunk/ulp/sdp/kernel/SdpSocket.h index b31ce87d..4092a4d2 100644 --- a/trunk/ulp/sdp/kernel/SdpSocket.h +++ b/trunk/ulp/sdp/kernel/SdpSocket.h @@ -16,14 +16,14 @@ const int MAX_SEND_PACKETS = 200; // This is the maximum number const int MAX_RECV_PACKETS = 200; // This is the maximum number of packets allocated per send -#define QP_ATTRIB_SQ_DEPTH 32 +#define QP_ATTRIB_SQ_DEPTH 64 #define QP_ATTRIB_SQ_SGE 1 /* Set based on inline data requirements */ /* * TODO: During testing, the switch has been observed to post * 12 receive buffers. It would be nice to know what the max is. */ -#define QP_ATTRIB_RQ_DEPTH 16 +#define QP_ATTRIB_RQ_DEPTH 64 #define QP_ATTRIB_RQ_SGE 1 /* Number of entries in a CQ */ @@ -74,6 +74,11 @@ private: KEVENT m_ConnectCmCompleteEvent; KEVENT m_ShutdownCompleteEvent; + ib_wc_t m_SendComplitionWC[QP_ATTRIB_SQ_DEPTH]; + ib_wc_t m_RecvComplitionWC[QP_ATTRIB_RQ_DEPTH]; + + + VOID SignalShutdown(); static VOID __send_cb1( -- 2.41.0