app/procinfo: add --show-tm
[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
84 /**< display usage */
85 static void
86 proc_info_usage(const char *prgname)
87 {
88         printf("%s [EAL options] -- -p PORTMASK\n"
89                 "  -m to display DPDK memory zones, segments and TAILQ information\n"
90                 "  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
91                 "  --stats: to display port statistics, enabled by default\n"
92                 "  --xstats: to display extended port statistics, disabled by "
93                         "default\n"
94                 "  --metrics: to display derived metrics of the ports, disabled by "
95                         "default\n"
96                 "  --xstats-name NAME: to display single xstat id by NAME\n"
97                 "  --xstats-ids IDLIST: to display xstat values by id. "
98                         "The argument is comma-separated list of xstat ids to print out.\n"
99                 "  --stats-reset: to reset port statistics\n"
100                 "  --xstats-reset: to reset port extended statistics\n"
101                 "  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
102                 "  --host-id STRING: host id used to identify the system process is running on\n"
103                 "  --show-port: to display ports information\n"
104                 "  --show-tm: to display traffic manager information for ports\n",
105                 prgname);
106 }
107
108 /*
109  * Parse the portmask provided at run time.
110  */
111 static int
112 parse_portmask(const char *portmask)
113 {
114         char *end = NULL;
115         unsigned long pm;
116
117         errno = 0;
118
119         /* parse hexadecimal string */
120         pm = strtoul(portmask, &end, 16);
121         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
122                 (errno != 0)) {
123                 printf("%s ERROR parsing the port mask\n", __func__);
124                 return -1;
125         }
126
127         if (pm == 0)
128                 return -1;
129
130         return pm;
131
132 }
133
134 /*
135  * Parse ids value list into array
136  */
137 static int
138 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
139         int length;
140         char *token;
141         char *ctx = NULL;
142         char *endptr;
143
144         length = 0;
145         token = strtok_r(list, ",", &ctx);
146         while (token != NULL) {
147                 ids[length] = strtoull(token, &endptr, 10);
148                 if (*endptr != '\0')
149                         return -EINVAL;
150
151                 length++;
152                 if (length >= limit)
153                         return -E2BIG;
154
155                 token = strtok_r(NULL, ",", &ctx);
156         }
157
158         return length;
159 }
160
161 static int
162 proc_info_preparse_args(int argc, char **argv)
163 {
164         char *prgname = argv[0];
165         int i;
166
167         for (i = 0; i < argc; i++) {
168                 /* Print stats or xstats to STDOUT in collectd format */
169                 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
170                         enable_collectd_format = 1;
171                         stdout_fd = dup(STDOUT_FILENO);
172                         close(STDOUT_FILENO);
173                 }
174                 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
175                         if ((i + 1) == argc) {
176                                 printf("Invalid host id or not specified\n");
177                                 proc_info_usage(prgname);
178                                 return -1;
179                         }
180                         snprintf(host_id, sizeof(host_id), "%s", argv[i+1]);
181                 }
182         }
183
184         if (!strlen(host_id)) {
185                 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
186
187                 if (err)
188                         strcpy(host_id, "unknown");
189         }
190
191         return 0;
192 }
193
194 /* Parse the argument given in the command line of the application */
195 static int
196 proc_info_parse_args(int argc, char **argv)
197 {
198         int opt;
199         int option_index;
200         char *prgname = argv[0];
201         static struct option long_option[] = {
202                 {"stats", 0, NULL, 0},
203                 {"stats-reset", 0, NULL, 0},
204                 {"xstats", 0, NULL, 0},
205                 {"metrics", 0, NULL, 0},
206                 {"xstats-reset", 0, NULL, 0},
207                 {"xstats-name", required_argument, NULL, 1},
208                 {"collectd-format", 0, NULL, 0},
209                 {"xstats-ids", 1, NULL, 1},
210                 {"host-id", 0, NULL, 0},
211                 {"show-port", 0, NULL, 0},
212                 {"show-tm", 0, NULL, 0},
213                 {NULL, 0, 0, 0}
214         };
215
216         if (argc == 1)
217                 proc_info_usage(prgname);
218
219         /* Parse command line */
220         while ((opt = getopt_long(argc, argv, "p:m",
221                         long_option, &option_index)) != EOF) {
222                 switch (opt) {
223                 /* portmask */
224                 case 'p':
225                         enabled_port_mask = parse_portmask(optarg);
226                         if (enabled_port_mask == 0) {
227                                 printf("invalid portmask\n");
228                                 proc_info_usage(prgname);
229                                 return -1;
230                         }
231                         break;
232                 case 'm':
233                         mem_info = 1;
234                         break;
235                 case 0:
236                         /* Print stats */
237                         if (!strncmp(long_option[option_index].name, "stats",
238                                         MAX_LONG_OPT_SZ))
239                                 enable_stats = 1;
240                         /* Print xstats */
241                         else if (!strncmp(long_option[option_index].name, "xstats",
242                                         MAX_LONG_OPT_SZ))
243                                 enable_xstats = 1;
244                         else if (!strncmp(long_option[option_index].name,
245                                         "metrics",
246                                         MAX_LONG_OPT_SZ))
247                                 enable_metrics = 1;
248                         /* Reset stats */
249                         if (!strncmp(long_option[option_index].name, "stats-reset",
250                                         MAX_LONG_OPT_SZ))
251                                 reset_stats = 1;
252                         /* Reset xstats */
253                         else if (!strncmp(long_option[option_index].name, "xstats-reset",
254                                         MAX_LONG_OPT_SZ))
255                                 reset_xstats = 1;
256                         else if (!strncmp(long_option[option_index].name,
257                                         "show-port", MAX_LONG_OPT_SZ))
258                                 enable_shw_port = 1;
259                         else if (!strncmp(long_option[option_index].name,
260                                         "show-tm", MAX_LONG_OPT_SZ))
261                                 enable_shw_tm = 1;
262                         break;
263                 case 1:
264                         /* Print xstat single value given by name*/
265                         if (!strncmp(long_option[option_index].name,
266                                         "xstats-name", MAX_LONG_OPT_SZ)) {
267                                 enable_xstats_name = 1;
268                                 xstats_name = optarg;
269                                 printf("name:%s:%s\n",
270                                                 long_option[option_index].name,
271                                                 optarg);
272                         } else if (!strncmp(long_option[option_index].name,
273                                         "xstats-ids",
274                                         MAX_LONG_OPT_SZ))       {
275                                 nb_xstats_ids = parse_xstats_ids(optarg,
276                                                 xstats_ids, MAX_NB_XSTATS_IDS);
277
278                                 if (nb_xstats_ids <= 0) {
279                                         printf("xstats-id list parse error.\n");
280                                         return -1;
281                                 }
282
283                         }
284                         break;
285                 default:
286                         proc_info_usage(prgname);
287                         return -1;
288                 }
289         }
290         return 0;
291 }
292
293 static void
294 meminfo_display(void)
295 {
296         printf("----------- MEMORY_SEGMENTS -----------\n");
297         rte_dump_physmem_layout(stdout);
298         printf("--------- END_MEMORY_SEGMENTS ---------\n");
299
300         printf("------------ MEMORY_ZONES -------------\n");
301         rte_memzone_dump(stdout);
302         printf("---------- END_MEMORY_ZONES -----------\n");
303
304         printf("------------- TAIL_QUEUES -------------\n");
305         rte_dump_tailq(stdout);
306         printf("---------- END_TAIL_QUEUES ------------\n");
307 }
308
309 static void
310 nic_stats_display(uint16_t port_id)
311 {
312         struct rte_eth_stats stats;
313         uint8_t i;
314
315         static const char *nic_stats_border = "########################";
316
317         rte_eth_stats_get(port_id, &stats);
318         printf("\n  %s NIC statistics for port %-2d %s\n",
319                    nic_stats_border, port_id, nic_stats_border);
320
321         printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
322                "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
323                stats.ibytes);
324         printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
325         printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
326                "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
327                stats.obytes);
328
329         printf("\n");
330         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
331                 printf("  Stats reg %2d RX-packets: %-10"PRIu64
332                        "  RX-errors: %-10"PRIu64
333                        "  RX-bytes: %-10"PRIu64"\n",
334                        i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
335         }
336
337         printf("\n");
338         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
339                 printf("  Stats reg %2d TX-packets: %-10"PRIu64
340                        "  TX-bytes: %-10"PRIu64"\n",
341                        i, stats.q_opackets[i], stats.q_obytes[i]);
342         }
343
344         printf("  %s############################%s\n",
345                    nic_stats_border, nic_stats_border);
346 }
347
348 static void
349 nic_stats_clear(uint16_t port_id)
350 {
351         printf("\n Clearing NIC stats for port %d\n", port_id);
352         rte_eth_stats_reset(port_id);
353         printf("\n  NIC statistics for port %d cleared\n", port_id);
354 }
355
356 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
357                                       const char *cnt_name) {
358         char *type_end = strrchr(cnt_name, '_');
359
360         if ((type_end != NULL) &&
361             (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
362                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
363                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
364                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
365                         strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
366                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
367                         strncpy(cnt_type, "if_rx_octets", cnt_type_len);
368                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
369                         strncpy(cnt_type, "if_rx_packets", cnt_type_len);
370                 else if (strncmp(type_end, "_placement",
371                                  strlen("_placement")) == 0)
372                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
373                 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
374                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
375                 else
376                         /* Does not fit obvious type: use a more generic one */
377                         strncpy(cnt_type, "derive", cnt_type_len);
378         } else if ((type_end != NULL) &&
379                 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
380                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
381                         strncpy(cnt_type, "if_tx_errors", cnt_type_len);
382                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
383                         strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
384                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
385                         strncpy(cnt_type, "if_tx_octets", cnt_type_len);
386                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
387                         strncpy(cnt_type, "if_tx_packets", cnt_type_len);
388                 else
389                         /* Does not fit obvious type: use a more generic one */
390                         strncpy(cnt_type, "derive", cnt_type_len);
391         } else if ((type_end != NULL) &&
392                    (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
393                 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
394                         strncpy(cnt_type, "operations", cnt_type_len);
395                 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
396                         strncpy(cnt_type, "errors", cnt_type_len);
397                 else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
398                         strncpy(cnt_type, "filter_result", cnt_type_len);
399         } else if ((type_end != NULL) &&
400                    (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
401                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
402                         strncpy(cnt_type, "errors", cnt_type_len);
403         } else {
404                 /* Does not fit obvious type, or strrchr error: */
405                 /* use a more generic type */
406                 strncpy(cnt_type, "derive", cnt_type_len);
407         }
408 }
409
410 static void
411 nic_xstats_by_name_display(uint16_t port_id, char *name)
412 {
413         uint64_t id;
414
415         printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
416                            port_id, name);
417
418         if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
419                 printf("%s: %"PRIu64"\n", name, id);
420         else
421                 printf("Statistic not found...\n");
422
423 }
424
425 static void
426 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
427 {
428         struct rte_eth_xstat_name *xstats_names;
429         uint64_t *values;
430         int ret, i;
431         static const char *nic_stats_border = "########################";
432
433         values = malloc(sizeof(*values) * len);
434         if (values == NULL) {
435                 printf("Cannot allocate memory for xstats\n");
436                 return;
437         }
438
439         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
440         if (xstats_names == NULL) {
441                 printf("Cannot allocate memory for xstat names\n");
442                 free(values);
443                 return;
444         }
445
446         if (len != rte_eth_xstats_get_names_by_id(
447                         port_id, xstats_names, len, ids)) {
448                 printf("Cannot get xstat names\n");
449                 goto err;
450         }
451
452         printf("###### NIC extended statistics for port %-2d #########\n",
453                            port_id);
454         printf("%s############################\n", nic_stats_border);
455         ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
456         if (ret < 0 || ret > len) {
457                 printf("Cannot get xstats\n");
458                 goto err;
459         }
460
461         for (i = 0; i < len; i++)
462                 printf("%s: %"PRIu64"\n",
463                         xstats_names[i].name,
464                         values[i]);
465
466         printf("%s############################\n", nic_stats_border);
467 err:
468         free(values);
469         free(xstats_names);
470 }
471
472 static void
473 nic_xstats_display(uint16_t port_id)
474 {
475         struct rte_eth_xstat_name *xstats_names;
476         uint64_t *values;
477         int len, ret, i;
478         static const char *nic_stats_border = "########################";
479
480         len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
481         if (len < 0) {
482                 printf("Cannot get xstats count\n");
483                 return;
484         }
485         values = malloc(sizeof(*values) * len);
486         if (values == NULL) {
487                 printf("Cannot allocate memory for xstats\n");
488                 return;
489         }
490
491         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
492         if (xstats_names == NULL) {
493                 printf("Cannot allocate memory for xstat names\n");
494                 free(values);
495                 return;
496         }
497         if (len != rte_eth_xstats_get_names_by_id(
498                         port_id, xstats_names, len, NULL)) {
499                 printf("Cannot get xstat names\n");
500                 goto err;
501         }
502
503         printf("###### NIC extended statistics for port %-2d #########\n",
504                            port_id);
505         printf("%s############################\n",
506                            nic_stats_border);
507         ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
508         if (ret < 0 || ret > len) {
509                 printf("Cannot get xstats\n");
510                 goto err;
511         }
512
513         for (i = 0; i < len; i++) {
514                 if (enable_collectd_format) {
515                         char counter_type[MAX_STRING_LEN];
516                         char buf[MAX_STRING_LEN];
517                         size_t n;
518
519                         collectd_resolve_cnt_type(counter_type,
520                                                   sizeof(counter_type),
521                                                   xstats_names[i].name);
522                         n = snprintf(buf, MAX_STRING_LEN,
523                                 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
524                                 PRIu64"\n", host_id, port_id, counter_type,
525                                 xstats_names[i].name, values[i]);
526                         if (n > sizeof(buf) - 1)
527                                 n = sizeof(buf) - 1;
528                         ret = write(stdout_fd, buf, n);
529                         if (ret < 0)
530                                 goto err;
531                 } else {
532                         printf("%s: %"PRIu64"\n", xstats_names[i].name,
533                                         values[i]);
534                 }
535         }
536
537         printf("%s############################\n",
538                            nic_stats_border);
539 err:
540         free(values);
541         free(xstats_names);
542 }
543
544 static void
545 nic_xstats_clear(uint16_t port_id)
546 {
547         printf("\n Clearing NIC xstats for port %d\n", port_id);
548         rte_eth_xstats_reset(port_id);
549         printf("\n  NIC extended statistics for port %d cleared\n", port_id);
550 }
551
552 static void
553 metrics_display(int port_id)
554 {
555         struct rte_metric_value *metrics;
556         struct rte_metric_name *names;
557         int len, ret;
558         static const char *nic_stats_border = "########################";
559
560         len = rte_metrics_get_names(NULL, 0);
561         if (len < 0) {
562                 printf("Cannot get metrics count\n");
563                 return;
564         }
565         if (len == 0) {
566                 printf("No metrics to display (none have been registered)\n");
567                 return;
568         }
569
570         metrics = rte_malloc("proc_info_metrics",
571                 sizeof(struct rte_metric_value) * len, 0);
572         if (metrics == NULL) {
573                 printf("Cannot allocate memory for metrics\n");
574                 return;
575         }
576
577         names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
578         if (names == NULL) {
579                 printf("Cannot allocate memory for metrcis names\n");
580                 rte_free(metrics);
581                 return;
582         }
583
584         if (len != rte_metrics_get_names(names, len)) {
585                 printf("Cannot get metrics names\n");
586                 rte_free(metrics);
587                 rte_free(names);
588                 return;
589         }
590
591         if (port_id == RTE_METRICS_GLOBAL)
592                 printf("###### Non port specific metrics  #########\n");
593         else
594                 printf("###### metrics for port %-2d #########\n", port_id);
595         printf("%s############################\n", nic_stats_border);
596         ret = rte_metrics_get_values(port_id, metrics, len);
597         if (ret < 0 || ret > len) {
598                 printf("Cannot get metrics values\n");
599                 rte_free(metrics);
600                 rte_free(names);
601                 return;
602         }
603
604         int i;
605         for (i = 0; i < len; i++)
606                 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
607
608         printf("%s############################\n", nic_stats_border);
609         rte_free(metrics);
610         rte_free(names);
611 }
612
613 static void
614 show_port(void)
615 {
616         uint16_t i = 0;
617         int ret = 0, j, k;
618
619         snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD %"PRIu64,
620                         rte_get_tsc_hz());
621         STATS_BDR_STR(10, bdr_str);
622
623         RTE_ETH_FOREACH_DEV(i) {
624                 uint16_t mtu = 0;
625                 struct rte_eth_link link;
626                 struct rte_eth_dev_info dev_info;
627                 struct rte_eth_rxq_info queue_info;
628                 struct rte_eth_rss_conf rss_conf;
629
630                 memset(&rss_conf, 0, sizeof(rss_conf));
631
632                 snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i);
633                 STATS_BDR_STR(5, bdr_str);
634                 printf("  - generic config\n");
635
636                 printf("\t  -- Socket %d\n", rte_eth_dev_socket_id(i));
637                 rte_eth_link_get(i, &link);
638                 printf("\t  -- link speed %d duplex %d,"
639                                 " auto neg %d status %d\n",
640                                 link.link_speed,
641                                 link.link_duplex,
642                                 link.link_autoneg,
643                                 link.link_status);
644                 printf("\t  -- promiscuous (%d)\n",
645                                 rte_eth_promiscuous_get(i));
646                 ret = rte_eth_dev_get_mtu(i, &mtu);
647                 if (ret == 0)
648                         printf("\t  -- mtu (%d)\n", mtu);
649
650                 rte_eth_dev_info_get(i, &dev_info);
651
652                 printf("  - queue\n");
653                 for (j = 0; j < dev_info.nb_rx_queues; j++) {
654                         ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
655                         if (ret == 0) {
656                                 printf("\t  -- queue %d rx scatter %d"
657                                                 " descriptors %d"
658                                                 " offloads 0x%"PRIx64
659                                                 " mempool socket %d\n",
660                                                 j,
661                                                 queue_info.scattered_rx,
662                                                 queue_info.nb_desc,
663                                                 queue_info.conf.offloads,
664                                                 queue_info.mp->socket_id);
665                         }
666                 }
667
668                 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
669                 if (ret == 0) {
670                         if (rss_conf.rss_key) {
671                                 printf("  - RSS\n");
672                                 printf("\t  -- RSS len %u key (hex):",
673                                                 rss_conf.rss_key_len);
674                                 for (k = 0; k < rss_conf.rss_key_len; k++)
675                                         printf(" %x", rss_conf.rss_key[k]);
676                                 printf("\t  -- hf 0x%"PRIx64"\n",
677                                                 rss_conf.rss_hf);
678                         }
679                 }
680
681                 printf("  - cyrpto context\n");
682                 void *p_ctx = rte_eth_dev_get_sec_ctx(i);
683                 printf("\t  -- security context - %p\n", p_ctx);
684
685                 if (p_ctx) {
686                         printf("\t  -- size %u\n",
687                                         rte_security_session_get_size(p_ctx));
688                         const struct rte_security_capability *s_cap =
689                                 rte_security_capabilities_get(p_ctx);
690                         if (s_cap) {
691                                 printf("\t  -- action (0x%x), protocol (0x%x),"
692                                                 " offload flags (0x%x)\n",
693                                                 s_cap->action,
694                                                 s_cap->protocol,
695                                                 s_cap->ol_flags);
696                                 printf("\t  -- capabilities - oper type %x\n",
697                                                 s_cap->crypto_capabilities->op);
698                         }
699                 }
700         }
701
702         STATS_BDR_STR(50, "");
703 }
704
705 static void
706 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap)
707 {
708         if (cap == NULL)
709                 return;
710
711         if (!is_leaf) {
712                 printf("\t  -- nonleaf sched max:\n"
713                         "\t\t  + children (%u)\n"
714                         "\t\t  + sp priorities (%u)\n"
715                         "\t\t  + wfq children per group (%u)\n"
716                         "\t\t  + wfq groups (%u)\n"
717                         "\t\t  + wfq weight (%u)\n",
718                         cap->nonleaf.sched_n_children_max,
719                         cap->nonleaf.sched_sp_n_priorities_max,
720                         cap->nonleaf.sched_wfq_n_children_per_group_max,
721                         cap->nonleaf.sched_wfq_n_groups_max,
722                         cap->nonleaf.sched_wfq_weight_max);
723         } else {
724                 printf("\t  -- leaf cman support:\n"
725                         "\t\t  + wred pkt mode (%d)\n"
726                         "\t\t  + wred byte mode (%d)\n"
727                         "\t\t  + head drop (%d)\n"
728                         "\t\t  + wred context private (%d)\n"
729                         "\t\t  + wred context shared (%u)\n",
730                         cap->leaf.cman_wred_packet_mode_supported,
731                         cap->leaf.cman_wred_byte_mode_supported,
732                         cap->leaf.cman_head_drop_supported,
733                         cap->leaf.cman_wred_context_private_supported,
734                         cap->leaf.cman_wred_context_shared_n_max);
735         }
736 }
737
738 static void
739 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap)
740 {
741         if (cap == NULL)
742                 return;
743
744         if (!is_leaf) {
745                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
746                         cap->nonleaf.shaper_private_supported,
747                         cap->nonleaf.shaper_private_dual_rate_supported);
748                 printf("\t  -- shaper share: (%u)\n",
749                         cap->nonleaf.shaper_shared_n_max);
750                 printf("\t  -- non leaf sched MAX:\n"
751                         "\t\t  + children (%u)\n"
752                         "\t\t  + sp (%u)\n"
753                         "\t\t  + wfq children per group (%u)\n"
754                         "\t\t  + wfq groups (%u)\n"
755                         "\t\t  + wfq weight (%u)\n",
756                         cap->nonleaf.sched_n_children_max,
757                         cap->nonleaf.sched_sp_n_priorities_max,
758                         cap->nonleaf.sched_wfq_n_children_per_group_max,
759                         cap->nonleaf.sched_wfq_n_groups_max,
760                         cap->nonleaf.sched_wfq_weight_max);
761         } else {
762                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
763                         cap->leaf.shaper_private_supported,
764                         cap->leaf.shaper_private_dual_rate_supported);
765                 printf("\t  -- shaper share: (%u)\n",
766                         cap->leaf.shaper_shared_n_max);
767                 printf("  -- leaf cman support:\n"
768                         "\t\t  + wred pkt mode (%d)\n"
769                         "\t\t  + wred byte mode (%d)\n"
770                         "\t\t  + head drop (%d)\n"
771                         "\t\t  + wred context private (%d)\n"
772                         "\t\t  + wred context shared (%u)\n",
773                         cap->leaf.cman_wred_packet_mode_supported,
774                         cap->leaf.cman_wred_byte_mode_supported,
775                         cap->leaf.cman_head_drop_supported,
776                         cap->leaf.cman_wred_context_private_supported,
777                         cap->leaf.cman_wred_context_shared_n_max);
778         }
779 }
780
781 static void
782 show_tm(void)
783 {
784         int ret = 0, check_for_leaf = 0, is_leaf = 0;
785         unsigned int j, k;
786         uint16_t i = 0;
787
788         snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD %"PRIu64,
789                         rte_get_tsc_hz());
790         STATS_BDR_STR(10, bdr_str);
791
792         RTE_ETH_FOREACH_DEV(i) {
793                 struct rte_eth_dev_info dev_info;
794                 struct rte_tm_capabilities cap;
795                 struct rte_tm_error error;
796                 struct rte_tm_node_capabilities capnode;
797                 struct rte_tm_level_capabilities caplevel;
798                 uint32_t n_leaf_nodes = 0;
799
800                 memset(&cap, 0, sizeof(cap));
801                 memset(&error, 0, sizeof(error));
802
803                 rte_eth_dev_info_get(i, &dev_info);
804                 printf("  - Generic for port (%u)\n"
805                         "\t  -- driver name %s\n"
806                         "\t  -- max vf (%u)\n"
807                         "\t  -- max tx queues (%u)\n"
808                         "\t  -- number of tx queues (%u)\n",
809                         i,
810                         dev_info.driver_name,
811                         dev_info.max_vfs,
812                         dev_info.max_tx_queues,
813                         dev_info.nb_tx_queues);
814
815                 ret = rte_tm_capabilities_get(i, &cap, &error);
816                 if (ret)
817                         continue;
818
819                 printf("  - MAX: nodes (%u) levels (%u) children (%u)\n",
820                         cap.n_nodes_max,
821                         cap.n_levels_max,
822                         cap.sched_n_children_max);
823
824                 printf("  - identical nodes: non leaf (%d) leaf (%d)\n",
825                         cap.non_leaf_nodes_identical,
826                         cap.leaf_nodes_identical);
827
828                 printf("  - Shaper MAX:\n"
829                         "\t  -- total (%u)\n"
830                         "\t  -- private (%u) private dual (%d)\n"
831                         "\t  -- shared (%u) shared dual (%u)\n",
832                         cap.shaper_n_max,
833                         cap.shaper_private_n_max,
834                         cap.shaper_private_dual_rate_n_max,
835                         cap.shaper_shared_n_max,
836                         cap.shaper_shared_dual_rate_n_max);
837
838                 printf("  - mark support:\n");
839                 printf("\t  -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n",
840                         cap.mark_vlan_dei_supported[RTE_TM_GREEN],
841                         cap.mark_vlan_dei_supported[RTE_TM_YELLOW],
842                         cap.mark_vlan_dei_supported[RTE_TM_RED]);
843                 printf("\t  -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n",
844                         cap.mark_ip_ecn_tcp_supported[RTE_TM_GREEN],
845                         cap.mark_ip_ecn_tcp_supported[RTE_TM_YELLOW],
846                         cap.mark_ip_ecn_tcp_supported[RTE_TM_RED]);
847                 printf("\t  -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n",
848                         cap.mark_ip_ecn_sctp_supported[RTE_TM_GREEN],
849                         cap.mark_ip_ecn_sctp_supported[RTE_TM_YELLOW],
850                         cap.mark_ip_ecn_sctp_supported[RTE_TM_RED]);
851                 printf("\t  -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n",
852                         cap.mark_ip_dscp_supported[RTE_TM_GREEN],
853                         cap.mark_ip_dscp_supported[RTE_TM_YELLOW],
854                         cap.mark_ip_dscp_supported[RTE_TM_RED]);
855
856                 printf("  - mask stats (0x%"PRIx64")"
857                         " dynamic update (0x%"PRIx64")\n",
858                         cap.stats_mask,
859                         cap.dynamic_update_mask);
860
861                 printf("  - sched MAX:\n"
862                         "\t  -- total (%u)\n"
863                         "\t  -- sp levels (%u)\n"
864                         "\t  -- wfq children per group (%u)\n"
865                         "\t  -- wfq groups (%u)\n"
866                         "\t  -- wfq weight (%u)\n",
867                         cap.sched_sp_n_priorities_max,
868                         cap.sched_sp_n_priorities_max,
869                         cap.sched_wfq_n_children_per_group_max,
870                         cap.sched_wfq_n_groups_max,
871                         cap.sched_wfq_weight_max);
872
873                 printf("  - CMAN support:\n"
874                         "\t  -- WRED mode: pkt (%d) byte (%d)\n"
875                         "\t  -- head drop (%d)\n",
876                         cap.cman_wred_packet_mode_supported,
877                         cap.cman_wred_byte_mode_supported,
878                         cap.cman_head_drop_supported);
879                 printf("\t  -- MAX WRED CONTEXT:"
880                         " total (%u) private (%u) shared (%u)\n",
881                         cap.cman_wred_context_n_max,
882                         cap.cman_wred_context_private_n_max,
883                         cap.cman_wred_context_shared_n_max);
884
885                 for (j = 0; j < cap.n_nodes_max; j++) {
886                         memset(&capnode, 0, sizeof(capnode));
887                         ret = rte_tm_node_capabilities_get(i, j,
888                                         &capnode, &error);
889                         if (ret)
890                                 continue;
891
892                         check_for_leaf = 1;
893
894                         printf("  NODE %u\n", j);
895                         printf("\t  - shaper private: (%d) dual rate (%d)\n",
896                                 capnode.shaper_private_supported,
897                                 capnode.shaper_private_dual_rate_supported);
898                         printf("\t  - shaper shared max: (%u)\n",
899                                 capnode.shaper_shared_n_max);
900                         printf("\t  - stats mask %"PRIx64"\n",
901                                 capnode.stats_mask);
902
903                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
904                         if (ret)
905                                 continue;
906
907                         display_nodecap_info(is_leaf, &capnode);
908                 }
909
910                 for (j = 0; j < cap.n_levels_max; j++) {
911                         memset(&caplevel, 0, sizeof(caplevel));
912                         ret = rte_tm_level_capabilities_get(i, j,
913                                         &caplevel, &error);
914                         if (ret)
915                                 continue;
916
917                         printf("  - Level %u\n", j);
918                         printf("\t  -- node MAX: %u non leaf %u leaf %u\n",
919                                 caplevel.n_nodes_max,
920                                 caplevel.n_nodes_nonleaf_max,
921                                 caplevel.n_nodes_leaf_max);
922                         printf("\t  -- indetical: non leaf %u leaf %u\n",
923                                 caplevel.non_leaf_nodes_identical,
924                                 caplevel.leaf_nodes_identical);
925
926                         for (k = 0; k < caplevel.n_nodes_max; k++) {
927                                 ret = rte_tm_node_type_get(i, k,
928                                         &is_leaf, &error);
929                                 if (ret)
930                                         continue;
931
932                                 display_levelcap_info(is_leaf, &caplevel);
933                         }
934                 }
935
936                 if (check_for_leaf) {
937                         ret = rte_tm_get_number_of_leaf_nodes(i,
938                                         &n_leaf_nodes, &error);
939                         if (ret == 0)
940                                 printf("  - leaf nodes (%u)\n", n_leaf_nodes);
941                 }
942
943                 for (j = 0; j < n_leaf_nodes; j++) {
944                         struct rte_tm_node_stats stats;
945                         memset(&stats, 0, sizeof(stats));
946
947                         ret = rte_tm_node_stats_read(i, j,
948                                         &stats, &cap.stats_mask, 0, &error);
949                         if (ret)
950                                 continue;
951
952                         printf("  - STATS for node (%u)\n", j);
953                         printf("  -- pkts (%"PRIu64") bytes (%"PRIu64")\n",
954                                 stats.n_pkts, stats.n_bytes);
955
956                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
957                         if (ret || (!is_leaf))
958                                 continue;
959
960                         printf("  -- leaf queued:"
961                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
962                                 stats.leaf.n_pkts_queued,
963                                 stats.leaf.n_bytes_queued);
964                         printf("  - dropped:\n"
965                                 "\t  -- GREEN:"
966                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
967                                 "\t  -- YELLOW:"
968                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
969                                 "\t  -- RED:"
970                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
971                                 stats.leaf.n_pkts_dropped[RTE_TM_GREEN],
972                                 stats.leaf.n_bytes_dropped[RTE_TM_GREEN],
973                                 stats.leaf.n_pkts_dropped[RTE_TM_YELLOW],
974                                 stats.leaf.n_bytes_dropped[RTE_TM_YELLOW],
975                                 stats.leaf.n_pkts_dropped[RTE_TM_RED],
976                                 stats.leaf.n_bytes_dropped[RTE_TM_RED]);
977                 }
978         }
979
980         STATS_BDR_STR(50, "");
981 }
982
983 int
984 main(int argc, char **argv)
985 {
986         int ret;
987         int i;
988         char c_flag[] = "-c1";
989         char n_flag[] = "-n4";
990         char mp_flag[] = "--proc-type=secondary";
991         char *argp[argc + 3];
992         uint16_t nb_ports;
993
994         /* preparse app arguments */
995         ret = proc_info_preparse_args(argc, argv);
996         if (ret < 0) {
997                 printf("Failed to parse arguments\n");
998                 return -1;
999         }
1000
1001         argp[0] = argv[0];
1002         argp[1] = c_flag;
1003         argp[2] = n_flag;
1004         argp[3] = mp_flag;
1005
1006         for (i = 1; i < argc; i++)
1007                 argp[i + 3] = argv[i];
1008
1009         argc += 3;
1010
1011         ret = rte_eal_init(argc, argp);
1012         if (ret < 0)
1013                 rte_panic("Cannot init EAL\n");
1014
1015         argc -= ret;
1016         argv += (ret - 3);
1017
1018         if (!rte_eal_primary_proc_alive(NULL))
1019                 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
1020
1021         /* parse app arguments */
1022         ret = proc_info_parse_args(argc, argv);
1023         if (ret < 0)
1024                 rte_exit(EXIT_FAILURE, "Invalid argument\n");
1025
1026         if (mem_info) {
1027                 meminfo_display();
1028                 return 0;
1029         }
1030
1031         nb_ports = rte_eth_dev_count_avail();
1032         if (nb_ports == 0)
1033                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1034
1035         /* If no port mask was specified*/
1036         if (enabled_port_mask == 0)
1037                 enabled_port_mask = 0xffff;
1038
1039         RTE_ETH_FOREACH_DEV(i) {
1040                 if (enabled_port_mask & (1 << i)) {
1041                         if (enable_stats)
1042                                 nic_stats_display(i);
1043                         else if (enable_xstats)
1044                                 nic_xstats_display(i);
1045                         else if (reset_stats)
1046                                 nic_stats_clear(i);
1047                         else if (reset_xstats)
1048                                 nic_xstats_clear(i);
1049                         else if (enable_xstats_name)
1050                                 nic_xstats_by_name_display(i, xstats_name);
1051                         else if (nb_xstats_ids > 0)
1052                                 nic_xstats_by_ids_display(i, xstats_ids,
1053                                                 nb_xstats_ids);
1054                         else if (enable_metrics)
1055                                 metrics_display(i);
1056                 }
1057         }
1058
1059         /* print port independent stats */
1060         if (enable_metrics)
1061                 metrics_display(RTE_METRICS_GLOBAL);
1062
1063         /* show information for PMD */
1064         if (enable_shw_port)
1065                 show_port();
1066         if (enable_shw_tm)
1067                 show_tm();
1068
1069         ret = rte_eal_cleanup();
1070         if (ret)
1071                 printf("Error from rte_eal_cleanup(), %d\n", ret);
1072
1073         snprintf(bdr_str, MAX_STRING_LEN, " ");
1074         STATS_BDR_STR(50, bdr_str);
1075
1076         return 0;
1077 }