Skip to content

Commit 9e4d5fe

Browse files
authored
Merge pull request #14 from sy-c/master
merging latest dev
2 parents ef51031 + 40f4012 commit 9e4d5fe

File tree

8 files changed

+107
-26
lines changed

8 files changed

+107
-26
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ELSE ()
5353
ENDIF ()
5454

5555
# Add compiler flags for warnings and (more importantly) fPIC and debug symbols
56-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -fPIC")
56+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -fPIC -g")
5757

5858
####################################
5959
# Module, library and executable definition

readout.cfg

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ enabled=0
3434
class=MockInjector
3535

3636

37+
###################################
38+
# memory banks
39+
###################################
40+
# All section names should start with 'bank-' to be taken into account.
41+
# They define memory to be allocated to readout
42+
# If bank name not specified in each equipment, the first available bank (created first) will be used.
43+
# Types of memory banks include: malloc, MemoryMappedFile
44+
# NB: the FairMQChannel consumers may also create some banks, which will not be
45+
# listed here, and created before them.
46+
47+
[bank-default]
48+
type=malloc
49+
size=128M
50+
51+
3752

3853
###################################
3954
# equipments
@@ -53,13 +68,18 @@ equipmentType=dummy
5368
enabled=1
5469
eventMaxSize=20000
5570
eventMinSize=10000
71+
memoryPoolNumberOfPages=100
72+
memoryPoolPageSize=128k
5673

5774
[equipment-dummy-2]
5875
name=dummy-2
5976
equipmentType=dummy
6077
enabled=1
6178
eventMaxSize=30000
6279
eventMinSize=20000
80+
memoryPoolNumberOfPages=100
81+
memoryPoolPageSize=128k
82+
6383

6484

6585

@@ -103,10 +123,9 @@ cardId=86:00.0
103123
consumerType=stats
104124
enabled=1
105125
# this publishes stats, if enabled, to O2 monitoring system
106-
monitoringEnabled=0
126+
monitoringEnabled=1
107127
monitoringUpdatePeriod=5
108-
monitoringConfig=file:/etc/monitoring.cfg
109-
128+
monitoringURI=infologger://
110129

111130

112131
# recording to file

src/ConsumerFMQchannel.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class ConsumerFMQchannel: public Consumer {
138138
}
139139

140140
~ConsumerFMQchannel() {
141+
// release in reverse order
142+
mp=nullptr;
143+
memoryBuffer=nullptr; // warning: data range may still be referenced in memory bank manager
144+
sendingChannel=nullptr;
145+
transportFactory=nullptr;
141146
}
142147

