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.
39 #include <netinet/in.h>
43 #include <net/socket.h>
48 #include <sys/queue.h>
50 #include <rte_common.h>
52 #include <rte_debug.h>
53 #include <rte_memory.h>
54 #include <rte_memcpy.h>
55 #include <rte_memzone.h>
56 #include <rte_launch.h>
57 #include <rte_cycles.h>
58 #include <rte_tailq.h>
60 #include <rte_per_lcore.h>
61 #include <rte_lcore.h>
62 #include <rte_atomic.h>
63 #include <rte_branch_prediction.h>
65 #include <rte_mempool.h>
68 #include <cmdline_rdline.h>
69 #include <cmdline_parse.h>
70 #include <cmdline_parse_ipaddr.h>
71 #include <cmdline_parse_num.h>
72 #include <cmdline_parse_string.h>
79 struct cmd_autotest_result {
80 cmdline_fixed_string_t autotest;
83 static void cmd_autotest_parsed(void *parsed_result,
84 __attribute__((unused)) struct cmdline *cl,
85 __attribute__((unused)) void *data)
87 struct cmd_autotest_result *res = parsed_result;
90 if (!strcmp(res->autotest, "version_autotest"))
92 if (!strcmp(res->autotest, "eal_fs_autotest"))
94 if (!strcmp(res->autotest, "debug_autotest"))
96 if (!strcmp(res->autotest, "pci_autotest"))
98 if (!strcmp(res->autotest, "prefetch_autotest"))
99 ret = test_prefetch();
100 if (!strcmp(res->autotest, "byteorder_autotest"))
101 ret = test_byteorder();
102 if (!strcmp(res->autotest, "per_lcore_autotest"))
103 ret = test_per_lcore();
104 if (!strcmp(res->autotest, "atomic_autotest"))
106 if (!strcmp(res->autotest, "malloc_autotest"))
108 if (!strcmp(res->autotest, "spinlock_autotest"))
109 ret = test_spinlock();
110 if (!strcmp(res->autotest, "memory_autotest"))
112 if (!strcmp(res->autotest, "memzone_autotest"))
113 ret = test_memzone();
114 if (!strcmp(res->autotest, "rwlock_autotest"))
116 if (!strcmp(res->autotest, "mbuf_autotest"))
118 if (!strcmp(res->autotest, "logs_autotest"))
120 if (!strcmp(res->autotest, "errno_autotest"))
122 if (!strcmp(res->autotest, "hash_autotest"))
124 if (!strcmp(res->autotest, "hash_perf_autotest"))
125 ret = test_hash_perf();
126 if (!strcmp(res->autotest, "lpm_autotest"))
128 if (!strcmp(res->autotest, "lpm6_autotest"))
130 if (!strcmp(res->autotest, "cpuflags_autotest"))
131 ret = test_cpuflags();
132 if (!strcmp(res->autotest, "cmdline_autotest"))
133 ret = test_cmdline();
134 if (!strcmp(res->autotest, "tailq_autotest"))
136 if (!strcmp(res->autotest, "multiprocess_autotest"))
137 ret = test_mp_secondary();
138 if (!strcmp(res->autotest, "memcpy_autotest"))
140 if (!strcmp(res->autotest, "string_autotest"))
141 ret = test_string_fns();
142 if (!strcmp(res->autotest, "eal_flags_autotest"))
143 ret = test_eal_flags();
144 if (!strcmp(res->autotest, "alarm_autotest"))
146 if (!strcmp(res->autotest, "interrupt_autotest"))
147 ret = test_interrupt();
148 if (!strcmp(res->autotest, "cycles_autotest"))
150 if (!strcmp(res->autotest, "ring_autotest"))
152 if (!strcmp(res->autotest, "ring_perf_autotest"))
153 ret = test_ring_perf();
154 if (!strcmp(res->autotest, "timer_autotest"))
156 if (!strcmp(res->autotest, "timer_perf_autotest"))
157 ret = test_timer_perf();
158 if (!strcmp(res->autotest, "mempool_autotest"))
159 ret = test_mempool();
160 if (!strcmp(res->autotest, "mempool_perf_autotest"))
161 ret = test_mempool_perf();
162 if (!strcmp(res->autotest, "memcpy_perf_autotest"))
163 ret = test_memcpy_perf();
164 if (!strcmp(res->autotest, "func_reentrancy_autotest"))
165 ret = test_func_reentrancy();
166 if (!strcmp(res->autotest, "red_autotest"))
168 if (!strcmp(res->autotest, "sched_autotest"))
170 if (!strcmp(res->autotest, "meter_autotest"))
172 if (!strcmp(res->autotest, "kni_autotest"))
174 if (!strcmp(res->autotest, "power_autotest"))
176 if (!strcmp(res->autotest, "common_autotest"))
178 if (!strcmp(res->autotest, "ivshmem_autotest"))
179 ret = test_ivshmem();
180 #ifdef RTE_LIBRTE_PMD_RING
181 if (!strcmp(res->autotest, "ring_pmd_autotest"))
182 ret = test_pmd_ring();
183 #endif /* RTE_LIBRTE_PMD_RING */
185 #ifdef RTE_LIBRTE_ACL
186 if (!strcmp(res->autotest, "acl_autotest"))
188 #endif /* RTE_LIBRTE_ACL */
193 printf("Test Failed\n");
197 cmdline_parse_token_string_t cmd_autotest_autotest =
198 TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest,
199 "pci_autotest#memory_autotest#"
200 "per_lcore_autotest#spinlock_autotest#"
201 "rwlock_autotest#atomic_autotest#"
202 "byteorder_autotest#prefetch_autotest#"
203 "cycles_autotest#logs_autotest#"
204 "memzone_autotest#ring_autotest#"
205 "mempool_autotest#mbuf_autotest#"
206 "timer_autotest#malloc_autotest#"
207 "memcpy_autotest#hash_autotest#"
208 "lpm_autotest#debug_autotest#"
210 "errno_autotest#tailq_autotest#"
211 "string_autotest#multiprocess_autotest#"
212 "cpuflags_autotest#eal_flags_autotest#"
213 "alarm_autotest#interrupt_autotest#"
214 "version_autotest#eal_fs_autotest#"
215 "cmdline_autotest#func_reentrancy_autotest#"
216 "mempool_perf_autotest#hash_perf_autotest#"
217 "memcpy_perf_autotest#ring_perf_autotest#"
218 "red_autotest#meter_autotest#sched_autotest#"
219 "memcpy_perf_autotest#kni_autotest#"
220 "pm_autotest#ivshmem_autotest#"
221 #ifdef RTE_LIBRTE_ACL
225 "timer_perf_autotest#"
226 #ifdef RTE_LIBRTE_PMD_RING
231 cmdline_parse_inst_t cmd_autotest = {
232 .f = cmd_autotest_parsed, /* function to call */
233 .data = NULL, /* 2nd arg of func */
234 .help_str = "launch autotest",
235 .tokens = { /* token list, NULL terminated */
236 (void *)&cmd_autotest_autotest,
243 struct cmd_dump_result {
244 cmdline_fixed_string_t dump;
248 dump_struct_sizes(void)
250 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
251 DUMP_SIZE(struct rte_mbuf);
252 DUMP_SIZE(struct rte_pktmbuf);
253 DUMP_SIZE(struct rte_ctrlmbuf);
254 DUMP_SIZE(struct rte_mempool);
255 DUMP_SIZE(struct rte_ring);
259 static void cmd_dump_parsed(void *parsed_result,
260 __attribute__((unused)) struct cmdline *cl,
261 __attribute__((unused)) void *data)
263 struct cmd_dump_result *res = parsed_result;
265 if (!strcmp(res->dump, "dump_physmem"))
266 rte_dump_physmem_layout();
267 else if (!strcmp(res->dump, "dump_memzone"))
269 else if (!strcmp(res->dump, "dump_log_history"))
270 rte_log_dump_history();
271 else if (!strcmp(res->dump, "dump_struct_sizes"))
273 else if (!strcmp(res->dump, "dump_ring"))
274 rte_ring_list_dump();
275 else if (!strcmp(res->dump, "dump_mempool"))
276 rte_mempool_list_dump();
279 cmdline_parse_token_string_t cmd_dump_dump =
280 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
281 "dump_physmem#dump_memzone#dump_log_history#"
282 "dump_struct_sizes#dump_ring#dump_mempool");
284 cmdline_parse_inst_t cmd_dump = {
285 .f = cmd_dump_parsed, /* function to call */
286 .data = NULL, /* 2nd arg of func */
287 .help_str = "dump status",
288 .tokens = { /* token list, NULL terminated */
289 (void *)&cmd_dump_dump,
296 struct cmd_dump_one_result {
297 cmdline_fixed_string_t dump;
298 cmdline_fixed_string_t name;
301 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
302 __attribute__((unused)) void *data)
304 struct cmd_dump_one_result *res = parsed_result;
306 if (!strcmp(res->dump, "dump_ring")) {
308 r = rte_ring_lookup(res->name);
310 cmdline_printf(cl, "Cannot find ring\n");
315 else if (!strcmp(res->dump, "dump_mempool")) {
316 struct rte_mempool *mp;
317 mp = rte_mempool_lookup(res->name);
319 cmdline_printf(cl, "Cannot find mempool\n");
322 rte_mempool_dump(mp);
326 cmdline_parse_token_string_t cmd_dump_one_dump =
327 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
328 "dump_ring#dump_mempool");
330 cmdline_parse_token_string_t cmd_dump_one_name =
331 TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
333 cmdline_parse_inst_t cmd_dump_one = {
334 .f = cmd_dump_one_parsed, /* function to call */
335 .data = NULL, /* 2nd arg of func */
336 .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
337 .tokens = { /* token list, NULL terminated */
338 (void *)&cmd_dump_one_dump,
339 (void *)&cmd_dump_one_name,
346 struct cmd_set_ring_result {
347 cmdline_fixed_string_t set;
348 cmdline_fixed_string_t name;
352 static void cmd_set_ring_parsed(void *parsed_result, struct cmdline *cl,
353 __attribute__((unused)) void *data)
355 struct cmd_set_ring_result *res = parsed_result;
359 r = rte_ring_lookup(res->name);
361 cmdline_printf(cl, "Cannot find ring\n");
365 if (!strcmp(res->set, "set_watermark")) {
366 ret = rte_ring_set_water_mark(r, res->value);
368 cmdline_printf(cl, "Cannot set water mark\n");
372 cmdline_parse_token_string_t cmd_set_ring_set =
373 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, set,
376 cmdline_parse_token_string_t cmd_set_ring_name =
377 TOKEN_STRING_INITIALIZER(struct cmd_set_ring_result, name, NULL);
379 cmdline_parse_token_num_t cmd_set_ring_value =
380 TOKEN_NUM_INITIALIZER(struct cmd_set_ring_result, value, UINT32);
382 cmdline_parse_inst_t cmd_set_ring = {
383 .f = cmd_set_ring_parsed, /* function to call */
384 .data = NULL, /* 2nd arg of func */
385 .help_str = "set watermark: "
386 "set_watermark <ring_name> <value>",
387 .tokens = { /* token list, NULL terminated */
388 (void *)&cmd_set_ring_set,
389 (void *)&cmd_set_ring_name,
390 (void *)&cmd_set_ring_value,
397 struct cmd_quit_result {
398 cmdline_fixed_string_t quit;
402 cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
404 __attribute__((unused)) void *data)
409 cmdline_parse_token_string_t cmd_quit_quit =
410 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit,
413 cmdline_parse_inst_t cmd_quit = {
414 .f = cmd_quit_parsed, /* function to call */
415 .data = NULL, /* 2nd arg of func */
416 .help_str = "exit application",
417 .tokens = { /* token list, NULL terminated */
418 (void *)&cmd_quit_quit,
425 cmdline_parse_ctx_t main_ctx[] = {
426 (cmdline_parse_inst_t *)&cmd_autotest,
427 (cmdline_parse_inst_t *)&cmd_dump,
428 (cmdline_parse_inst_t *)&cmd_dump_one,
429 (cmdline_parse_inst_t *)&cmd_set_ring,
430 (cmdline_parse_inst_t *)&cmd_quit,