4 * Copyright(c) 2010-2014 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.
38 #include <sys/types.h>
40 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
52 #include <rte_per_lcore.h>
53 #include <rte_launch.h>
54 #include <rte_atomic.h>
55 #include <rte_cycles.h>
56 #include <rte_prefetch.h>
57 #include <rte_lcore.h>
58 #include <rte_per_lcore.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_interrupts.h>
62 #include <rte_random.h>
63 #include <rte_debug.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
67 #include <rte_mempool.h>
73 #include <rte_string_fns.h>
74 #include <rte_cfgfile.h>
78 struct app_params app;
80 static const char usage[] =
81 "Usage: %s EAL_OPTIONS-- -p PORT_MASK [-f CONFIG_FILE]\n";
84 app_print_usage(char *prgname)
86 printf(usage, prgname);
90 app_core_type_id_to_string(enum app_core_type id)
93 case APP_CORE_NONE: return "NONE";
94 case APP_CORE_MASTER: return "MASTER";
95 case APP_CORE_RX: return "RX";
96 case APP_CORE_TX: return "TX";
97 case APP_CORE_PT: return "PT";
98 case APP_CORE_FC: return "FC";
99 case APP_CORE_FW: return "FW";
100 case APP_CORE_RT: return "RT";
101 case APP_CORE_TM: return "TM";
102 case APP_CORE_IPV4_FRAG: return "IPV4_FRAG";
103 case APP_CORE_IPV4_RAS: return "IPV4_RAS";
104 default: return NULL;
109 app_core_type_string_to_id(const char *string, enum app_core_type *id)
111 if (strcmp(string, "NONE") == 0) {
115 if (strcmp(string, "MASTER") == 0) {
116 *id = APP_CORE_MASTER;
119 if (strcmp(string, "RX") == 0) {
123 if (strcmp(string, "TX") == 0) {
127 if (strcmp(string, "PT") == 0) {
131 if (strcmp(string, "FC") == 0) {
135 if (strcmp(string, "FW") == 0) {
139 if (strcmp(string, "RT") == 0) {
143 if (strcmp(string, "TM") == 0) {
147 if (strcmp(string, "IPV4_FRAG") == 0) {
148 *id = APP_CORE_IPV4_FRAG;
151 if (strcmp(string, "IPV4_RAS") == 0) {
152 *id = APP_CORE_IPV4_RAS;
160 app_get_core_mask(void)
162 uint64_t core_mask = 0;
165 for (i = 0; i < RTE_MAX_LCORE; i++) {
166 if (rte_lcore_is_enabled(i) == 0)
169 core_mask |= 1LLU << i;
176 app_install_coremask(uint64_t core_mask)
180 for (n_cores = 0, i = 0; i < RTE_MAX_LCORE; i++)
181 if (app.cores[i].core_type != APP_CORE_NONE)
184 if (n_cores != app.n_cores) {
185 rte_panic("Number of cores in COREMASK should be %u instead "
186 "of %u\n", n_cores, app.n_cores);
190 for (i = 0; i < RTE_MAX_LCORE; i++) {
193 if (app.cores[i].core_type == APP_CORE_NONE)
196 core_id = __builtin_ctzll(core_mask);
197 core_mask &= ~(1LLU << core_id);
199 app.cores[i].core_id = core_id;
205 app_install_cfgfile(const char *file_name)
207 struct rte_cfgfile *file;
210 memset(app.cores, 0, sizeof(app.cores));
212 if (file_name[0] == '\0')
215 file = rte_cfgfile_load(file_name, 0);
217 rte_panic("Config file %s not found\n", file_name);
221 n_cores = (uint32_t) rte_cfgfile_num_sections(file, "core",
223 if (n_cores < app.n_cores) {
224 rte_panic("Config file parse error: not enough cores specified "
225 "(%u cores missing)\n", app.n_cores - n_cores);
228 if (n_cores > app.n_cores) {
229 rte_panic("Config file parse error: too many cores specified "
230 "(%u cores too many)\n", n_cores - app.n_cores);
234 for (i = 0; i < n_cores; i++) {
235 struct app_core_params *p = &app.cores[i];
236 char section_name[16];
241 snprintf(section_name, sizeof(section_name), "core %u", i);
242 if (!rte_cfgfile_has_section(file, section_name)) {
243 rte_panic("Config file parse error: core IDs are not "
244 "sequential (core %u missing)\n", i);
249 entry = rte_cfgfile_get_entry(file, section_name, "type");
251 rte_panic("Config file parse error: core %u type not "
255 if ((app_core_type_string_to_id(entry, &p->core_type) != 0) ||
256 (p->core_type == APP_CORE_NONE)) {
257 rte_panic("Config file parse error: core %u type "
263 entry = rte_cfgfile_get_entry(file, section_name, "queues in");
265 rte_panic("Config file parse error: core %u queues in "
270 for (j = 0; (j < APP_MAX_SWQ_PER_CORE) && (entry != NULL);
274 p->swq_in[j] = (uint32_t) strtol(entry, &next, 10);
280 if ((j != APP_MAX_SWQ_PER_CORE) || (*entry != '\0')) {
281 rte_panic("Config file parse error: core %u queues in "
287 entry = rte_cfgfile_get_entry(file, section_name, "queues out");
289 rte_panic("Config file parse error: core %u queues out "
294 for (j = 0; (j < APP_MAX_SWQ_PER_CORE) && (entry != NULL);
298 p->swq_out[j] = (uint32_t) strtol(entry, &next, 10);
303 if ((j != APP_MAX_SWQ_PER_CORE) || (*entry != '\0')) {
304 rte_panic("Config file parse error: core %u queues out "
310 rte_cfgfile_close(file);
315 void app_cores_config_print(void)
319 for (i = 0; i < RTE_MAX_LCORE; i++) {
320 struct app_core_params *p = &app.cores[i];
323 if (app.cores[i].core_type == APP_CORE_NONE)
326 printf("---> core %u: id = %u type = %6s [", i, p->core_id,
327 app_core_type_id_to_string(p->core_type));
328 for (j = 0; j < APP_MAX_SWQ_PER_CORE; j++)
329 printf("%2d ", (int) p->swq_in[j]);
332 for (j = 0; j < APP_MAX_SWQ_PER_CORE; j++)
333 printf("%2d ", (int) p->swq_out[j]);
340 app_install_port_mask(const char *arg)
349 port_mask = strtoul(arg, &end, 16);
350 if ((end == NULL) || (*end != '\0'))
357 for (i = 0; i < 64; i++) {
358 if ((port_mask & (1LLU << i)) == 0)
361 if (app.n_ports >= APP_MAX_PORTS)
364 app.ports[app.n_ports] = i;
368 if (!rte_is_power_of_2(app.n_ports))
375 app_parse_args(int argc, char **argv)
380 char *prgname = argv[0];
381 static struct option lgopts[] = {
384 uint64_t core_mask = app_get_core_mask();
386 app.n_cores = __builtin_popcountll(core_mask);
389 while ((opt = getopt_long(argc, argvopt, "p:f:", lgopts,
390 &option_index)) != EOF) {
393 if (app_install_port_mask(optarg) != 0)
394 rte_panic("PORT_MASK should specify a number "
395 "of ports that is power of 2 less or "
396 "equal to %u\n", APP_MAX_PORTS);
400 app_install_cfgfile(optarg);
408 app_install_coremask(core_mask);
410 app_cores_config_print();
413 argv[optind - 1] = prgname;
416 optind = 0; /* reset getopt lib */