From: tzachid Date: Mon, 19 Dec 2005 09:05:16 +0000 (+0000) Subject: [SDP] Updated the test program to use Multiple Overlapped operation + Minor fixes... X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=91059ce68e6c01f3fa07ae6563961b4c52316f73;p=~shefty%2Frdma-win.git [SDP] Updated the test program to use Multiple Overlapped operation + Minor fixes to driver (Rev 827) git-svn-id: svn://openib.tc.cornell.edu/gen1@209 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/ulp/sdp/kernel/SdpBufferPool.cpp b/trunk/ulp/sdp/kernel/SdpBufferPool.cpp index c58d34eb..b554f1cc 100644 --- a/trunk/ulp/sdp/kernel/SdpBufferPool.cpp +++ b/trunk/ulp/sdp/kernel/SdpBufferPool.cpp @@ -252,7 +252,7 @@ BufferPool::ReturnBuffer(BufferDescriptor *pBufferDescriptor) #if DBG if (m_CurrentlySentBuffers == 1) { - SDP_PRINT(TRACE_LEVEL_WARNING, SDP_PERFORMANCE, "Currently no packets are bing sent \n"); + SDP_PRINT(TRACE_LEVEL_VERBOSE, SDP_PERFORMANCE, "Currently no packets are bing sent \n"); } #endif ASSERT( pBufferDescriptor->GetFlags() == CREDIT_UPDATE || @@ -338,7 +338,7 @@ BufferPool::AddToUserBuffers( IRP* pIrp ) { - SDP_PRINT(TRACE_LEVEL_VERBOSE, SDP_BUFFER_POOL, "this = 0x%p \n",this); + SDP_PRINT(TRACE_LEVEL_VERBOSE, SDP_BUFFER_POOL, "this = 0x%p m_UserPackets.Size() = %d \n",this, m_UserPackets.Size()); AssertLocked(); NTSTATUS rc = STATUS_SUCCESS; @@ -355,7 +355,6 @@ BufferPool::AddToUserBuffers( SetSocket(pIrp,m_pSdpSocket); - ASSERT(m_UserPackets.Size()==0); IoMarkIrpPending(pIrp); m_UserPackets.InsertTailList(&pIrp->Tail.Overlay.ListEntry); *pCopied = true; @@ -369,11 +368,10 @@ Cleanup: #if 0 The above code should be activated if we want to allow returning offsetof the user mode thread as fast as possible. - if (m_CallBackPending == false) { NTSTATUS rc1 = m_pSdpSocket->RequestCallBack(); if (!NT_SUCCESS(rc1)) { - SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("PostCredits failed rc = 0x%x\n", rc )); + SDP_PRINT(TRACE_LEVEL_ERROR, SDP_BUFFER_POOL, "RequestCallBack failed rc = 0x%x\n", rc ); ASSERT(FALSE); } m_CallBackPending = true; diff --git a/trunk/ulp/sdp/kernel/SdpDriver.cpp b/trunk/ulp/sdp/kernel/SdpDriver.cpp index 3d52f827..050676c0 100644 --- a/trunk/ulp/sdp/kernel/SdpDriver.cpp +++ b/trunk/ulp/sdp/kernel/SdpDriver.cpp @@ -63,7 +63,7 @@ VOID DriverUnload ( IN PDRIVER_OBJECT pDriverObject ) { - SDP_PRINT(TRACE_LEVEL_INFORMATION, SDP_DRIVER,"called pDriverObject = 0x%x\n", (uint32_t)pDriverObject ); + SDP_PRINT(TRACE_LEVEL_INFORMATION, SDP_DRIVER,"called pDriverObject = 0x%p\n", pDriverObject ); ib_api_status_t ib_status; g_pSdpDriver->Shutdown(); @@ -271,8 +271,8 @@ NTSTATUS SdpDriver::Dispatch( switch (pIrpSp->MajorFunction) { case IRP_MJ_CREATE: { - SDP_PRINT(TRACE_LEVEL_INFORMATION, SDP_DRIVER, "IRP_MJ_CREATE pIrpSp->FileObject = 0x%x\n", - (uint32_t)pIrpSp->FileObject ); + SDP_PRINT(TRACE_LEVEL_INFORMATION, SDP_DRIVER, "IRP_MJ_CREATE pIrpSp->FileObject = 0x%p\n", + pIrpSp->FileObject ); pSdpUserFile = new SdpUserFile; if (pSdpUserFile == NULL) { rc = STATUS_NO_MEMORY; diff --git a/trunk/ulp/sdp/kernel/SdpGenUtils.cpp b/trunk/ulp/sdp/kernel/SdpGenUtils.cpp index 77626886..db77ec45 100644 --- a/trunk/ulp/sdp/kernel/SdpGenUtils.cpp +++ b/trunk/ulp/sdp/kernel/SdpGenUtils.cpp @@ -39,6 +39,8 @@ #include "SdpGenUtils.tmh" #endif +//#define DONT_COPY_DATA + USHORT ntohs(USHORT in) { return ((in & 0xff) << 8) | ((in & 0xff00) >> 8); diff --git a/trunk/ulp/sdp/kernel/SdpTrace.cpp b/trunk/ulp/sdp/kernel/SdpTrace.cpp index 5b8e388a..1fcbdf82 100644 --- a/trunk/ulp/sdp/kernel/SdpTrace.cpp +++ b/trunk/ulp/sdp/kernel/SdpTrace.cpp @@ -35,9 +35,12 @@ #include #include - #if !defined(EVENT_TRACING) +const int g_SdpDbgLevel = SDP_WARN; +//const int g_SdpDbgLevel = SDP_TRACE; +//const int g_SdpDbgLevel = SDP_DEBUG; + #if DBG //int g_SdpDbgLevel = TRACE_LEVEL_WARNING; @@ -91,7 +94,7 @@ Return Value: KdPrint ((": RtlStringCbVPrintfA failed %x\n", status)); return; } - if (lvl <= TRACE_LEVEL_INFORMATION || (lvl <= g_SdpDbgLevel && + if ((lvl <= g_SdpDbgLevel && ((flags & g_SdpDbgFlags) == flags))) { KdPrint(("%s:",__FUNCTION__)); if(lvl == TRACE_LEVEL_ERROR) KdPrint (("ERROR - ")); @@ -104,4 +107,4 @@ Return Value: #endif } -#endif \ No newline at end of file +#endif diff --git a/trunk/ulp/sdp/tests/basic/SdpConnect.cpp b/trunk/ulp/sdp/tests/basic/SdpConnect.cpp index 257db86b..b43f503a 100644 --- a/trunk/ulp/sdp/tests/basic/SdpConnect.cpp +++ b/trunk/ulp/sdp/tests/basic/SdpConnect.cpp @@ -29,32 +29,32 @@ #endif // Windows linux -const int NumberOfThreads = 1; +const int NumberOfThreads = 2; HANDLE g_ComplitionPort; -HANDLE *g_pThreads; +HANDLE g_pThreads[NumberOfThreads]; #define ASSERT assert struct sockaddr addressFromString(char *address, int port) { - unsigned int b1,b2,b3,b4; + unsigned int b1,b2,b3,b4; - struct sockaddr_in socket_address; - struct sockaddr *socket_address_ptr = (struct sockaddr*)&socket_address; + struct sockaddr_in socket_address; + struct sockaddr *socket_address_ptr = (struct sockaddr*)&socket_address; - memset(&socket_address, 0, sizeof(socket_address)); - socket_address.sin_family = AF_INET; - socket_address.sin_port = htons((u_short)port); - - - sscanf(address, "%d.%d.%d.%d",&b1, &b2, &b3, &b4); - socket_address.sin_addr.s_addr = b4 * 256 * 256 *256 + - b3 * 256 * 256 + - b2 * 256 + - b1; - - return *socket_address_ptr; + memset(&socket_address, 0, sizeof(socket_address)); + socket_address.sin_family = AF_INET; + socket_address.sin_port = htons((u_short)port); + + + sscanf(address, "%d.%d.%d.%d",&b1, &b2, &b3, &b4); + socket_address.sin_addr.s_addr = b4 * 256 * 256 *256 + + b3 * 256 * 256 + + b2 * 256 + + b1; + + return *socket_address_ptr; } @@ -64,13 +64,18 @@ struct OverlappedSend { void *Buffer; // The data to send int DataSize; DWORD NumberOfBytesSent; - int RemainingSends; - int SendsInAir; // Curently sent data - CRITICAL_SECTION Lock; - HANDLE SendDoneEvent; + static int s_RemainingSends; + static int s_SendsInAir; // Curently sent data (debug only) + static CRITICAL_SECTION s_Lock; + static HANDLE s_SendDoneEvent; }; +int OverlappedSend::s_RemainingSends; +int OverlappedSend::s_SendsInAir; // Curently sent data (debug only) +CRITICAL_SECTION OverlappedSend::s_Lock; +HANDLE OverlappedSend::s_SendDoneEvent; + DWORD WINAPI WorkerThreadFunc( LPVOID lpParam ) { @@ -92,16 +97,15 @@ DWORD WINAPI WorkerThreadFunc( LPVOID lpParam ) ASSERT(ret != 0); pOverLappedSend = CONTAINING_RECORD(lpOverlapped, OverlappedSend, Overlapped); // Work on the object itself: - EnterCriticalSection(&pOverLappedSend->Lock); - pOverLappedSend->SendsInAir--; - ASSERT(pOverLappedSend->SendsInAir ==0); // Only one thread - if (pOverLappedSend->RemainingSends > 0) { + EnterCriticalSection(&pOverLappedSend->s_Lock); + pOverLappedSend->s_SendsInAir--; + if (pOverLappedSend->s_RemainingSends > 0) { // do the next send WSABUF Buffers; Buffers.len = pOverLappedSend->DataSize; Buffers.buf = (char *) pOverLappedSend->Buffer; - pOverLappedSend->SendsInAir++; - pOverLappedSend->RemainingSends--; + pOverLappedSend->s_SendsInAir++; + pOverLappedSend->s_RemainingSends--; iRet = WSASend( pOverLappedSend->Socket, @@ -116,10 +120,10 @@ DWORD WINAPI WorkerThreadFunc( LPVOID lpParam ) } else { // Nothing more to send - signal compleation and exit - SetEvent(pOverLappedSend->SendDoneEvent); + SetEvent(pOverLappedSend->s_SendDoneEvent); ContinueLoop = false; } - LeaveCriticalSection(&pOverLappedSend->Lock); + LeaveCriticalSection(&pOverLappedSend->s_Lock); if (!ContinueLoop) { break; } @@ -130,9 +134,6 @@ DWORD WINAPI WorkerThreadFunc( LPVOID lpParam ) void CreateComplitionPort(SOCKET newfd) { - g_pThreads = new HANDLE [NumberOfThreads]; - ASSERT(g_pThreads != NULL); - g_ComplitionPort = CreateIoCompletionPort((HANDLE)newfd, NULL, NULL, 2); if(g_ComplitionPort == NULL) { @@ -140,72 +141,94 @@ void CreateComplitionPort(SOCKET newfd) exit(1); } - // Create the threads that will work on the complitions - g_pThreads[0] = CreateThread(NULL, 0 ,WorkerThreadFunc ,NULL, 0,NULL ); + + for (int i=0; i s_RemainingSends = (size_t)NumberOfBuffers; + pOverLappedSend->s_SendsInAir = 1; // To force a simulate of the compleation + InitializeCriticalSection(&pOverLappedSend->s_Lock); + pOverLappedSend->s_SendDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + + double Start = GetTimeMs(); + + for(i = 0; i < NumberOfOverlappedSend; i++) { - pOverLappedSend = new OverlappedSend; + buffer = new char [(size_t)BufferSize]; + if (buffer == NULL) { + printf("Error allocating buffer\n"); + exit(1); + } - // Set it's fields - memset(&pOverLappedSend->Overlapped, 0, sizeof (pOverLappedSend->Overlapped)); - pOverLappedSend->Socket = newfd; - pOverLappedSend->Buffer = buffer; - pOverLappedSend->DataSize = (size_t)BufferSize; - pOverLappedSend->RemainingSends = (size_t)NumberOfBuffers; - pOverLappedSend->SendsInAir = 1; // To force a simulate of the compleation - InitializeCriticalSection(&pOverLappedSend->Lock); - pOverLappedSend->SendDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + pOverLappedSend = new OverlappedSend; - double Start = GetTimeMs(); - // Post the message that will do the first send - ret = PostQueuedCompletionStatus( + // Set it's fields + memset(&pOverLappedSend->Overlapped, 0, sizeof (pOverLappedSend->Overlapped)); + pOverLappedSend->Socket = newfd; + pOverLappedSend->Buffer = buffer; + pOverLappedSend->DataSize = (size_t)BufferSize; + + // Post the message that will do the first send + ret = PostQueuedCompletionStatus( g_ComplitionPort, (DWORD)BufferSize, NULL, &pOverLappedSend->Overlapped ); - ASSERT(ret != 0); + ASSERT(ret != 0); + + } // wait for the send - WaitForSingleObject(pOverLappedSend->SendDoneEvent, INFINITE); + WaitForSingleObject(pOverLappedSend->s_SendDoneEvent, INFINITE); elapsed = (GetTimeMs() - Start) / 1000; printf("Finishd sending correctly %f mbytes/sec\n", NumberOfBuffers * BufferSize /elapsed/1024/1024 ); CloseComplitionPort(); //Cleanup: - free(buffer); - - + for(i = 0; i < NumberOfOverlappedSend; i++) { + delete []pOverLappedSend->Buffer; + delete pOverLappedSend; + } } @@ -223,7 +246,7 @@ void SendData(SOCKET newfd, double NumberOfBuffers, double BufferSize, BOOL Send exit(1); } - printf("Starting to send %lf messages of size %lf\n", NumberOfBuffers, BufferSize ); + printf("Starting to send syncroniously %lf messages of size %lf\n", NumberOfBuffers, BufferSize ); i = 0; @@ -279,8 +302,8 @@ void RecvData(SOCKET newfd, double NumberOfBuffers, double BufferSize ) else { acc += read1; -// printf("read returned %d \"%c%c%c%c\"\n",read1, -// buffer[0],buffer[1], buffer[2], buffer[3]); +// printf("read returned %d \"%c%c%c%c\"\n",read1, +// buffer[0],buffer[1], buffer[2], buffer[3]); } } @@ -297,28 +320,28 @@ void RecvData(SOCKET newfd, double NumberOfBuffers, double BufferSize ) void PrintUsage(char *name) { printf("The program might be used in client or server mode\n"); - printf("usage is %s \n", name); + printf("usage is %s \n", name); printf("usage is %s