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