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