1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <cmdline_rdline.h>
11 #include <cmdline_parse.h>
12 #include <cmdline_parse_num.h>
13 #include <cmdline_parse_string.h>
14 #include <cmdline_socket.h>
19 /* *** Help command with introduction. *** */
20 struct cmd_help_result {
21 cmdline_fixed_string_t help;
24 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
26 __attribute__((unused)) void *data)
31 "The following commands are currently available:\n\n"
33 " quit : Quit the application.\n"
35 " stats app : Show app statistics.\n"
36 " stats port X subport Y : Show stats of a specific subport.\n"
37 " stats port X subport Y pipe Z : Show stats of a specific pipe.\n"
38 "\nAverage queue size:\n"
39 " qavg port X subport Y : Show average queue size per subport.\n"
40 " qavg port X subport Y tc Z : Show average queue size per subport and TC.\n"
41 " qavg port X subport Y pipe Z : Show average queue size per pipe.\n"
42 " qavg port X subport Y pipe Z tc A : Show average queue size per pipe and TC.\n"
43 " qavg port X subport Y pipe Z tc A q B : Show average queue size of a specific queue.\n"
44 " qavg [n|period] X : Set number of times and peiod (us).\n\n"
49 cmdline_parse_token_string_t cmd_help_help =
50 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
52 cmdline_parse_inst_t cmd_help = {
55 .help_str = "show help",
57 (void *)&cmd_help_help,
63 struct cmd_quit_result {
64 cmdline_fixed_string_t quit;
67 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
69 __attribute__((unused)) void *data)
74 cmdline_parse_token_string_t cmd_quit_quit =
75 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
77 cmdline_parse_inst_t cmd_quit = {
80 .help_str = "exit application",
82 (void *)&cmd_quit_quit,
87 /* *** SET QAVG PARAMETERS *** */
88 struct cmd_setqavg_result {
89 cmdline_fixed_string_t qavg_string;
90 cmdline_fixed_string_t param_string;
94 static void cmd_setqavg_parsed(void *parsed_result,
95 __attribute__((unused)) struct cmdline *cl,
96 __attribute__((unused)) void *data)
98 struct cmd_setqavg_result *res = parsed_result;
100 if (!strcmp(res->param_string, "period"))
101 qavg_period = res->number;
102 else if (!strcmp(res->param_string, "n"))
103 qavg_ntimes = res->number;
105 printf("\nUnknown parameter.\n\n");
108 cmdline_parse_token_string_t cmd_setqavg_qavg_string =
109 TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, qavg_string,
111 cmdline_parse_token_string_t cmd_setqavg_param_string =
112 TOKEN_STRING_INITIALIZER(struct cmd_setqavg_result, param_string,
114 cmdline_parse_token_num_t cmd_setqavg_number =
115 TOKEN_NUM_INITIALIZER(struct cmd_setqavg_result, number,
118 cmdline_parse_inst_t cmd_setqavg = {
119 .f = cmd_setqavg_parsed,
121 .help_str = "Show subport stats.",
123 (void *)&cmd_setqavg_qavg_string,
124 (void *)&cmd_setqavg_param_string,
125 (void *)&cmd_setqavg_number,
130 /* *** SHOW APP STATS *** */
131 struct cmd_appstats_result {
132 cmdline_fixed_string_t stats_string;
133 cmdline_fixed_string_t app_string;
136 static void cmd_appstats_parsed(__attribute__((unused)) void *parsed_result,
137 __attribute__((unused)) struct cmdline *cl,
138 __attribute__((unused)) void *data)
143 cmdline_parse_token_string_t cmd_appstats_stats_string =
144 TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, stats_string,
146 cmdline_parse_token_string_t cmd_appstats_app_string =
147 TOKEN_STRING_INITIALIZER(struct cmd_appstats_result, app_string,
150 cmdline_parse_inst_t cmd_appstats = {
151 .f = cmd_appstats_parsed,
153 .help_str = "Show app stats.",
155 (void *)&cmd_appstats_stats_string,
156 (void *)&cmd_appstats_app_string,
161 /* *** SHOW SUBPORT STATS *** */
162 struct cmd_subportstats_result {
163 cmdline_fixed_string_t stats_string;
164 cmdline_fixed_string_t port_string;
165 uint16_t port_number;
166 cmdline_fixed_string_t subport_string;
167 uint32_t subport_number;
170 static void cmd_subportstats_parsed(void *parsed_result,
171 __attribute__((unused)) struct cmdline *cl,
172 __attribute__((unused)) void *data)
174 struct cmd_subportstats_result *res = parsed_result;
176 if (subport_stat(res->port_number, res->subport_number) < 0)
177 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
180 cmdline_parse_token_string_t cmd_subportstats_stats_string =
181 TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, stats_string,
183 cmdline_parse_token_string_t cmd_subportstats_port_string =
184 TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, port_string,
186 cmdline_parse_token_string_t cmd_subportstats_subport_string =
187 TOKEN_STRING_INITIALIZER(struct cmd_subportstats_result, subport_string,
189 cmdline_parse_token_num_t cmd_subportstats_subport_number =
190 TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, subport_number,
192 cmdline_parse_token_num_t cmd_subportstats_port_number =
193 TOKEN_NUM_INITIALIZER(struct cmd_subportstats_result, port_number,
196 cmdline_parse_inst_t cmd_subportstats = {
197 .f = cmd_subportstats_parsed,
199 .help_str = "Show subport stats.",
201 (void *)&cmd_subportstats_stats_string,
202 (void *)&cmd_subportstats_port_string,
203 (void *)&cmd_subportstats_port_number,
204 (void *)&cmd_subportstats_subport_string,
205 (void *)&cmd_subportstats_subport_number,
210 /* *** SHOW PIPE STATS *** */
211 struct cmd_pipestats_result {
212 cmdline_fixed_string_t stats_string;
213 cmdline_fixed_string_t port_string;
214 uint16_t port_number;
215 cmdline_fixed_string_t subport_string;
216 uint32_t subport_number;
217 cmdline_fixed_string_t pipe_string;
218 uint32_t pipe_number;
221 static void cmd_pipestats_parsed(void *parsed_result,
222 __attribute__((unused)) struct cmdline *cl,
223 __attribute__((unused)) void *data)
225 struct cmd_pipestats_result *res = parsed_result;
227 if (pipe_stat(res->port_number, res->subport_number, res->pipe_number) < 0)
228 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
231 cmdline_parse_token_string_t cmd_pipestats_stats_string =
232 TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, stats_string,
234 cmdline_parse_token_string_t cmd_pipestats_port_string =
235 TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, port_string,
237 cmdline_parse_token_num_t cmd_pipestats_port_number =
238 TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, port_number,
240 cmdline_parse_token_string_t cmd_pipestats_subport_string =
241 TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, subport_string,
243 cmdline_parse_token_num_t cmd_pipestats_subport_number =
244 TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, subport_number,
246 cmdline_parse_token_string_t cmd_pipestats_pipe_string =
247 TOKEN_STRING_INITIALIZER(struct cmd_pipestats_result, pipe_string,
249 cmdline_parse_token_num_t cmd_pipestats_pipe_number =
250 TOKEN_NUM_INITIALIZER(struct cmd_pipestats_result, pipe_number,
253 cmdline_parse_inst_t cmd_pipestats = {
254 .f = cmd_pipestats_parsed,
256 .help_str = "Show pipe stats.",
258 (void *)&cmd_pipestats_stats_string,
259 (void *)&cmd_pipestats_port_string,
260 (void *)&cmd_pipestats_port_number,
261 (void *)&cmd_pipestats_subport_string,
262 (void *)&cmd_pipestats_subport_number,
263 (void *)&cmd_pipestats_pipe_string,
264 (void *)&cmd_pipestats_pipe_number,
269 /* *** SHOW AVERAGE QUEUE SIZE (QUEUE) *** */
270 struct cmd_avg_q_result {
271 cmdline_fixed_string_t qavg_string;
272 cmdline_fixed_string_t port_string;
273 uint16_t port_number;
274 cmdline_fixed_string_t subport_string;
275 uint32_t subport_number;
276 cmdline_fixed_string_t pipe_string;
277 uint32_t pipe_number;
278 cmdline_fixed_string_t tc_string;
280 cmdline_fixed_string_t q_string;
284 static void cmd_avg_q_parsed(void *parsed_result,
285 __attribute__((unused)) struct cmdline *cl,
286 __attribute__((unused)) void *data)
288 struct cmd_avg_q_result *res = parsed_result;
290 if (qavg_q(res->port_number, res->subport_number, res->pipe_number, res->tc_number, res->q_number) < 0)
291 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
294 cmdline_parse_token_string_t cmd_avg_q_qavg_string =
295 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, qavg_string,
297 cmdline_parse_token_string_t cmd_avg_q_port_string =
298 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, port_string,
300 cmdline_parse_token_num_t cmd_avg_q_port_number =
301 TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, port_number,
303 cmdline_parse_token_string_t cmd_avg_q_subport_string =
304 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, subport_string,
306 cmdline_parse_token_num_t cmd_avg_q_subport_number =
307 TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, subport_number,
309 cmdline_parse_token_string_t cmd_avg_q_pipe_string =
310 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, pipe_string,
312 cmdline_parse_token_num_t cmd_avg_q_pipe_number =
313 TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, pipe_number,
315 cmdline_parse_token_string_t cmd_avg_q_tc_string =
316 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, tc_string,
318 cmdline_parse_token_num_t cmd_avg_q_tc_number =
319 TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, tc_number,
321 cmdline_parse_token_string_t cmd_avg_q_q_string =
322 TOKEN_STRING_INITIALIZER(struct cmd_avg_q_result, q_string,
324 cmdline_parse_token_num_t cmd_avg_q_q_number =
325 TOKEN_NUM_INITIALIZER(struct cmd_avg_q_result, q_number,
328 cmdline_parse_inst_t cmd_avg_q = {
329 .f = cmd_avg_q_parsed,
331 .help_str = "Show pipe stats.",
333 (void *)&cmd_avg_q_qavg_string,
334 (void *)&cmd_avg_q_port_string,
335 (void *)&cmd_avg_q_port_number,
336 (void *)&cmd_avg_q_subport_string,
337 (void *)&cmd_avg_q_subport_number,
338 (void *)&cmd_avg_q_pipe_string,
339 (void *)&cmd_avg_q_pipe_number,
340 (void *)&cmd_avg_q_tc_string,
341 (void *)&cmd_avg_q_tc_number,
342 (void *)&cmd_avg_q_q_string,
343 (void *)&cmd_avg_q_q_number,
348 /* *** SHOW AVERAGE QUEUE SIZE (tc/pipe) *** */
349 struct cmd_avg_tcpipe_result {
350 cmdline_fixed_string_t qavg_string;
351 cmdline_fixed_string_t port_string;
352 uint16_t port_number;
353 cmdline_fixed_string_t subport_string;
354 uint32_t subport_number;
355 cmdline_fixed_string_t pipe_string;
356 uint32_t pipe_number;
357 cmdline_fixed_string_t tc_string;
361 static void cmd_avg_tcpipe_parsed(void *parsed_result,
362 __attribute__((unused)) struct cmdline *cl,
363 __attribute__((unused)) void *data)
365 struct cmd_avg_tcpipe_result *res = parsed_result;
367 if (qavg_tcpipe(res->port_number, res->subport_number, res->pipe_number, res->tc_number) < 0)
368 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
371 cmdline_parse_token_string_t cmd_avg_tcpipe_qavg_string =
372 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, qavg_string,
374 cmdline_parse_token_string_t cmd_avg_tcpipe_port_string =
375 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, port_string,
377 cmdline_parse_token_num_t cmd_avg_tcpipe_port_number =
378 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, port_number,
380 cmdline_parse_token_string_t cmd_avg_tcpipe_subport_string =
381 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, subport_string,
383 cmdline_parse_token_num_t cmd_avg_tcpipe_subport_number =
384 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, subport_number,
386 cmdline_parse_token_string_t cmd_avg_tcpipe_pipe_string =
387 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_string,
389 cmdline_parse_token_num_t cmd_avg_tcpipe_pipe_number =
390 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, pipe_number,
392 cmdline_parse_token_string_t cmd_avg_tcpipe_tc_string =
393 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcpipe_result, tc_string,
395 cmdline_parse_token_num_t cmd_avg_tcpipe_tc_number =
396 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcpipe_result, tc_number,
399 cmdline_parse_inst_t cmd_avg_tcpipe = {
400 .f = cmd_avg_tcpipe_parsed,
402 .help_str = "Show pipe stats.",
404 (void *)&cmd_avg_tcpipe_qavg_string,
405 (void *)&cmd_avg_tcpipe_port_string,
406 (void *)&cmd_avg_tcpipe_port_number,
407 (void *)&cmd_avg_tcpipe_subport_string,
408 (void *)&cmd_avg_tcpipe_subport_number,
409 (void *)&cmd_avg_tcpipe_pipe_string,
410 (void *)&cmd_avg_tcpipe_pipe_number,
411 (void *)&cmd_avg_tcpipe_tc_string,
412 (void *)&cmd_avg_tcpipe_tc_number,
417 /* *** SHOW AVERAGE QUEUE SIZE (pipe) *** */
418 struct cmd_avg_pipe_result {
419 cmdline_fixed_string_t qavg_string;
420 cmdline_fixed_string_t port_string;
421 uint16_t port_number;
422 cmdline_fixed_string_t subport_string;
423 uint32_t subport_number;
424 cmdline_fixed_string_t pipe_string;
425 uint32_t pipe_number;
428 static void cmd_avg_pipe_parsed(void *parsed_result,
429 __attribute__((unused)) struct cmdline *cl,
430 __attribute__((unused)) void *data)
432 struct cmd_avg_pipe_result *res = parsed_result;
434 if (qavg_pipe(res->port_number, res->subport_number, res->pipe_number) < 0)
435 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
438 cmdline_parse_token_string_t cmd_avg_pipe_qavg_string =
439 TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, qavg_string,
441 cmdline_parse_token_string_t cmd_avg_pipe_port_string =
442 TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, port_string,
444 cmdline_parse_token_num_t cmd_avg_pipe_port_number =
445 TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, port_number,
447 cmdline_parse_token_string_t cmd_avg_pipe_subport_string =
448 TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, subport_string,
450 cmdline_parse_token_num_t cmd_avg_pipe_subport_number =
451 TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, subport_number,
453 cmdline_parse_token_string_t cmd_avg_pipe_pipe_string =
454 TOKEN_STRING_INITIALIZER(struct cmd_avg_pipe_result, pipe_string,
456 cmdline_parse_token_num_t cmd_avg_pipe_pipe_number =
457 TOKEN_NUM_INITIALIZER(struct cmd_avg_pipe_result, pipe_number,
460 cmdline_parse_inst_t cmd_avg_pipe = {
461 .f = cmd_avg_pipe_parsed,
463 .help_str = "Show pipe stats.",
465 (void *)&cmd_avg_pipe_qavg_string,
466 (void *)&cmd_avg_pipe_port_string,
467 (void *)&cmd_avg_pipe_port_number,
468 (void *)&cmd_avg_pipe_subport_string,
469 (void *)&cmd_avg_pipe_subport_number,
470 (void *)&cmd_avg_pipe_pipe_string,
471 (void *)&cmd_avg_pipe_pipe_number,
476 /* *** SHOW AVERAGE QUEUE SIZE (tc/subport) *** */
477 struct cmd_avg_tcsubport_result {
478 cmdline_fixed_string_t qavg_string;
479 cmdline_fixed_string_t port_string;
480 uint16_t port_number;
481 cmdline_fixed_string_t subport_string;
482 uint32_t subport_number;
483 cmdline_fixed_string_t tc_string;
487 static void cmd_avg_tcsubport_parsed(void *parsed_result,
488 __attribute__((unused)) struct cmdline *cl,
489 __attribute__((unused)) void *data)
491 struct cmd_avg_tcsubport_result *res = parsed_result;
493 if (qavg_tcsubport(res->port_number, res->subport_number, res->tc_number) < 0)
494 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
497 cmdline_parse_token_string_t cmd_avg_tcsubport_qavg_string =
498 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, qavg_string,
500 cmdline_parse_token_string_t cmd_avg_tcsubport_port_string =
501 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, port_string,
503 cmdline_parse_token_num_t cmd_avg_tcsubport_port_number =
504 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, port_number,
506 cmdline_parse_token_string_t cmd_avg_tcsubport_subport_string =
507 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, subport_string,
509 cmdline_parse_token_num_t cmd_avg_tcsubport_subport_number =
510 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, subport_number,
512 cmdline_parse_token_string_t cmd_avg_tcsubport_tc_string =
513 TOKEN_STRING_INITIALIZER(struct cmd_avg_tcsubport_result, tc_string,
515 cmdline_parse_token_num_t cmd_avg_tcsubport_tc_number =
516 TOKEN_NUM_INITIALIZER(struct cmd_avg_tcsubport_result, tc_number,
519 cmdline_parse_inst_t cmd_avg_tcsubport = {
520 .f = cmd_avg_tcsubport_parsed,
522 .help_str = "Show pipe stats.",
524 (void *)&cmd_avg_tcsubport_qavg_string,
525 (void *)&cmd_avg_tcsubport_port_string,
526 (void *)&cmd_avg_tcsubport_port_number,
527 (void *)&cmd_avg_tcsubport_subport_string,
528 (void *)&cmd_avg_tcsubport_subport_number,
529 (void *)&cmd_avg_tcsubport_tc_string,
530 (void *)&cmd_avg_tcsubport_tc_number,
535 /* *** SHOW AVERAGE QUEUE SIZE (subport) *** */
536 struct cmd_avg_subport_result {
537 cmdline_fixed_string_t qavg_string;
538 cmdline_fixed_string_t port_string;
539 uint16_t port_number;
540 cmdline_fixed_string_t subport_string;
541 uint32_t subport_number;
544 static void cmd_avg_subport_parsed(void *parsed_result,
545 __attribute__((unused)) struct cmdline *cl,
546 __attribute__((unused)) void *data)
548 struct cmd_avg_subport_result *res = parsed_result;
550 if (qavg_subport(res->port_number, res->subport_number) < 0)
551 printf ("\nStats not available for these parameters. Check that both the port and subport are correct.\n\n");
554 cmdline_parse_token_string_t cmd_avg_subport_qavg_string =
555 TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, qavg_string,
557 cmdline_parse_token_string_t cmd_avg_subport_port_string =
558 TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, port_string,
560 cmdline_parse_token_num_t cmd_avg_subport_port_number =
561 TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, port_number,
563 cmdline_parse_token_string_t cmd_avg_subport_subport_string =
564 TOKEN_STRING_INITIALIZER(struct cmd_avg_subport_result, subport_string,
566 cmdline_parse_token_num_t cmd_avg_subport_subport_number =
567 TOKEN_NUM_INITIALIZER(struct cmd_avg_subport_result, subport_number,
570 cmdline_parse_inst_t cmd_avg_subport = {
571 .f = cmd_avg_subport_parsed,
573 .help_str = "Show pipe stats.",
575 (void *)&cmd_avg_subport_qavg_string,
576 (void *)&cmd_avg_subport_port_string,
577 (void *)&cmd_avg_subport_port_number,
578 (void *)&cmd_avg_subport_subport_string,
579 (void *)&cmd_avg_subport_subport_number,
584 /* ******************************************************************************** */
586 /* list of instructions */
587 cmdline_parse_ctx_t main_ctx[] = {
588 (cmdline_parse_inst_t *)&cmd_help,
589 (cmdline_parse_inst_t *)&cmd_setqavg,
590 (cmdline_parse_inst_t *)&cmd_appstats,
591 (cmdline_parse_inst_t *)&cmd_subportstats,
592 (cmdline_parse_inst_t *)&cmd_pipestats,
593 (cmdline_parse_inst_t *)&cmd_avg_q,
594 (cmdline_parse_inst_t *)&cmd_avg_tcpipe,
595 (cmdline_parse_inst_t *)&cmd_avg_pipe,
596 (cmdline_parse_inst_t *)&cmd_avg_tcsubport,
597 (cmdline_parse_inst_t *)&cmd_avg_subport,
598 (cmdline_parse_inst_t *)&cmd_quit,
602 /* prompt function, called from main on MASTER lcore */
608 cl = cmdline_stdin_new(main_ctx, "qos_sched> ");
612 cmdline_interact(cl);
613 cmdline_stdin_exit(cl);