4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <netinet/in.h>
44 #include <net/socket.h>
49 #include <sys/queue.h>
51 #include <rte_common.h>
53 #include <rte_debug.h>
54 #include <rte_memory.h>
55 #include <rte_memcpy.h>
56 #include <rte_memzone.h>
57 #include <rte_launch.h>
58 #include <rte_cycles.h>
59 #include <rte_tailq.h>
61 #include <rte_per_lcore.h>
62 #include <rte_lcore.h>
63 #include <rte_atomic.h>
64 #include <rte_branch_prediction.h>
66 #include <rte_mempool.h>
68 #include <rte_devargs.h>
70 #include <cmdline_rdline.h>
71 #include <cmdline_parse.h>
72 #include <cmdline_parse_ipaddr.h>
73 #include <cmdline_parse_num.h>
74 #include <cmdline_parse_string.h>
81 struct cmd_autotest_result {
82 cmdline_fixed_string_t autotest;
85 static void cmd_autotest_parsed(void *parsed_result,
86 __attribute__((unused)) struct cmdline *cl,
87 __attribute__((unused)) void *data)
89 struct cmd_autotest_result *res = parsed_result;
92 if (!strcmp(res->autotest, "version_autotest"))
94 if (!strcmp(res->autotest, "eal_fs_autotest"))
96 if (!strcmp(res->autotest, "debug_autotest"))
98 if (!strcmp(res->autotest, "pci_autotest"))
100 if (!strcmp(res->autotest, "prefetch_autotest"))
101 ret = test_prefetch();
102 if (!strcmp(res->autotest, "byteorder_autotest"))
103 ret = test_byteorder();
104 if (!strcmp(res->autotest, "per_lcore_autotest"))
105 ret = test_per_lcore();
106 if (!strcmp(res->autotest, "atomic_autotest"))
108 if (!strcmp(res->autotest, "malloc_autotest"))
110 if (!strcmp(res->autotest, "spinlock_autotest"))
111 ret = test_spinlock();
112 if (!strcmp(res->autotest, "memory_autotest"))
114 if (!strcmp(res->autotest, "memzone_autotest"))
115 ret = test_memzone();
116 if (!strcmp(res->autotest, "rwlock_autotest"))
118 if (!strcmp(res->autotest, "mbuf_autotest"))
120 if (!strcmp(res->autotest, "logs_autotest"))
122 if (!strcmp(res->autotest, "errno_autotest"))
124 if (!strcmp(res->autotest, "hash_autotest"))
126 if (!strcmp(res->autotest, "hash_perf_autotest"))
127 ret = test_hash_perf();
128 if (!strcmp(res->autotest, "lpm_autotest"))
130 if (!strcmp(res->autotest, "lpm6_autotest"))
132 if (!strcmp(res->autotest, "cpuflags_autotest"))
133 ret = test_cpuflags();
134 if (!strcmp(res->autotest, "cmdline_autotest"))
135 ret = test_cmdline();
136 if (!strcmp(res->autotest, "tailq_autotest"))
138 if (!strcmp(res->autotest, "multiprocess_autotest"))
139 ret = test_mp_secondary();
140 if (!strcmp(res->autotest, "memcpy_autotest"))
142 if (!strcmp(res->autotest, "string_autotest"))
143 ret = test_string_fns();
144 if (!strcmp(res->autotest, "eal_flags_autotest"))
145 ret = test_eal_flags();
146 if (!strcmp(res->autotest, "alarm_autotest"))
148 if (!strcmp(res->autotest, "interrupt_autotest"))
149 ret = test_interrupt();
150 if (!strcmp(res->autotest, "cycles_autotest"))
152 if (!strcmp(res->autotest, "ring_autotest"))
154 if (!strcmp(res->autotest, "table_autotest"))
156 if (!strcmp(res->autotest, "ring_perf_autotest"))
157 ret = test_ring_perf();
158 if (!strcmp(res->autotest, "timer_autotest"))
160 if (!strcmp(res->autotest, "timer_perf_autotest"))
161 ret = test_timer_perf();
162 #ifdef RTE_LIBRTE_PMD_BOND
163 if (!strcmp(res->autotest, "link_bonding_autotest"))
164 ret = test_link_bonding();
166 if (!strcmp(res->autotest, "mempool_autotest"))
167 ret = test_mempool();
168 if (!strcmp(res->autotest, "mempool_perf_autotest"))
169 ret = test_mempool_perf();
170 if (!strcmp(res->autotest, "memcpy_perf_autotest"))
171 ret = test_memcpy_perf();
172 if (!strcmp(res->autotest, "func_reentrancy_autotest"))
173 ret = test_func_reentrancy();
174 if (!strcmp(res->autotest, "red_autotest"))
176 if (!strcmp(res->autotest, "sched_autotest"))
178 if (!strcmp(res->autotest, "meter_autotest"))
180 if (!strcmp(res->autotest, "kni_autotest"))
182 if (!strcmp(res->autotest, "power_autotest"))
184 if (!strcmp(res->autotest, "common_autotest"))
186 if (!strcmp(res->autotest, "ivshmem_autotest"))
187 ret = test_ivshmem();
188 if (!strcmp(res->autotest, "distributor_autotest"))
189 ret = test_distributor();
190 if (!strcmp(res->autotest, "distributor_perf_autotest"))
191 ret = test_distributor_perf();
192 if (!strcmp(res->autotest, "devargs_autotest"))
193 ret = test_devargs();
194 #ifdef RTE_LIBRTE_PMD_RING
195 if (!strcmp(res->autotest, "ring_pmd_autotest"))
196 ret = test_pmd_ring();
197 #endif /* RTE_LIBRTE_PMD_RING */
199 #ifdef RTE_LIBRTE_ACL
200 if (!strcmp(res->autotest, "acl_autotest"))
202 #endif /* RTE_LIBRTE_ACL */
203 #ifdef RTE_LIBRTE_KVARGS
204 if (!strcmp(res->autotest, "kvargs_autotest"))
205 ret |= test_kvargs();
206 #endif /* RTE_LIBRTE_KVARGS */
211 printf("Test Failed\n");
215 cmdline_parse_token_string_t cmd_autotest_autotest =
216 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
217 "pci_autotest#memory_autotest#"
218 "per_lcore_autotest#spinlock_autotest#"
219 "rwlock_autotest#atomic_autotest#"
220 "byteorder_autotest#prefetch_autotest#"
221 "cycles_autotest#logs_autotest#"
222 "memzone_autotest#ring_autotest#"
223 "mempool_autotest#mbuf_autotest#"
224 "timer_autotest#malloc_autotest#"
225 "memcpy_autotest#hash_autotest#"
226 "lpm_autotest#debug_autotest#"
228 "errno_autotest#tailq_autotest#"
229 "string_autotest#multiprocess_autotest#"
230 "cpuflags_autotest#eal_flags_autotest#"
231 "alarm_autotest#interrupt_autotest#"
232 "version_autotest#eal_fs_autotest#"
233 "cmdline_autotest#func_reentrancy_autotest#"
234 #ifdef RTE_LIBRTE_PMD_BOND
235 "link_bonding_autotest#"
237 "mempool_perf_autotest#hash_perf_autotest#"
238 "memcpy_perf_autotest#ring_perf_autotest#"
239 "red_autotest#meter_autotest#sched_autotest#"
240 "memcpy_perf_autotest#kni_autotest#"
241 "pm_autotest#ivshmem_autotest#"
242 "devargs_autotest#table_autotest#"
243 #ifdef RTE_LIBRTE_ACL
247 "timer_perf_autotest#"
248 #ifdef RTE_LIBRTE_PMD_RING
251 #ifdef RTE_LIBRTE_KVARGS
255 "distributor_autotest#distributor_perf_autotest");
257 cmdline_parse_inst_t cmd_autotest = {
258 .f = cmd_autotest_parsed, /* function to call */
259 .data = NULL, /* 2nd arg of func */
260 .help_str = "launch autotest",
261 .tokens = { /* token list, NULL terminated */
262 (void *)&cmd_autotest_autotest,
269 struct cmd_dump_result {
270 cmdline_fixed_string_t dump;
274 dump_struct_sizes(void)
276 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
277 DUMP_SIZE(struct rte_mbuf);
278 DUMP_SIZE(struct rte_pktmbuf);
279 DUMP_SIZE(struct rte_ctrlmbuf);
280 DUMP_SIZE(struct rte_mempool);
281 DUMP_SIZE(struct rte_ring);
285 static void cmd_dump_parsed(void *parsed_result,
286 __attribute__((unused)) struct cmdline *cl,
287 __attribute__((unused)) void *data)
289 struct cmd_dump_result *res = parsed_result;
291 if (!strcmp(res->dump, "dump_physmem"))
292 rte_dump_physmem_layout(stdout);
293 else if (!strcmp(res->dump, "dump_memzone"))
294 rte_memzone_dump(stdout);
295 else if (!strcmp(res->dump, "dump_log_history"))
296 rte_log_dump_history(stdout);
297 else if (!strcmp(res->dump, "dump_struct_sizes"))
299 else if (!strcmp(res->dump, "dump_ring"))
300 rte_ring_list_dump(stdout);
301 else if (!strcmp(res->dump, "dump_mempool"))
302 rte_mempool_list_dump(stdout);
303 else if (!strcmp(res->dump, "dump_devargs"))
304 rte_eal_devargs_dump(stdout);
307 cmdline_parse_token_string_t cmd_dump_dump =
308 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
309 "dump_physmem#dump_memzone#dump_log_history#"
310 "dump_struct_sizes#dump_ring#dump_mempool#"
313 cmdline_parse_inst_t cmd_dump = {
314 .f = cmd_dump_parsed, /* function to call */
315 .data = NULL, /* 2nd arg of func */
316 .help_str = "dump status",
317 .tokens = { /* token list, NULL terminated */
318 (void *)&cmd_dump_dump,
325 struct cmd_dump_one_result {
326 cmdline_fixed_string_t dump;
327 cmdline_fixed_string_t name;
330 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
331 __attribute__((unused)) void *data)
333 struct cmd_dump_one_result *res = parsed_result;
335 if (!strcmp(res->dump, "dump_ring")) {
337 r = rte_ring_lookup(res->name);
339 cmdline_printf(cl, "Cannot find ring\n");
342 rte_ring_dump(stdout, r);
344 else if (!strcmp(res->dump, "dump_mempool")) {
345 struct rte_mempool *mp;
346 mp = rte_mempool_lookup(res->name);
348 cmdline_printf(cl, "Cannot find mempool\n");
351 rte_mempool_dump(stdout, mp);
355 cmdline_parse_token_string_t cmd_dump_one_dump =
356 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
357 "dump_ring#dump_mempool");
359 cmdline_parse_token_string_t cmd_dump_one_name =
360 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
362 cmdline_parse_inst_t cmd_dump_one = {
363 .f = cmd_dump_one_parsed, /* function to call */
364 .data = NULL, /* 2nd arg of func */
365 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
366 .tokens = { /* token list, NULL terminated */
367 (void *)&cmd_dump_one_dump,
368 (void *)&cmd_dump_one_name,
375 struct cmd_set_ring_result {
376 cmdline_fixed_string_t set;
377 cmdline_fixed_string_t name;
381 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
382 __attribute__((unused)) void *data)
384 struct cmd_set_ring_result *res = parsed_result;
388 r = rte_ring_lookup(res->name);
390 cmdline_printf(cl, "Cannot find ring\n");
394 if (!strcmp(res->set, "set_watermark")) {
395 ret = rte_ring_set_water_mark(r, res->value);
397 cmdline_printf(cl, "Cannot set water mark\n");
401 cmdline_parse_token_string_t cmd_set_ring_set =
402 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
405 cmdline_parse_token_string_t cmd_set_ring_name =
406 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
408 cmdline_parse_token_num_t cmd_set_ring_value =
409 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
411 cmdline_parse_inst_t cmd_set_ring = {
412 .f = cmd_set_ring_parsed, /* function to call */
413 .data = NULL, /* 2nd arg of func */
414 .help_str = "set watermark: "
415 "set_watermark <ring_name> <value>",
416 .tokens = { /* token list, NULL terminated */
417 (void *)&cmd_set_ring_set,
418 (void *)&cmd_set_ring_name,
419 (void *)&cmd_set_ring_value,
426 struct cmd_quit_result {
427 cmdline_fixed_string_t quit;
431 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
433 __attribute__((unused)) void *data)
438 cmdline_parse_token_string_t cmd_quit_quit =
439 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
442 cmdline_parse_inst_t cmd_quit = {
443 .f = cmd_quit_parsed, /* function to call */
444 .data = NULL, /* 2nd arg of func */
445 .help_str = "exit application",
446 .tokens = { /* token list, NULL terminated */
447 (void *)&cmd_quit_quit,
454 cmdline_parse_ctx_t main_ctx[] = {
455 (cmdline_parse_inst_t *)&cmd_autotest,
456 (cmdline_parse_inst_t *)&cmd_dump,
457 (cmdline_parse_inst_t *)&cmd_dump_one,
458 (cmdline_parse_inst_t *)&cmd_set_ring,
459 (cmdline_parse_inst_t *)&cmd_quit,