4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * version: DPDK.L.1.2.3-3
43 #include <sys/queue.h>
46 #include <rte_memory.h>
47 #include <rte_memzone.h>
48 #include <rte_launch.h>
49 #include <rte_tailq.h>
51 #include <rte_per_lcore.h>
52 #include <rte_lcore.h>
53 #include <rte_debug.h>
55 #include "eal_private.h"
57 #define PROC_CPUINFO "/proc/cpuinfo"
58 #define PROC_PROCESSOR_FMT ""
60 /* parse one line and try to match "processor : %d". */
62 parse_processor_id(const char *buf, unsigned *lcore_id)
64 static const char _processor[] = "processor";
67 if (strncmp(buf, _processor, sizeof(_processor) - 1) != 0)
75 *lcore_id = strtoul(s+1, NULL, 10);
84 /* parse one line and try to match "physical id : %d". */
86 parse_socket_id(const char *buf, unsigned *socket_id)
88 static const char _physical_id[] = "physical id";
91 if (strncmp(buf, _physical_id, sizeof(_physical_id) - 1) != 0)
99 *socket_id = strtoul(s+1, NULL, 10);
107 * Parse /proc/cpuinfo to get the number of physical and logical
108 * processors on the machine. The function will fill the cpu_info
112 rte_eal_cpu_init(void)
114 struct rte_config *config;
117 unsigned lcore_id = 0;
118 unsigned socket_id = 0;
121 /* get pointer to global configuration */
122 config = rte_eal_get_configuration();
124 /* open /proc/cpuinfo */
125 f = fopen(PROC_CPUINFO, "r");
127 RTE_LOG(ERR, EAL, "%s(): Cannot find "PROC_CPUINFO"\n", __func__);
132 * browse lines of /proc/cpuinfo and fill memseg entries in
133 * global configuration
135 while (fgets(buf, sizeof(buf), f) != NULL) {
137 if (parse_processor_id(buf, &lcore_id) == 0)
140 if (parse_socket_id(buf, &socket_id) == 0)
143 if (buf[0] == '\n') {
144 RTE_LOG(DEBUG, EAL, "Detected lcore %u on socket %u\n",
145 lcore_id, socket_id);
146 if (lcore_id >= RTE_MAX_LCORE) {
148 "Skip lcore %u >= RTE_MAX_LCORE\n",
154 * In a virtualization environment, the socket ID
155 * reported by the system may not be linked to a real
156 * physical socket ID, and may be incoherent. So in this
157 * case, a default socket ID of 0 is assigned.
159 if (socket_id >= RTE_MAX_NUMA_NODES) {
160 #ifdef CONFIG_RTE_EAL_ALLOW_INV_SOCKET_ID
163 rte_panic("Socket ID (%u) is greater than "
164 "RTE_MAX_NUMA_NODES (%d)\n",
165 socket_id, RTE_MAX_NUMA_NODES);
169 lcore_config[lcore_id].detected = 1;
170 lcore_config[lcore_id].socket_id = socket_id;
177 /* disable lcores that were not detected */
178 RTE_LCORE_FOREACH(lcore_id) {
180 if (lcore_config[lcore_id].detected == 0) {
181 RTE_LOG(DEBUG, EAL, "Skip lcore %u (not detected)\n",
183 config->lcore_role[lcore_id] = ROLE_OFF;
189 config->lcore_count = count;