* count the number of "node*" files in /sys/devices/system/node/ */
| 285 | * count the number of "node*" files in /sys/devices/system/node/ |
| 286 | */ |
| 287 | static int |
| 288 | get_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 | /* |