Skip to content

Commit eb656e7

Browse files
authored
Merge pull request #9 from sy-c/master
added numa support
2 parents adb2834 + b907f01 commit eb656e7

File tree

5 files changed

+94
-36
lines changed

5 files changed

+94
-36
lines changed

CMakeLists.txt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,18 @@ set(MODULE_NAME "Readout")
6363

6464
O2_SETUP(NAME ${MODULE_NAME})
6565

66-
set(SRCS
67-
src/Consumer.cxx
68-
src/ConsumerStats.cxx
69-
src/ConsumerFileRecorder.cxx
70-
src/ConsumerDataChecker.cxx
71-
src/ConsumerDataSampling.cxx
72-
# src/ConsumerFMQ.cxx
73-
src/ReadoutEquipment.cxx
74-
src/ReadoutEquipmentDummy.cxx
75-
src/ReadoutEquipmentRORC.cxx
76-
src/DataBlockAggregator.cxx
77-
src/mainReadout.cxx
78-
src/ReadoutUtils.cxx
79-
)
80-
8166
include_directories(
82-
${CMAKE_CURRENT_SOURCE_DIR}/../RORC/include
8367
${Boost_INCLUDE_DIRS}
8468
${Monitoring_INCLUDE_DIRS}
8569
${FAIRROOT_INCLUDE_DIR}
8670
${FAIRROOT_INCLUDE_DIR}/fairmq
87-
${ZeroMQ_INCLUDE_DIR}
71+
# ${ZeroMQ_INCLUDE_DIR}
8872
${Common_INCLUDE_DIRS}
8973
${Configuration_INCLUDE_DIRS}
9074
${InfoLogger_INCLUDE_DIRS}
9175
${ReadoutCard_INCLUDE_DIRS}
76+
${DataSampling_INCLUDE_DIRS}
77+
${Numa_INCLUDE_DIRS}
9278
)
9379

