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_debug.h>
16 #include "eal_private.h"
17 #include "eal_thread.h"
20 * Parse /sys/devices/system/cpu to get the number of physical and logical
21 * processors on the machine. The function will fill the cpu_info
25 rte_eal_cpu_init(void)
27 /* pointer to global configuration */
28 struct rte_config *config = rte_eal_get_configuration();
33 * Parse the maximum set of logical cores, detect the subset of running
34 * ones and enable them by default.
36 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
37 lcore_config[lcore_id].core_index = count;
39 /* init cpuset for per lcore config */
40 CPU_ZERO(&lcore_config[lcore_id].cpuset);
42 /* in 1:1 mapping, record related cpu detected state */
43 lcore_config[lcore_id].detected = eal_cpu_detected(lcore_id);
44 if (lcore_config[lcore_id].detected == 0) {
45 config->lcore_role[lcore_id] = ROLE_OFF;
46 lcore_config[lcore_id].core_index = -1;
50 /* By default, lcore 1:1 map to cpu id */
51 CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
53 /* By default, each detected core is enabled */
54 config->lcore_role[lcore_id] = ROLE_RTE;
55 lcore_config[lcore_id].core_role = ROLE_RTE;
56 lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id);
57 lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
58 if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES) {
59 #ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
60 lcore_config[lcore_id].socket_id = 0;
62 RTE_LOG(ERR, EAL, "Socket ID (%u) is greater than "
63 "RTE_MAX_NUMA_NODES (%d)\n",
64 lcore_config[lcore_id].socket_id,
69 RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
70 "core %u on socket %u\n",
71 lcore_id, lcore_config[lcore_id].core_id,
72 lcore_config[lcore_id].socket_id);
75 /* Set the count of enabled logical cores of the EAL configuration */
76 config->lcore_count = count;
78 "Support maximum %u logical core(s) by configuration.\n",
80 RTE_LOG(INFO, EAL, "Detected %u lcore(s)\n", config->lcore_count);