143148
int pushData(DataBlockContainerReference &) {

src/ConsumerStats.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ConsumerStats: public Consumer {
8989
// https://alice.its.cern.ch/jira/browse/FLPPROT-69
9090

9191
monitoringCollector->send({counterBlocks, "readout.Blocks"});
92-
monitoringCollector->send({counterBytesTotal, "readout.BytesTotal"});
92+
// monitoringCollector->send({counterBytesTotal, "readout.BytesTotal"});
9393
monitoringCollector->send({counterBytesTotal, "readout.BytesTotal"}, DerivedMetricMode::RATE);
9494
monitoringCollector->send({counterBytesDiff, "readout.BytesInterval"});
9595
// monitoringCollector->send({(counterBytesTotal/(1024*1024)), "readout.MegaBytesTotal"});

src/RAWDataHeader.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,24 @@ typedef struct _RAWDataHeaderV3
114114
struct {
115115
uint32_t version:8; /// bit 0 to 7: header version
116116
uint32_t headerSize:8; /// bit 8 to 15: header size
117-
uint32_t blockLength:16; /// bit 16 to 32: block length
117+
uint32_t blockLength:16; /// bit 16 to 31: block length
118118
};
119119
};
120120

121121
union {
122122
uint32_t word2 = 0x00ffffff;
123123
struct {
124-
uint32_t feeId:8; /// bit 0 to 15: FEE id
124+
uint32_t feeId:16; /// bit 0 to 15: FEE id
125125
uint32_t priorityBit:8; /// bit 16 to 23: priority bit
126-
uint32_t zero2:16; /// bit 16 to 32: reserved
126+
uint32_t zero2:8; /// bit 24 to 31: reserved
127127
};
128128
};
129129

130130
union {
131131
uint32_t word1 = 0x0;
132132
struct {
133-
uint32_t zero1:32; /// bit 0 to 31: reserved
133+
uint32_t offsetNextPacket:16; /// bit 0 to 15: offset of next block
134+
uint32_t memorySize:16; /// bit 16 to 31: size of block (in bytes) in memory
134135
};
135136
};
136137

@@ -152,7 +153,7 @@ typedef struct _RAWDataHeaderV3
152153
union {
153154
uint32_t word6 = 0xffffffff;
154155
struct {
155-
uint32_t heartbeatOrbit; /// bit 0 to 31: TRG orbit
156+
uint32_t heartbeatOrbit; /// bit 0 to 31: HB orbit
156157
};
157158
};
158159

@@ -173,9 +174,9 @@ typedef struct _RAWDataHeaderV3
173174
union {
174175
uint32_t word11 = 0x0;
175176
struct {
176-
uint32_t triggerBC:12; /// bit 0 to 11: trigger BC ID
177+
uint32_t triggerBC:12; /// bit 0 to 11: TRG BC ID
177178
uint32_t zero11_0:4; /// bit 12 to 15: reserved
178-
uint32_t heartbeatBC:12; /// bit 16 to 27: heartbeat BC ID
179+
uint32_t heartbeatBC:12; /// bit 16 to 27: HB BC ID
179180
uint32_t zero11_1:4; /// bit 28 to 31: reserved
180181
};
181182
};
@@ -212,9 +213,9 @@ typedef struct _RAWDataHeaderV3
212213
union {
213214
uint32_t word14 = 0x0;
214215
struct {
215-
uint32_t stopBit:8; /// bit 0 to 7: stop bit
216+
uint32_t stopBit:8; /// bit 0 to 7: stop bit
216217
uint32_t pagesCoutner:16; /// bit 8 to 23: pages counter
217-
uint32_t zero14:8; /// bit 24 to 31: reserved
218+
uint32_t zero14:8; /// bit 24 to 31: reserved
218219
};
219220
};
220221

src/RdhUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class RdhHandle {
3939
inline uint8_t getHeaderSize() {
4040
return rdhPtr->headerSize;
4141
}
42+
inline uint32_t getHbOrbit() {
43+
return (uint32_t) rdhPtr->heartbeatOrbit;
44+
}
4245

4346
private:
4447
o2::Header::RAWDataHeader *rdhPtr; // pointer to RDH in memory

src/ReadoutEquipmentRORC.cxx

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,21 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
4747

4848
unsigned long long statsRdhCheckOk=0; // number of RDH structs which have passed check ok
4949
unsigned long long statsRdhCheckErr=0; // number of RDH structs which have not passed check
50+
unsigned long long statsNumberOfPages=0; // number of pages read out
51+
unsigned long long statsNumberOfTimeframes=0; // number of timeframes read out
52+
5053

5154
AliceO2::Common::Timer timeframeClock; // timeframe id should be increased at each clock cycle
52-
int currentTimeframe=0; // id of current timeframe
55+
int currentTimeframe=0; // id of current timeframe
56+
bool usingSoftwareClock=false; // if set, using internal software clock to generate timeframe id
57+
58+
const unsigned int LHCBunches=3564; // number of bunches in LHC
59+
const unsigned int LHCOrbitRate=11246; // LHC orbit rate, in Hz. 299792458 / 26659
60+
const uint32_t timeframePeriodOrbits=256; // timeframe interval duration in number of LHC orbits
5361

62+
uint32_t currentTimeframeHbOrbitBegin=0; // HbOrbit of beginning of timeframe
63+
uint32_t firstTimeframeHbOrbitBegin=0; // HbOrbit of beginning of first timeframe
64+
5465
size_t superPageSize=0; // usable size of a superpage
5566
};
5667

@@ -202,9 +213,19 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
202213
theLog.log("ROC input queue size = %d pages",RocFifoSize);
203214
if (RocFifoSize==0) {RocFifoSize=1;}
204215

205-
// reset timeframe clock
206-
timeframeClock.reset(1000000/50.0); // 50Hz rate
216+
// reset timeframe id
207217
currentTimeframe=0;
218+
if (!cfgRdhCheckEnabled) {
219+
usingSoftwareClock=true; // if RDH disabled, use internal clock for TF id
220+
}
221+
if (usingSoftwareClock) {
222+
// reset timeframe clock
223+
double timeframeRate=LHCOrbitRate*1.0/timeframePeriodOrbits; // timeframe rate, in Hz
224+
theLog.log("Timeframe IDs generated by software, %.2lf Hz",timeframeRate);
225+
timeframeClock.reset(1000000/timeframeRate);
226+
} else {
227+
theLog.log("Timeframe IDs generated from RDH trigger counters");
228+
}
208229

209230
}
210231
catch (const std::exception& e) {
@@ -222,7 +243,7 @@ ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {
222243
}
223244

224245
if (cfgRdhCheckEnabled) {
225-
theLog.log("Equipment %s : RDH checks %llu ok, %llu errors",name.c_str(),statsRdhCheckOk,statsRdhCheckErr);
246+
theLog.log("Equipment %s : %llu timeframes, %llu pages, RDH checks %llu ok, %llu errors",name.c_str(),statsNumberOfTimeframes,statsNumberOfPages,statsRdhCheckOk,statsRdhCheckErr);
226247
}
227248
}
228249

