Commit efc9b89c authored by dauncey's avatar dauncey

Throttling and exceeding

parent 56642b92
......@@ -19,6 +19,9 @@ public:
void boj(const BeSlinkSim &b, unsigned nHistory=100000) {
fBeSlinkSim=&b;
fPreviousThrottleActive=false;
fRaisedThrottleBx=-1;
fEndedThrottleBx=-1;
std::ostringstream sout;
sout << "BeSlinkAna" << std::setw(2) << std::setfill('0')
......@@ -26,15 +29,7 @@ public:
std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08",
"09","10","11","12","13","14","15","16","17"};
/*
hBitmapWordsVsChannels=new TH1I((sout.str()+"BitmapWordsVsChannels").c_str(),
";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5);
hLabelsWordsVsChannels=new TH1I((sout.str()+"LabelsWordsVsChannels").c_str(),
";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5);
hTotalChannels=new TH1D((sout.str()+"TotalChannels").c_str(),
";ECON total number of channels",1300,0,1300);
*/
hTotalEventWords=new TH1D((sout.str()+"TotalEventWords").c_str(),
";Total number of bytes per event",250,0,4000);
......@@ -46,45 +41,22 @@ public:
";Number of event buffer words used",1000,0,10000);
hEventBufferUsedHistory[e][b]=new TH1I((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferUsedHistory").c_str(),
";BX;Number of event buffer words used",nHistory,0,nHistory);
hEventBufferExceeded[e][b]=new TH1D((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferExceeded").c_str(),
";Number of event buffer words used",1000,0,10000);
}
}
/*
for(unsigned h(0);h<18;h++) {
hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(),
";Number of channels per HGCROC packet",73,0,73);
hWords[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Words").c_str(),
";Number of words per HGCROC packet",60,0,60);
hWordsVsChannels[h]=new TH2D((sout.str()+"Hgcroc"+sHgcroc[h]+"WordsVsChannels").c_str(),
";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5,60,-0.5,59.5);
}
*/
}
void analyseL1Accept(uint64_t bx) {
/*
unsigned nChannels(0),nWords(0);
for(unsigned h(0);h<18;h++) {
hChannels[h]->Fill(fEconSim->numberOfChannels(h));
hWords[h]->Fill(fEconSim->numberOfWords(h));
hWordsVsChannels[h]->Fill(fEconSim->numberOfChannels(h),fEconSim->numberOfWords(h));
nChannels+=fEconSim->numberOfChannels(h);
nWords+=fEconSim->numberOfWords(h);
hThrottleActiveHistory=new TH1I((sout.str()+"ThrottleActiveHistory").c_str(),
";BX;Throttle active",nHistory,0,nHistory);
hRaisedThrottleToL1Accept=new TH1D((sout.str()+"RaisedThrottleToL1Accept").c_str(),
";L1Accept - ended throttle (BX)",1000,0,1000);
hEndedThrottleToL1Accept=new TH1D((sout.str()+"EndedThrottleToL1Accept").c_str(),
";L1Accept - ended throttle (BX)",1000,0,1000);
}
hTotalChannels->Fill(nChannels);
hTotalWords->Fill(nWords);
for(unsigned block(0);block<fEconSim->fEconArch.fNumberOfBlocks;block++) {
unsigned nBlockChannels(0),nBlockWords(0);
for(unsigned i(0);i<fEconSim->fEconArch.fHgcrocNumber[block].size();i++) {
unsigned h(fEconSim->fEconArch.fHgcrocNumber[block][i]);
nBlockChannels+=fEconSim->numberOfChannels(h);
nBlockWords+=fEconSim->numberOfWords(h);
}
hBlockTotalChannels[block]->Fill(nBlockChannels);
hBlockTotalWords[block]->Fill(nBlockWords);
}
*/
void analyseL1Accept(uint64_t bx) {
if(fRaisedThrottleBx!=-1) hRaisedThrottleToL1Accept->Fill(bx-fRaisedThrottleBx);
if(fEndedThrottleBx!=-1) hEndedThrottleToL1Accept->Fill(bx-fEndedThrottleBx);
}
void analyseBx(uint64_t bx) {
......@@ -94,12 +66,22 @@ public:
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
hEventBufferUsed[e][b]->Fill(fBeSlinkSim->fEventBuffer[e][b].used());
hEventBufferUsedHistory[e][b]->Fill(bx,fBeSlinkSim->fEventBuffer[e][b].used());
if(fBeSlinkSim->exceededBuffer()) hEventBufferExceeded[e][b]->Fill(fBeSlinkSim->fEventBuffer[e][b].used());
}
}
if(fBeSlinkSim->fL1AcceptEoe) {
hTotalEventWords->Fill(16*fBeSlinkSim->fTotalNumberOfEventWords);
}
if(fBeSlinkSim->fThrottleActive) {
if(!fPreviousThrottleActive) fRaisedThrottleBx=bx;
hThrottleActiveHistory->Fill(bx);
} else {
if(fPreviousThrottleActive) fEndedThrottleBx=bx;
}
fPreviousThrottleActive=fBeSlinkSim->fThrottleActive;
}
void eoj() {
......@@ -108,24 +90,18 @@ public:
private:
const BeSlinkSim *fBeSlinkSim;
//TH1I *hBitmapWordsVsChannels;
//TH1I *hLabelsWordsVsChannels;
//TH1D *hMeans;
//TH1D *hChannels[18];
//TH1D *hWords[18];
//TH2D *hWordsVsChannels[18];
//TH1D *hTotalChannels;
//TH1D *hTotalWords;
//TH1D *hBlockTotalChannels[7];
//TH1D *hBlockTotalWords[7];
bool fPreviousThrottleActive;
uint64_t fRaisedThrottleBx;
uint64_t fEndedThrottleBx;
TH1D *hTotalEventWords;
TH1I *hThrottleActiveHistory;
TH1D *hRaisedThrottleToL1Accept;
TH1D *hEndedThrottleToL1Accept;
TH1D *hEventBufferUsed[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
TH1I *hEventBufferUsedHistory[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
TH1D *hEventBufferExceeded[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
};
#endif
......@@ -44,22 +44,20 @@ public:
BeSlinkSim() {
}
void boj(const SlinkArch &a) {
//fSlink=a.slinkNumber();
void boj(const SlinkArch &a, unsigned bl) {
fSlinkArch=&a;
fBufferLimit=bl;
if(fPrintLevel>0) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::ctor() "
<< "Entered" << std::endl;
<< "Entered with buffer limit = " << fBufferLimit << std::endl;
}
fThrottleActive=false;
fEventActive=false;
fActiveInputBuffer=0;
fWriteElink=0;
//fBufferLimit=1048;
fBufferLimit=1000000000;
fArrayWrite=0;
for(unsigned i(0);i<4;i++) fArrayWord[i]=0;
......@@ -89,74 +87,21 @@ public:
void processBx(uint64_t bx, const SlinkElinkData &d) {
//#define OLD_METHOD
#ifdef OLD_METHOD
if((bx%2)==0) {
fSlinkElinkData=d;
fExceededBuffer=false;
} else {
uint64_t word,word2;
#endif
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) {
const EconArch &econArch(fSlinkArch->econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
const std::vector<unsigned> &elinkNumber(econArch.elinkNumber(b));
#ifdef OLD_METHOD
unsigned eo(0);
for(unsigned w(0);w<elinkNumber.size();w++) {
if((eo%2)==0) {
word=fSlinkElinkData.fData[e][elinkNumber[w]];
} else {
word2=fSlinkElinkData.fData[e][elinkNumber[w]];
word+=(word2<<32);
//if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
}
eo++;
}
for(unsigned w(0);w<elinkNumber.size();w++) {
if((eo%2)==0) {
word=d.fData[e][elinkNumber[w]];
} else {
word2=d.fData[e][elinkNumber[w]];
word+=(word2<<32);
//if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
}
eo++;
}
/*
// DO BY ARCH PROPERLY!!!
for(unsigned w(0);w<Dimensions::MaxNumberOfElinksPerEcon;w++) {
word=fSlinkElinkData.fData[e][w];
if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
}
for(unsigned w(0);w<Dimensions::MaxNumberOfElinksPerEcon;w++) {
word=d.fData[e][w];
//word=(word<<32)+fSlinkElinkData.fData[e][w];
if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
}
*/
}
#else
uint32_t word;
for(unsigned w(0);w<elinkNumber.size();w++) {
word=d.fData[e][elinkNumber[w]];
if(word!=0 || fEventBuffer[e][b].isCachedWriteWord()) assert(fEventBuffer[e][b].halfWriteAndIncrementPtr(word));
}
#endif
//processEconBx(e,d.fData[e]);
if(fEventBuffer[e][b].used()>=4095) fExceededBuffer=true;
}
}
......@@ -304,6 +249,10 @@ public:
}
}
bool exceededBuffer() const {
return fExceededBuffer;
}
void processEconBx(unsigned ec, const uint32_t *d) {
return;
......@@ -477,7 +426,9 @@ public:
#endif
}
bool throttle() const {
bool throttle() {
if(fThrottleActive) return false;
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) {
const EconArch &econArch(fSlinkArch->econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
......@@ -487,12 +438,36 @@ public:
<< "Applying throttle"
<< std::endl;
}
fThrottleActive=true;
return true;
}
}
}
return false;
}
bool unThrottle() {
if(!fThrottleActive) return false;
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) {
return false;
}
}
}
if(fPrintLevel>5) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::throttle() "
<< "Removing throttle"
<< std::endl;
}
fThrottleActive=false;
return true;
}
unsigned numberOfSlinkWords() const {
return fNumberOfSlinkWords;
......@@ -507,7 +482,7 @@ public:
return fSlinkArch->slinkNumber();
}
public:
public:
static unsigned fPrintLevel;
/*
static DataRandomMethod fDataRandomMethod;
......@@ -519,8 +494,8 @@ public:
double fTotalMean;
double fTotalWords;
*/
protected:
private:
protected:
private:
//unsigned fSlink;
const SlinkArch *fSlinkArch;
......@@ -545,7 +520,9 @@ private:
//unsigned fNumberOfChannels[18];
//unsigned fNumberOfWords[18];
bool fThrottleActive;
bool fEventActive;
bool fExceededBuffer;
unsigned fEconRead;
unsigned fBlockRead;
unsigned fArrayWrite;
......@@ -574,13 +551,13 @@ private:
CircularBufferUR<1> fSlinkBoeCb;
unsigned fNumberOfSlinkWords;
std::pair<uint128_t,bool> fSlinkWord[3];
};
unsigned BeSlinkSim::fPrintLevel(1);
/*
BeSlinkSim::DataRandomMethod BeSlinkSim::fDataRandomMethod(BeSlinkSim::Binomial);
BeSlinkSim::DataFormatMethod BeSlinkSim::fDataFormatMethod(BeSlinkSim::FixedChannelBitmap);
BeSlinkSim::DataFlowMethod BeSlinkSim::fDataFlowMethod(BeSlinkSim::FixedHgcrocMap);
unsigned BeSlinkSim::fFormatBreakEven(0);
*/
};
unsigned BeSlinkSim::fPrintLevel(1);
/*
BeSlinkSim::DataRandomMethod BeSlinkSim::fDataRandomMethod(BeSlinkSim::Binomial);
BeSlinkSim::DataFormatMethod BeSlinkSim::fDataFormatMethod(BeSlinkSim::FixedChannelBitmap);
BeSlinkSim::DataFlowMethod BeSlinkSim::fDataFlowMethod(BeSlinkSim::FixedHgcrocMap);
unsigned BeSlinkSim::fFormatBreakEven(0);
*/
#endif
......@@ -46,6 +46,12 @@ public:
";Number of event buffer words used",50000,0,50000);
hEventBufferUsedHistory[block]=new TH1I((sout.str()+"Block"+sHgcroc[block]+"EventBufferUsedHistory").c_str(),
";BX;Number of event buffer words used",nHistory,0,nHistory);
hEventBufferExceeded[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"EventBufferExceeded").c_str(),
";Number of event buffer words used",50000,0,50000);
hL1AcceptDifference[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"L1AcceptDifference").c_str(),
";Difference in L1Accept numbers",100,0,100);
hL1AcceptDifferenceHistory[block]=new TH1I((sout.str()+"Block"+sHgcroc[block]+"L1AcceptDifferenceHistory").c_str(),
";BX;Difference in L1Accept numbers",nHistory,0,nHistory);
}
for(unsigned c(0);c<=72;c++) {
......@@ -100,6 +106,10 @@ public:
for(unsigned block(0);block<fEconSim->econArch().fNumberOfBlocks;block++) {
hEventBufferUsed[block]->Fill(fEconSim->fEventBuffer[block].used());
hEventBufferUsedHistory[block]->Fill(bx,fEconSim->fEventBuffer[block].used());
if(fEconSim->exceededBuffer()) hEventBufferExceeded[block]->Fill(fEconSim->fEventBuffer[block].used());
hL1AcceptDifference[block]->Fill(fEconSim->l1AcceptDifference(block));
hL1AcceptDifferenceHistory[block]->Fill(bx,fEconSim->l1AcceptDifference(block));
}
}
......@@ -124,6 +134,9 @@ private:
TH1D *hBlockTotalWords[7];
TH1D *hEventBufferUsed[7];
TH1I *hEventBufferUsedHistory[7];
TH1D *hEventBufferExceeded[7];
TH1D *hL1AcceptDifference[7];
TH1I *hL1AcceptDifferenceHistory[7];
};
#endif
......@@ -52,56 +52,6 @@ public:
fActiveInputBuffer=0;
fWriteElink=0;
/*
if(false) {
fNumberOfBlocks=1;
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[0].push_back(h);
}
for(unsigned e(0);e<7;e++) {
fElinkNumber[0].push_back(e);
}
} else {
fNumberOfBlocks=7;
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[h%7].push_back(h);
}
for(unsigned e(0);e<7;e++) {
fElinkNumber[e].push_back(e);
}
}
if(fPrintLevel>1) {
std::cout << "EconSim::ctor() "
<< "Number of blocks = " << fNumberOfBlocks << std::endl;
for(unsigned block(0);block<fNumberOfBlocks;block++) {
std::cout << " Block " << block << ", HGCROCs =";
for(unsigned h(0);h<fHgcrocNumber[block].size();h++) {
std::cout << " " << fHgcrocNumber[block][h];
}
std::cout << ", Elinks =";
for(unsigned e(0);e<fElinkNumber[block].size();e++) {
std::cout << " " << fElinkNumber[block][e];
}
std::cout << std::endl;
}
}
*/
for(unsigned b(0);b<NumberOfParallelBuffers;b++) {
for(unsigned block(0);block<20;block++) {
fReadHgcrocNumber[b][block]=EconFile::MaxNumberOfHgcrocs;
......@@ -114,12 +64,11 @@ public:
<< ", word number " << fReadWord[b][block] << std::endl;
}
}
for(unsigned h(0);h<EconFile::MaxNumberOfHgcrocs;h++) {
fFirstBuffer[b][h].resize(channelsToWords(72,false));
}
}
//fHgcrocToElink[h]=(h%7);
}
void boj(unsigned s, unsigned e, const EconFile &f, const EconArch &a) {
......@@ -128,104 +77,14 @@ public:
fEconFile=&f;
fEconArch=&a;
fNewestL1Accept=0;
for(unsigned block(0);block<fEconArch->fNumberOfBlocks;block++) {
fEventBuffer[block].reset(16*4096);
fOldestL1Accept[block]=0;
}
}
#ifdef CRAP
void initialise(unsigned m) {
//assert(fEconFile->fNumberOfHgcrocs<=18);
setFormatBreakEven();
fActiveInputBuffer=0;
fWriteElink=0;
// Random values for now
/*
for(unsigned h(0);h<fNumberOfHgcrocs;h++) {
fEconFile->fHgcrocMean[h]=0.5*h+1;
fHgcrocToElink[h]=(h%7);
}
*/
for(unsigned h(0);h<18;h++) {
fFirstBuffer[0][h].resize(channelsToWords(72,false));
fFirstBuffer[1][h].resize(channelsToWords(72,false));
fEconFile->fHgcrocMean[h]=0.0;
}
for(unsigned h(0);h<fEconFile->fNumberOfHgcrocs;h++) {
if(m==0) {
fEconFile->fHgcrocMean[h]=10;
if(h<14) fEconFile->fHgcrocMean[h]=20;
if(h< 7) fEconFile->fHgcrocMean[h]=35;
if(h==6) fEconFile->fHgcrocMean[h]=40;
}
if(m==1) {
fEconFile->fHgcrocMean[h]=5;
if(h<14) fEconFile->fHgcrocMean[h]=10;
if(h< 7) fEconFile->fHgcrocMean[h]=15;
}
if(m==2) {
fEconFile->fHgcrocMean[h]=3;
if(h<14) fEconFile->fHgcrocMean[h]=7;
if(h< 7) fEconFile->fHgcrocMean[h]=10;
}
if(m==3) {
fEconFile->fHgcrocMean[h]=2;
if(h<14) fEconFile->fHgcrocMean[h]=4;
if(h< 7) fEconFile->fHgcrocMean[h]=5;
}
if(m>=4) {
fEconFile->fHgcrocMean[h]=1;
if(h<14) fEconFile->fHgcrocMean[h]=2;
if(h< 7) fEconFile->fHgcrocMean[h]=3;
}
fHgcrocToElink[h]=(h%7);
}
std::cout << std::endl << "Econ::ctor() number of HGCROCs = "
<< fEconFile->fNumberOfHgcrocs << std::endl;
double elinkNum[7]={0,0,0,0,0,0,0};
double elinkMean[7]={0,0,0,0,0,0,0};
for(unsigned h(0);h<fEconFile->fNumberOfHgcrocs;h++) {
std::cout << " HGCROC " << std::setw(2) << h
<< ", average number of channels = " << fEconFile->fHgcrocMean[h]
<< ", assigned to Elink = " << fHgcrocToElink[h] << std::endl;
elinkNum[fHgcrocToElink[h]]++;
elinkMean[fHgcrocToElink[h]]+=fEconFile->fHgcrocMean[h];
}
/*
fTotalNum=0;
fTotalMean=0;
for(unsigned e(0);e<7;e++) {
fTotalNum+=elinkNum[e];
fTotalMean+=elinkMean[e];
std::cout << " Elink " << e << ", number of HGCROCs = " << elinkNum[e]
<< ", total average number of channels = "
<< elinkMean[e] << ", average number of 32-bit words = "
<< 3*elinkNum[e]+0.5*elinkMean[e]
<< std::endl;
}
fTotalWords=3*fTotalNum+0.5*fTotalMean;
std::cout << " ECON, total average number of channels = "
<< fTotalMean << ", average number of 32-bit words = "
<< fTotalWords
<< std::endl;
*/
}
#endif
void slinkNumber(unsigned s) {
fSlink=s;
}
......@@ -247,13 +106,20 @@ public:
return fEconFile->fHgcrocMean[h];
}
void processZs(uint8_t bx, uint8_t l1a) {
void processZs(uint64_t bx, uint64_t l1a) {
if(fPrintLevel>3) {
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx)
<< "," << unsigned(l1a) << ") "
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << bx
<< "," << l1a << ") "
<< "Entered" << std::endl;
}
fNewestL1Accept=l1a;
if(fPrintLevel>5) {
std::cout << "Incrementing newest L1Accept to " << fNewestL1Accept
<< std::endl;
}
TRandom &random(Random::random());
bool binomialOrFlat;
......@@ -311,8 +177,8 @@ public:
}
if(fPrintLevel>4) {
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx)
<< "," << unsigned(l1a) << ") "
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << bx
<< "," << l1a << ") "
<< "Hgcroc " << h << ", number of channels = "
<< fNumberOfChannels[h] << ", words = "
<< fNumberOfWords[h] << std::endl;
......@@ -320,23 +186,23 @@ public:
// Create HGCROC header
HgcrocBoe hboe(fEcon,h,bx,l1a,fNumberOfWords[h]);
HgcrocBoe hboe(fEcon,h,bx&0xff,l1a&0xff,fNumberOfWords[h]);
if(fPrintLevel>4) {
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx)
<< "," << unsigned(l1a) << ") "
std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << bx
<< "," << l1a << ") "
<< "Hgcroc " << h << " BOE" << std::endl;
hboe.print();
}
// Write data into selected buffer
assert((fActiveInputBuffer&0xff)==l1a);
assert(fActiveInputBuffer==l1a);
fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h].resize(fNumberOfWords[h]);
fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h][0]=hboe.word();
for(unsigned i(1);i<fNumberOfWords[h];i++) {
fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h][i]=(l1a<<24)+i;
fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h][i]=((l1a&0xff)<<24)+i;
}
}
......@@ -350,14 +216,15 @@ public:
fActiveInputBuffer++;
}
void processBx(uint32_t *a) {
fExceededBuffer=false;
// Switch for different dataflow methods
if(fDataFlowMethod==FixedHgcrocMap) {
#ifdef NOT_YET
// 4 words per BX for 7 eLinks
unsigned nWords(4);
......@@ -367,6 +234,10 @@ public:
<< nWords << " words per BX" << std::endl;