1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
11 #include <sys/queue.h>
17 #include <rte_common.h>
18 #include <rte_debug.h>
19 #include <rte_ethdev.h>
20 #include <rte_malloc.h>
21 #include <rte_memory.h>
22 #include <rte_memzone.h>
23 #include <rte_launch.h>
24 #include <rte_tailq.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
28 #include <rte_atomic.h>
29 #include <rte_branch_prediction.h>
30 #include <rte_string_fns.h>
31 #include <rte_metrics.h>
32 #include <rte_cycles.h>
33 #ifdef RTE_LIB_SECURITY
34 #include <rte_security.h>
36 #include <rte_cryptodev.h>
38 #include <rte_hexdump.h>
40 /* Maximum long option length for option parsing. */
41 #define MAX_LONG_OPT_SZ 64
42 #define MAX_STRING_LEN 256
44 #define STATS_BDR_FMT "========================================"
45 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \
46 STATS_BDR_FMT, s, w, STATS_BDR_FMT)
48 /**< mask of enabled ports */
49 static uint32_t enabled_port_mask;
51 static uint32_t enable_stats;
52 /**< Enable xstats. */
53 static uint32_t enable_xstats;
54 /**< Enable collectd format*/
55 static uint32_t enable_collectd_format;
56 /**< FD to send collectd format messages to STDOUT*/
58 /**< Host id process is running on */
59 static char host_id[MAX_LONG_OPT_SZ];
60 /**< Enable metrics. */
61 static uint32_t enable_metrics;
62 /**< Enable stats reset. */
63 static uint32_t reset_stats;
64 /**< Enable xstats reset. */
65 static uint32_t reset_xstats;
66 /**< Enable memory info. */
67 static uint32_t mem_info;
68 /**< Enable displaying xstat name. */
69 static uint32_t enable_xstats_name;
70 static char *xstats_name;
72 /**< Enable xstats by ids. */
73 #define MAX_NB_XSTATS_IDS 1024
74 static uint32_t nb_xstats_ids;
75 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
78 static char bdr_str[MAX_STRING_LEN];
80 /**< Enable show port. */
81 static uint32_t enable_shw_port;
82 /**< Enable show tm. */
83 static uint32_t enable_shw_tm;
84 /**< Enable show crypto. */
85 static uint32_t enable_shw_crypto;
86 /**< Enable show ring. */
87 static uint32_t enable_shw_ring;
88 static char *ring_name;
89 /**< Enable show mempool. */
90 static uint32_t enable_shw_mempool;
91 static char *mempool_name;
92 /**< Enable iter mempool. */
93 static uint32_t enable_iter_mempool;
94 static char *mempool_iter_name;
98 proc_info_usage(const char *prgname)
100 printf("%s [EAL options] -- -p PORTMASK\n"
101 " -m to display DPDK memory zones, segments and TAILQ information\n"
102 " -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
103 " --stats: to display port statistics, enabled by default\n"
104 " --xstats: to display extended port statistics, disabled by "
106 " --metrics: to display derived metrics of the ports, disabled by "
108 " --xstats-name NAME: to display single xstat id by NAME\n"
109 " --xstats-ids IDLIST: to display xstat values by id. "
110 "The argument is comma-separated list of xstat ids to print out.\n"
111 " --stats-reset: to reset port statistics\n"
112 " --xstats-reset: to reset port extended statistics\n"
113 " --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
114 " --host-id STRING: host id used to identify the system process is running on\n"
115 " --show-port: to display ports information\n"
116 " --show-tm: to display traffic manager information for ports\n"
117 " --show-crypto: to display crypto information\n"
118 " --show-ring[=name]: to display ring information\n"
119 " --show-mempool[=name]: to display mempool information\n"
120 " --iter-mempool=name: iterate mempool elements to display content\n",
125 * Parse the portmask provided at run time.
128 parse_portmask(const char *portmask)
135 /* parse hexadecimal string */
136 pm = strtoul(portmask, &end, 16);
137 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
139 printf("%s ERROR parsing the port mask\n", __func__);
151 * Parse ids value list into array
154 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
161 token = strtok_r(list, ",", &ctx);
162 while (token != NULL) {
163 ids[length] = strtoull(token, &endptr, 10);
171 token = strtok_r(NULL, ",", &ctx);
178 proc_info_preparse_args(int argc, char **argv)
180 char *prgname = argv[0];
183 for (i = 0; i < argc; i++) {
184 /* Print stats or xstats to STDOUT in collectd format */
185 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
186 enable_collectd_format = 1;
187 stdout_fd = dup(STDOUT_FILENO);
188 close(STDOUT_FILENO);
190 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
191 if ((i + 1) == argc) {
192 printf("Invalid host id or not specified\n");
193 proc_info_usage(prgname);
196 strlcpy(host_id, argv[i + 1], sizeof(host_id));
200 if (!strlen(host_id)) {
201 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
204 strlcpy(host_id, "unknown", sizeof(host_id));
210 /* Parse the argument given in the command line of the application */
212 proc_info_parse_args(int argc, char **argv)
216 char *prgname = argv[0];
217 static struct option long_option[] = {
218 {"stats", 0, NULL, 0},
219 {"stats-reset", 0, NULL, 0},
220 {"xstats", 0, NULL, 0},
221 {"metrics", 0, NULL, 0},
222 {"xstats-reset", 0, NULL, 0},
223 {"xstats-name", required_argument, NULL, 1},
224 {"collectd-format", 0, NULL, 0},
225 {"xstats-ids", 1, NULL, 1},
226 {"host-id", 0, NULL, 0},
227 {"show-port", 0, NULL, 0},
228 {"show-tm", 0, NULL, 0},
229 {"show-crypto", 0, NULL, 0},
230 {"show-ring", optional_argument, NULL, 0},
231 {"show-mempool", optional_argument, NULL, 0},
232 {"iter-mempool", required_argument, NULL, 0},
237 proc_info_usage(prgname);
239 /* Parse command line */
240 while ((opt = getopt_long(argc, argv, "p:m",
241 long_option, &option_index)) != EOF) {
245 enabled_port_mask = parse_portmask(optarg);
246 if (enabled_port_mask == 0) {
247 printf("invalid portmask\n");
248 proc_info_usage(prgname);
257 if (!strncmp(long_option[option_index].name, "stats",
261 else if (!strncmp(long_option[option_index].name, "xstats",
264 else if (!strncmp(long_option[option_index].name,
269 if (!strncmp(long_option[option_index].name, "stats-reset",
273 else if (!strncmp(long_option[option_index].name, "xstats-reset",
276 else if (!strncmp(long_option[option_index].name,
277 "show-port", MAX_LONG_OPT_SZ))
279 else if (!strncmp(long_option[option_index].name,
280 "show-tm", MAX_LONG_OPT_SZ))
282 else if (!strncmp(long_option[option_index].name,
283 "show-crypto", MAX_LONG_OPT_SZ))
284 enable_shw_crypto = 1;
285 else if (!strncmp(long_option[option_index].name,
286 "show-ring", MAX_LONG_OPT_SZ)) {
289 } else if (!strncmp(long_option[option_index].name,
290 "show-mempool", MAX_LONG_OPT_SZ)) {
291 enable_shw_mempool = 1;
292 mempool_name = optarg;
293 } else if (!strncmp(long_option[option_index].name,
294 "iter-mempool", MAX_LONG_OPT_SZ)) {
295 enable_iter_mempool = 1;
296 mempool_iter_name = optarg;
300 /* Print xstat single value given by name*/
301 if (!strncmp(long_option[option_index].name,
302 "xstats-name", MAX_LONG_OPT_SZ)) {
303 enable_xstats_name = 1;
304 xstats_name = optarg;
305 printf("name:%s:%s\n",
306 long_option[option_index].name,
308 } else if (!strncmp(long_option[option_index].name,
311 nb_xstats_ids = parse_xstats_ids(optarg,
312 xstats_ids, MAX_NB_XSTATS_IDS);
314 if (nb_xstats_ids <= 0) {
315 printf("xstats-id list parse error.\n");
322 proc_info_usage(prgname);
330 meminfo_display(void)
332 printf("----------- MEMORY_SEGMENTS -----------\n");
333 rte_dump_physmem_layout(stdout);
334 printf("--------- END_MEMORY_SEGMENTS ---------\n");
336 printf("------------ MEMORY_ZONES -------------\n");
337 rte_memzone_dump(stdout);
338 printf("---------- END_MEMORY_ZONES -----------\n");
340 printf("------------- TAIL_QUEUES -------------\n");
341 rte_dump_tailq(stdout);
342 printf("---------- END_TAIL_QUEUES ------------\n");
346 nic_stats_display(uint16_t port_id)
348 struct rte_eth_stats stats;
351 static const char *nic_stats_border = "########################";
353 rte_eth_stats_get(port_id, &stats);
354 printf("\n %s NIC statistics for port %-2d %s\n",
355 nic_stats_border, port_id, nic_stats_border);
357 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64
358 " RX-bytes: %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
360 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
361 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64
362 " TX-bytes: %-10"PRIu64"\n", stats.opackets, stats.oerrors,
366 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
367 printf(" Stats reg %2d RX-packets: %-10"PRIu64
368 " RX-errors: %-10"PRIu64
369 " RX-bytes: %-10"PRIu64"\n",
370 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
374 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
375 printf(" Stats reg %2d TX-packets: %-10"PRIu64
376 " TX-bytes: %-10"PRIu64"\n",
377 i, stats.q_opackets[i], stats.q_obytes[i]);
380 printf(" %s############################%s\n",
381 nic_stats_border, nic_stats_border);
385 nic_stats_clear(uint16_t port_id)
387 printf("\n Clearing NIC stats for port %d\n", port_id);
388 rte_eth_stats_reset(port_id);
389 printf("\n NIC statistics for port %d cleared\n", port_id);
392 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
393 const char *cnt_name) {
394 char *type_end = strrchr(cnt_name, '_');
396 if ((type_end != NULL) &&
397 (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
398 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
399 strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
400 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
401 strlcpy(cnt_type, "if_rx_dropped", cnt_type_len);
402 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
403 strlcpy(cnt_type, "if_rx_octets", cnt_type_len);
404 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
405 strlcpy(cnt_type, "if_rx_packets", cnt_type_len);
406 else if (strncmp(type_end, "_placement",
407 strlen("_placement")) == 0)
408 strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
409 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
410 strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
412 /* Does not fit obvious type: use a more generic one */
413 strlcpy(cnt_type, "derive", cnt_type_len);
414 } else if ((type_end != NULL) &&
415 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
416 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
417 strlcpy(cnt_type, "if_tx_errors", cnt_type_len);
418 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
419 strlcpy(cnt_type, "if_tx_dropped", cnt_type_len);
420 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
421 strlcpy(cnt_type, "if_tx_octets", cnt_type_len);
422 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
423 strlcpy(cnt_type, "if_tx_packets", cnt_type_len);
425 /* Does not fit obvious type: use a more generic one */
426 strlcpy(cnt_type, "derive", cnt_type_len);
427 } else if ((type_end != NULL) &&
428 (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
429 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
430 strlcpy(cnt_type, "operations", cnt_type_len);
431 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
432 strlcpy(cnt_type, "errors", cnt_type_len);
433 else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
434 strlcpy(cnt_type, "filter_result", cnt_type_len);
435 } else if ((type_end != NULL) &&
436 (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
437 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
438 strlcpy(cnt_type, "errors", cnt_type_len);
440 /* Does not fit obvious type, or strrchr error: */
441 /* use a more generic type */
442 strlcpy(cnt_type, "derive", cnt_type_len);
447 nic_xstats_by_name_display(uint16_t port_id, char *name)
451 printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
454 if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
455 printf("%s: %"PRIu64"\n", name, id);
457 printf("Statistic not found...\n");
462 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
464 struct rte_eth_xstat_name *xstats_names;
467 static const char *nic_stats_border = "########################";
469 values = malloc(sizeof(*values) * len);
470 if (values == NULL) {
471 printf("Cannot allocate memory for xstats\n");
475 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
476 if (xstats_names == NULL) {
477 printf("Cannot allocate memory for xstat names\n");
482 if (len != rte_eth_xstats_get_names_by_id(
483 port_id, xstats_names, len, ids)) {
484 printf("Cannot get xstat names\n");
488 printf("###### NIC extended statistics for port %-2d #########\n",
490 printf("%s############################\n", nic_stats_border);
491 ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
492 if (ret < 0 || ret > len) {
493 printf("Cannot get xstats\n");
497 for (i = 0; i < len; i++)
498 printf("%s: %"PRIu64"\n",
499 xstats_names[i].name,
502 printf("%s############################\n", nic_stats_border);
509 nic_xstats_display(uint16_t port_id)
511 struct rte_eth_xstat_name *xstats_names;
514 static const char *nic_stats_border = "########################";
516 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
518 printf("Cannot get xstats count\n");
521 values = malloc(sizeof(*values) * len);
522 if (values == NULL) {
523 printf("Cannot allocate memory for xstats\n");
527 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
528 if (xstats_names == NULL) {
529 printf("Cannot allocate memory for xstat names\n");
533 if (len != rte_eth_xstats_get_names_by_id(
534 port_id, xstats_names, len, NULL)) {
535 printf("Cannot get xstat names\n");
539 printf("###### NIC extended statistics for port %-2d #########\n",
541 printf("%s############################\n",
543 ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
544 if (ret < 0 || ret > len) {
545 printf("Cannot get xstats\n");
549 for (i = 0; i < len; i++) {
550 if (enable_collectd_format) {
551 char counter_type[MAX_STRING_LEN];
552 char buf[MAX_STRING_LEN];
555 collectd_resolve_cnt_type(counter_type,
556 sizeof(counter_type),
557 xstats_names[i].name);
558 n = snprintf(buf, MAX_STRING_LEN,
559 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
560 PRIu64"\n", host_id, port_id, counter_type,
561 xstats_names[i].name, values[i]);
562 if (n > sizeof(buf) - 1)
564 ret = write(stdout_fd, buf, n);
568 printf("%s: %"PRIu64"\n", xstats_names[i].name,
573 printf("%s############################\n",
581 nic_xstats_clear(uint16_t port_id)
585 printf("\n Clearing NIC xstats for port %d\n", port_id);
586 ret = rte_eth_xstats_reset(port_id);
588 printf("\n Error clearing xstats for port %d: %s\n", port_id,
593 printf("\n NIC extended statistics for port %d cleared\n", port_id);
597 metrics_display(int port_id)
599 struct rte_metric_value *metrics;
600 struct rte_metric_name *names;
602 static const char *nic_stats_border = "########################";
604 len = rte_metrics_get_names(NULL, 0);
606 printf("Cannot get metrics count\n");
610 printf("No metrics to display (none have been registered)\n");
614 metrics = rte_malloc("proc_info_metrics",
615 sizeof(struct rte_metric_value) * len, 0);
616 if (metrics == NULL) {
617 printf("Cannot allocate memory for metrics\n");
621 names = rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
623 printf("Cannot allocate memory for metrcis names\n");
628 if (len != rte_metrics_get_names(names, len)) {
629 printf("Cannot get metrics names\n");
635 if (port_id == RTE_METRICS_GLOBAL)
636 printf("###### Non port specific metrics #########\n");
638 printf("###### metrics for port %-2d #########\n", port_id);
639 printf("%s############################\n", nic_stats_border);
640 ret = rte_metrics_get_values(port_id, metrics, len);
641 if (ret < 0 || ret > len) {
642 printf("Cannot get metrics values\n");
649 for (i = 0; i < len; i++)
650 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
652 printf("%s############################\n", nic_stats_border);
663 snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD ");
664 STATS_BDR_STR(10, bdr_str);
666 RTE_ETH_FOREACH_DEV(i) {
668 struct rte_eth_link link;
669 struct rte_eth_dev_info dev_info;
670 struct rte_eth_rxq_info queue_info;
671 struct rte_eth_rss_conf rss_conf;
672 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
673 struct rte_eth_fc_conf fc_conf;
674 struct rte_ether_addr mac;
676 memset(&rss_conf, 0, sizeof(rss_conf));
678 snprintf(bdr_str, MAX_STRING_LEN, " Port %u ", i);
679 STATS_BDR_STR(5, bdr_str);
680 printf(" - generic config\n");
682 ret = rte_eth_dev_info_get(i, &dev_info);
684 printf("Error during getting device info: %s\n",
689 printf("\t -- driver %s device %s socket %d\n",
690 dev_info.driver_name, dev_info.device->name,
691 rte_eth_dev_socket_id(i));
693 ret = rte_eth_link_get(i, &link);
695 printf("Link get failed (port %u): %s\n",
696 i, rte_strerror(-ret));
698 rte_eth_link_to_str(link_status_text,
699 sizeof(link_status_text),
701 printf("\t%s\n", link_status_text);
704 ret = rte_eth_dev_flow_ctrl_get(i, &fc_conf);
705 if (ret == 0 && fc_conf.mode != RTE_FC_NONE) {
706 printf("\t -- flow control mode %s%s high %u low %u pause %u%s%s\n",
707 fc_conf.mode == RTE_FC_RX_PAUSE ? "rx " :
708 fc_conf.mode == RTE_FC_TX_PAUSE ? "tx " :
709 fc_conf.mode == RTE_FC_FULL ? "full" : "???",
710 fc_conf.autoneg ? " auto" : "",
714 fc_conf.send_xon ? " xon" : "",
715 fc_conf.mac_ctrl_frame_fwd ? " mac_ctrl" : "");
718 ret = rte_eth_macaddr_get(i, &mac);
720 char ebuf[RTE_ETHER_ADDR_FMT_SIZE];
721 rte_ether_format_addr(ebuf, sizeof(ebuf), &mac);
722 printf("\t -- mac %s\n", ebuf);
725 ret = rte_eth_promiscuous_get(i);
727 printf("\t -- promiscuous mode %s\n",
728 ret > 0 ? "enabled" : "disabled");
730 ret = rte_eth_allmulticast_get(i);
732 printf("\t -- all multicast mode %s\n",
733 ret > 0 ? "enabled" : "disabled");
735 ret = rte_eth_dev_get_mtu(i, &mtu);
737 printf("\t -- mtu (%d)\n", mtu);
739 printf(" - queue\n");
740 for (j = 0; j < dev_info.nb_rx_queues; j++) {
741 ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
743 printf("\t -- queue %u rx scatter %u"
745 " offloads %#" PRIx64
746 " mempool name %s socket %d",
748 queue_info.scattered_rx,
750 queue_info.conf.offloads,
752 queue_info.mp->socket_id);
754 if (queue_info.rx_buf_size != 0)
755 printf(" rx buffer size %u",
756 queue_info.rx_buf_size);
761 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
763 if (rss_conf.rss_key) {
765 printf("\t -- RSS len %u key (hex):",
766 rss_conf.rss_key_len);
767 for (k = 0; k < rss_conf.rss_key_len; k++)
768 printf(" %x", rss_conf.rss_key[k]);
769 printf("\t -- hf 0x%"PRIx64"\n",
774 printf(" - cyrpto context\n");
775 #ifdef RTE_LIB_SECURITY
776 void *p_ctx = rte_eth_dev_get_sec_ctx(i);
777 printf("\t -- security context - %p\n", p_ctx);
780 printf("\t -- size %u\n",
781 rte_security_session_get_size(p_ctx));
782 const struct rte_security_capability *s_cap =
783 rte_security_capabilities_get(p_ctx);
785 printf("\t -- action (0x%x), protocol (0x%x),"
786 " offload flags (0x%x)\n",
790 printf("\t -- capabilities - oper type %x\n",
791 s_cap->crypto_capabilities->op);
799 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap)
805 printf("\t -- nonleaf sched max:\n"
806 "\t\t + children (%u)\n"
807 "\t\t + sp priorities (%u)\n"
808 "\t\t + wfq children per group (%u)\n"
809 "\t\t + wfq groups (%u)\n"
810 "\t\t + wfq weight (%u)\n",
811 cap->nonleaf.sched_n_children_max,
812 cap->nonleaf.sched_sp_n_priorities_max,
813 cap->nonleaf.sched_wfq_n_children_per_group_max,
814 cap->nonleaf.sched_wfq_n_groups_max,
815 cap->nonleaf.sched_wfq_weight_max);
817 printf("\t -- leaf cman support:\n"
818 "\t\t + wred pkt mode (%d)\n"
819 "\t\t + wred byte mode (%d)\n"
820 "\t\t + head drop (%d)\n"
821 "\t\t + wred context private (%d)\n"
822 "\t\t + wred context shared (%u)\n",
823 cap->leaf.cman_wred_packet_mode_supported,
824 cap->leaf.cman_wred_byte_mode_supported,
825 cap->leaf.cman_head_drop_supported,
826 cap->leaf.cman_wred_context_private_supported,
827 cap->leaf.cman_wred_context_shared_n_max);
832 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap)
838 printf("\t -- shaper private: (%d) dual rate (%d)\n",
839 cap->nonleaf.shaper_private_supported,
840 cap->nonleaf.shaper_private_dual_rate_supported);
841 printf("\t -- shaper share: (%u)\n",
842 cap->nonleaf.shaper_shared_n_max);
843 printf("\t -- non leaf sched MAX:\n"
844 "\t\t + children (%u)\n"
846 "\t\t + wfq children per group (%u)\n"
847 "\t\t + wfq groups (%u)\n"
848 "\t\t + wfq weight (%u)\n",
849 cap->nonleaf.sched_n_children_max,
850 cap->nonleaf.sched_sp_n_priorities_max,
851 cap->nonleaf.sched_wfq_n_children_per_group_max,
852 cap->nonleaf.sched_wfq_n_groups_max,
853 cap->nonleaf.sched_wfq_weight_max);
855 printf("\t -- shaper private: (%d) dual rate (%d)\n",
856 cap->leaf.shaper_private_supported,
857 cap->leaf.shaper_private_dual_rate_supported);
858 printf("\t -- shaper share: (%u)\n",
859 cap->leaf.shaper_shared_n_max);
860 printf(" -- leaf cman support:\n"
861 "\t\t + wred pkt mode (%d)\n"
862 "\t\t + wred byte mode (%d)\n"
863 "\t\t + head drop (%d)\n"
864 "\t\t + wred context private (%d)\n"
865 "\t\t + wred context shared (%u)\n",
866 cap->leaf.cman_wred_packet_mode_supported,
867 cap->leaf.cman_wred_byte_mode_supported,
868 cap->leaf.cman_head_drop_supported,
869 cap->leaf.cman_wred_context_private_supported,
870 cap->leaf.cman_wred_context_shared_n_max);
877 int ret = 0, check_for_leaf = 0, is_leaf = 0;
881 snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD ");
882 STATS_BDR_STR(10, bdr_str);
884 RTE_ETH_FOREACH_DEV(i) {
885 struct rte_eth_dev_info dev_info;
886 struct rte_tm_capabilities cap;
887 struct rte_tm_error error;
888 struct rte_tm_node_capabilities capnode;
889 struct rte_tm_level_capabilities caplevel;
890 uint32_t n_leaf_nodes = 0;
892 memset(&cap, 0, sizeof(cap));
893 memset(&error, 0, sizeof(error));
895 ret = rte_eth_dev_info_get(i, &dev_info);
897 printf("Error during getting device (port %u) info: %s\n",
902 printf(" - Generic for port (%u)\n"
903 "\t -- driver name %s\n"
904 "\t -- max vf (%u)\n"
905 "\t -- max tx queues (%u)\n"
906 "\t -- number of tx queues (%u)\n",
908 dev_info.driver_name,
910 dev_info.max_tx_queues,
911 dev_info.nb_tx_queues);
913 ret = rte_tm_capabilities_get(i, &cap, &error);
917 printf(" - MAX: nodes (%u) levels (%u) children (%u)\n",
920 cap.sched_n_children_max);
922 printf(" - identical nodes: non leaf (%d) leaf (%d)\n",
923 cap.non_leaf_nodes_identical,
924 cap.leaf_nodes_identical);
926 printf(" - Shaper MAX:\n"
928 "\t -- private (%u) private dual (%d)\n"
929 "\t -- shared (%u) shared dual (%u)\n",
931 cap.shaper_private_n_max,
932 cap.shaper_private_dual_rate_n_max,
933 cap.shaper_shared_n_max,
934 cap.shaper_shared_dual_rate_n_max);
936 printf(" - mark support:\n");
937 printf("\t -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n",
938 cap.mark_vlan_dei_supported[RTE_COLOR_GREEN],
939 cap.mark_vlan_dei_supported[RTE_COLOR_YELLOW],
940 cap.mark_vlan_dei_supported[RTE_COLOR_RED]);
941 printf("\t -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n",
942 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_GREEN],
943 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_YELLOW],
944 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_RED]);
945 printf("\t -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n",
946 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_GREEN],
947 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_YELLOW],
948 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_RED]);
949 printf("\t -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n",
950 cap.mark_ip_dscp_supported[RTE_COLOR_GREEN],
951 cap.mark_ip_dscp_supported[RTE_COLOR_YELLOW],
952 cap.mark_ip_dscp_supported[RTE_COLOR_RED]);
954 printf(" - mask stats (0x%"PRIx64")"
955 " dynamic update (0x%"PRIx64")\n",
957 cap.dynamic_update_mask);
959 printf(" - sched MAX:\n"
961 "\t -- sp levels (%u)\n"
962 "\t -- wfq children per group (%u)\n"
963 "\t -- wfq groups (%u)\n"
964 "\t -- wfq weight (%u)\n",
965 cap.sched_sp_n_priorities_max,
966 cap.sched_sp_n_priorities_max,
967 cap.sched_wfq_n_children_per_group_max,
968 cap.sched_wfq_n_groups_max,
969 cap.sched_wfq_weight_max);
971 printf(" - CMAN support:\n"
972 "\t -- WRED mode: pkt (%d) byte (%d)\n"
973 "\t -- head drop (%d)\n",
974 cap.cman_wred_packet_mode_supported,
975 cap.cman_wred_byte_mode_supported,
976 cap.cman_head_drop_supported);
977 printf("\t -- MAX WRED CONTEXT:"
978 " total (%u) private (%u) shared (%u)\n",
979 cap.cman_wred_context_n_max,
980 cap.cman_wred_context_private_n_max,
981 cap.cman_wred_context_shared_n_max);
983 for (j = 0; j < cap.n_nodes_max; j++) {
984 memset(&capnode, 0, sizeof(capnode));
985 ret = rte_tm_node_capabilities_get(i, j,
992 printf(" NODE %u\n", j);
993 printf("\t - shaper private: (%d) dual rate (%d)\n",
994 capnode.shaper_private_supported,
995 capnode.shaper_private_dual_rate_supported);
996 printf("\t - shaper shared max: (%u)\n",
997 capnode.shaper_shared_n_max);
998 printf("\t - stats mask %"PRIx64"\n",
1001 ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1005 display_nodecap_info(is_leaf, &capnode);
1008 for (j = 0; j < cap.n_levels_max; j++) {
1009 memset(&caplevel, 0, sizeof(caplevel));
1010 ret = rte_tm_level_capabilities_get(i, j,
1015 printf(" - Level %u\n", j);
1016 printf("\t -- node MAX: %u non leaf %u leaf %u\n",
1017 caplevel.n_nodes_max,
1018 caplevel.n_nodes_nonleaf_max,
1019 caplevel.n_nodes_leaf_max);
1020 printf("\t -- indetical: non leaf %u leaf %u\n",
1021 caplevel.non_leaf_nodes_identical,
1022 caplevel.leaf_nodes_identical);
1024 for (k = 0; k < caplevel.n_nodes_max; k++) {
1025 ret = rte_tm_node_type_get(i, k,
1030 display_levelcap_info(is_leaf, &caplevel);
1034 if (check_for_leaf) {
1035 ret = rte_tm_get_number_of_leaf_nodes(i,
1036 &n_leaf_nodes, &error);
1038 printf(" - leaf nodes (%u)\n", n_leaf_nodes);
1041 for (j = 0; j < n_leaf_nodes; j++) {
1042 struct rte_tm_node_stats stats;
1043 memset(&stats, 0, sizeof(stats));
1045 ret = rte_tm_node_stats_read(i, j,
1046 &stats, &cap.stats_mask, 0, &error);
1050 printf(" - STATS for node (%u)\n", j);
1051 printf(" -- pkts (%"PRIu64") bytes (%"PRIu64")\n",
1052 stats.n_pkts, stats.n_bytes);
1054 ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1055 if (ret || (!is_leaf))
1058 printf(" -- leaf queued:"
1059 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
1060 stats.leaf.n_pkts_queued,
1061 stats.leaf.n_bytes_queued);
1062 printf(" - dropped:\n"
1064 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
1066 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
1068 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
1069 stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN],
1070 stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN],
1071 stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW],
1072 stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW],
1073 stats.leaf.n_pkts_dropped[RTE_COLOR_RED],
1074 stats.leaf.n_bytes_dropped[RTE_COLOR_RED]);
1080 display_crypto_feature_info(uint64_t x)
1085 printf("\t -- feature flags\n");
1086 printf("\t\t + symmetric (%c), asymmetric (%c)\n"
1087 "\t\t + symmetric operation chaining (%c)\n",
1088 (x & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ? 'y' : 'n',
1089 (x & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) ? 'y' : 'n',
1090 (x & RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING) ? 'y' : 'n');
1091 printf("\t\t + CPU: SSE (%c), AVX (%c), AVX2 (%c), AVX512 (%c)\n",
1092 (x & RTE_CRYPTODEV_FF_CPU_SSE) ? 'y' : 'n',
1093 (x & RTE_CRYPTODEV_FF_CPU_AVX) ? 'y' : 'n',
1094 (x & RTE_CRYPTODEV_FF_CPU_AVX2) ? 'y' : 'n',
1095 (x & RTE_CRYPTODEV_FF_CPU_AVX512) ? 'y' : 'n');
1096 printf("\t\t + AESNI: CPU (%c), HW (%c)\n",
1097 (x & RTE_CRYPTODEV_FF_CPU_AESNI) ? 'y' : 'n',
1098 (x & RTE_CRYPTODEV_FF_HW_ACCELERATED) ? 'y' : 'n');
1099 printf("\t\t + INLINE (%c)\n",
1100 (x & RTE_CRYPTODEV_FF_SECURITY) ? 'y' : 'n');
1101 printf("\t\t + ARM: NEON (%c), CE (%c)\n",
1102 (x & RTE_CRYPTODEV_FF_CPU_NEON) ? 'y' : 'n',
1103 (x & RTE_CRYPTODEV_FF_CPU_ARM_CE) ? 'y' : 'n');
1104 printf("\t -- buffer offload\n");
1105 printf("\t\t + IN_PLACE_SGL (%c)\n",
1106 (x & RTE_CRYPTODEV_FF_IN_PLACE_SGL) ? 'y' : 'n');
1107 printf("\t\t + OOP_SGL_IN_SGL_OUT (%c)\n",
1108 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT) ? 'y' : 'n');
1109 printf("\t\t + OOP_SGL_IN_LB_OUT (%c)\n",
1110 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT) ? 'y' : 'n');
1111 printf("\t\t + OOP_LB_IN_SGL_OUT (%c)\n",
1112 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT) ? 'y' : 'n');
1113 printf("\t\t + OOP_LB_IN_LB_OUT (%c)\n",
1114 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT) ? 'y' : 'n');
1120 uint8_t crypto_dev_count = rte_cryptodev_count(), i;
1122 snprintf(bdr_str, MAX_STRING_LEN, " show - CRYPTO PMD ");
1123 STATS_BDR_STR(10, bdr_str);
1125 for (i = 0; i < crypto_dev_count; i++) {
1126 struct rte_cryptodev_info dev_info;
1127 struct rte_cryptodev_stats stats;
1129 rte_cryptodev_info_get(i, &dev_info);
1131 printf(" - device (%u)\n", i);
1132 printf("\t -- name (%s)\n"
1133 "\t -- driver (%s)\n"
1134 "\t -- id (%u) on socket (%d)\n"
1135 "\t -- queue pairs (%d)\n",
1136 rte_cryptodev_name_get(i),
1137 dev_info.driver_name,
1139 dev_info.device->numa_node,
1140 rte_cryptodev_queue_pair_count(i));
1142 display_crypto_feature_info(dev_info.feature_flags);
1144 memset(&stats, 0, sizeof(0));
1145 if (rte_cryptodev_stats_get(i, &stats) == 0) {
1146 printf("\t -- stats\n");
1147 printf("\t\t + enqueue count (%"PRIu64")"
1148 " error (%"PRIu64")\n",
1149 stats.enqueued_count,
1150 stats.enqueue_err_count);
1151 printf("\t\t + dequeue count (%"PRIu64")"
1152 " error (%"PRIu64")\n",
1153 stats.dequeued_count,
1154 stats.dequeue_err_count);
1160 show_ring(char *name)
1162 snprintf(bdr_str, MAX_STRING_LEN, " show - RING ");
1163 STATS_BDR_STR(10, bdr_str);
1166 struct rte_ring *ptr = rte_ring_lookup(name);
1168 printf(" - Name (%s) on socket (%d)\n"
1170 "\t -- Single Producer Enqueue (%u)\n"
1171 "\t -- Single Consmer Dequeue (%u)\n",
1173 ptr->memzone->socket_id,
1174 ptr->flags & RING_F_SP_ENQ,
1175 ptr->flags & RING_F_SC_DEQ);
1176 printf(" - size (%u) mask (0x%x) capacity (%u)\n",
1180 printf(" - count (%u) free count (%u)\n",
1181 rte_ring_count(ptr),
1182 rte_ring_free_count(ptr));
1183 printf(" - full (%d) empty (%d)\n",
1185 rte_ring_empty(ptr));
1187 STATS_BDR_STR(50, "");
1192 rte_ring_list_dump(stdout);
1196 show_mempool(char *name)
1200 snprintf(bdr_str, MAX_STRING_LEN, " show - MEMPOOL ");
1201 STATS_BDR_STR(10, bdr_str);
1204 struct rte_mempool *ptr = rte_mempool_lookup(name);
1206 struct rte_mempool_ops *ops;
1209 ops = rte_mempool_get_ops(ptr->ops_index);
1210 printf(" - Name: %s on socket %d\n"
1212 "\t -- No spread (%c)\n"
1213 "\t -- No cache align (%c)\n"
1214 "\t -- SP put (%c), SC get (%c)\n"
1215 "\t -- Pool created (%c)\n"
1216 "\t -- No IOVA config (%c)\n",
1219 (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
1220 (flags & MEMPOOL_F_NO_CACHE_ALIGN) ? 'y' : 'n',
1221 (flags & MEMPOOL_F_SP_PUT) ? 'y' : 'n',
1222 (flags & MEMPOOL_F_SC_GET) ? 'y' : 'n',
1223 (flags & MEMPOOL_F_POOL_CREATED) ? 'y' : 'n',
1224 (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n');
1225 printf(" - Size %u Cache %u element %u\n"
1226 " - header %u trailer %u\n"
1227 " - private data size %u\n",
1233 ptr->private_data_size);
1234 printf(" - memezone - socket %d\n",
1235 ptr->mz->socket_id);
1236 printf(" - Count: avail (%u), in use (%u)\n",
1237 rte_mempool_avail_count(ptr),
1238 rte_mempool_in_use_count(ptr));
1239 printf(" - ops_index %d ops_name %s\n",
1240 ptr->ops_index, ops ? ops->name : "NA");
1246 rte_mempool_list_dump(stdout);
1250 mempool_itr_obj(struct rte_mempool *mp, void *opaque,
1251 void *obj, unsigned int obj_idx)
1253 printf(" - obj_idx %u opaque %p obj %p\n",
1254 obj_idx, opaque, obj);
1257 rte_hexdump(stdout, " Obj Content",
1258 obj, (mp->elt_size > 256)?256:mp->elt_size);
1262 iter_mempool(char *name)
1264 snprintf(bdr_str, MAX_STRING_LEN, " iter - MEMPOOL ");
1265 STATS_BDR_STR(10, bdr_str);
1268 struct rte_mempool *ptr = rte_mempool_lookup(name);
1270 /* iterate each object */
1271 uint32_t ret = rte_mempool_obj_iter(ptr,
1272 mempool_itr_obj, NULL);
1273 printf("\n - iterated %u objects\n", ret);
1280 main(int argc, char **argv)
1284 char c_flag[] = "-c1";
1285 char n_flag[] = "-n4";
1286 char mp_flag[] = "--proc-type=secondary";
1287 char log_flag[] = "--log-level=6";
1288 char *argp[argc + 4];
1291 /* preparse app arguments */
1292 ret = proc_info_preparse_args(argc, argv);
1294 printf("Failed to parse arguments\n");
1304 for (i = 1; i < argc; i++)
1305 argp[i + 4] = argv[i];
1309 ret = rte_eal_init(argc, argp);
1311 rte_panic("Cannot init EAL\n");
1316 if (!rte_eal_primary_proc_alive(NULL))
1317 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
1319 /* parse app arguments */
1320 ret = proc_info_parse_args(argc, argv);
1322 rte_exit(EXIT_FAILURE, "Invalid argument\n");
1329 nb_ports = rte_eth_dev_count_avail();
1331 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1333 /* If no port mask was specified*/
1334 if (enabled_port_mask == 0)
1335 enabled_port_mask = 0xffff;
1337 RTE_ETH_FOREACH_DEV(i) {
1338 if (enabled_port_mask & (1 << i)) {
1340 nic_stats_display(i);
1341 else if (enable_xstats)
1342 nic_xstats_display(i);
1343 else if (reset_stats)
1345 else if (reset_xstats)
1346 nic_xstats_clear(i);
1347 else if (enable_xstats_name)
1348 nic_xstats_by_name_display(i, xstats_name);
1349 else if (nb_xstats_ids > 0)
1350 nic_xstats_by_ids_display(i, xstats_ids,
1352 else if (enable_metrics)
1357 /* print port independent stats */
1359 metrics_display(RTE_METRICS_GLOBAL);
1361 /* show information for PMD */
1362 if (enable_shw_port)
1366 if (enable_shw_crypto)
1368 if (enable_shw_ring)
1369 show_ring(ring_name);
1370 if (enable_shw_mempool)
1371 show_mempool(mempool_name);
1372 if (enable_iter_mempool)
1373 iter_mempool(mempool_iter_name);
1375 RTE_ETH_FOREACH_DEV(i)
1376 rte_eth_dev_close(i);
1378 ret = rte_eal_cleanup();
1380 printf("Error from rte_eal_cleanup(), %d\n", ret);