@@ -323,20 +344,22 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
323344
theLog.log("make_shared<DataBlock> failed");
324345
}
325346
if (d!=nullptr) {
347+
statsNumberOfPages++;
348+
326349
d->getData()->header.dataSize=superpage.getReceived();
327350
d->getData()->header.linkId=0; // TODO
328351

329352
channel->popSuperpage();
330353
nextBlock=d;
331-
332-
if (timeframeClock.isTimeout()) {
333-
currentTimeframe++;
334-
timeframeClock.increment();
335-
}
336-
d->getData()->header.id=currentTimeframe;
337354

338355
// validate RDH structure, if configured to do so
339356
int linkId=-1;
357+
int hbOrbit=-1;
358+
359+
// checks to do:
360+
// - HB clock consistent in all RDHs
361+
// - increasing counters
362+
340363
if (cfgRdhCheckEnabled) {
341364
std::string errorDescription;
342365
size_t blockSize=d->getData()->header.dataSize;
@@ -352,6 +375,26 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
352375
}
353376
}
354377

378+
if (hbOrbit==-1) {
379+
hbOrbit=h.getHbOrbit();
380+
if ((statsNumberOfPages==1) || ((uint32_t)hbOrbit>=currentTimeframeHbOrbitBegin+timeframePeriodOrbits)) {
381+
if (statsNumberOfPages==1) {
382+
firstTimeframeHbOrbitBegin=hbOrbit;
383+
}
384+
statsNumberOfTimeframes++;
385+
currentTimeframeHbOrbitBegin=hbOrbit-((hbOrbit-firstTimeframeHbOrbitBegin)%timeframePeriodOrbits); // keep it periodic and aligned to 1st timeframe
386+
int newTimeframe=1+(currentTimeframeHbOrbitBegin-firstTimeframeHbOrbitBegin)/timeframePeriodOrbits;
387+
if (newTimeframe!=currentTimeframe+1) {
388+
printf("Non-contiguous timeframe IDs %d ... %d\n",currentTimeframe,newTimeframe);
389+
}
390+
currentTimeframe=newTimeframe;
391+
//printf("Starting timeframe %d @ orbit %d (actual: %d)\n",currentTimeframe,(int)currentTimeframeHbOrbitBegin,(int)hbOrbit);
392+
} else {
393+
//printf("HB orbit %d\n",hbOrbit);
394+
}
395+
396+
}
397+
355398
//data format:
356399
// RDH v3 = https://docs.google.com/document/d/1otkSDYasqpVBDnxplBI7dWNxaZohctA-bvhyrzvtLoQ/edit?usp=sharing
357400
if (h.validateRdh(errorDescription)) {
@@ -383,7 +426,17 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
383426
if (linkId>=0) {
384427
d->getData()->header.linkId=linkId;
385428
}
386-
429+
430+
if (usingSoftwareClock) {
431+
if (timeframeClock.isTimeout()) {
432+
currentTimeframe++;
433+
statsNumberOfTimeframes++;
434+
timeframeClock.increment();
435+
}
436+
}
437+
438+
// set timeframe id
439+
d->getData()->header.id=currentTimeframe;
387440
}
388441
else {
389442
// no data block container... what to do???

src/mainReadout.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main(int argc, char* argv[])
9494
sigaction(SIGINT,&signalSettings,NULL);
9595

9696
// log startup and options
97-
theLog.log("Readout process starting");
97+
theLog.log("Readout process starting, pid %d",getpid());
9898
theLog.log("Optional built features enabled:");
9999
#ifdef WITH_FAIRMQ
100100
theLog.log("FAIRMQ : yes");

0 commit comments

Comments
 (0)