xref: /dpdk/app/proc-info/main.c (revision 68a03efeed657e6e05f281479b33b51102797e15)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4 
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include <errno.h>
10 #include <stdarg.h>
11 #include <inttypes.h>
12 #include <sys/queue.h>
13 #include <stdlib.h>
14 #include <getopt.h>
15 #include <unistd.h>
16 #include <strings.h>
17 
18 #include <rte_eal.h>
19 #include <rte_common.h>
20 #include <rte_debug.h>
21 #include <rte_ethdev.h>
22 #include <rte_malloc.h>
23 #include <rte_memory.h>
24 #include <rte_memzone.h>
25 #include <rte_launch.h>
26 #include <rte_tailq.h>
27 #include <rte_per_lcore.h>
28 #include <rte_lcore.h>
29 #include <rte_log.h>
30 #include <rte_atomic.h>
31 #include <rte_branch_prediction.h>
32 #include <rte_string_fns.h>
33 #include <rte_metrics.h>
34 #include <rte_cycles.h>
35 #ifdef RTE_LIB_SECURITY
36 #include <rte_security.h>
37 #endif
38 #include <rte_cryptodev.h>
39 #include <rte_tm.h>
40 #include <rte_hexdump.h>
41 
42 /* Maximum long option length for option parsing. */
43 #define MAX_LONG_OPT_SZ 64
44 #define MAX_STRING_LEN 256
45 
46 #define STATS_BDR_FMT "========================================"
47 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \
48 	STATS_BDR_FMT, s, w, STATS_BDR_FMT)
49 
50 /**< mask of enabled ports */
51 static unsigned long enabled_port_mask;
52 /**< Enable stats. */
53 static uint32_t enable_stats;
54 /**< Enable xstats. */
55 static uint32_t enable_xstats;
56 /**< Enable collectd format*/
57 static uint32_t enable_collectd_format;
58 /**< FD to send collectd format messages to STDOUT*/
59 static int stdout_fd;
60 /**< Host id process is running on */
61 static char host_id[MAX_LONG_OPT_SZ];
62 /**< Enable metrics. */
63 static uint32_t enable_metrics;
64 /**< Enable stats reset. */
65 static uint32_t reset_stats;
66 /**< Enable xstats reset. */
67 static uint32_t reset_xstats;
68 /**< Enable memory info. */
69 static uint32_t mem_info;
70 /**< Enable displaying xstat name. */
71 static uint32_t enable_xstats_name;
72 static char *xstats_name;
73 
74 /**< Enable xstats by ids. */
75 #define MAX_NB_XSTATS_IDS 1024
76 static uint32_t nb_xstats_ids;
77 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
78 
79 /* show border */
80 static char bdr_str[MAX_STRING_LEN];
81 
82 /**< Enable show port. */
83 static uint32_t enable_shw_port;
84 /**< Enable show tm. */
85 static uint32_t enable_shw_tm;
86 /**< Enable show crypto. */
87 static uint32_t enable_shw_crypto;
88 /**< Enable show ring. */
89 static uint32_t enable_shw_ring;
90 static char *ring_name;
91 /**< Enable show mempool. */
92 static uint32_t enable_shw_mempool;
93 static char *mempool_name;
94 /**< Enable iter mempool. */
95 static uint32_t enable_iter_mempool;
96 static char *mempool_iter_name;
97 
98 /**< display usage */
99 static void
100 proc_info_usage(const char *prgname)
101 {
102 	printf("%s [EAL options] -- -p PORTMASK\n"
103 		"  -m to display DPDK memory zones, segments and TAILQ information\n"
104 		"  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
105 		"  --stats: to display port statistics, enabled by default\n"
106 		"  --xstats: to display extended port statistics, disabled by "
107 			"default\n"
108 		"  --metrics: to display derived metrics of the ports, disabled by "
109 			"default\n"
110 		"  --xstats-name NAME: to display single xstat id by NAME\n"
111 		"  --xstats-ids IDLIST: to display xstat values by id. "
112 			"The argument is comma-separated list of xstat ids to print out.\n"
113 		"  --stats-reset: to reset port statistics\n"
114 		"  --xstats-reset: to reset port extended statistics\n"
115 		"  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
116 		"  --host-id STRING: host id used to identify the system process is running on\n"
117 		"  --show-port: to display ports information\n"
118 		"  --show-tm: to display traffic manager information for ports\n"
119 		"  --show-crypto: to display crypto information\n"
120 		"  --show-ring[=name]: to display ring information\n"
121 		"  --show-mempool[=name]: to display mempool information\n"
122 		"  --iter-mempool=name: iterate mempool elements to display content\n",
123 		prgname);
124 }
125 
126 /*
127  * Parse the portmask provided at run time.
128  */
129 static int
130 parse_portmask(const char *portmask)
131 {
132 	char *end = NULL;
133 
134 	errno = 0;
135 
136 	/* parse hexadecimal string */
137 	enabled_port_mask = strtoul(portmask, &end, 16);
138 	if (portmask[0] == '\0' || end == NULL || *end != '\0' || errno != 0) {
139 		fprintf(stderr, "Invalid portmask '%s'\n", portmask);
140 		return -1;
141 	}
142 
143 	return 0;
144 }
145 
146 /*
147  * Parse ids value list into array
148  */
149 static int
150 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
151 	int length;
152 	char *token;
153 	char *ctx = NULL;
154 	char *endptr;
155 
156 	length = 0;
157 	token = strtok_r(list, ",", &ctx);
158 	while (token != NULL) {
159 		ids[length] = strtoull(token, &endptr, 10);
160 		if (*endptr != '\0')
161 			return -EINVAL;
162 
163 		length++;
164 		if (length >= limit)
165 			return -E2BIG;
166 
167 		token = strtok_r(NULL, ",", &ctx);
168 	}
169 
170 	return length;
171 }
172 
173 static int
174 proc_info_preparse_args(int argc, char **argv)
175 {
176 	char *prgname = argv[0];
177 	int i;
178 
179 	for (i = 0; i < argc; i++) {
180 		/* Print stats or xstats to STDOUT in collectd format */
181 		if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
182 			enable_collectd_format = 1;
183 			stdout_fd = dup(STDOUT_FILENO);
184 			close(STDOUT_FILENO);
185 		}
186 		if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
187 			if ((i + 1) == argc) {
188 				printf("Invalid host id or not specified\n");
189 				proc_info_usage(prgname);
190 				return -1;
191 			}
192 			strlcpy(host_id, argv[i + 1], sizeof(host_id));
193 		}
194 	}
195 
196 	if (!strlen(host_id)) {
197 		int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
198 
199 		if (err)
200 			strlcpy(host_id, "unknown", sizeof(host_id));
201 	}
202 
203 	return 0;
204 }
205 
206 /* Parse the argument given in the command line of the application */
207 static int
208 proc_info_parse_args(int argc, char **argv)
209 {
210 	int opt;
211 	int option_index;
212 	char *prgname = argv[0];
213 	static struct option long_option[] = {
214 		{"stats", 0, NULL, 0},
215 		{"stats-reset", 0, NULL, 0},
216 		{"xstats", 0, NULL, 0},
217 		{"metrics", 0, NULL, 0},
218 		{"xstats-reset", 0, NULL, 0},
219 		{"xstats-name", required_argument, NULL, 1},
220 		{"collectd-format", 0, NULL, 0},
221 		{"xstats-ids", 1, NULL, 1},
222 		{"host-id", 0, NULL, 0},
223 		{"show-port", 0, NULL, 0},
224 		{"show-tm", 0, NULL, 0},
225 		{"show-crypto", 0, NULL, 0},
226 		{"show-ring", optional_argument, NULL, 0},
227 		{"show-mempool", optional_argument, NULL, 0},
228 		{"iter-mempool", required_argument, NULL, 0},
229 		{NULL, 0, 0, 0}
230 	};
231 
232 	if (argc == 1)
233 		proc_info_usage(prgname);
234 
235 	/* Parse command line */
236 	while ((opt = getopt_long(argc, argv, "p:m",
237 			long_option, &option_index)) != EOF) {
238 		switch (opt) {
239 		/* portmask */
240 		case 'p':
241 			if (parse_portmask(optarg) < 0) {
242 				proc_info_usage(prgname);
243 				return -1;
244 			}
245 			break;
246 		case 'm':
247 			mem_info = 1;
248 			break;
249 		case 0:
250 			/* Print stats */
251 			if (!strncmp(long_option[option_index].name, "stats",
252 					MAX_LONG_OPT_SZ))
253 				enable_stats = 1;
254 			/* Print xstats */
255 			else if (!strncmp(long_option[option_index].name, "xstats",
256 					MAX_LONG_OPT_SZ))
257 				enable_xstats = 1;
258 			else if (!strncmp(long_option[option_index].name,
259 					"metrics",
260 					MAX_LONG_OPT_SZ))
261 				enable_metrics = 1;
262 			/* Reset stats */
263 			if (!strncmp(long_option[option_index].name, "stats-reset",
264 					MAX_LONG_OPT_SZ))
265 				reset_stats = 1;
266 			/* Reset xstats */
267 			else if (!strncmp(long_option[option_index].name, "xstats-reset",
268 					MAX_LONG_OPT_SZ))
269 				reset_xstats = 1;
270 			else if (!strncmp(long_option[option_index].name,
271 					"show-port", MAX_LONG_OPT_SZ))
272 				enable_shw_port = 1;
273 			else if (!strncmp(long_option[option_index].name,
274 					"show-tm", MAX_LONG_OPT_SZ))
275 				enable_shw_tm = 1;
276 			else if (!strncmp(long_option[option_index].name,
277 					"show-crypto", MAX_LONG_OPT_SZ))
278 				enable_shw_crypto = 1;
279 			else if (!strncmp(long_option[option_index].name,
280 					"show-ring", MAX_LONG_OPT_SZ)) {
281 				enable_shw_ring = 1;
282 				ring_name = optarg;
283 			} else if (!strncmp(long_option[option_index].name,
284 					"show-mempool", MAX_LONG_OPT_SZ)) {
285 				enable_shw_mempool = 1;
286 				mempool_name = optarg;
287 			} else if (!strncmp(long_option[option_index].name,
288 					"iter-mempool", MAX_LONG_OPT_SZ)) {
289 				enable_iter_mempool = 1;
290 				mempool_iter_name = optarg;
291 			}
292 			break;
293 		case 1:
294 			/* Print xstat single value given by name*/
295 			if (!strncmp(long_option[option_index].name,
296 					"xstats-name", MAX_LONG_OPT_SZ)) {
297 				enable_xstats_name = 1;
298 				xstats_name = optarg;
299 				printf("name:%s:%s\n",
300 						long_option[option_index].name,
301 						optarg);
302 			} else if (!strncmp(long_option[option_index].name,
303 					"xstats-ids",
304 					MAX_LONG_OPT_SZ))	{
305 				int ret = parse_xstats_ids(optarg,
306 						xstats_ids, MAX_NB_XSTATS_IDS);
307 				if (ret <= 0) {
308 					printf("xstats-id list parse error.\n");
309 					return -1;
310 				}
311 				nb_xstats_ids = ret;
312 			}
313 			break;
314 		default:
315 			proc_info_usage(prgname);
316 			return -1;
317 		}
318 	}
319 	return 0;
320 }
321 
322 static void
323 meminfo_display(void)
324 {
325 	printf("----------- MEMORY_SEGMENTS -----------\n");
326 	rte_dump_physmem_layout(stdout);
327 	printf("--------- END_MEMORY_SEGMENTS ---------\n");
328 
329 	printf("------------ MEMORY_ZONES -------------\n");
330 	rte_memzone_dump(stdout);
331 	printf("---------- END_MEMORY_ZONES -----------\n");
332 
333 	printf("------------- TAIL_QUEUES -------------\n");
334 	rte_dump_tailq(stdout);
335 	printf("---------- END_TAIL_QUEUES ------------\n");
336 }
337 
338 static void
339 nic_stats_display(uint16_t port_id)
340 {
341 	struct rte_eth_stats stats;
342 	uint8_t i;
343 
344 	static const char *nic_stats_border = "########################";
345 
346 	rte_eth_stats_get(port_id, &stats);
347 	printf("\n  %s NIC statistics for port %-2d %s\n",
348 		   nic_stats_border, port_id, nic_stats_border);
349 
350 	printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
351 	       "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
352 	       stats.ibytes);
353 	printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
354 	printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
355 	       "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
356 	       stats.obytes);
357 
358 	printf("\n");
359 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
360 		printf("  Stats reg %2d RX-packets: %-10"PRIu64
361 		       "  RX-errors: %-10"PRIu64
362 		       "  RX-bytes: %-10"PRIu64"\n",
363 		       i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
364 	}
365 
366 	printf("\n");
367 	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
368 		printf("  Stats reg %2d TX-packets: %-10"PRIu64
369 		       "  TX-bytes: %-10"PRIu64"\n",
370 		       i, stats.q_opackets[i], stats.q_obytes[i]);
371 	}
372 
373 	printf("  %s############################%s\n",
374 		   nic_stats_border, nic_stats_border);
375 }
376 
377 static void
378 nic_stats_clear(uint16_t port_id)
379 {
380 	printf("\n Clearing NIC stats for port %d\n", port_id);
381 	rte_eth_stats_reset(port_id);
382 	printf("\n  NIC statistics for port %d cleared\n", port_id);
383 }
384 
385 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
386 				      const char *cnt_name) {
387 	char *type_end = strrchr(cnt_name, '_');
388 
389 	if ((type_end != NULL) &&
390 	    (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
391 		if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
392 			strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
393 		else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
394 			strlcpy(cnt_type, "if_rx_dropped", cnt_type_len);
395 		else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
396 			strlcpy(cnt_type, "if_rx_octets", cnt_type_len);
397 		else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
398 			strlcpy(cnt_type, "if_rx_packets", cnt_type_len);
399 		else if (strncmp(type_end, "_placement",
400 				 strlen("_placement")) == 0)
401 			strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
402 		else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
403 			strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
404 		else
405 			/* Does not fit obvious type: use a more generic one */
406 			strlcpy(cnt_type, "derive", cnt_type_len);
407 	} else if ((type_end != NULL) &&
408 		(strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
409 		if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
410 			strlcpy(cnt_type, "if_tx_errors", cnt_type_len);
411 		else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
412 			strlcpy(cnt_type, "if_tx_dropped", cnt_type_len);
413 		else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
414 			strlcpy(cnt_type, "if_tx_octets", cnt_type_len);
415 		else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
416 			strlcpy(cnt_type, "if_tx_packets", cnt_type_len);
417 		else
418 			/* Does not fit obvious type: use a more generic one */
419 			strlcpy(cnt_type, "derive", cnt_type_len);
420 	} else if ((type_end != NULL) &&
421 		   (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
422 		if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
423 			strlcpy(cnt_type, "filter_result", cnt_type_len);
424 		else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
425 			strlcpy(cnt_type, "errors", cnt_type_len);
426 	} else if ((type_end != NULL) &&
427 		   (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
428 		if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
429 			strlcpy(cnt_type, "errors", cnt_type_len);
430 	} else {
431 		/* Does not fit obvious type, or strrchr error: */
432 		/* use a more generic type */
433 		strlcpy(cnt_type, "derive", cnt_type_len);
434 	}
435 }
436 
437 static void
438 nic_xstats_by_name_display(uint16_t port_id, char *name)
439 {
440 	uint64_t id;
441 
442 	printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
443 			   port_id, name);
444 
445 	if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
446 		printf("%s: %"PRIu64"\n", name, id);
447 	else
448 		printf("Statistic not found...\n");
449 
450 }
451 
452 static void
453 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
454 {
455 	struct rte_eth_xstat_name *xstats_names;
456 	uint64_t *values;
457 	int ret, i;
458 	static const char *nic_stats_border = "########################";
459 
460 	values = malloc(sizeof(*values) * len);
461 	if (values == NULL) {
462 		printf("Cannot allocate memory for xstats\n");
463 		return;
464 	}
465 
466 	xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
467 	if (xstats_names == NULL) {
468 		printf("Cannot allocate memory for xstat names\n");
469 		free(values);
470 		return;
471 	}
472 
473 	if (len != rte_eth_xstats_get_names_by_id(
474 			port_id, xstats_names, len, ids)) {
475 		printf("Cannot get xstat names\n");
476 		goto err;
477 	}
478 
479 	printf("###### NIC extended statistics for port %-2d #########\n",
480 			   port_id);
481 	printf("%s############################\n", nic_stats_border);
482 	ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
483 	if (ret < 0 || ret > len) {
484 		printf("Cannot get xstats\n");
485 		goto err;
486 	}
487 
488 	for (i = 0; i < len; i++)
489 		printf("%s: %"PRIu64"\n",
490 			xstats_names[i].name,
491 			values[i]);
492 
493 	printf("%s############################\n", nic_stats_border);
494 err:
495 	free(values);
496 	free(xstats_names);
497 }
498 
499 static void
500 nic_xstats_display(uint16_t port_id)
501 {
502 	struct rte_eth_xstat_name *xstats_names;
503 	uint64_t *values;
504 	int len, ret, i;
505 	static const char *nic_stats_border = "########################";
506 
507 	len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
508 	if (len < 0) {
509 		printf("Cannot get xstats count\n");
510 		return;
511 	}
512 	values = malloc(sizeof(*values) * len);
513 	if (values == NULL) {
514 		printf("Cannot allocate memory for xstats\n");
515 		return;
516 	}
517 
518 	xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
519 	if (xstats_names == NULL) {
520 		printf("Cannot allocate memory for xstat names\n");
521 		free(values);
522 		return;
523 	}
524 	if (len != rte_eth_xstats_get_names_by_id(
525 			port_id, xstats_names, len, NULL)) {
526 		printf("Cannot get xstat names\n");
527 		goto err;
528 	}
529 
530 	printf("###### NIC extended statistics for port %-2d #########\n",
531 			   port_id);
532 	printf("%s############################\n",
533 			   nic_stats_border);
534 	ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
535 	if (ret < 0 || ret > len) {
536 		printf("Cannot get xstats\n");
537 		goto err;
538 	}
539 
540 	for (i = 0; i < len; i++) {
541 		if (enable_collectd_format) {
542 			char counter_type[MAX_STRING_LEN];
543 			char buf[MAX_STRING_LEN];
544 			size_t n;
545 
546 			collectd_resolve_cnt_type(counter_type,
547 						  sizeof(counter_type),
548 						  xstats_names[i].name);
549 			n = snprintf(buf, MAX_STRING_LEN,
550 				"PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
551 				PRIu64"\n", host_id, port_id, counter_type,
552 				xstats_names[i].name, values[i]);
553 			if (n > sizeof(buf) - 1)
554 				n = sizeof(buf) - 1;
555 			ret = write(stdout_fd, buf, n);
556 			if (ret < 0)
557 				goto err;
558 		} else {
559 			printf("%s: %"PRIu64"\n", xstats_names[i].name,
560 					values[i]);
561 		}
562 	}
563 
564 	printf("%s############################\n",
565 			   nic_stats_border);
566 err:
567 	free(values);
568 	free(xstats_names);
569 }
570 
571 static void
572 nic_xstats_clear(uint16_t port_id)
573 {
574 	int ret;
575 
576 	printf("\n Clearing NIC xstats for port %d\n", port_id);
577 	ret = rte_eth_xstats_reset(port_id);
578 	if (ret != 0) {
579 		printf("\n Error clearing xstats for port %d: %s\n", port_id,
580 		       strerror(-ret));
581 		return;
582 	}
583 
584 	printf("\n  NIC extended statistics for port %d cleared\n", port_id);
585 }
586 
587 static void
588 metrics_display(int port_id)
589 {
590 	struct rte_metric_value *metrics;
591 	struct rte_metric_name *names;
592 	int len, ret;
593 	static const char *nic_stats_border = "########################";
594 
595 	len = rte_metrics_get_names(NULL, 0);
596 	if (len < 0) {
597 		printf("Cannot get metrics count\n");
598 		return;
599 	}
600 	if (len == 0) {
601 		printf("No metrics to display (none have been registered)\n");
602 		return;
603 	}
604 
605 	metrics = rte_malloc("proc_info_metrics",
606 		sizeof(struct rte_metric_value) * len, 0);
607 	if (metrics == NULL) {
608 		printf("Cannot allocate memory for metrics\n");
609 		return;
610 	}
611 
612 	names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
613 	if (names == NULL) {
614 		printf("Cannot allocate memory for metrcis names\n");
615 		rte_free(metrics);
616 		return;
617 	}
618 
619 	if (len != rte_metrics_get_names(names, len)) {
620 		printf("Cannot get metrics names\n");
621 		rte_free(metrics);
622 		rte_free(names);
623 		return;
624 	}
625 
626 	if (port_id == RTE_METRICS_GLOBAL)
627 		printf("###### Non port specific metrics  #########\n");
628 	else
629 		printf("###### metrics for port %-2d #########\n", port_id);
630 	printf("%s############################\n", nic_stats_border);
631 	ret = rte_metrics_get_values(port_id, metrics, len);
632 	if (ret < 0 || ret > len) {
633 		printf("Cannot get metrics values\n");
634 		rte_free(metrics);
635 		rte_free(names);
636 		return;
637 	}
638 
639 	int i;
640 	for (i = 0; i < len; i++)
641 		printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
642 
643 	printf("%s############################\n", nic_stats_border);
644 	rte_free(metrics);
645 	rte_free(names);
646 }
647 
648 static void
649 show_security_context(uint16_t portid, bool inline_offload)
650 {
651 	void *p_ctx;
652 	const struct rte_security_capability *s_cap;
653 
654 	if (inline_offload)
655 		p_ctx = rte_eth_dev_get_sec_ctx(portid);
656 	else
657 		p_ctx = rte_cryptodev_get_sec_ctx(portid);
658 
659 	if (p_ctx == NULL)
660 		return;
661 
662 	printf("  - crypto context\n");
663 	printf("\t  -- security context - %p\n", p_ctx);
664 	printf("\t  -- size %u\n",
665 	       rte_security_session_get_size(p_ctx));
666 
667 	s_cap = rte_security_capabilities_get(p_ctx);
668 	if (s_cap) {
669 		printf("\t  -- action (0x%x), protocol (0x%x),"
670 		       " offload flags (0x%x)\n",
671 		       s_cap->action,
672 		       s_cap->protocol,
673 		       s_cap->ol_flags);
674 		printf("\t  -- capabilities - oper type %x\n",
675 		       s_cap->crypto_capabilities->op);
676 	}
677 }
678 
679 static void
680 show_offloads(uint64_t offloads,
681 	      const char *(show_offload)(uint64_t))
682 {
683 	printf(" offloads :");
684 	while (offloads != 0) {
685 		uint64_t offload_flag = 1ULL << __builtin_ctzll(offloads);
686 		printf(" %s", show_offload(offload_flag));
687 		offloads &= ~offload_flag;
688 	}
689 }
690 
691 static void
692 show_port(void)
693 {
694 	int i, ret, j, k;
695 
696 	snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD ");
697 	STATS_BDR_STR(10, bdr_str);
698 
699 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
700 		uint16_t mtu = 0;
701 		struct rte_eth_link link;
702 		struct rte_eth_dev_info dev_info;
703 		struct rte_eth_rss_conf rss_conf;
704 		char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
705 		struct rte_eth_fc_conf fc_conf;
706 		struct rte_ether_addr mac;
707 		struct rte_eth_dev_owner owner;
708 
709 		/* Skip if port is not in mask */
710 		if ((enabled_port_mask & (1ul << i)) == 0)
711 			continue;
712 
713 		/* Skip if port is unused */
714 		if (!rte_eth_dev_is_valid_port(i))
715 			continue;
716 
717 		memset(&rss_conf, 0, sizeof(rss_conf));
718 
719 		snprintf(bdr_str, MAX_STRING_LEN, " Port %u ", i);
720 		STATS_BDR_STR(5, bdr_str);
721 		printf("  - generic config\n");
722 
723 		ret = rte_eth_dev_info_get(i, &dev_info);
724 		if (ret != 0) {
725 			printf("Error during getting device info: %s\n",
726 				strerror(-ret));
727 			return;
728 		}
729 
730 		printf("\t  -- driver %s device %s socket %d\n",
731 		       dev_info.driver_name, dev_info.device->name,
732 		       rte_eth_dev_socket_id(i));
733 
734 		ret = rte_eth_dev_owner_get(i, &owner);
735 		if (ret == 0 && owner.id != RTE_ETH_DEV_NO_OWNER)
736 			printf("\t --  owner %#"PRIx64":%s\n",
737 			       owner.id, owner.name);
738 
739 		ret = rte_eth_link_get(i, &link);
740 		if (ret < 0) {
741 			printf("Link get failed (port %u): %s\n",
742 			       i, rte_strerror(-ret));
743 		} else {
744 			rte_eth_link_to_str(link_status_text,
745 					sizeof(link_status_text),
746 					&link);
747 			printf("\t%s\n", link_status_text);
748 		}
749 
750 		ret = rte_eth_dev_flow_ctrl_get(i, &fc_conf);
751 		if (ret == 0 && fc_conf.mode != RTE_FC_NONE)  {
752 			printf("\t  -- flow control mode %s%s high %u low %u pause %u%s%s\n",
753 			       fc_conf.mode == RTE_FC_RX_PAUSE ? "rx " :
754 			       fc_conf.mode == RTE_FC_TX_PAUSE ? "tx " :
755 			       fc_conf.mode == RTE_FC_FULL ? "full" : "???",
756 			       fc_conf.autoneg ? " auto" : "",
757 			       fc_conf.high_water,
758 			       fc_conf.low_water,
759 			       fc_conf.pause_time,
760 			       fc_conf.send_xon ? " xon" : "",
761 			       fc_conf.mac_ctrl_frame_fwd ? " mac_ctrl" : "");
762 		}
763 
764 		ret = rte_eth_macaddr_get(i, &mac);
765 		if (ret == 0) {
766 			char ebuf[RTE_ETHER_ADDR_FMT_SIZE];
767 
768 			rte_ether_format_addr(ebuf, sizeof(ebuf), &mac);
769 			printf("\t  -- mac %s\n", ebuf);
770 		}
771 
772 		ret = rte_eth_promiscuous_get(i);
773 		if (ret >= 0)
774 			printf("\t  -- promiscuous mode %s\n",
775 			       ret > 0 ? "enabled" : "disabled");
776 
777 		ret = rte_eth_allmulticast_get(i);
778 		if (ret >= 0)
779 			printf("\t  -- all multicast mode %s\n",
780 			       ret > 0 ? "enabled" : "disabled");
781 
782 		ret = rte_eth_dev_get_mtu(i, &mtu);
783 		if (ret == 0)
784 			printf("\t  -- mtu (%d)\n", mtu);
785 
786 		for (j = 0; j < dev_info.nb_rx_queues; j++) {
787 			struct rte_eth_rxq_info queue_info;
788 			int count;
789 
790 			ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
791 			if (ret != 0)
792 				break;
793 
794 			if (j == 0)
795 				printf("  - rx queue\n");
796 
797 			printf("\t  -- %d descriptors ", j);
798 			count = rte_eth_rx_queue_count(i, j);
799 			if (count >= 0)
800 				printf("%d/", count);
801 			printf("%u", queue_info.nb_desc);
802 
803 			if (queue_info.scattered_rx)
804 				printf(" scattered");
805 
806 			if (queue_info.conf.rx_drop_en)
807 				printf(" drop_en");
808 
809 			if (queue_info.conf.rx_deferred_start)
810 				printf(" deferred_start");
811 
812 			if (queue_info.rx_buf_size != 0)
813 				printf(" rx buffer size %u",
814 				       queue_info.rx_buf_size);
815 
816 			printf(" mempool %s socket %d",
817 			       queue_info.mp->name,
818 			       queue_info.mp->socket_id);
819 
820 			if (queue_info.conf.offloads != 0)
821 				show_offloads(queue_info.conf.offloads, rte_eth_dev_rx_offload_name);
822 
823 			printf("\n");
824 		}
825 
826 		for (j = 0; j < dev_info.nb_tx_queues; j++) {
827 			struct rte_eth_txq_info queue_info;
828 
829 			ret = rte_eth_tx_queue_info_get(i, j, &queue_info);
830 			if (ret != 0)
831 				break;
832 
833 			if (j == 0)
834 				printf("  - tx queue\n");
835 
836 			printf("\t  -- %d descriptors %d",
837 			       j, queue_info.nb_desc);
838 
839 			printf(" thresh %u/%u",
840 			       queue_info.conf.tx_rs_thresh,
841 			       queue_info.conf.tx_free_thresh);
842 
843 			if (queue_info.conf.tx_deferred_start)
844 				printf(" deferred_start");
845 
846 			if (queue_info.conf.offloads != 0)
847 				show_offloads(queue_info.conf.offloads, rte_eth_dev_tx_offload_name);
848 			printf("\n");
849 		}
850 
851 		ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
852 		if (ret == 0) {
853 			if (rss_conf.rss_key) {
854 				printf("  - RSS\n");
855 				printf("\t  -- RSS len %u key (hex):",
856 						rss_conf.rss_key_len);
857 				for (k = 0; k < rss_conf.rss_key_len; k++)
858 					printf(" %x", rss_conf.rss_key[k]);
859 				printf("\t  -- hf 0x%"PRIx64"\n",
860 						rss_conf.rss_hf);
861 			}
862 		}
863 
864 #ifdef RTE_LIB_SECURITY
865 		show_security_context(i, true);
866 #endif
867 	}
868 }
869 
870 static void
871 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap)
872 {
873 	if (cap == NULL)
874 		return;
875 
876 	if (!is_leaf) {
877 		printf("\t  -- nonleaf sched max:\n"
878 			"\t\t  + children (%u)\n"
879 			"\t\t  + sp priorities (%u)\n"
880 			"\t\t  + wfq children per group (%u)\n"
881 			"\t\t  + wfq groups (%u)\n"
882 			"\t\t  + wfq weight (%u)\n",
883 			cap->nonleaf.sched_n_children_max,
884 			cap->nonleaf.sched_sp_n_priorities_max,
885 			cap->nonleaf.sched_wfq_n_children_per_group_max,
886 			cap->nonleaf.sched_wfq_n_groups_max,
887 			cap->nonleaf.sched_wfq_weight_max);
888 	} else {
889 		printf("\t  -- leaf cman support:\n"
890 			"\t\t  + wred pkt mode (%d)\n"
891 			"\t\t  + wred byte mode (%d)\n"
892 			"\t\t  + head drop (%d)\n"
893 			"\t\t  + wred context private (%d)\n"
894 			"\t\t  + wred context shared (%u)\n",
895 			cap->leaf.cman_wred_packet_mode_supported,
896 			cap->leaf.cman_wred_byte_mode_supported,
897 			cap->leaf.cman_head_drop_supported,
898 			cap->leaf.cman_wred_context_private_supported,
899 			cap->leaf.cman_wred_context_shared_n_max);
900 	}
901 }
902 
903 static void
904 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap)
905 {
906 	if (cap == NULL)
907 		return;
908 
909 	if (!is_leaf) {
910 		printf("\t  -- shaper private: (%d) dual rate (%d)\n",
911 			cap->nonleaf.shaper_private_supported,
912 			cap->nonleaf.shaper_private_dual_rate_supported);
913 		printf("\t  -- shaper share: (%u)\n",
914 			cap->nonleaf.shaper_shared_n_max);
915 		printf("\t  -- non leaf sched MAX:\n"
916 			"\t\t  + children (%u)\n"
917 			"\t\t  + sp (%u)\n"
918 			"\t\t  + wfq children per group (%u)\n"
919 			"\t\t  + wfq groups (%u)\n"
920 			"\t\t  + wfq weight (%u)\n",
921 			cap->nonleaf.sched_n_children_max,
922 			cap->nonleaf.sched_sp_n_priorities_max,
923 			cap->nonleaf.sched_wfq_n_children_per_group_max,
924 			cap->nonleaf.sched_wfq_n_groups_max,
925 			cap->nonleaf.sched_wfq_weight_max);
926 	} else {
927 		printf("\t  -- shaper private: (%d) dual rate (%d)\n",
928 			cap->leaf.shaper_private_supported,
929 			cap->leaf.shaper_private_dual_rate_supported);
930 		printf("\t  -- shaper share: (%u)\n",
931 			cap->leaf.shaper_shared_n_max);
932 		printf("  -- leaf cman support:\n"
933 			"\t\t  + wred pkt mode (%d)\n"
934 			"\t\t  + wred byte mode (%d)\n"
935 			"\t\t  + head drop (%d)\n"
936 			"\t\t  + wred context private (%d)\n"
937 			"\t\t  + wred context shared (%u)\n",
938 			cap->leaf.cman_wred_packet_mode_supported,
939 			cap->leaf.cman_wred_byte_mode_supported,
940 			cap->leaf.cman_head_drop_supported,
941 			cap->leaf.cman_wred_context_private_supported,
942 			cap->leaf.cman_wred_context_shared_n_max);
943 	}
944 }
945 
946 static void
947 show_tm(void)
948 {
949 	int ret = 0, check_for_leaf = 0, is_leaf = 0;
950 	unsigned int j, k;
951 	uint16_t i = 0;
952 
953 	snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD ");
954 	STATS_BDR_STR(10, bdr_str);
955 
956 	RTE_ETH_FOREACH_DEV(i) {
957 		struct rte_eth_dev_info dev_info;
958 		struct rte_tm_capabilities cap;
959 		struct rte_tm_error error;
960 		struct rte_tm_node_capabilities capnode;
961 		struct rte_tm_level_capabilities caplevel;
962 		uint32_t n_leaf_nodes = 0;
963 
964 		memset(&cap, 0, sizeof(cap));
965 		memset(&error, 0, sizeof(error));
966 
967 		ret = rte_eth_dev_info_get(i, &dev_info);
968 		if (ret != 0) {
969 			printf("Error during getting device (port %u) info: %s\n",
970 				i, strerror(-ret));
971 			return;
972 		}
973 
974 		printf("  - Generic for port (%u)\n"
975 			"\t  -- driver name %s\n"
976 			"\t  -- max vf (%u)\n"
977 			"\t  -- max tx queues (%u)\n"
978 			"\t  -- number of tx queues (%u)\n",
979 			i,
980 			dev_info.driver_name,
981 			dev_info.max_vfs,
982 			dev_info.max_tx_queues,
983 			dev_info.nb_tx_queues);
984 
985 		ret = rte_tm_capabilities_get(i, &cap, &error);
986 		if (ret)
987 			continue;
988 
989 		printf("  - MAX: nodes (%u) levels (%u) children (%u)\n",
990 			cap.n_nodes_max,
991 			cap.n_levels_max,
992 			cap.sched_n_children_max);
993 
994 		printf("  - identical nodes: non leaf (%d) leaf (%d)\n",
995 			cap.non_leaf_nodes_identical,
996 			cap.leaf_nodes_identical);
997 
998 		printf("  - Shaper MAX:\n"
999 			"\t  -- total (%u)\n"
1000 			"\t  -- private (%u) private dual (%d)\n"
1001 			"\t  -- shared (%u) shared dual (%u)\n",
1002 			cap.shaper_n_max,
1003 			cap.shaper_private_n_max,
1004 			cap.shaper_private_dual_rate_n_max,
1005 			cap.shaper_shared_n_max,
1006 			cap.shaper_shared_dual_rate_n_max);
1007 
1008 		printf("  - mark support:\n");
1009 		printf("\t  -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n",
1010 			cap.mark_vlan_dei_supported[RTE_COLOR_GREEN],
1011 			cap.mark_vlan_dei_supported[RTE_COLOR_YELLOW],
1012 			cap.mark_vlan_dei_supported[RTE_COLOR_RED]);
1013 		printf("\t  -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1014 			cap.mark_ip_ecn_tcp_supported[RTE_COLOR_GREEN],
1015 			cap.mark_ip_ecn_tcp_supported[RTE_COLOR_YELLOW],
1016 			cap.mark_ip_ecn_tcp_supported[RTE_COLOR_RED]);
1017 		printf("\t  -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1018 			cap.mark_ip_ecn_sctp_supported[RTE_COLOR_GREEN],
1019 			cap.mark_ip_ecn_sctp_supported[RTE_COLOR_YELLOW],
1020 			cap.mark_ip_ecn_sctp_supported[RTE_COLOR_RED]);
1021 		printf("\t  -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1022 			cap.mark_ip_dscp_supported[RTE_COLOR_GREEN],
1023 			cap.mark_ip_dscp_supported[RTE_COLOR_YELLOW],
1024 			cap.mark_ip_dscp_supported[RTE_COLOR_RED]);
1025 
1026 		printf("  - mask stats (0x%"PRIx64")"
1027 			" dynamic update (0x%"PRIx64")\n",
1028 			cap.stats_mask,
1029 			cap.dynamic_update_mask);
1030 
1031 		printf("  - sched MAX:\n"
1032 			"\t  -- total (%u)\n"
1033 			"\t  -- sp levels (%u)\n"
1034 			"\t  -- wfq children per group (%u)\n"
1035 			"\t  -- wfq groups (%u)\n"
1036 			"\t  -- wfq weight (%u)\n",
1037 			cap.sched_sp_n_priorities_max,
1038 			cap.sched_sp_n_priorities_max,
1039 			cap.sched_wfq_n_children_per_group_max,
1040 			cap.sched_wfq_n_groups_max,
1041 			cap.sched_wfq_weight_max);
1042 
1043 		printf("  - CMAN support:\n"
1044 			"\t  -- WRED mode: pkt (%d) byte (%d)\n"
1045 			"\t  -- head drop (%d)\n",
1046 			cap.cman_wred_packet_mode_supported,
1047 			cap.cman_wred_byte_mode_supported,
1048 			cap.cman_head_drop_supported);
1049 		printf("\t  -- MAX WRED CONTEXT:"
1050 			" total (%u) private (%u) shared (%u)\n",
1051 			cap.cman_wred_context_n_max,
1052 			cap.cman_wred_context_private_n_max,
1053 			cap.cman_wred_context_shared_n_max);
1054 
1055 		for (j = 0; j < cap.n_nodes_max; j++) {
1056 			memset(&capnode, 0, sizeof(capnode));
1057 			ret = rte_tm_node_capabilities_get(i, j,
1058 					&capnode, &error);
1059 			if (ret)
1060 				continue;
1061 
1062 			check_for_leaf = 1;
1063 
1064 			printf("  NODE %u\n", j);
1065 			printf("\t  - shaper private: (%d) dual rate (%d)\n",
1066 				capnode.shaper_private_supported,
1067 				capnode.shaper_private_dual_rate_supported);
1068 			printf("\t  - shaper shared max: (%u)\n",
1069 				capnode.shaper_shared_n_max);
1070 			printf("\t  - stats mask %"PRIx64"\n",
1071 				capnode.stats_mask);
1072 
1073 			ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1074 			if (ret)
1075 				continue;
1076 
1077 			display_nodecap_info(is_leaf, &capnode);
1078 		}
1079 
1080 		for (j = 0; j < cap.n_levels_max; j++) {
1081 			memset(&caplevel, 0, sizeof(caplevel));
1082 			ret = rte_tm_level_capabilities_get(i, j,
1083 					&caplevel, &error);
1084 			if (ret)
1085 				continue;
1086 
1087 			printf("  - Level %u\n", j);
1088 			printf("\t  -- node MAX: %u non leaf %u leaf %u\n",
1089 				caplevel.n_nodes_max,
1090 				caplevel.n_nodes_nonleaf_max,
1091 				caplevel.n_nodes_leaf_max);
1092 			printf("\t  -- indetical: non leaf %u leaf %u\n",
1093 				caplevel.non_leaf_nodes_identical,
1094 				caplevel.leaf_nodes_identical);
1095 
1096 			for (k = 0; k < caplevel.n_nodes_max; k++) {
1097 				ret = rte_tm_node_type_get(i, k,
1098 					&is_leaf, &error);
1099 				if (ret)
1100 					continue;
1101 
1102 				display_levelcap_info(is_leaf, &caplevel);
1103 			}
1104 		}
1105 
1106 		if (check_for_leaf) {
1107 			ret = rte_tm_get_number_of_leaf_nodes(i,
1108 					&n_leaf_nodes, &error);
1109 			if (ret == 0)
1110 				printf("  - leaf nodes (%u)\n", n_leaf_nodes);
1111 		}
1112 
1113 		for (j = 0; j < n_leaf_nodes; j++) {
1114 			struct rte_tm_node_stats stats;
1115 			memset(&stats, 0, sizeof(stats));
1116 
1117 			ret = rte_tm_node_stats_read(i, j,
1118 					&stats, &cap.stats_mask, 0, &error);
1119 			if (ret)
1120 				continue;
1121 
1122 			printf("  - STATS for node (%u)\n", j);
1123 			printf("  -- pkts (%"PRIu64") bytes (%"PRIu64")\n",
1124 				stats.n_pkts, stats.n_bytes);
1125 
1126 			ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1127 			if (ret || (!is_leaf))
1128 				continue;
1129 
1130 			printf("  -- leaf queued:"
1131 				" pkts (%"PRIu64") bytes (%"PRIu64")\n",
1132 				stats.leaf.n_pkts_queued,
1133 				stats.leaf.n_bytes_queued);
1134 			printf("  - dropped:\n"
1135 				"\t  -- GREEN:"
1136 				" pkts (%"PRIu64") bytes (%"PRIu64")\n"
1137 				"\t  -- YELLOW:"
1138 				" pkts (%"PRIu64") bytes (%"PRIu64")\n"
1139 				"\t  -- RED:"
1140 				" pkts (%"PRIu64") bytes (%"PRIu64")\n",
1141 				stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN],
1142 				stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN],
1143 				stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW],
1144 				stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW],
1145 				stats.leaf.n_pkts_dropped[RTE_COLOR_RED],
1146 				stats.leaf.n_bytes_dropped[RTE_COLOR_RED]);
1147 		}
1148 	}
1149 }
1150 
1151 static void
1152 display_crypto_feature_info(uint64_t x)
1153 {
1154 	if (x == 0)
1155 		return;
1156 
1157 	printf("\t  -- feature flags\n");
1158 	printf("\t\t  + symmetric (%c), asymmetric (%c)\n"
1159 		"\t\t  + symmetric operation chaining (%c)\n",
1160 		(x & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ? 'y' : 'n',
1161 		(x & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) ? 'y' : 'n',
1162 		(x & RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING) ? 'y' : 'n');
1163 	printf("\t\t  + CPU: SSE (%c), AVX (%c), AVX2 (%c), AVX512 (%c)\n",
1164 		(x & RTE_CRYPTODEV_FF_CPU_SSE) ? 'y' : 'n',
1165 		(x & RTE_CRYPTODEV_FF_CPU_AVX) ? 'y' : 'n',
1166 		(x & RTE_CRYPTODEV_FF_CPU_AVX2) ? 'y' : 'n',
1167 		(x & RTE_CRYPTODEV_FF_CPU_AVX512) ? 'y' : 'n');
1168 	printf("\t\t  + AESNI: CPU (%c), HW (%c)\n",
1169 		(x & RTE_CRYPTODEV_FF_CPU_AESNI) ? 'y' : 'n',
1170 		(x & RTE_CRYPTODEV_FF_HW_ACCELERATED) ? 'y' : 'n');
1171 	printf("\t\t  + SECURITY OFFLOAD (%c)\n",
1172 		(x & RTE_CRYPTODEV_FF_SECURITY) ? 'y' : 'n');
1173 	printf("\t\t  + ARM: NEON (%c), CE (%c)\n",
1174 		(x & RTE_CRYPTODEV_FF_CPU_NEON) ? 'y' : 'n',
1175 		(x & RTE_CRYPTODEV_FF_CPU_ARM_CE) ? 'y' : 'n');
1176 	printf("\t  -- buffer offload\n");
1177 	printf("\t\t  + IN_PLACE_SGL (%c)\n",
1178 		(x & RTE_CRYPTODEV_FF_IN_PLACE_SGL) ? 'y' : 'n');
1179 	printf("\t\t  + OOP_SGL_IN_SGL_OUT (%c)\n",
1180 		(x & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT) ? 'y' : 'n');
1181 	printf("\t\t  + OOP_SGL_IN_LB_OUT (%c)\n",
1182 		(x & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT) ? 'y' : 'n');
1183 	printf("\t\t  + OOP_LB_IN_SGL_OUT (%c)\n",
1184 		(x & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT) ? 'y' : 'n');
1185 	printf("\t\t  + OOP_LB_IN_LB_OUT (%c)\n",
1186 		(x & RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT) ? 'y' : 'n');
1187 }
1188 
1189 static void
1190 show_crypto(void)
1191 {
1192 	uint8_t crypto_dev_count = rte_cryptodev_count(), i;
1193 
1194 	snprintf(bdr_str, MAX_STRING_LEN, " show - CRYPTO PMD ");
1195 	STATS_BDR_STR(10, bdr_str);
1196 
1197 	for (i = 0; i < crypto_dev_count; i++) {
1198 		struct rte_cryptodev_info dev_info;
1199 		struct rte_cryptodev_stats stats;
1200 
1201 		rte_cryptodev_info_get(i, &dev_info);
1202 
1203 		printf("  - device (%u)\n", i);
1204 		printf("\t  -- name (%s)\n"
1205 		       "\t  -- driver (%s)\n"
1206 		       "\t  -- id (%u) on socket (%d)\n"
1207 		       "\t  -- queue pairs (%d)\n",
1208 		       rte_cryptodev_name_get(i),
1209 		       dev_info.driver_name,
1210 		       dev_info.driver_id,
1211 		       dev_info.device->numa_node,
1212 		       rte_cryptodev_queue_pair_count(i));
1213 
1214 		display_crypto_feature_info(dev_info.feature_flags);
1215 
1216 		if (rte_cryptodev_stats_get(i, &stats) == 0) {
1217 			printf("\t  -- stats\n");
1218 			printf("\t\t  + enqueue count (%"PRIu64")"
1219 			       " error (%"PRIu64")\n",
1220 			       stats.enqueued_count,
1221 			       stats.enqueue_err_count);
1222 			printf("\t\t  + dequeue count (%"PRIu64")"
1223 			       " error (%"PRIu64")\n",
1224 			       stats.dequeued_count,
1225 			       stats.dequeue_err_count);
1226 		}
1227 
1228 #ifdef RTE_LIB_SECURITY
1229 		show_security_context(i, false);
1230 #endif
1231 	}
1232 }
1233 
1234 static void
1235 show_ring(char *name)
1236 {
1237 	snprintf(bdr_str, MAX_STRING_LEN, " show - RING ");
1238 	STATS_BDR_STR(10, bdr_str);
1239 
1240 	if (name != NULL) {
1241 		struct rte_ring *ptr = rte_ring_lookup(name);
1242 		if (ptr != NULL) {
1243 			printf("  - Name (%s) on socket (%d)\n"
1244 				"  - flags:\n"
1245 				"\t  -- Single Producer Enqueue (%u)\n"
1246 				"\t  -- Single Consmer Dequeue (%u)\n",
1247 				ptr->name,
1248 				ptr->memzone->socket_id,
1249 				ptr->flags & RING_F_SP_ENQ,
1250 				ptr->flags & RING_F_SC_DEQ);
1251 			printf("  - size (%u) mask (0x%x) capacity (%u)\n",
1252 				ptr->size,
1253 				ptr->mask,
1254 				ptr->capacity);
1255 			printf("  - count (%u) free count (%u)\n",
1256 				rte_ring_count(ptr),
1257 				rte_ring_free_count(ptr));
1258 			printf("  - full (%d) empty (%d)\n",
1259 				rte_ring_full(ptr),
1260 				rte_ring_empty(ptr));
1261 
1262 			STATS_BDR_STR(50, "");
1263 			return;
1264 		}
1265 	}
1266 
1267 	rte_ring_list_dump(stdout);
1268 }
1269 
1270 static void
1271 show_mempool(char *name)
1272 {
1273 	snprintf(bdr_str, MAX_STRING_LEN, " show - MEMPOOL ");
1274 	STATS_BDR_STR(10, bdr_str);
1275 
1276 	if (name != NULL) {
1277 		struct rte_mempool *ptr = rte_mempool_lookup(name);
1278 		if (ptr != NULL) {
1279 			struct rte_mempool_ops *ops;
1280 			uint64_t flags = ptr->flags;
1281 
1282 			ops = rte_mempool_get_ops(ptr->ops_index);
1283 			printf("  - Name: %s on socket %d\n"
1284 				"  - flags:\n"
1285 				"\t  -- No spread (%c)\n"
1286 				"\t  -- No cache align (%c)\n"
1287 				"\t  -- SP put (%c), SC get (%c)\n"
1288 				"\t  -- Pool created (%c)\n"
1289 				"\t  -- No IOVA config (%c)\n",
1290 				ptr->name,
1291 				ptr->socket_id,
1292 				(flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
1293 				(flags & MEMPOOL_F_NO_CACHE_ALIGN) ? 'y' : 'n',
1294 				(flags & MEMPOOL_F_SP_PUT) ? 'y' : 'n',
1295 				(flags & MEMPOOL_F_SC_GET) ? 'y' : 'n',
1296 				(flags & MEMPOOL_F_POOL_CREATED) ? 'y' : 'n',
1297 				(flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n');
1298 			printf("  - Size %u Cache %u element %u\n"
1299 				"  - header %u trailer %u\n"
1300 				"  - private data size %u\n",
1301 				ptr->size,
1302 				ptr->cache_size,
1303 				ptr->elt_size,
1304 				ptr->header_size,
1305 				ptr->trailer_size,
1306 				ptr->private_data_size);
1307 			printf("  - memezone - socket %d\n",
1308 				ptr->mz->socket_id);
1309 			printf("  - Count: avail (%u), in use (%u)\n",
1310 				rte_mempool_avail_count(ptr),
1311 				rte_mempool_in_use_count(ptr));
1312 			printf("  - ops_index %d ops_name %s\n",
1313 				ptr->ops_index, ops ? ops->name : "NA");
1314 
1315 			return;
1316 		}
1317 	}
1318 
1319 	rte_mempool_list_dump(stdout);
1320 }
1321 
1322 static void
1323 mempool_itr_obj(struct rte_mempool *mp, void *opaque,
1324 		void *obj, unsigned int obj_idx)
1325 {
1326 	printf("  - obj_idx %u opaque %p obj %p\n",
1327 			obj_idx, opaque, obj);
1328 
1329 	if (obj)
1330 		rte_hexdump(stdout, " Obj Content",
1331 				obj, (mp->elt_size > 256)?256:mp->elt_size);
1332 }
1333 
1334 static void
1335 iter_mempool(char *name)
1336 {
1337 	snprintf(bdr_str, MAX_STRING_LEN, " iter - MEMPOOL ");
1338 	STATS_BDR_STR(10, bdr_str);
1339 
1340 	if (name != NULL) {
1341 		struct rte_mempool *ptr = rte_mempool_lookup(name);
1342 		if (ptr != NULL) {
1343 			/* iterate each object */
1344 			uint32_t ret = rte_mempool_obj_iter(ptr,
1345 					mempool_itr_obj, NULL);
1346 			printf("\n  - iterated %u objects\n", ret);
1347 			return;
1348 		}
1349 	}
1350 }
1351 
1352 int
1353 main(int argc, char **argv)
1354 {
1355 	int ret;
1356 	int i;
1357 	char c_flag[] = "-c1";
1358 	char n_flag[] = "-n4";
1359 	char mp_flag[] = "--proc-type=secondary";
1360 	char log_flag[] = "--log-level=6";
1361 	char *argp[argc + 4];
1362 	uint16_t nb_ports;
1363 
1364 	/* preparse app arguments */
1365 	ret = proc_info_preparse_args(argc, argv);
1366 	if (ret < 0) {
1367 		printf("Failed to parse arguments\n");
1368 		return -1;
1369 	}
1370 
1371 	argp[0] = argv[0];
1372 	argp[1] = c_flag;
1373 	argp[2] = n_flag;
1374 	argp[3] = mp_flag;
1375 	argp[4] = log_flag;
1376 
1377 	for (i = 1; i < argc; i++)
1378 		argp[i + 4] = argv[i];
1379 
1380 	argc += 4;
1381 
1382 	ret = rte_eal_init(argc, argp);
1383 	if (ret < 0)
1384 		rte_panic("Cannot init EAL\n");
1385 
1386 	argc -= ret;
1387 	argv += ret - 4;
1388 
1389 	if (!rte_eal_primary_proc_alive(NULL))
1390 		rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
1391 
1392 	/* parse app arguments */
1393 	ret = proc_info_parse_args(argc, argv);
1394 	if (ret < 0)
1395 		rte_exit(EXIT_FAILURE, "Invalid argument\n");
1396 
1397 	if (mem_info) {
1398 		meminfo_display();
1399 		return 0;
1400 	}
1401 
1402 	nb_ports = rte_eth_dev_count_avail();
1403 	if (nb_ports == 0)
1404 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1405 
1406 	/* If no port mask was specified, then show non-owned ports */
1407 	if (enabled_port_mask == 0) {
1408 		RTE_ETH_FOREACH_DEV(i)
1409 			enabled_port_mask = 1ul << i;
1410 	}
1411 
1412 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
1413 
1414 		/* Skip if port is not in mask */
1415 		if ((enabled_port_mask & (1ul << i)) == 0)
1416 			continue;
1417 
1418 		/* Skip if port is unused */
1419 		if (!rte_eth_dev_is_valid_port(i))
1420 			continue;
1421 
1422 		if (enable_stats)
1423 			nic_stats_display(i);
1424 		else if (enable_xstats)
1425 			nic_xstats_display(i);
1426 		else if (reset_stats)
1427 			nic_stats_clear(i);
1428 		else if (reset_xstats)
1429 			nic_xstats_clear(i);
1430 		else if (enable_xstats_name)
1431 			nic_xstats_by_name_display(i, xstats_name);
1432 		else if (nb_xstats_ids > 0)
1433 			nic_xstats_by_ids_display(i, xstats_ids,
1434 						  nb_xstats_ids);
1435 		else if (enable_metrics)
1436 			metrics_display(i);
1437 
1438 	}
1439 
1440 	/* print port independent stats */
1441 	if (enable_metrics)
1442 		metrics_display(RTE_METRICS_GLOBAL);
1443 
1444 	/* show information for PMD */
1445 	if (enable_shw_port)
1446 		show_port();
1447 	if (enable_shw_tm)
1448 		show_tm();
1449 	if (enable_shw_crypto)
1450 		show_crypto();
1451 	if (enable_shw_ring)
1452 		show_ring(ring_name);
1453 	if (enable_shw_mempool)
1454 		show_mempool(mempool_name);
1455 	if (enable_iter_mempool)
1456 		iter_mempool(mempool_iter_name);
1457 
1458 	RTE_ETH_FOREACH_DEV(i)
1459 		rte_eth_dev_close(i);
1460 
1461 	ret = rte_eal_cleanup();
1462 	if (ret)
1463 		printf("Error from rte_eal_cleanup(), %d\n", ret);
1464 
1465 	return 0;
1466 }
1467