From 40a7b3983a724713c76d524e59f2adf759c3ea13 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 8 Dec 2017 11:40:07 +0100 Subject: [PATCH] put some locking in stop acquisition and startandreadallnowait (bugs threadpool with more evernts than normal due to main and processing thread with no locks for detector releated stuff, zmqthreadpool not required, r_restreamstop moved to status stop when idle --- .../multiSlsDetector/multiSlsDetector.cpp | 23 +++---------- .../multiSlsDetector/multiSlsDetector.h | 8 ----- .../slsDetector/slsDetector.cpp | 12 ++++++- .../slsDetector/slsDetectorCommand.cpp | 34 +++---------------- .../slsDetector/slsDetectorUtils.h | 10 ------ .../slsDetectorAnalysis/postProcessing.cpp | 8 ++--- .../threadFiles/ThreadPool.cpp | 20 ++++------- slsDetectorSoftware/threadFiles/ThreadPool.h | 2 -- 8 files changed, 28 insertions(+), 89 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index d25729cb4..7a934f26c 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1547,6 +1547,7 @@ int multiSlsDetector::startAcquisition(){ int multiSlsDetector::stopAcquisition(){ + pthread_mutex_lock(&mg); // locks due to processing thread using threadpool when in use int i=0; int ret=OK,ret1=OK; int posmin=0, posmax=thisMultiDetector->numberOfDetectors; @@ -1591,7 +1592,7 @@ int multiSlsDetector::stopAcquisition(){ } *stoppedFlag=1; - + pthread_mutex_unlock(&mg); return ret; }; @@ -1840,7 +1841,7 @@ int* multiSlsDetector::startAndReadAll(){ int multiSlsDetector::startAndReadAllNoWait(){ - + pthread_mutex_lock(&mg); // locks due to processing thread using threadpool when in use int i=0; int ret=OK; int posmin=0, posmax=thisMultiDetector->numberOfDetectors; @@ -1885,7 +1886,7 @@ int multiSlsDetector::startAndReadAllNoWait(){ ret=FAIL; } } - + pthread_mutex_unlock(&mg); return ret; } @@ -6594,19 +6595,3 @@ bool multiSlsDetector::isAcquireReady() { return OK; } - - -int multiSlsDetector::restreamStopFromReceiver() { - int ret=OK, ret1; - for(int idet=0; idetnumberOfDetectors; ++idet){ - if (detectors[idet]) { - ret1=detectors[idet]->restreamStopFromReceiver(); - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<stoppedFlag=1; + + if ((thisDetector->receiver_upstream) && (s == IDLE) && (r == IDLE)) { + restreamStopFromReceiver(); + } + return ret; @@ -9232,8 +9240,10 @@ int slsDetector::restreamStopFromReceiver(){ } if(ret==FORCE_UPDATE) ret=updateReceiver(); - else if (ret == FAIL) + else if (ret == FAIL) { setErrorMask((getErrorMask())|(RESTREAM_STOP_FROM_RECEIVER)); + std::cout << " Could not restream stop dummy packet from receiver" << endl; + } } return ret; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index b949e465d..6e3a63ada 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -191,7 +191,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { ++i; /*! \page acquisition - - status [s] starts or stops acquisition in detector in non blocking mode. \c s: [\c start, \c stop]. \c Returns the detector status: [\c running, \c error, \c transmitting, \c finished, \c waiting, \c idle]. \c Returns \c (string) + - status [s] starts or stops acquisition in detector in non blocking mode. When using stop acquisition and if acquisition is done, it will restream the stop packet from receiver (if data streaming in receiver is on). \c s: [\c start, \c stop]. \c Returns the detector status: [\c running, \c error, \c transmitting, \c finished, \c waiting, \c idle]. \c Returns \c (string) */ descrToFuncMap[i].m_pFuncName="status"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; @@ -2047,15 +2047,6 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; ++i; - /*! \page receiver - - r_restreamstop [i] If data streaming in receiver is enabled, restreams the stop dummy packet via zmq. i can be any value. Only put! \cReturns 1 for success 0 for fail \c (int) - */ - descrToFuncMap[i].m_pFuncName="r_restreamstop"; // - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; - ++i; - - - /* pattern generator */ /*! \page ctb Chiptest board @@ -2434,8 +2425,10 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) { //myDet->setThreadedProcessing(0); if (string(args[1])=="start") myDet->startAcquisition(); - else if (string(args[1])=="stop") + else if (string(args[1])=="stop") { + myDet->setReceiverOnline(ONLINE_FLAG); myDet->stopAcquisition(); + } else return string("unknown action"); } @@ -2467,7 +2460,7 @@ string slsDetectorCommand::helpStatus(int narg, char *args[], int action) { os << string("busy \t gets the status of acquire- can be: 0 or 1. 0 for idle, 1 for running\n"); } if (action==PUT_ACTION || action==HELP_ACTION) { - os << string("status \t controls the detector acquisition - can be start or stop \n"); + os << string("status \t controls the detector acquisition - can be start or stop. When using stop acquisition and if acquisition is done, it will restream the stop packet from receiver (if data streaming in receiver is on). \n"); os << string("busy i\t sets the status of acquire- can be: 0(idle) or 1(running).Command Acquire sets it to 1 at beignning of acquire and back to 0 at the end. Clear Flag for unexpected acquire terminations. \n"); } return os.str(); @@ -6016,21 +6009,6 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { } - - else if(cmd=="r_restreamstop"){ - if (action==GET_ACTION) - return string("cannot get"); - else { - if ((myDet->getRunStatus() != IDLE) || (myDet->getReceiverStatus() != IDLE)) { - std::cout << "Could not restream stop from receiver. Acquisition still in progress" << std::endl; - sprintf(answer,"%d",0); - } - sprintf(answer,"%d",(myDet->restreamStopFromReceiver() == OK) ? 1 : 0); - } - return string(answer); - } - - return string("could not decode command"); } @@ -6047,7 +6025,6 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) { os << "tengiga \t sets system to be configure for 10Gbe if set to 1, else 1Gbe if set to 0" << std::endl; os << "rx_fifodepth [val]\t sets receiver fifo depth to val" << std::endl; os << "r_silent [i]\t sets receiver in silent mode, ie. it will not print anything during real time acquisition. 1 sets, 0 unsets." << std::endl; - os << "r_restreamstop [i]\t If data streaming in receiver is enabled and receiver is idle, restreams the stop dummy packet via zmq. i can be any value." << std::endl; } if (action==GET_ACTION || action==HELP_ACTION){ os << "receiver \t returns the status of receiver - can be running or idle" << std::endl; @@ -6057,7 +6034,6 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) { os << "tengiga \t returns 1 if the system is configured for 10Gbe else 0 for 1Gbe" << std::endl; os << "rx_fifodepth \t returns receiver fifo depth" << std::endl; os << "r_silent \t returns receiver silent mode enable. 1 is silent, 0 not silent." << std::endl; - os << "r_restreamstop \t returns if restreaming the stop dummy packet from receiver via zmq was success(1) or fail(0)" << std:: endl; } return os.str(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 5774e6b0b..c5705c72d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -930,16 +930,6 @@ virtual int setReceiverSilentMode(int i = -1)=0; */ virtual bool isAcquireReady() = 0; - /** - If data streaming in receiver is enabled, - restream the stop dummy packet from receiver - Used usually for Moench, - in case it is lost in network due to high data rate - \returns OK if success else FAIL - */ - virtual int restreamStopFromReceiver() = 0; - - protected: diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 1cc761757..f25eef9bc 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -418,9 +418,7 @@ int postProcessing::fillBadChannelMask() { void* postProcessing::processData(int delflag) { - pthread_mutex_lock(&mg); if(setReceiverOnline()==OFFLINE_FLAG){ - pthread_mutex_unlock(&mg); #ifdef VERBOSE std::cout<< " ??????????????????????????????????????????? processing data - threaded mode " << *threadedProcessing << endl; @@ -505,8 +503,6 @@ void* postProcessing::processData(int delflag) { } } //receiver else{ - - pthread_mutex_unlock(&mg); //cprintf(RED,"In post processing threads\n"); if(dataReady) { @@ -535,11 +531,11 @@ void* postProcessing::processData(int delflag) { //get progress - pthread_mutex_lock(&mg); if(setReceiverOnline() == ONLINE_FLAG){ + pthread_mutex_lock(&mg); caught = getFramesCaughtByAnyReceiver(); + pthread_mutex_unlock(&mg); } - pthread_mutex_unlock(&mg); //updating progress diff --git a/slsDetectorSoftware/threadFiles/ThreadPool.cpp b/slsDetectorSoftware/threadFiles/ThreadPool.cpp index cb2a00faf..9a1dfddce 100644 --- a/slsDetectorSoftware/threadFiles/ThreadPool.cpp +++ b/slsDetectorSoftware/threadFiles/ThreadPool.cpp @@ -7,7 +7,6 @@ ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size){ #endif m_tasks_loaded = false; thread_started = false; - zmqthreadpool = false; current_thread_number = -1; number_of_ongoing_tasks = 0; number_of_total_tasks = 0; @@ -117,7 +116,6 @@ void* ThreadPool::execute_thread(){ /*cout << "Unlocking: " << pthread_self() << endl;*/ m_task_mutex.unlock(); - //if(zmqthreadpool) cout<<"***"<