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