From a0208778c11bd3d439c6299fd004dbf9e8a19a8c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 15:21:19 +0100 Subject: [PATCH 1/9] bugfix: high fifo depth more than 32 bit --- slsReceiverSoftware/src/Fifo.cpp | 4 ++-- slsReceiverSoftware/src/Implementation.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index 0271f8685..bb37de5f5 100755 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -45,13 +45,13 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { fifoFree = new CircularFifo(fifoDepth); fifoStream = new CircularFifo(fifoDepth); //allocate memory - size_t mem_len = fifoItemSize * fifoDepth * sizeof(char); + size_t mem_len = (size_t)fifoItemSize * (size_t)fifoDepth * sizeof(char); memory = (char*) malloc (mem_len); if (memory == nullptr){ throw sls::RuntimeError("Could not allocate memory for fifos"); } memset(memory, 0, mem_len); - FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << mem_len << " bytes"; + FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << (double)mem_len/(1000.00 * 1000.00) << " Mb"; { //push free addresses into fifoFree fifo char* buffer = memory; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 0025d1e80..cfb79773f 100755 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -193,10 +193,10 @@ void Implementation::SetupFifoStructure() { } FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " - << (((generalData->imageSize) + + << (double)(((generalData->imageSize) + (generalData->fifoBufferHeaderSize)) * - fifoDepth) - << " bytes"; + fifoDepth) / (1000.00 * 1000.00) + << " Mb"; FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed"; } From e527aad6ab32a3b7c1f154f8021522b28399766b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 15:25:41 +0100 Subject: [PATCH 2/9] bugfix: high fifo depth more than 32 bit --- slsReceiverSoftware/src/Implementation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index cfb79773f..d6e645be4 100755 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -193,9 +193,9 @@ void Implementation::SetupFifoStructure() { } FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " - << (double)(((generalData->imageSize) + - (generalData->fifoBufferHeaderSize)) * - fifoDepth) / (1000.00 * 1000.00) + << (double)(((size_t)(generalData->imageSize) + + (size_t)(generalData->fifoBufferHeaderSize)) * + (size_t)fifoDepth) / (1000.00 * 1000.00) << " Mb"; FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed"; } From 53e5a097abcb22b4c8e3c03934c11ba52b189575 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 18:03:03 +0100 Subject: [PATCH 3/9] rxr: semaphore instead of keeprunning variable at startup --- slsReceiverSoftware/src/main.cpp | 12 +++++++----- slsReceiverSoftware/src/multiReceiver.cpp | 16 ++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 6cb7b147e..ef99ab8a7 100755 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -14,11 +14,12 @@ #include #include //usleep #include +#include -bool keeprunning; +sem_t semaphore; void sigInterruptHandler(int p){ - keeprunning = false; + sem_post(&semaphore); } /** Define Colors to print data call back in different colors for different recievers */ @@ -65,7 +66,8 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){ int main(int argc, char *argv[]) { - keeprunning = true; + sem_init(&semaphore,1,0); + FILE_LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]"; // Catch signal SIGINT to close files and call destructors properly @@ -136,8 +138,8 @@ int main(int argc, char *argv[]) { //receiver->registerCallBackRawDataReady(rawDataReadyCallBack,NULL); FILE_LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]"; - while(keeprunning) - pause(); + sem_wait(&semaphore); + sem_destroy(&semaphore); FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; FILE_LOG(logINFO) << "Exiting Receiver"; return 0; diff --git a/slsReceiverSoftware/src/multiReceiver.cpp b/slsReceiverSoftware/src/multiReceiver.cpp index ce9053113..87fd37b6e 100755 --- a/slsReceiverSoftware/src/multiReceiver.cpp +++ b/slsReceiverSoftware/src/multiReceiver.cpp @@ -29,6 +29,7 @@ It is linked in manual/manual-api from slsReceiverSoftware/include ] #include //wait #include //tid #include //usleep +#include using namespace std; @@ -36,15 +37,14 @@ using namespace std; #define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__) -/** Variable is true to continue running, set to false upon interrupt */ -bool keeprunning; +sem_t semaphore; /** * Control+C Interrupt Handler - * Sets the variable keeprunning to false, to let all the processes know to exit properly + * to let all the processes know to exit properly */ void sigInterruptHandler(int p){ - keeprunning = false; + sem_post(&semaphore); } /** @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { int numReceivers = 1; int startTCPPort = 1954; int withCallback = 0; - keeprunning = true; + sem_init(&semaphore,1,0); /** - get number of receivers and start tcp port from command line arguments */ if ( (argc != 4) || (!sscanf(argv[1],"%d", &startTCPPort)) || (!sscanf(argv[2],"%d", &numReceivers)) || (!sscanf(argv[3],"%d", &withCallback)) ) @@ -238,9 +238,9 @@ int main(int argc, char *argv[]) { else if (withCallback == 2) receiver->registerCallBackRawDataModifyReady(GetData,nullptr); } - /** - as long as keeprunning is true (changes with Ctrl+C) */ - while(keeprunning) - pause(); + /** - as long as no Ctrl+C */ + sem_wait(&semaphore); + sem_destroy(&semaphore); cprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid)); exit(EXIT_SUCCESS); break; From ab6f448e1f1f14e4a6ee2bd90922c290a1c7a28a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 18:34:10 +0100 Subject: [PATCH 4/9] performance optimization in fifodepth, ensure memory is allocated by writing something in the beginning --- slsReceiverSoftware/src/Fifo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index bb37de5f5..98799168b 100755 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -56,7 +56,7 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { { //push free addresses into fifoFree fifo char* buffer = memory; for (int i = 0; i < fifoDepth; ++i) { - //sprintf(buffer,"memory"); + strcpy(buffer, "memory"); //ensures the memory is allocated FreeAddress(buffer); buffer += fifoItemSize; } From 9f22c8008176b734b55602f15b62fe7e907f7b81 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 19:59:18 +0100 Subject: [PATCH 5/9] Revert "performance optimization in fifodepth, ensure memory is allocated by writing something in the beginning" This reverts commit ab6f448e1f1f14e4a6ee2bd90922c290a1c7a28a. --- slsReceiverSoftware/src/Fifo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index 98799168b..bb37de5f5 100755 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -56,7 +56,7 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { { //push free addresses into fifoFree fifo char* buffer = memory; for (int i = 0; i < fifoDepth; ++i) { - strcpy(buffer, "memory"); //ensures the memory is allocated + //sprintf(buffer,"memory"); FreeAddress(buffer); buffer += fifoItemSize; } From d9b88ea7d25f91ca43020e327a9e4bd2eb0d6b06 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jan 2020 20:10:49 +0100 Subject: [PATCH 6/9] performance optimization in fifodepth, ensure memory is allocated by writing something in the beginning --- slsReceiverSoftware/src/Fifo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index bb37de5f5..0ad833966 100755 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -51,6 +51,10 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { throw sls::RuntimeError("Could not allocate memory for fifos"); } memset(memory, 0, mem_len); + int pagesize = getpagesize(); + for (size_t i = 0; i < mem_len; i += pagesize) { + strcpy(memory + i, "memory"); + } FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << (double)mem_len/(1000.00 * 1000.00) << " Mb"; { //push free addresses into fifoFree fifo From c42b4b8c0e74217f7534c690f19ebaa269e5811c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 28 Jan 2020 10:43:06 +0100 Subject: [PATCH 7/9] incorrect printout to MB --- slsReceiverSoftware/src/Fifo.cpp | 2 +- slsReceiverSoftware/src/Implementation.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index 0ad833966..b100fdaec 100755 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -55,7 +55,7 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) { for (size_t i = 0; i < mem_len; i += pagesize) { strcpy(memory + i, "memory"); } - FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << (double)mem_len/(1000.00 * 1000.00) << " Mb"; + FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << (double)mem_len/(double)(1024 * 1024) << " MB"; { //push free addresses into fifoFree fifo char* buffer = memory; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index d6e645be4..c3136aeb9 100755 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -195,8 +195,8 @@ void Implementation::SetupFifoStructure() { FILE_LOG(logINFO) << "Memory Allocated Per Fifo: " << (double)(((size_t)(generalData->imageSize) + (size_t)(generalData->fifoBufferHeaderSize)) * - (size_t)fifoDepth) / (1000.00 * 1000.00) - << " Mb"; + (size_t)fifoDepth) / (double)(1024 * 1024) + << " MB"; FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed"; } From af2f2708ad08c0b2f6c441d36e39dad7962b71e5 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 28 Jan 2020 13:55:44 +0100 Subject: [PATCH 8/9] rxr: remove file buffering --- slsReceiverSoftware/include/BinaryFileStatic.h | 7 +++---- slsReceiverSoftware/src/BinaryFile.cpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/include/BinaryFileStatic.h b/slsReceiverSoftware/include/BinaryFileStatic.h index 032aeed30..b1e60fd00 100755 --- a/slsReceiverSoftware/include/BinaryFileStatic.h +++ b/slsReceiverSoftware/include/BinaryFileStatic.h @@ -196,10 +196,9 @@ class BinaryFileStatic { * @param fd file pointer * @param owenable overwrite enable * @param fname complete file name - * @param filebuffersize file buffer size * @returns 0 for success and 1 for fail */ - static void CreateDataFile(FILE*& fd, bool owenable, std::string fname, size_t filebuffersize) + static void CreateDataFile(FILE*& fd, bool owenable, std::string fname) { if(!owenable){ if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ @@ -210,8 +209,8 @@ class BinaryFileStatic { fd = 0; throw sls::RuntimeError("Could not create file " + fname); } - //setting file buffer size to 16mb - setvbuf(fd,NULL,_IOFBF,filebuffersize); + //setting to no file buffering + setvbuf(fd, NULL, _IONBF, 0); } }; diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index bad78e8f2..a5119dec1 100755 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -49,7 +49,7 @@ void BinaryFile::CreateFile() { currentFileName = BinaryFileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex, subFileIndex, *detIndex, *numUnitsPerDetector, index); - BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE); + BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName); if(!(*silentMode)) { FILE_LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName; From 70ffdf9709d415916642302d80f7cdc5e3885d02 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 28 Jan 2020 15:00:05 +0100 Subject: [PATCH 9/9] fixes for IpAddr and MacAddr in Gui --- slsDetectorGui/src/qTabAdvanced.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index 61991fe45..31a683cfe 100755 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -361,7 +361,7 @@ void qTabAdvanced::SetDetectorUDPIP() { std::string s = dispDetectorUDPIP->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Detector UDP IP:" << s; try { - det->setSourceUDPIP(s, {comboDetector->currentIndex()}); + det->setSourceUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Detector UDP IP.", "qTabAdvanced::SetDetectorUDPIP", this, &qTabAdvanced::GetDetectorUDPIP) @@ -371,7 +371,7 @@ void qTabAdvanced::SetDetectorUDPMAC() { std::string s = dispDetectorUDPMAC->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Detector UDP MAC:" << s; try { - det->setSourceUDPMAC(s, {comboDetector->currentIndex()}); + det->setSourceUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Detector UDP MAC.", "qTabAdvanced::SetDetectorUDPMAC", this, &qTabAdvanced::GetDetectorUDPMAC) @@ -390,7 +390,7 @@ void qTabAdvanced::SetCltZMQIP() { std::string s = dispZMQIP->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Client ZMQ IP:" << s; try { - det->setClientZmqIp(s, {comboDetector->currentIndex()}); + det->setClientZmqIp(sls::IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Client ZMQ IP.", "qTabAdvanced::SetCltZMQIP", this, &qTabAdvanced::GetCltZMQIP) @@ -431,7 +431,7 @@ void qTabAdvanced::SetRxrUDPIP() { std::string s = dispRxrUDPIP->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Receiver UDP IP:" << s; try { - det->setDestinationUDPIP(s, {comboDetector->currentIndex()}); + det->setDestinationUDPIP(sls::IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Receiver UDP IP.", "qTabAdvanced::SetRxrUDPIP", this, &qTabAdvanced::GetRxrUDPIP) @@ -441,7 +441,7 @@ void qTabAdvanced::SetRxrUDPMAC() { std::string s = dispRxrUDPMAC->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Receiver UDP MAC:" << s; try { - det->setDestinationUDPMAC(s, {comboDetector->currentIndex()}); + det->setDestinationUDPMAC(sls::MacAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Receiver UDP MAC.", "qTabAdvanced::SetRxrUDPMAC", this, &qTabAdvanced::GetRxrUDPMAC) @@ -460,7 +460,7 @@ void qTabAdvanced::SetRxrZMQIP() { std::string s = dispRxrZMQIP->text().toAscii().constData(); FILE_LOG(logINFO) << "Setting Receiver ZMQ IP:" << s; try { - det->setRxZmqIP(s, {comboDetector->currentIndex()}); + det->setRxZmqIP(sls::IpAddr{s}, {comboDetector->currentIndex()}); } CATCH_HANDLE ("Could not set Receiver ZMQ IP.", "qTabAdvanced::SetRxrZMQIP", this, &qTabAdvanced::GetRxrZMQIP)