@@ -19,14 +19,10 @@ class ReadoutEquipmentCruEmulator : public ReadoutEquipment {
1919 Thread::CallbackResult prepareBlocks ();
2020
2121 private:
22- std::shared_ptr<MemoryHandler> mh; // a memory pool from which to allocate data pages
2322 Thread::CallbackResult populateFifoOut (); // iterative callback
2423
2524 DataBlockId currentId; // current block id
2625
27- int memPoolNumberOfElements; // number of pages in memory pool
28- int memPoolElementSize; // size of each page
29-
3026 int cfgNumberOfLinks; // number of links to simulate. Will create data blocks round-robin.
3127 int cfgFeeId; // FEE id to be used
3228 int cfgLinkId; // Link id to be used (base number - will be incremented if multiple links selected)
@@ -36,32 +32,17 @@ class ReadoutEquipmentCruEmulator : public ReadoutEquipment {
3632 const unsigned int LHCBCRate=LHCOrbitRate*LHCBunches; // LHC bunch crossing rate, in Hz
3733
3834 int cruBlockSize; // size of 1 data block (RDH+payload)
39-
40- // interval in BC clocks between two CRU block transfers, based on link input data rate
41- int bcStep;
42-
35+ int bcStep; // interval in BC clocks between two CRU block transfers, based on link input data rate
4336
4437 int cfgTFperiod=256 ; // duration of a timeframe, in number of LHC orbits
4538 int cfgHBperiod=1 ; // interval between 2 HeartBeat triggers, in number of LHC orbits
4639 double cfgGbtLinkThroughput=3.2 ; // input link data rate in Gigabits/s per second, for one link (GBT=3.2 or 4.8 gbps)
4740
48-
4941 int cfgMaxBlocksPerPage; // max number of CRU blocks per page (0 => fill the page)
50- /*
51- int cfgNumberOfBlocksPerTrigger; // number of CRU blocks for 1 trigger
52- int randomize;
53- int pagesToGoForCurrentLink; // number of data pages left to send for current link
54- int currentLink; // id of current Link sending data
55- */
5642
5743 uint32_t LHCorbit=0 ; // current LHC orbit
5844 uint32_t LHCbc=0 ; // current LHC bunch crossing
59- // uint32_t HBid=0; // id of last HB frame received
60-
61- // int TFperiod=256; // duration of a time frame, in number of LHC orbits
62- // int HBperiod=1; // interval betweenHB triggers, in number of LHC orbits
6345
64-
6546 Timer elapsedTime; // elapsed time since equipment started
6647 double t0=0 ; // time of first block generated
6748
@@ -71,33 +52,16 @@ class ReadoutEquipmentCruEmulator : public ReadoutEquipment {
7152
7253ReadoutEquipmentCruEmulator::ReadoutEquipmentCruEmulator (ConfigFile &cfg, std::string cfgEntryPoint) : ReadoutEquipment(cfg, cfgEntryPoint) {
7354
74-
7555 // get configuration values
76- cfg.getOptionalValue <int >(cfgEntryPoint + " .memPoolNumberOfElements" , memPoolNumberOfElements,10000 );
77- std::string cfgMemPoolElementSize;
78- cfg.getOptionalValue <std::string>(cfgEntryPoint + " .memPoolElementSize" , cfgMemPoolElementSize);
79- memPoolElementSize=ReadoutUtils::getNumberOfBytesFromString (cfgMemPoolElementSize.c_str ());
80- if (memPoolElementSize<=0 ) {
81- memPoolElementSize=1024 *1024 ;
82- }
8356 cfg.getOptionalValue <int >(cfgEntryPoint + " .maxBlocksPerPage" , cfgMaxBlocksPerPage, (int )0 );
8457 cfg.getOptionalValue <int >(cfgEntryPoint + " .cruBlockSize" , cruBlockSize, (int )8192 );
8558 cfg.getOptionalValue <int >(cfgEntryPoint + " .numberOfLinks" , cfgNumberOfLinks, (int )1 );
8659 cfg.getOptionalValue <int >(cfgEntryPoint + " .feeId" , cfgFeeId, (int )0 );
8760 cfg.getOptionalValue <int >(cfgEntryPoint + " .linkId" , cfgLinkId, (int )0 );
8861
8962 // log config summary
90- theLog.log (" Config summary: memPoolNumberOfElements=%d memPoolElementSize=%d maxBlocksPerPage=%d cruBlockSize=%d numberOfLinks=%d feeId=%d linkId=%d" ,
91- memPoolNumberOfElements, memPoolElementSize, cfgMaxBlocksPerPage, cruBlockSize, cfgNumberOfLinks, cfgFeeId, cfgLinkId);
92-
93- // create memory pool
94- if (bigBlock==nullptr ) {
95- theLog.log (" big block unavailable for output" );
96- throw __LINE__;
97- } else {
98- theLog.log (" Using big block @ %p" ,bigBlock->ptr );
99- mh=std::make_shared<MemoryHandler>(memPoolElementSize,memPoolNumberOfElements);
100- }
63+ theLog.log (" Equipment %s: maxBlocksPerPage=%d cruBlockSize=%d numberOfLinks=%d feeId=%d linkId=%d" ,
64+ name.c_str (), cfgMaxBlocksPerPage, cruBlockSize, cfgNumberOfLinks, cfgFeeId, cfgLinkId);
10165
10266 // init variables
10367 currentId=1 ; // TFid starts on 1
@@ -110,10 +74,13 @@ ReadoutEquipmentCruEmulator::ReadoutEquipmentCruEmulator(ConfigFile &cfg, std::s
11074
11175 // output queue: 1 block per link
11276 readyBlocks=std::make_unique<AliceO2::Common::Fifo<DataBlockContainerReference>>(cfgNumberOfLinks);
77+ if (readyBlocks==nullptr ) {
78+ throw __LINE__;
79+ }
11380
11481 // init parameters
11582 bcStep=(int )(LHCBCRate*((cruBlockSize-sizeof (o2::Header::RAWDataHeader))*1.0 /(cfgGbtLinkThroughput*1024 *1024 *1024 /8 )));
116- theLog.log (" Using block rate = %d BC" ,bcStep);
83+ theLog.log (" Equipment %s: using block rate = %d BC" , name. c_str (), bcStep);
11784}
11885
11986ReadoutEquipmentCruEmulator::~ReadoutEquipmentCruEmulator () {
@@ -122,9 +89,8 @@ ReadoutEquipmentCruEmulator::~ReadoutEquipmentCruEmulator() {
12289
12390
12491Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks () {
125- /*
126- cru emulator creates a set of data pages for each link and put them in the fifo to be retrieve by getNextBlock
127- */
92+
93+ // cru emulator creates a set of data pages for each link and put them in the fifo to be retrieve by getNextBlock
12894
12995 // check that we don't go faster than LHC...
13096 double t=elapsedTime.getTime ();
@@ -148,13 +114,13 @@ Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks() {
148114 // query memory pool for a free block
149115 DataBlockContainerReference nextBlock=nullptr ;
150116 try {
151- // nextBlock=std::make_shared<DataBlockContainerFromMemPool>(mp);
152- nextBlock=std::make_shared<DataBlockContainerFromMemoryHandler>(mh);
117+ nextBlock=mp->getNewDataBlockContainer ();
153118 }
154119 catch (...) {
155120 }
156121 if (nextBlock==nullptr ) {
157122 // no pages left, retry later
123+ // todo: check how long we starve pages. monitor this counter.
158124 return Thread::CallbackResult::Idle;
159125 }
160126 pendingBlocks[i]=nextBlock;
@@ -172,8 +138,10 @@ Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks() {
172138 for (int currentLink=0 ; currentLink<cfgNumberOfLinks; currentLink++) {
173139
174140 // fill the new data page for this link
175- DataBlock *b=pendingBlocks[currentLink]->getData ();
141+ DataBlock *b=pendingBlocks[currentLink]->getData ();
176142
143+ // printf ("data block %p data=%p\n",b,b->data);
144+
177145 int offset; // number of bytes used in page
178146 int nBlocksInPage=0 ;
179147
@@ -182,8 +150,10 @@ Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks() {
182150 unsigned int nowId=currentId;
183151
184152 int linkId=cfgLinkId+currentLink;
153+ int bytesAvailableInPage=b->header .dataSize ; // a bit less than memoryPoolPageSize;
154+ // printf("bytes available: %d bytes\n",bytesAvailableInPage);
185155
186- for (offset=0 ;offset+cruBlockSize<=memPoolElementSize ;offset+=cruBlockSize) {
156+ for (offset=0 ;offset+cruBlockSize<=bytesAvailableInPage ;offset+=cruBlockSize) {
187157
188158 unsigned int nextBc=nowBc+bcStep;
189159 unsigned int nextOrbit=nowOrbit;
@@ -212,6 +182,8 @@ Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks() {
212182 // https://docs.google.com/document/d/1KUoLnEw5PndVcj4FKR5cjV-MBN3Bqfx_B0e6wQOIuVE/edit#heading=h.5q65he8hp62c
213183
214184 o2::Header::RAWDataHeader *rdh=(o2::Header::RAWDataHeader *)&b->data [offset];
185+ // printf("rdh=%p block=%p delta=%d\n",rdh,b->data,(int)((char *)rdh-(char *)b->data));
186+
215187 *rdh=defaultRDH; // reset fields to defaults
216188 rdh->blockLength =(uint16_t )cruBlockSize;
217189 rdh->triggerOrbit =nowOrbit;
@@ -227,7 +199,9 @@ Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks() {
227199
228200 // size used (bytes) in page is last offset
229201 int dSize=offset;
230-
202+
203+ // printf("wrote %d bytes\n",dSize);
204+
231205 b->header .blockType =DataBlockType::H_BASE;
232206 b->header .headerSize =sizeof (DataBlockHeaderBase);
233207 b->header .dataSize =dSize;
0 commit comments