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;
0 commit comments