1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include "eal_private.h"
11 #include "eal_filesystem.h"
12 #include "eal_thread.h"
14 #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
15 #define CORE_ID_FILE "topology/core_id"
16 #define NUMA_NODE_PATH "/sys/devices/system/node"
18 /* Check if a cpu is present by the presence of the cpu information for it */
20 eal_cpu_detected(unsigned lcore_id)
23 int len = snprintf(path, sizeof(path), SYS_CPU_DIR
24 "/"CORE_ID_FILE, lcore_id);
25 if (len <= 0 || (unsigned)len >= sizeof(path))
27 if (access(path, F_OK) != 0)
34 * Get CPU socket id (NUMA node) for a logical core.
36 * This searches each nodeX directories in /sys for the symlink for the given
37 * lcore_id and returns the numa node where the lcore is found. If lcore is not
38 * found on any numa node, returns zero.
41 eal_cpu_socket_id(unsigned lcore_id)
45 for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
48 snprintf(path, sizeof(path), "%s/node%u/cpu%u", NUMA_NODE_PATH,
50 if (access(path, F_OK) == 0)
56 /* Get the cpu core id value from the /sys/.../cpuX core_id value */
58 eal_cpu_core_id(unsigned lcore_id)
63 int len = snprintf(path, sizeof(path), SYS_CPU_DIR "/%s", lcore_id, CORE_ID_FILE);
64 if (len <= 0 || (unsigned)len >= sizeof(path))
66 if (eal_parse_sysfs_value(path, &id) != 0)
71 RTE_LOG(ERR, EAL, "Error reading core id value from %s "
72 "for lcore %u - assuming core 0\n", SYS_CPU_DIR, lcore_id);