9480
add_library(
@@ -131,17 +117,11 @@ add_library(
131117
${CONSUMERS_SRCS}
132118
)
133119

134-
135-
set(LIBRARY_NAME ${MODULE_NAME})
136120
set(BUCKET_NAME o2_readout_bucket)
137-
138121
if (FAIRROOT_FOUND)
139-
list(APPEND SRCS src/ConsumerFMQ.cxx)
140122
set(BUCKET_NAME o2_readout_with_fair)
141123
endif ()
142124

143-
O2_GENERATE_LIBRARY()
144-
145125
add_subdirectory(doc)
146126

147127
O2_GENERATE_EXECUTABLE(
@@ -183,7 +163,7 @@ O2_GENERATE_EXECUTABLE(
183163
O2_GENERATE_EXECUTABLE(
184164
EXE_NAME testROC.exe
185165
SOURCES src/testROC.cxx $<TARGET_OBJECTS:objMemUtils>
186-
BUCKET_NAME o2_readout_numa_bucket
166+
BUCKET_NAME ${BUCKET_NAME}
187167
)
188168

189169
# Install some extra files

cmake/FindNuma.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Try to find the Numa package include dirs and libraries
2+
# Author: Sylvain Chapeland
3+
#
4+
# This script will set the following variables:
5+
# Numa_FOUND - System has Numa
6+
# Numa_INCLUDE_DIRS - The Numa include directories
7+
# Numa_LIBRARIES - The libraries needed to use Numa
8+
#
9+
# This script can use the following variables:
10+
# Numa_ROOT - Installation root to tell this module where to look.
11+
12+
13+
find_path(
14+
Numa_INCLUDE_DIRS NAMES numa.h
15+
PATHS ${Numa_ROOT} ${Numa_ROOT}/include)
16+
17+
find_library(
18+
Numa_LIBRARIES NAMES numa
19+
PATHS ${Numa_ROOT} ${Numa_ROOT}/lib)
20+
21+
include(FindPackageHandleStandardArgs)
22+
find_package_handle_standard_args(
23+
Numa DEFAULT_MSG Numa_INCLUDE_DIRS Numa_LIBRARIES)
24+
25+
if(${Numa_FOUND})
26+
message(
27+
STATUS
28+
"Found Numa (include: ${Numa_INCLUDE_DIRS} library: ${Numa_LIBRARIES}")
29+
endif()
30+
31+
mark_as_advanced(Numa_INCLUDE_DIRS Numa_LIBRARIES)

cmake/ReadoutDependencies.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ find_package(Common REQUIRED)
77
find_package(InfoLogger REQUIRED)
88
find_package(ReadoutCard REQUIRED)
99
find_package(DataSampling REQUIRED)
10-
find_package(ZeroMQ REQUIRED)
10+
#find_package(ZeroMQ REQUIRED)
11+
find_package(Numa)
1112

1213
if (FAIRROOT_FOUND)
1314
# this should go away when fairrot provides a proper Find script or proper config scripts
@@ -19,6 +20,14 @@ else (FAIRROOT_FOUND)
1920
message(WARNING "FairRoot not found, corresponding classes will not be compiled.")
2021
endif (FAIRROOT_FOUND)
2122

23+
if (Numa_FOUND)
24+
ADD_DEFINITIONS(-DWITH_NUMA)
25+
else (Numa_FOUND)
26+
message(WARNING "Numa not found, corresponding features will be disabled.")
27+
set(Numa_LIBRARIES "")
28+
set(Numa_INCLUDE_DIRS "")
29+
endif (Numa_FOUND)
30+
2231
ADD_DEFINITIONS(-DWITH_DATASAMPLING)
2332

2433
o2_define_bucket(
@@ -37,6 +46,7 @@ o2_define_bucket(
3746
${InfoLogger_LIBRARIES}
3847
${ReadoutCard_LIBRARIES}
3948
${DataSampling_LIBRARIES}
49+
${Numa_LIBRARIES}
4050

4151
SYSTEMINCLUDE_DIRECTORIES
4252
${Boost_INCLUDE_DIRS}
@@ -45,6 +55,7 @@ o2_define_bucket(
4555
${ReadoutCard_INCLUDE_DIRS}
4656
${DataSampling_INCLUDE_DIRS}
4757
${Configuration_INCLUDE_DIRS}
58+
${Numa_INCLUDE_DIRS}
4859
)
4960

5061

@@ -61,12 +72,3 @@ o2_define_bucket(
6172
${FAIRROOT_INCLUDE_DIR}
6273
${FAIRROOT_INCLUDE_DIR}/fairmq
6374
)
64-
65-
o2_define_bucket(
66-
NAME
67-
o2_readout_numa_bucket
68-
69-
DEPENDENCIES
70-
o2_readout_bucket
71-
numa
72-
)

src/mainReadout.cxx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <sys/stat.h>
3434
#include <fcntl.h>
3535

36+
#ifdef WITH_NUMA
37+
#include <numa.h>
38+
#endif
3639

3740
// option to add callgrind instrumentation
3841
// to use: valgrind --tool=callgrind --instr-atstart=no --dump-instr=yes ./a.out
@@ -100,7 +103,11 @@ int main(int argc, char* argv[])
100103
#else
101104
theLog.log("FAIRMQ : no");
102105
#endif
103-
106+
#ifdef WITH_NUMA
107+
theLog.log("NUMA : yes");
108+
#else
109+
theLog.log("NUMA : no");
110+
#endif
104111
// load configuration file
105112
theLog.log("Reading configuration from %s",cfgFileURI);
106113
try {
@@ -114,7 +121,7 @@ int main(int argc, char* argv[])
114121

115122
// try to prevent deep sleeps
116123
theLog.log("Disabling CPU deep sleep for process");
117-
int maxLatency=1;
124+
int maxLatency=2;
118125
int latencyFd = open("/dev/cpu_dma_latency", O_WRONLY);
119126
if (latencyFd < 0) {
120127
theLog.log("Error opening /dev/cpu_dma_latency");
@@ -131,6 +138,7 @@ int main(int argc, char* argv[])
131138

132139

133140
// configuration of memory banks
141+
int numaNodeChanged=0;
134142
for (auto kName : ConfigFileBrowser (&cfg,"bank-")) {
135143
// skip disabled
136144
int enabled=1;
@@ -161,7 +169,24 @@ int main(int argc, char* argv[])
161169
}
162170
if (cfgType.length()==0) {continue;}
163171

172+
// numa node
173+
int cfgNumaNode=-1;
174+
cfg.getOptionalValue<int>(kName + ".numaNode",cfgNumaNode);
175+
164176
// instanciate new memory pool
177+
if (cfgNumaNode>=0) {
178+
#ifdef WITH_NUMA
179+
struct bitmask *nodemask;
180+
nodemask=numa_allocate_nodemask();
181+
if (nodemask==NULL) {return -1;}
182+
numa_bitmask_clearall(nodemask);
183+
numa_bitmask_setbit(nodemask,cfgNumaNode);
184+
numa_set_membind(nodemask);
185+
numa_free_nodemask(nodemask);
186+
theLog.log("Enforcing memory allocated on NUMA node %d",cfgNumaNode);
187+
numaNodeChanged=1;
188+
#endif
189+
}
165190
theLog.log("Creating memory bank %s: type %s size %lld",kName.c_str(),cfgType.c_str(),mSize);
166191
std::shared_ptr<MemoryBank> b=nullptr;
167192
try {
@@ -180,6 +205,18 @@ int main(int argc, char* argv[])
180205
theLog.log("Bank %s added",kName.c_str());
181206
}
182207

208+
// releasing memory bind policy
209+
if (numaNodeChanged){
210+
#ifdef WITH_NUMA
211+
struct bitmask *nodemask;
212+
nodemask=numa_get_mems_allowed();
213+
numa_set_membind(nodemask);
214+
// is this needed? not specified in doc...
215+
//numa_free_nodemask(nodemask);
216+
theLog.log("Releasing memory NUMA node enforcment");
217+
#endif
218+
}
219+
183220

184221
// configuration of data consumers
185222
std::vector<std::unique_ptr<Consumer>> dataConsumers;

src/testROC.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ InfoLogger theLog;
1818
#include <time.h>
1919

2020
#include <sys/mman.h>
21+
22+
#ifdef WITH_NUMA
2123
#include <numa.h>
24+
#endif
25+
2226
#include <sched.h>
2327
#include <sys/types.h>
2428
#include <sys/stat.h>
@@ -220,13 +224,17 @@ int main(int argc, char**argv) {
220224

221225
// bind alloc/exec on numa node
222226
if (numaNodeId>=0) {
227+
#ifdef WITH_NUMA
223228
struct bitmask *nodemask;
224229
nodemask=numa_allocate_nodemask();
225230
if (nodemask==NULL) {return -1;}
226231
numa_bitmask_clearall(nodemask);
227232
numa_bitmask_setbit(nodemask,numaNodeId);
228233
numa_bind(nodemask);
229234
printf("Locked to numa node %d\n",numaNodeId);
235+
#else
236+
printf("Can not set numaNode ... program compiled without NUMA support\n");
237+
#endif
230238
}
231239

232240

0 commit comments

Comments
 (0)