MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_number_of_sockets

Function get_number_of_sockets

dpdk/app/test/test_eal_flags.c:287–312  ·  view source on GitHub ↗

* count the number of "node*" files in /sys/devices/system/node/ */

Source from the content-addressed store, hash-verified

285 * count the number of "node*" files in /sys/devices/system/node/
286 */
287static int
288get_number_of_sockets(void)
289{
290 struct dirent *dirent = NULL;
291 const char * nodedir = "/sys/devices/system/node/";
292 DIR * dir = NULL;
293 int result = 0;
294
295 /* check if directory exists */
296 if ((dir = opendir(nodedir)) == NULL) {
297 /* if errno==ENOENT this means we don't have NUMA support */
298 if (errno == ENOENT) {
299 printf("No NUMA nodes detected: assuming 1 available socket\n");
300 return 1;
301 }
302 printf("Error opening %s: %s\n", nodedir, strerror(errno));
303 return -1;
304 }
305
306 while ((dirent = readdir(dir)) != NULL)
307 if (strncmp(dirent->d_name, "node", sizeof("node") - 1) == 0)
308 result++;
309
310 closedir(dir);
311 return result;
312}
313#endif
314
315/*

Callers 1

test_memory_flagsFunction · 0.85

Calls 5

opendirFunction · 0.85
readdirFunction · 0.85
strncmpFunction · 0.85
closedirFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected