Skip to content

Commit f650e89

Browse files
committed
instanciation of memory pool in base class
1 parent 338e1ee commit f650e89

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/ReadoutEquipment.cxx

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,56 @@ ReadoutEquipment::ReadoutEquipment(ConfigFile &cfg, std::string cfgEntryPoint) {
1414
// printf("%s.%s = %s\n",cfgEntryPoint.c_str(),cfgKey.c_str(),cfgValue.c_str());
1515
//}
1616

17-
1817
// by default, name the equipment as the config node entry point
1918
cfg.getOptionalValue<std::string>(cfgEntryPoint + ".name", name, cfgEntryPoint);
2019

2120
// target readout rate in Hz, -1 for unlimited (default). Global parameter, same for all equipments.
22-
cfg.getOptionalValue<double>("readout.rate",readoutRate,-1.0);
21+
cfg.getOptionalValue<double>("readout.rate", readoutRate, -1.0);
2322

2423
// idle sleep time, in microseconds.
2524
int cfgIdleSleepTime=200;
2625
cfg.getOptionalValue<int>(cfgEntryPoint + ".idleSleepTime", cfgIdleSleepTime);
2726

28-
readoutThread=std::make_unique<Thread>(ReadoutEquipment::threadCallback,this,name,cfgIdleSleepTime);
29-
3027
// size of equipment output FIFO
3128
int cfgOutputFifoSize=1000;
3229
cfg.getOptionalValue<int>(cfgEntryPoint + ".outputFifoSize", cfgOutputFifoSize);
30+
31+
// get memory bank parameters
32+
cfg.getOptionalValue<std::string>(cfgEntryPoint + ".memoryBankName", memoryBankName);
33+
std::string cfgMemoryPoolPageSize="";
34+
cfg.getOptionalValue<std::string>(cfgEntryPoint + ".memoryPoolPageSize",cfgMemoryPoolPageSize);
35+
memoryPoolPageSize=(int)ReadoutUtils::getNumberOfBytesFromString(cfgMemoryPoolPageSize.c_str());
36+
cfg.getOptionalValue<int>(cfgEntryPoint + ".memoryPoolNumberOfPages", memoryPoolNumberOfPages);
3337

38+
// log config summary
39+
theLog.log("Equipment %s: from config [%s], max rate=%lf Hz, idleSleepTime=%d us, outputFifoSize=%d", name.c_str(), cfgEntryPoint.c_str(), readoutRate, cfgIdleSleepTime, cfgOutputFifoSize);
40+
theLog.log("Equipment %s: memory pool %d pages x %d bytes from bank %s", name.c_str(),(int) memoryPoolNumberOfPages, (int) memoryPoolPageSize, memoryBankName.c_str());
41+
42+
// init stats
43+
equipmentStats.resize(EquipmentStatsIndexes::maxIndex);
44+
45+
// create output fifo
3446
dataOut=std::make_shared<AliceO2::Common::Fifo<DataBlockContainerReference>>(cfgOutputFifoSize);
47+
if (dataOut==nullptr) {
48+
throw __LINE__;
49+
}
50+
51+
// creation of memory pool for data pages
52+
// todo: also allocate pool of DataBlockContainers? at the same time? reserve space at start of pages?
53+
if ((memoryPoolPageSize<=0)||(memoryPoolNumberOfPages<=0)) {
54+
theLog.log("Equipment %s: wrong memory pool settings", name.c_str());
55+
throw __LINE__;
56+
}
57+
mp=theMemoryBankManager.getPagedPool(memoryPoolPageSize, memoryPoolNumberOfPages, memoryBankName);
58+
if (mp==nullptr) {
59+
throw __LINE__;
60+
}
3561

36-
equipmentStats.resize(EquipmentStatsIndexes::maxIndex);
62+
// create thread
63+
readoutThread=std::make_unique<Thread>(ReadoutEquipment::threadCallback, this, name, cfgIdleSleepTime);
64+
if (readoutThread==nullptr) {
65+
throw __LINE__;
66+
}
3767
}
3868

3969
const std::string & ReadoutEquipment::getName() {
@@ -67,7 +97,10 @@ void ReadoutEquipment::stop() {
6797
}
6898

6999
ReadoutEquipment::~ReadoutEquipment() {
70-
// printf("deleted %s\n",name.c_str());
100+
// check if mempool still referenced
101+
if (!mp.unique()) {
102+
theLog.log("Equipment %s : mempool still has %d references\n",name.c_str(),(int)mp.use_count());
103+
}
71104
}
72105

73106

@@ -149,12 +182,20 @@ Thread::CallbackResult ReadoutEquipment::threadCallback(void *arg) {
149182
isActive=true;
150183
}
151184
ptr->equipmentStats[EquipmentStatsIndexes::nBlocksOut].increment(nPushedOut);
185+
186+
// consider inactive if we have not pushed much compared to free space in output fifo
187+
// todo: instead, have dynamic 'inactive sleep time' as function of actual outgoing page rate to optimize polling interval
188+
if (nPushedOut<ptr->dataOut->getNumberOfFreeSlots()/4) {
189+
isActive=0;
190+
}
152191

153192
// todo: add SLICER to aggregate together time-range data
154193
// todo: get other FIFO status
155194

156195
break;
157196
}
197+
198+
158199

159200
if (!isActive) {
160201
ptr->equipmentStats[EquipmentStatsIndexes::nIdle].increment();

src/ReadoutEquipment.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "CounterStats.h"
1313
#include "MemoryHandler.h"
1414

15+
#include "MemoryBankManager.h"
16+
17+
1518
using namespace AliceO2::Common;
1619

1720

@@ -83,8 +86,12 @@ class ReadoutEquipment {
8386

8487
// unsigned long long nBlocksOut;
8588
double readoutRate;
86-
protected:
87-
std::string name;
89+
std::string name; // name of the equipment
90+
91+
std::shared_ptr<MemoryPagesPool> mp; // a memory pool from which to allocate data pages
92+
int memoryPoolPageSize=0; // size if each page in pool
93+
int memoryPoolNumberOfPages=0; // number of pages in pool
94+
std::string memoryBankName=""; // memory bank to be used. by default, this uses the first memory bank available
8895
};
8996

9097

0 commit comments

Comments
 (0)