From b5fb6be6df2f818c402f11789b5a6763d6889df1 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Fri, 12 Jul 2013 09:24:55 +0000 Subject: [PATCH] updated rxr to use 10 times less memory for moench and plugged possible memory leaks git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@634 951219d9-93cf-4727-9268-0efd64621fa3 --- .../eigerDetectorServer/svnInfoEiger.h | 4 +-- .../gotthardDetectorServer/svnInfoGotthard.h | 6 ++-- .../moenchDetectorServer/svnInfoMoench.h | 6 ++-- .../mythenDetectorServer/svnInfoMythen.h | 6 ++-- slsDetectorSoftware/slsDetector/svnInfoLib.h | 4 +-- .../slsReceiver/circularFifo.h | 34 ++++++++++-------- .../slsReceiver/receiver_defs.h | 6 ++-- .../slsReceiver/slsReceiverFunctionList.cpp | 35 +++++++++++-------- .../slsReceiver/slsReceiverFunctionList.h | 8 +++-- .../slsReceiver/svnInfoReceiver.h | 6 ++-- 10 files changed, 64 insertions(+), 51 deletions(-) diff --git a/slsDetectorSoftware/eigerDetectorServer/svnInfoEiger.h b/slsDetectorSoftware/eigerDetectorServer/svnInfoEiger.h index e57ef2baa..da8362a55 100644 --- a/slsDetectorSoftware/eigerDetectorServer/svnInfoEiger.h +++ b/slsDetectorSoftware/eigerDetectorServer/svnInfoEiger.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/eigerDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x631 +//#define SVNREV 0x632 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x631 +#define SVNREV 0x632 #define SVNDATE 0x20130711 // diff --git a/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h b/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h index da9a98835..7cfbd3aee 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h +++ b/slsDetectorSoftware/gotthardDetectorServer/svnInfoGotthard.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x628 +//#define SVNREV 0x632 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x628 -#define SVNDATE 0x20130625 +#define SVNREV 0x632 +#define SVNDATE 0x20130711 // diff --git a/slsDetectorSoftware/moenchDetectorServer/svnInfoMoench.h b/slsDetectorSoftware/moenchDetectorServer/svnInfoMoench.h index 97548e659..10857eb3c 100644 --- a/slsDetectorSoftware/moenchDetectorServer/svnInfoMoench.h +++ b/slsDetectorSoftware/moenchDetectorServer/svnInfoMoench.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x629 +//#define SVNREV 0x632 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x629 -#define SVNDATE 0x20130710 +#define SVNREV 0x632 +#define SVNDATE 0x20130711 // diff --git a/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h b/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h index d01fe9c7c..cc545c313 100644 --- a/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h +++ b/slsDetectorSoftware/mythenDetectorServer/svnInfoMythen.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x628 +//#define SVNREV 0x632 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x628 -#define SVNDATE 0x20130625 +#define SVNREV 0x632 +#define SVNDATE 0x20130711 // diff --git a/slsDetectorSoftware/slsDetector/svnInfoLib.h b/slsDetectorSoftware/slsDetector/svnInfoLib.h index 738d5d9c4..885d6e784 100644 --- a/slsDetectorSoftware/slsDetector/svnInfoLib.h +++ b/slsDetectorSoftware/slsDetector/svnInfoLib.h @@ -2,10 +2,10 @@ #define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware" //#define SVNREPPATH "" #define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x631 +//#define SVNREV 0x633 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTHLIB "l_maliakal_d" -#define SVNREVLIB 0x631 +#define SVNREVLIB 0x633 #define SVNDATELIB 0x20130711 // diff --git a/slsDetectorSoftware/slsReceiver/circularFifo.h b/slsDetectorSoftware/slsReceiver/circularFifo.h index 9f834dc02..154c89117 100644 --- a/slsDetectorSoftware/slsReceiver/circularFifo.h +++ b/slsDetectorSoftware/slsReceiver/circularFifo.h @@ -17,14 +17,19 @@ #include "sls_detector_defs.h" +#include +using namespace std; + /** Circular Fifo (a.k.a. Circular Buffer) * Thread safe for one reader, and one writer */ -template +template class CircularFifo { public: - enum {Capacity = Size+1}; - CircularFifo() : tail(0), head(0){} + CircularFifo(unsigned int Size) : tail(0), head(0){ + Capacity = Size + 1; + array.resize(Capacity); + } virtual ~CircularFifo() {} bool push(Element*& item_); @@ -35,8 +40,9 @@ public: private: volatile unsigned int tail; // input index - Element* array[Capacity]; + vector array; volatile unsigned int head; // output index + unsigned int Capacity; unsigned int increment(unsigned int idx_) const; }; @@ -50,8 +56,8 @@ private: * * \param item_ copy by reference the input item * \return whether operation was successful or not */ -template -bool CircularFifo::push(Element*& item_) +template +bool CircularFifo::push(Element*& item_) { int nextTail = increment(tail); if(nextTail != head) @@ -71,8 +77,8 @@ bool CircularFifo::push(Element*& item_) * * \param item_ return by reference the wanted item * \return whether operation was successful or not */ -template -bool CircularFifo::pop(Element*& item_) +template +bool CircularFifo::pop(Element*& item_) { if(head == tail) return false; // empty queue @@ -87,8 +93,8 @@ bool CircularFifo::pop(Element*& item_) * as the Procuder adds more items. * * \return true if circular buffer is empty */ -template -bool CircularFifo::isEmpty() const +template +bool CircularFifo::isEmpty() const { return (head == tail); } @@ -98,8 +104,8 @@ bool CircularFifo::isEmpty() const * as the Consumer catches up. * * \return true if circular buffer is full. */ -template -bool CircularFifo::isFull() const +template +bool CircularFifo::isFull() const { int tailCheck = (tail+1) % Capacity; return (tailCheck == head); @@ -110,8 +116,8 @@ bool CircularFifo::isFull() const * * \param idx_ the index to the incremented/wrapped * \return new value for the index */ -template -unsigned int CircularFifo::increment(unsigned int idx_) const +template +unsigned int CircularFifo::increment(unsigned int idx_) const { // increment or wrap // ================= diff --git a/slsDetectorSoftware/slsReceiver/receiver_defs.h b/slsDetectorSoftware/slsReceiver/receiver_defs.h index 6472966cd..30587eb86 100755 --- a/slsDetectorSoftware/slsReceiver/receiver_defs.h +++ b/slsDetectorSoftware/slsReceiver/receiver_defs.h @@ -14,9 +14,7 @@ //all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench -#define FIFO_SIZE 25000 - - +#define GOTTHARD_FIFO_SIZE 25000 #define GOTTHARD_ALIGNED_FRAME_SIZE 4096 #define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_BUFFER_SIZE (1286*GOTTHARD_PACKETS_PER_FRAME) @@ -32,7 +30,7 @@ - +#define MOENCH_FIFO_SIZE 2500 #define MOENCH_ALIGNED_FRAME_SIZE 65536 #define MOENCH_PACKETS_PER_FRAME 40 #define MOENCH_BUFFER_SIZE (1286*MOENCH_PACKETS_PER_FRAME) diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 4d71d5cef..c0a170ffe 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -44,6 +44,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit udpSocket(NULL), server_port(DEFAULT_UDP_PORTNO), fifo(NULL), + fifofree(NULL), + fifosize(GOTTHARD_FIFO_SIZE), shortFrame(-1), bufferSize(GOTTHARD_BUFFER_SIZE), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), @@ -63,7 +65,11 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET) { + int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE; + if(myDetectorType == MOENCH){ + aligned_frame_size = MOENCH_ALIGNED_FRAME_SIZE; + fifosize = MOENCH_FIFO_SIZE; maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE; bufferSize = MOENCH_BUFFER_SIZE; packetsPerFrame = MOENCH_PACKETS_PER_FRAME; @@ -71,7 +77,6 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit frameIndexMask = MOENCH_FRAME_INDEX_MASK; frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; } - } strcpy(savefilename,""); @@ -83,20 +88,17 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit strcpy(eth,""); latestData = new char[bufferSize]; - fifofree = new CircularFifo(); - fifo = new CircularFifo(); - - int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE; - if (det == MOENCH) - aligned_frame_size = MOENCH_ALIGNED_FRAME_SIZE; + fifofree = new CircularFifo(fifosize); + fifo = new CircularFifo(fifosize); - mem0=(char*)malloc(aligned_frame_size*FIFO_SIZE); + + mem0=(char*)malloc(aligned_frame_size*fifosize); if (mem0==NULL) { cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; } buffer=mem0; - while (buffer<(mem0+aligned_frame_size*(FIFO_SIZE-1))) { + while (buffer<(mem0+aligned_frame_size*(fifosize-1))) { fifofree->push(buffer); buffer+=aligned_frame_size; } @@ -284,7 +286,7 @@ int slsReceiverFunctionList::stopReceiver(){ #endif //stop listening thread listening_thread_running=0; - udpSocket->ShutDownSocket(); + if(udpSocket) udpSocket->ShutDownSocket(); pthread_join(listening_thread,NULL); status = IDLE; @@ -357,6 +359,7 @@ int slsReceiverFunctionList::startListening(){ if (!fifofree->isEmpty()) { fifofree->pop(buffer); + //receiver 2 half frames / 1 short frame / 40 moench frames rc = udpSocket->ReceiveDataOnly(buffer,bufferSize); if( rc < 0) @@ -440,7 +443,7 @@ int slsReceiverFunctionList::startWriting(){ framesInFile=0; framesCaught=0; frameIndex=0; - if(sfilefd) sfilefd=0; + if(sfilefd) sfilefd=NULL; strcpy(savefilename,""); //reset this before each acq or you send old data @@ -478,8 +481,10 @@ int slsReceiverFunctionList::startWriting(){ if(enableFileWrite && cbAction > DO_NOTHING){ - if(sfilefd) + if(sfilefd){ fclose(sfilefd); + sfilefd = NULL; + } if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ cout << "Error: Could not create file " << savefilename << endl; @@ -594,11 +599,13 @@ int slsReceiverFunctionList::startWriting(){ cout << "Total Frames Caught:"<< totalFramesCaught << endl; - if(sfilefd) - fclose(sfilefd); + if(sfilefd){ #ifdef VERBOSE cout << "sfield:" << (int)sfilefd << endl; #endif + fclose(sfilefd); + sfilefd = NULL; + } //acquistion over call back if (acquisitionFinishedCallBack) diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index 97b716737..f5c6f6591 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -291,11 +291,13 @@ private: }; /** circular fifo to read and write data*/ - //CircularFifo* fifo; - CircularFifo* fifo; + CircularFifo* fifo; /** circular fifo to read and write data*/ - CircularFifo* fifofree; + CircularFifo* fifofree; + + /** fifo size */ + unsigned int fifosize; /** short frames */ int shortFrame; diff --git a/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h b/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h index 4b8caa8cf..0b2073669 100644 --- a/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h +++ b/slsDetectorSoftware/slsReceiver/svnInfoReceiver.h @@ -2,10 +2,10 @@ #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver" //#define SVNREPPATH "" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" -//#define SVNREV 0x629 +//#define SVNREV 0x632 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "l_maliakal_d" -#define SVNREV 0x629 -#define SVNDATE 0x20130710 +#define SVNREV 0x632 +#define SVNDATE 0x20130711 //