Commit 5dbff3e1 authored by dauncey's avatar dauncey

Add throttling class and interrupts

parent eb93db5d
......@@ -57,6 +57,9 @@ public:
fActiveInputBuffer=0;
fWriteElink=0;
//fBufferLimit=1048;
fBufferLimit=1000000000;
fArrayWrite=0;
for(unsigned i(0);i<4;i++) fArrayWord[i]=0;
......@@ -474,6 +477,23 @@ public:
#endif
}
bool throttle() const {
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) {
const EconArch &econArch(fSlinkArch->econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
if(fEventBuffer[e][b].used()>=fBufferLimit) {
if(fPrintLevel>5) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::throttle() "
<< "Applying throttle"
<< std::endl;
}
return true;
}
}
}
return false;
}
unsigned numberOfSlinkWords() const {
return fNumberOfSlinkWords;
}
......@@ -547,6 +567,7 @@ private:
std::vector<unsigned> fHgcrocNumber[7];
std::vector<unsigned> fElinkNumber[7];
unsigned fBufferLimit;
unsigned fActiveInputBuffer;
//std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18];
......
#ifndef Throttle_HH
#define Throttle_HH
class Throttle {
public:
Throttle(uint64_t b) : fDelay(60), fRaisedBx(b), fEndedBx(-1) {
}
void endThrottle(uint64_t bx) {
if(fEndedBx==-1) fEndedBx=bx;
}
bool allowL1Accept(uint64_t bx) {
return bx<(fRaisedBx+fDelay) || bx>=(fEndedBx+fDelay);
}
private:
const uint64_t fDelay;
uint64_t fRaisedBx;
uint64_t fEndedBx;
};
#endif
#ifndef interrupts_CC
#define interrupts_CC
#include <signal.h>
#include <unistd.h>
#include <string>
bool continueJob=true;
std::vector<std::string> sSignal;
void signalHandler(int signal) {
std::string theSignal("Unknown");
if(signal<(int)sSignal.size()) theSignal=sSignal[signal];
std::cout << "Process " << getpid() << " received signal "
<< signal << " = " << theSignal << std::endl;
std::cerr << "Process " << getpid() << " received signal "
<< signal << " = " << theSignal << std::endl;
continueJob=false;
}
void defineSignals() {
if(sSignal.size()==0) {
sSignal.push_back("Unknown");
sSignal.push_back("SIGHUP");
sSignal.push_back("SIGINT");
sSignal.push_back("SIGQUIT");
sSignal.push_back("SIGILL");
sSignal.push_back("SIGTRAP");
sSignal.push_back("SIGABRT");
sSignal.push_back("SIGBUS");
sSignal.push_back("SIGFPE");
sSignal.push_back("SIGKILL");
sSignal.push_back("SIGUSR1");
sSignal.push_back("SIGSEGV");
sSignal.push_back("SIGUSR2");
sSignal.push_back("SIGPIPE");
sSignal.push_back("SIGALRM");
sSignal.push_back("SIGTERM");
sSignal.push_back("SIGSTKFLT");
sSignal.push_back("SIGCHLD");
sSignal.push_back("SIGCONT");
sSignal.push_back("SIGSTOP");
sSignal.push_back("SIGTSTP");
sSignal.push_back("SIGTTIN");
sSignal.push_back("SIGTTOU");
sSignal.push_back("SIGURG");
sSignal.push_back("SIGXCPU");
sSignal.push_back("SIGXFSZ");
sSignal.push_back("SIGVTALRM");
sSignal.push_back("SIGPROF");
sSignal.push_back("SIGWINCH");
sSignal.push_back("SIGPOLL");
sSignal.push_back("SIGPWR");
sSignal.push_back("SIGSYS");
sSignal.push_back("SIGRTMIN");
}
}
bool catchSignal(std::string sig) {
defineSignals();
for(unsigned s(0);s<sSignal.size();s++) {
if(sSignal[s]==sig) {
std::cout << "Setting catch for signal = " << s << " = " << sig << std::endl;
signal(s,signalHandler);
return true;
}
}
return false;
}
void catchSignals() {
/*
std::vector<std::string> vSig;
vSig.push_back("SIGINT");
vSig.push_back("SIGUSR1");
vSig.push_back("SIGUSR2");
vSig.push_back("SIGTERM");
vSig.push_back("SIGXCPU");
*/
defineSignals();
//BACKTRACE_AND_ASSERT(catchSignal("SIGINT"));
// Catch signals, mainly for batch
for(unsigned s(0);s<sSignal.size();s++) {
if(sSignal[s]=="SIGINT" ||
sSignal[s]=="SIGUSR1" ||
sSignal[s]=="SIGUSR2" ||
sSignal[s]=="SIGTERM" ||
sSignal[s]=="SIGXCPU") {
std::cout << "Setting catch for signal = " << s
<< " = " << sSignal[s] << std::endl;
signal(s,signalHandler);
}
}
}
#endif
......@@ -39,7 +39,9 @@ public:
#include "Buffering/SlinkEoe.hh"
#define DEBUG_PRINT if(false) std::cout << "Line " << __LINE__ << ": "
#include "Buffering/SlinkCheck.hh"
#include "Buffering/Throttle.hh"
#include "Buffering/interrupts.cc"
#ifndef TriggerRule_PrintLevel
#define TriggerRule_PrintLevel 10
......@@ -204,8 +206,8 @@ int main(int argc, char* argv[]) {
unsigned l1AcceptRate(750);
unsigned l1AcceptRandom(1);
bool doingEcon(false);
bool doingBe(false);
bool doingEcon(true);
bool doingBe(true);
// HGCROC
unsigned hgcrocLimit(7);
......@@ -221,11 +223,30 @@ int main(int argc, char* argv[]) {
// BE
if((argc%2)!=1) {
std::cerr << "Usage: " << argv[0] << " --<parameter> <value>" << std::endl;
if(argc>2 && (argc%2)!=1) {
std::cerr << "Usage: " << argv[0] << " --<parameter> <value> or <parameter number>" << std::endl;
return 1;
}
if(argc==2) {
unsigned nArg(0);
std::istringstream sArg(argv[1]);
sArg >> nArg;
// nArg--;
seconds=pow(10,(nArg%10));
nArg/=10;
l1AcceptRate=550+50*(nArg%10);
nArg/=10;
l1AcceptRandom=(nArg%10);
nArg/=10;
hgcrocLimit=(nArg%10);
nArg/=10;
hgcrocTransmission=40+2*(nArg%10);
} else {
for(int i(1);i<argc;i+=2) {
std::string sarg1(argv[i]);
std::istringstream sarg2(argv[i+1]);
......@@ -246,6 +267,7 @@ int main(int argc, char* argv[]) {
if(sarg1=="--econFormat") sarg2 >> econFormat;
//if(sarg1=="--econFlow") sarg2 >> econFlow;
}
}
std::ostringstream sout;
sout << "_L1AcceptRate" << l1AcceptRate;
......@@ -486,10 +508,15 @@ int main(int argc, char* argv[]) {
uint64_t numberL1AOut(0);
uint64_t nHgcrocDeadtime(0);
uint64_t nThrottleDeadtime(0);
//TriggerRule tr(50);
for(uint64_t bx(0);bx<maxBx;bx++) {
std::vector<Throttle> vThrottle;
catchSignals();
uint64_t bx;
for(bx=0;bx<maxBx && continueJob;bx++) {
if(((100*bx)%maxBx)==0) std::cout << "BX " << bx << " = " << 100*bx/maxBx << " %" << std::endl;
//if(bx>100000) {
......@@ -506,9 +533,17 @@ int main(int argc, char* argv[]) {
bool newL1AIn(false);
bool newL1AOut(false);
bool allowL1a(true);
for(unsigned t(0);t<vThrottle.size() && allowL1a;t++) {
allowL1a=vThrottle[t].allowL1Accept(bx);
}
if(!hgcrocSim.allowL1Accept()) {
nHgcrocDeadtime++;
} else if(!allowL1a) {
nThrottleDeadtime++;
} else {
if(l1AcceptRandom!=0) newL1AIn=(random.random().Uniform()<(l1AcceptRate/40000.0));
else newL1AIn=((bx%53)==0);
......@@ -570,6 +605,14 @@ int main(int argc, char* argv[]) {
}
beSlinkSim[sl].processBx(bx,slinkElinkData[sl]);
if(beSlinkSim[sl].throttle()) vThrottle.push_back(Throttle(bx));
else {
if(vThrottle.size()>0) {
vThrottle[vThrottle.size()-1].endThrottle(bx);
}
}
beSlinkAna[sl].analyseBx(bx);
for(unsigned w(0);w<beSlinkSim[sl].numberOfSlinkWords();w++) {
......@@ -938,16 +981,21 @@ int main(int argc, char* argv[]) {
} // End of BX loop
hCounts->SetBinContent(1,maxBx);
hCounts->SetBinContent(1,bx);
hCounts->SetBinContent(2,numberL1AIn);
hCounts->SetBinContent(3,numberL1AOut);
hCounts->SetBinContent(4,nHgcrocDeadtime);
hCounts->SetBinContent(5,nThrottleDeadtime);
std::cout << "Number of L1As = " << numberL1AIn << ", " << numberL1AOut
<< ", rate = " << numberL1AIn/runSecs << " kHz" << std::endl;
std::cout << "Number of BXs = " << bx
<< ", number of L1As = " << numberL1AIn << ", " << numberL1AOut
<< ", rate = " << numberL1AIn*double(bxPerSec)/bx << " kHz"
<< std::endl;
std::cout << "Number of HGCROC deadtime BXs = " << nHgcrocDeadtime
<< ", fraction = " << 1.0*nHgcrocDeadtime/maxBx << std::endl;
<< ", fraction = " << 1.0*nHgcrocDeadtime/bx << std::endl;
std::cout << "Number of throttle deadtime BXs = " << nThrottleDeadtime
<< ", fraction = " << 1.0*nThrottleDeadtime/bx << std::endl;
// Finish up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment