app/procinfo: add --show-port
[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
36 /* Maximum long option length for option parsing. */
37 #define MAX_LONG_OPT_SZ 64
38 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
39
40 #define MAX_STRING_LEN 256
41
42 #define STATS_BDR_FMT "========================================"
43 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \
44         STATS_BDR_FMT, s, w, STATS_BDR_FMT)
45
46 /**< mask of enabled ports */
47 static uint32_t enabled_port_mask;
48 /**< Enable stats. */
49 static uint32_t enable_stats;
50 /**< Enable xstats. */
51 static uint32_t enable_xstats;
52 /**< Enable collectd format*/
53 static uint32_t enable_collectd_format;
54 /**< FD to send collectd format messages to STDOUT*/
55 static int stdout_fd;
56 /**< Host id process is running on */
57 static char host_id[MAX_LONG_OPT_SZ];
58 /**< Enable metrics. */
59 static uint32_t enable_metrics;
60 /**< Enable stats reset. */
61 static uint32_t reset_stats;
62 /**< Enable xstats reset. */
63 static uint32_t reset_xstats;
64 /**< Enable memory info. */
65 static uint32_t mem_info;
66 /**< Enable displaying xstat name. */
67 static uint32_t enable_xstats_name;
68 static char *xstats_name;
69
70 /**< Enable xstats by ids. */
71 #define MAX_NB_XSTATS_IDS 1024
72 static uint32_t nb_xstats_ids;
73 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
74
75 /* show border */
76 static char bdr_str[MAX_STRING_LEN];
77
78 /**< Enable show port. */
79 static uint32_t enable_shw_port;
80
81 /**< display usage */
82 static void
83 proc_info_usage(const char *prgname)
84 {
85         printf("%s [EAL options] -- -p PORTMASK\n"
86                 "  -m to display DPDK memory zones, segments and TAILQ information\n"
87                 "  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
88                 "  --stats: to display port statistics, enabled by default\n"
89                 "  --xstats: to display extended port statistics, disabled by "
90                         "default\n"
91                 "  --metrics: to display derived metrics of the ports, disabled by "
92                         "default\n"
93                 "  --xstats-name NAME: to display single xstat id by NAME\n"
94                 "  --xstats-ids IDLIST: to display xstat values by id. "
95                         "The argument is comma-separated list of xstat ids to print out.\n"
96                 "  --stats-reset: to reset port statistics\n"
97                 "  --xstats-reset: to reset port extended statistics\n"
98                 "  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
99                 "  --host-id STRING: host id used to identify the system process is running on\n"
100                 "  --show-port: to display ports information\n",
101                 prgname);
102 }
103
104 /*
105  * Parse the portmask provided at run time.
106  */
107 static int
108 parse_portmask(const char *portmask)
109 {
110         char *end = NULL;
111         unsigned long pm;
112
113         errno = 0;
114
115         /* parse hexadecimal string */
116         pm = strtoul(portmask, &end, 16);
117         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
118                 (errno != 0)) {
119                 printf("%s ERROR parsing the port mask\n", __func__);
120                 return -1;
121         }
122
123         if (pm == 0)
124                 return -1;
125
126         return pm;
127
128 }
129
130 /*
131  * Parse ids value list into array
132  */
133 static int
134 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
135         int length;
136         char *token;
137         char *ctx = NULL;
138         char *endptr;
139
140         length = 0;
141         token = strtok_r(list, ",", &ctx);
142         while (token != NULL) {
143                 ids[length] = strtoull(token, &endptr, 10);
144                 if (*endptr != '\0')
145                         return -EINVAL;
146
147                 length++;
148                 if (length >= limit)
149                         return -E2BIG;
150
151                 token = strtok_r(NULL, ",", &ctx);
152         }
153
154         return length;
155 }
156
157 static int
158 proc_info_preparse_args(int argc, char **argv)
159 {
160         char *prgname = argv[0];
161         int i;
162
163         for (i = 0; i < argc; i++) {
164                 /* Print stats or xstats to STDOUT in collectd format */
165                 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
166                         enable_collectd_format = 1;
167                         stdout_fd = dup(STDOUT_FILENO);
168                         close(STDOUT_FILENO);
169                 }
170                 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
171                         if ((i + 1) == argc) {
172                                 printf("Invalid host id or not specified\n");
173                                 proc_info_usage(prgname);
174                                 return -1;
175                         }
176                         snprintf(host_id, sizeof(host_id), "%s", argv[i+1]);
177                 }
178         }
179
180         if (!strlen(host_id)) {
181                 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
182
183                 if (err)
184                         strcpy(host_id, "unknown");
185         }
186
187         return 0;
188 }
189
190 /* Parse the argument given in the command line of the application */
191 static int
192 proc_info_parse_args(int argc, char **argv)
193 {
194         int opt;
195         int option_index;
196         char *prgname = argv[0];
197         static struct option long_option[] = {
198                 {"stats", 0, NULL, 0},
199                 {"stats-reset", 0, NULL, 0},
200                 {"xstats", 0, NULL, 0},
201                 {"metrics", 0, NULL, 0},
202                 {"xstats-reset", 0, NULL, 0},
203                 {"xstats-name", required_argument, NULL, 1},
204                 {"collectd-format", 0, NULL, 0},
205                 {"xstats-ids", 1, NULL, 1},
206                 {"host-id", 0, NULL, 0},
207                 {"show-port", 0, NULL, 0},
208                 {NULL, 0, 0, 0}
209         };
210
211         if (argc == 1)
212                 proc_info_usage(prgname);
213
214         /* Parse command line */
215         while ((opt = getopt_long(argc, argv, "p:m",
216                         long_option, &option_index)) != EOF) {
217                 switch (opt) {
218                 /* portmask */
219                 case 'p':
220                         enabled_port_mask = parse_portmask(optarg);
221                         if (enabled_port_mask == 0) {
222                                 printf("invalid portmask\n");
223                                 proc_info_usage(prgname);
224                                 return -1;
225                         }
226                         break;
227                 case 'm':
228                         mem_info = 1;
229                         break;
230                 case 0:
231                         /* Print stats */
232                         if (!strncmp(long_option[option_index].name, "stats",
233                                         MAX_LONG_OPT_SZ))
234                                 enable_stats = 1;
235                         /* Print xstats */
236                         else if (!strncmp(long_option[option_index].name, "xstats",
237                                         MAX_LONG_OPT_SZ))
238                                 enable_xstats = 1;
239                         else if (!strncmp(long_option[option_index].name,
240                                         "metrics",
241                                         MAX_LONG_OPT_SZ))
242                                 enable_metrics = 1;
243                         /* Reset stats */
244                         if (!strncmp(long_option[option_index].name, "stats-reset",
245                                         MAX_LONG_OPT_SZ))
246                                 reset_stats = 1;
247                         /* Reset xstats */
248                         else if (!strncmp(long_option[option_index].name, "xstats-reset",
249                                         MAX_LONG_OPT_SZ))
250                                 reset_xstats = 1;
251                         else if (!strncmp(long_option[option_index].name,
252                                         "show-port", MAX_LONG_OPT_SZ))
253                                 enable_shw_port = 1;
254                         break;
255                 case 1:
256                         /* Print xstat single value given by name*/
257                         if (!strncmp(long_option[option_index].name,
258                                         "xstats-name", MAX_LONG_OPT_SZ)) {
259                                 enable_xstats_name = 1;
260                                 xstats_name = optarg;
261                                 printf("name:%s:%s\n",
262                                                 long_option[option_index].name,
263                                                 optarg);
264                         } else if (!strncmp(long_option[option_index].name,
265                                         "xstats-ids",
266                                         MAX_LONG_OPT_SZ))       {
267                                 nb_xstats_ids = parse_xstats_ids(optarg,
268                                                 xstats_ids, MAX_NB_XSTATS_IDS);
269
270                                 if (nb_xstats_ids <= 0) {
271                                         printf("xstats-id list parse error.\n");
272                                         return -1;
273                                 }
274
275                         }
276                         break;
277                 default:
278                         proc_info_usage(prgname);
279                         return -1;
280                 }
281         }
282         return 0;
283 }
284
285 static void
286 meminfo_display(void)
287 {
288         printf("----------- MEMORY_SEGMENTS -----------\n");
289         rte_dump_physmem_layout(stdout);
290         printf("--------- END_MEMORY_SEGMENTS ---------\n");
291
292         printf("------------ MEMORY_ZONES -------------\n");
293         rte_memzone_dump(stdout);
294         printf("---------- END_MEMORY_ZONES -----------\n");
295
296         printf("------------- TAIL_QUEUES -------------\n");
297         rte_dump_tailq(stdout);
298         printf("---------- END_TAIL_QUEUES ------------\n");
299 }
300
301 static void
302 nic_stats_display(uint16_t port_id)
303 {
304         struct rte_eth_stats stats;
305         uint8_t i;
306
307         static const char *nic_stats_border = "########################";
308
309         rte_eth_stats_get(port_id, &stats);
310         printf("\n  %s NIC statistics for port %-2d %s\n",
311                    nic_stats_border, port_id, nic_stats_border);
312
313         printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
314                "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
315                stats.ibytes);
316         printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
317         printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
318                "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
319                stats.obytes);
320
321         printf("\n");
322         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
323                 printf("  Stats reg %2d RX-packets: %-10"PRIu64
324                        "  RX-errors: %-10"PRIu64
325                        "  RX-bytes: %-10"PRIu64"\n",
326                        i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
327         }
328
329         printf("\n");
330         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
331                 printf("  Stats reg %2d TX-packets: %-10"PRIu64
332                        "  TX-bytes: %-10"PRIu64"\n",
333                        i, stats.q_opackets[i], stats.q_obytes[i]);
334         }
335
336         printf("  %s############################%s\n",
337                    nic_stats_border, nic_stats_border);
338 }
339
340 static void
341 nic_stats_clear(uint16_t port_id)
342 {
343         printf("\n Clearing NIC stats for port %d\n", port_id);
344         rte_eth_stats_reset(port_id);
345         printf("\n  NIC statistics for port %d cleared\n", port_id);
346 }
347
348 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
349                                       const char *cnt_name) {
350         char *type_end = strrchr(cnt_name, '_');
351
352         if ((type_end != NULL) &&
353             (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
354                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
355                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
356                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
357                         strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
358                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
359                         strncpy(cnt_type, "if_rx_octets", cnt_type_len);
360                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
361                         strncpy(cnt_type, "if_rx_packets", cnt_type_len);
362                 else if (strncmp(type_end, "_placement",
363                                  strlen("_placement")) == 0)
364                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
365                 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
366                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
367                 else
368                         /* Does not fit obvious type: use a more generic one */
369                         strncpy(cnt_type, "derive", cnt_type_len);
370         } else if ((type_end != NULL) &&
371                 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
372                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
373                         strncpy(cnt_type, "if_tx_errors", cnt_type_len);
374                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
375                         strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
376                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
377                         strncpy(cnt_type, "if_tx_octets", cnt_type_len);
378                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
379                         strncpy(cnt_type, "if_tx_packets", cnt_type_len);
380                 else
381                         /* Does not fit obvious type: use a more generic one */
382                         strncpy(cnt_type, "derive", cnt_type_len);
383         } else if ((type_end != NULL) &&
384                    (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
385                 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
386                         strncpy(cnt_type, "operations", cnt_type_len);
387                 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
388                         strncpy(cnt_type, "errors", cnt_type_len);
389                 else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
390                         strncpy(cnt_type, "filter_result", cnt_type_len);
391         } else if ((type_end != NULL) &&
392                    (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
393                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
394                         strncpy(cnt_type, "errors", cnt_type_len);
395         } else {
396                 /* Does not fit obvious type, or strrchr error: */
397                 /* use a more generic type */
398                 strncpy(cnt_type, "derive", cnt_type_len);
399         }
400 }
401
402 static void
403 nic_xstats_by_name_display(uint16_t port_id, char *name)
404 {
405         uint64_t id;
406
407         printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
408                            port_id, name);
409
410         if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
411                 printf("%s: %"PRIu64"\n", name, id);
412         else
413                 printf("Statistic not found...\n");
414
415 }
416
417 static void
418 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
419 {
420         struct rte_eth_xstat_name *xstats_names;
421         uint64_t *values;
422         int ret, i;
423         static const char *nic_stats_border = "########################";
424
425         values = malloc(sizeof(*values) * len);
426         if (values == NULL) {
427                 printf("Cannot allocate memory for xstats\n");
428                 return;
429         }
430
431         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
432         if (xstats_names == NULL) {
433                 printf("Cannot allocate memory for xstat names\n");
434                 free(values);
435                 return;
436         }
437
438         if (len != rte_eth_xstats_get_names_by_id(
439                         port_id, xstats_names, len, ids)) {
440                 printf("Cannot get xstat names\n");
441                 goto err;
442         }
443
444         printf("###### NIC extended statistics for port %-2d #########\n",
445                            port_id);
446         printf("%s############################\n", nic_stats_border);
447         ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
448         if (ret < 0 || ret > len) {
449                 printf("Cannot get xstats\n");
450                 goto err;
451         }
452
453         for (i = 0; i < len; i++)
454                 printf("%s: %"PRIu64"\n",
455                         xstats_names[i].name,
456                         values[i]);
457
458         printf("%s############################\n", nic_stats_border);
459 err:
460         free(values);
461         free(xstats_names);
462 }
463
464 static void
465 nic_xstats_display(uint16_t port_id)
466 {
467         struct rte_eth_xstat_name *xstats_names;
468         uint64_t *values;
469         int len, ret, i;
470         static const char *nic_stats_border = "########################";
471
472         len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
473         if (len < 0) {
474                 printf("Cannot get xstats count\n");
475                 return;
476         }
477         values = malloc(sizeof(*values) * len);
478         if (values == NULL) {
479                 printf("Cannot allocate memory for xstats\n");
480                 return;
481         }
482
483         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
484         if (xstats_names == NULL) {
485                 printf("Cannot allocate memory for xstat names\n");
486                 free(values);
487                 return;
488         }
489         if (len != rte_eth_xstats_get_names_by_id(
490                         port_id, xstats_names, len, NULL)) {
491                 printf("Cannot get xstat names\n");
492                 goto err;
493         }
494
495         printf("###### NIC extended statistics for port %-2d #########\n",
496                            port_id);
497         printf("%s############################\n",
498                            nic_stats_border);
499         ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
500         if (ret < 0 || ret > len) {
501                 printf("Cannot get xstats\n");
502                 goto err;
503         }
504
505         for (i = 0; i < len; i++) {
506                 if (enable_collectd_format) {
507                         char counter_type[MAX_STRING_LEN];
508                         char buf[MAX_STRING_LEN];
509                         size_t n;
510
511                         collectd_resolve_cnt_type(counter_type,
512                                                   sizeof(counter_type),
513                                                   xstats_names[i].name);
514                         n = snprintf(buf, MAX_STRING_LEN,
515                                 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
516                                 PRIu64"\n", host_id, port_id, counter_type,
517                                 xstats_names[i].name, values[i]);
518                         if (n > sizeof(buf) - 1)
519                                 n = sizeof(buf) - 1;
520                         ret = write(stdout_fd, buf, n);
521                         if (ret < 0)
522                                 goto err;
523                 } else {
524                         printf("%s: %"PRIu64"\n", xstats_names[i].name,
525                                         values[i]);
526                 }
527         }
528
529         printf("%s############################\n",
530                            nic_stats_border);
531 err:
532         free(values);
533         free(xstats_names);
534 }
535
536 static void
537 nic_xstats_clear(uint16_t port_id)
538 {
539         printf("\n Clearing NIC xstats for port %d\n", port_id);
540         rte_eth_xstats_reset(port_id);
541         printf("\n  NIC extended statistics for port %d cleared\n", port_id);
542 }
543
544 static void
545 metrics_display(int port_id)
546 {
547         struct rte_metric_value *metrics;
548         struct rte_metric_name *names;
549         int len, ret;
550         static const char *nic_stats_border = "########################";
551
552         len = rte_metrics_get_names(NULL, 0);
553         if (len < 0) {
554                 printf("Cannot get metrics count\n");
555                 return;
556         }
557         if (len == 0) {
558                 printf("No metrics to display (none have been registered)\n");
559                 return;
560         }
561
562         metrics = rte_malloc("proc_info_metrics",
563                 sizeof(struct rte_metric_value) * len, 0);
564         if (metrics == NULL) {
565                 printf("Cannot allocate memory for metrics\n");
566                 return;
567         }
568
569         names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
570         if (names == NULL) {
571                 printf("Cannot allocate memory for metrcis names\n");
572                 rte_free(metrics);
573                 return;
574         }
575
576         if (len != rte_metrics_get_names(names, len)) {
577                 printf("Cannot get metrics names\n");
578                 rte_free(metrics);
579                 rte_free(names);
580                 return;
581         }
582
583         if (port_id == RTE_METRICS_GLOBAL)
584                 printf("###### Non port specific metrics  #########\n");
585         else
586                 printf("###### metrics for port %-2d #########\n", port_id);
587         printf("%s############################\n", nic_stats_border);
588         ret = rte_metrics_get_values(port_id, metrics, len);
589         if (ret < 0 || ret > len) {
590                 printf("Cannot get metrics values\n");
591                 rte_free(metrics);
592                 rte_free(names);
593                 return;
594         }
595
596         int i;
597         for (i = 0; i < len; i++)
598                 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
599
600         printf("%s############################\n", nic_stats_border);
601         rte_free(metrics);
602         rte_free(names);
603 }
604
605 static void
606 show_port(void)
607 {
608         uint16_t i = 0;
609         int ret = 0, j, k;
610
611         snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD %"PRIu64,
612                         rte_get_tsc_hz());
613         STATS_BDR_STR(10, bdr_str);
614
615         RTE_ETH_FOREACH_DEV(i) {
616                 uint16_t mtu = 0;
617                 struct rte_eth_link link;
618                 struct rte_eth_dev_info dev_info;
619                 struct rte_eth_rxq_info queue_info;
620                 struct rte_eth_rss_conf rss_conf;
621
622                 memset(&rss_conf, 0, sizeof(rss_conf));
623
624                 snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i);
625                 STATS_BDR_STR(5, bdr_str);
626                 printf("  - generic config\n");
627
628                 printf("\t  -- Socket %d\n", rte_eth_dev_socket_id(i));
629                 rte_eth_link_get(i, &link);
630                 printf("\t  -- link speed %d duplex %d,"
631                                 " auto neg %d status %d\n",
632                                 link.link_speed,
633                                 link.link_duplex,
634                                 link.link_autoneg,
635                                 link.link_status);
636                 printf("\t  -- promiscuous (%d)\n",
637                                 rte_eth_promiscuous_get(i));
638                 ret = rte_eth_dev_get_mtu(i, &mtu);
639                 if (ret == 0)
640                         printf("\t  -- mtu (%d)\n", mtu);
641
642                 rte_eth_dev_info_get(i, &dev_info);
643
644                 printf("  - queue\n");
645                 for (j = 0; j < dev_info.nb_rx_queues; j++) {
646                         ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
647                         if (ret == 0) {
648                                 printf("\t  -- queue %d rx scatter %d"
649                                                 " descriptors %d"
650                                                 " offloads 0x%"PRIx64
651                                                 " mempool socket %d\n",
652                                                 j,
653                                                 queue_info.scattered_rx,
654                                                 queue_info.nb_desc,
655                                                 queue_info.conf.offloads,
656                                                 queue_info.mp->socket_id);
657                         }
658                 }
659
660                 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
661                 if (ret == 0) {
662                         if (rss_conf.rss_key) {
663                                 printf("  - RSS\n");
664                                 printf("\t  -- RSS len %u key (hex):",
665                                                 rss_conf.rss_key_len);
666                                 for (k = 0; k < rss_conf.rss_key_len; k++)
667                                         printf(" %x", rss_conf.rss_key[k]);
668                                 printf("\t  -- hf 0x%"PRIx64"\n",
669                                                 rss_conf.rss_hf);
670                         }
671                 }
672
673                 printf("  - cyrpto context\n");
674                 void *p_ctx = rte_eth_dev_get_sec_ctx(i);
675                 printf("\t  -- security context - %p\n", p_ctx);
676
677                 if (p_ctx) {
678                         printf("\t  -- size %u\n",
679                                         rte_security_session_get_size(p_ctx));
680                         const struct rte_security_capability *s_cap =
681                                 rte_security_capabilities_get(p_ctx);
682                         if (s_cap) {
683                                 printf("\t  -- action (0x%x), protocol (0x%x),"
684                                                 " offload flags (0x%x)\n",
685                                                 s_cap->action,
686                                                 s_cap->protocol,
687                                                 s_cap->ol_flags);
688                                 printf("\t  -- capabilities - oper type %x\n",
689                                                 s_cap->crypto_capabilities->op);
690                         }
691                 }
692         }
693
694         STATS_BDR_STR(50, "");
695 }
696
697 int
698 main(int argc, char **argv)
699 {
700         int ret;
701         int i;
702         char c_flag[] = "-c1";
703         char n_flag[] = "-n4";
704         char mp_flag[] = "--proc-type=secondary";
705         char *argp[argc + 3];
706         uint16_t nb_ports;
707
708         /* preparse app arguments */
709         ret = proc_info_preparse_args(argc, argv);
710         if (ret < 0) {
711                 printf("Failed to parse arguments\n");
712                 return -1;
713         }
714
715         argp[0] = argv[0];
716         argp[1] = c_flag;
717         argp[2] = n_flag;
718         argp[3] = mp_flag;
719
720         for (i = 1; i < argc; i++)
721                 argp[i + 3] = argv[i];
722
723         argc += 3;
724
725         ret = rte_eal_init(argc, argp);
726         if (ret < 0)
727                 rte_panic("Cannot init EAL\n");
728
729         argc -= ret;
730         argv += (ret - 3);
731
732         if (!rte_eal_primary_proc_alive(NULL))
733                 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
734
735         /* parse app arguments */
736         ret = proc_info_parse_args(argc, argv);
737         if (ret < 0)
738                 rte_exit(EXIT_FAILURE, "Invalid argument\n");
739
740         if (mem_info) {
741                 meminfo_display();
742                 return 0;
743         }
744
745         nb_ports = rte_eth_dev_count_avail();
746         if (nb_ports == 0)
747                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
748
749         /* If no port mask was specified*/
750         if (enabled_port_mask == 0)
751                 enabled_port_mask = 0xffff;
752
753         RTE_ETH_FOREACH_DEV(i) {
754                 if (enabled_port_mask & (1 << i)) {
755                         if (enable_stats)
756                                 nic_stats_display(i);
757                         else if (enable_xstats)
758                                 nic_xstats_display(i);
759                         else if (reset_stats)
760                                 nic_stats_clear(i);
761                         else if (reset_xstats)
762                                 nic_xstats_clear(i);
763                         else if (enable_xstats_name)
764                                 nic_xstats_by_name_display(i, xstats_name);
765                         else if (nb_xstats_ids > 0)
766                                 nic_xstats_by_ids_display(i, xstats_ids,
767                                                 nb_xstats_ids);
768                         else if (enable_metrics)
769                                 metrics_display(i);
770                 }
771         }
772
773         /* print port independent stats */
774         if (enable_metrics)
775                 metrics_display(RTE_METRICS_GLOBAL);
776
777         /* show information for PMD */
778         if (enable_shw_port)
779                 show_port();
780
781         ret = rte_eal_cleanup();
782         if (ret)
783                 printf("Error from rte_eal_cleanup(), %d\n", ret);
784
785         snprintf(bdr_str, MAX_STRING_LEN, " ");
786         STATS_BDR_STR(50, bdr_str);
787
788         return 0;
789 }