]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/lib/librte_eal/linuxapp/eal/eal_lcore.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <rte_lcore.h>
13 #include <rte_common.h>
14 #include <rte_string_fns.h>
15 #include <rte_debug.h>
17 #include "eal_private.h"
18 #include "eal_filesystem.h"
19 #include "eal_thread.h"
21 #define SYS_CPU_DIR "/sys/devices/system/cpu/cpu%u"
22 #define CORE_ID_FILE "topology/core_id"
23 #define NUMA_NODE_PATH "/sys/devices/system/node"
25 /* Check if a cpu is present by the presence of the cpu information for it */
27 eal_cpu_detected(unsigned lcore_id
)
30 int len
= snprintf(path
, sizeof(path
), SYS_CPU_DIR
31 "/"CORE_ID_FILE
, lcore_id
);
32 if (len
<= 0 || (unsigned)len
>= sizeof(path
))
34 if (access(path
, F_OK
) != 0)
41 * Get CPU socket id (NUMA node) for a logical core.
43 * This searches each nodeX directories in /sys for the symlink for the given
44 * lcore_id and returns the numa node where the lcore is found. If lcore is not
45 * found on any numa node, returns zero.
48 eal_cpu_socket_id(unsigned lcore_id
)
52 for (socket
= 0; socket
< RTE_MAX_NUMA_NODES
; socket
++) {
55 snprintf(path
, sizeof(path
), "%s/node%u/cpu%u", NUMA_NODE_PATH
,
57 if (access(path
, F_OK
) == 0)
63 /* Get the cpu core id value from the /sys/.../cpuX core_id value */
65 eal_cpu_core_id(unsigned lcore_id
)
70 int len
= snprintf(path
, sizeof(path
), SYS_CPU_DIR
"/%s", lcore_id
, CORE_ID_FILE
);
71 if (len
<= 0 || (unsigned)len
>= sizeof(path
))
73 if (eal_parse_sysfs_value(path
, &id
) != 0)
78 RTE_LOG(ERR
, EAL
, "Error reading core id value from %s "
79 "for lcore %u - assuming core 0\n", SYS_CPU_DIR
, lcore_id
);