Skip to content

Commit 8eec248

Browse files
committed
added equipment.numaNode option to force numa for mem/cpu of corresponding equipment
1 parent 98ecb71 commit 8eec248

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/mainReadout.cxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <inttypes.h>
3131
#include <sys/types.h>
3232
#include <sys/wait.h>
33+
#include <string>
34+
#include <charconv>
3335

3436
#include "DataBlock.h"
3537
#include "DataBlockContainer.h"
@@ -969,6 +971,33 @@ int Readout::configure(const boost::property_tree::ptree& properties)
969971
cfgEquipmentType = cfg.getValue<std::string>(kName + ".equipmentType");
970972
theLog.log(LogInfoDevel, "Configuring equipment %s: %s", kName.c_str(), cfgEquipmentType.c_str());
971973

974+
#ifdef WITH_NUMA
975+
// configuration parameter: | equipment-* | numaNode | string | auto | If set, memory / thread will try to use given NUMA node. If "auto", will try to guess it for given equipment (eg ROC). |
976+
std::string cfgNumaNode = "auto";
977+
cfg.getOptionalValue<std::string>(kName + ".numaNode", cfgNumaNode);
978+
int numaNode = -1;
979+
if (cfgNumaNode == "auto") {
980+
// equipment-specific method to get preferred NUMA node can not be implemented in a derived class method
981+
// because we need info here in the equipment base class before allocating the memory
982+
// call corresponding external function
983+
extern int getPreferredROCNumaNode(ConfigFile&, std::string);
984+
if (!cfgEquipmentType.compare("rorc")) {
985+
numaNode = getPreferredROCNumaNode(cfg, kName);
986+
}
987+
} else {
988+
// try to convert value to int
989+
int n;
990+
auto [ptr, ec] = std::from_chars(cfgNumaNode.data(), cfgNumaNode.data() + cfgNumaNode.size(), n);
991+
if (ec == std::errc{}) {
992+
numaNode = n;
993+
}
994+
}
995+
if (numaNode >= 0) {
996+
theLog.log(LogInfoDevel_(3008), "Preferred NUMA node = %d", numaNode);
997+
numaBind(numaNode);
998+
}
999+
#endif
1000+
9721001
std::unique_ptr<ReadoutEquipment> newDevice = nullptr;
9731002
try {
9741003
if (!cfgEquipmentType.compare("dummy")) {
@@ -1006,6 +1035,13 @@ int Readout::configure(const boost::property_tree::ptree& properties)
10061035
continue;
10071036
}
10081037

1038+
#ifdef WITH_NUMA
1039+
// reset settings after instanciating equipment
1040+
if (numaNode >= 0) {
1041+
numaBind(-1);
1042+
}
1043+
#endif
1044+
10091045
// add to list of equipments
10101046
if (newDevice != nullptr) {
10111047
readoutDevices.push_back(std::move(newDevice));

0 commit comments

Comments
 (0)