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 <stdbool.h> 9 #include <errno.h> 10 #include <stdarg.h> 11 #include <inttypes.h> 12 #include <sys/queue.h> 13 #include <stdlib.h> 14 #include <getopt.h> 15 #include <unistd.h> 16 #include <strings.h> 17 18 #include <rte_eal.h> 19 #include <rte_common.h> 20 #include <rte_debug.h> 21 #include <rte_ethdev.h> 22 #include <rte_malloc.h> 23 #include <rte_memory.h> 24 #include <rte_memzone.h> 25 #include <rte_launch.h> 26 #include <rte_tailq.h> 27 #include <rte_per_lcore.h> 28 #include <rte_lcore.h> 29 #include <rte_log.h> 30 #include <rte_atomic.h> 31 #include <rte_branch_prediction.h> 32 #include <rte_string_fns.h> 33 #include <rte_metrics.h> 34 #include <rte_cycles.h> 35 #ifdef RTE_LIB_SECURITY 36 #include <rte_security.h> 37 #endif 38 #include <rte_cryptodev.h> 39 #include <rte_tm.h> 40 #include <rte_hexdump.h> 41 42 /* Maximum long option length for option parsing. */ 43 #define MAX_LONG_OPT_SZ 64 44 #define MAX_STRING_LEN 256 45 46 #define STATS_BDR_FMT "========================================" 47 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \ 48 STATS_BDR_FMT, s, w, STATS_BDR_FMT) 49 50 /**< mask of enabled ports */ 51 static unsigned long enabled_port_mask; 52 /**< Enable stats. */ 53 static uint32_t enable_stats; 54 /**< Enable xstats. */ 55 static uint32_t enable_xstats; 56 /**< Enable collectd format*/ 57 static uint32_t enable_collectd_format; 58 /**< FD to send collectd format messages to STDOUT*/ 59 static int stdout_fd; 60 /**< Host id process is running on */ 61 static char host_id[MAX_LONG_OPT_SZ]; 62 /**< Enable metrics. */ 63 static uint32_t enable_metrics; 64 /**< Enable stats reset. */ 65 static uint32_t reset_stats; 66 /**< Enable xstats reset. */ 67 static uint32_t reset_xstats; 68 /**< Enable memory info. */ 69 static uint32_t mem_info; 70 /**< Enable displaying xstat name. */ 71 static uint32_t enable_xstats_name; 72 static char *xstats_name; 73 74 /**< Enable xstats by ids. */ 75 #define MAX_NB_XSTATS_IDS 1024 76 static uint32_t nb_xstats_ids; 77 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS]; 78 79 /* show border */ 80 static char bdr_str[MAX_STRING_LEN]; 81 82 /**< Enable show port. */ 83 static uint32_t enable_shw_port; 84 /**< Enable show tm. */ 85 static uint32_t enable_shw_tm; 86 /**< Enable show crypto. */ 87 static uint32_t enable_shw_crypto; 88 /**< Enable show ring. */ 89 static uint32_t enable_shw_ring; 90 static char *ring_name; 91 /**< Enable show mempool. */ 92 static uint32_t enable_shw_mempool; 93 static char *mempool_name; 94 /**< Enable iter mempool. */ 95 static uint32_t enable_iter_mempool; 96 static char *mempool_iter_name; 97 /**< Enable dump regs. */ 98 static uint32_t enable_dump_regs; 99 static char *dump_regs_file_prefix; 100 101 /**< display usage */ 102 static void 103 proc_info_usage(const char *prgname) 104 { 105 printf("%s [EAL options] -- -p PORTMASK\n" 106 " -m to display DPDK memory zones, segments and TAILQ information\n" 107 " -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n" 108 " --stats: to display port statistics, enabled by default\n" 109 " --xstats: to display extended port statistics, disabled by " 110 "default\n" 111 " --metrics: to display derived metrics of the ports, disabled by " 112 "default\n" 113 " --xstats-name NAME: to display single xstat id by NAME\n" 114 " --xstats-ids IDLIST: to display xstat values by id. " 115 "The argument is comma-separated list of xstat ids to print out.\n" 116 " --stats-reset: to reset port statistics\n" 117 " --xstats-reset: to reset port extended statistics\n" 118 " --collectd-format: to print statistics to STDOUT in expected by collectd format\n" 119 " --host-id STRING: host id used to identify the system process is running on\n" 120 " --show-port: to display ports information\n" 121 " --show-tm: to display traffic manager information for ports\n" 122 " --show-crypto: to display crypto information\n" 123 " --show-ring[=name]: to display ring information\n" 124 " --show-mempool[=name]: to display mempool information\n" 125 " --iter-mempool=name: iterate mempool elements to display content\n" 126 " --dump-regs=file-prefix: dump registers to file with the file-prefix\n", 127 prgname); 128 } 129 130 /* 131 * Parse the portmask provided at run time. 132 */ 133 static int 134 parse_portmask(const char *portmask) 135 { 136 char *end = NULL; 137 138 errno = 0; 139 140 /* parse hexadecimal string */ 141 enabled_port_mask = strtoul(portmask, &end, 16); 142 if (portmask[0] == '\0' || end == NULL || *end != '\0' || errno != 0) { 143 fprintf(stderr, "Invalid portmask '%s'\n", portmask); 144 return -1; 145 } 146 147 return 0; 148 } 149 150 /* 151 * Parse ids value list into array 152 */ 153 static int 154 parse_xstats_ids(char *list, uint64_t *ids, int limit) { 155 int length; 156 char *token; 157 char *ctx = NULL; 158 char *endptr; 159 160 length = 0; 161 token = strtok_r(list, ",", &ctx); 162 while (token != NULL) { 163 ids[length] = strtoull(token, &endptr, 10); 164 if (*endptr != '\0') 165 return -EINVAL; 166 167 length++; 168 if (length >= limit) 169 return -E2BIG; 170 171 token = strtok_r(NULL, ",", &ctx); 172 } 173 174 return length; 175 } 176 177 static int 178 proc_info_preparse_args(int argc, char **argv) 179 { 180 char *prgname = argv[0]; 181 int i; 182 183 for (i = 0; i < argc; i++) { 184 /* Print stats or xstats to STDOUT in collectd format */ 185 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) { 186 enable_collectd_format = 1; 187 stdout_fd = dup(STDOUT_FILENO); 188 close(STDOUT_FILENO); 189 } 190 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) { 191 if ((i + 1) == argc) { 192 printf("Invalid host id or not specified\n"); 193 proc_info_usage(prgname); 194 return -1; 195 } 196 strlcpy(host_id, argv[i + 1], sizeof(host_id)); 197 } 198 } 199 200 if (!strlen(host_id)) { 201 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1); 202 203 if (err) 204 strlcpy(host_id, "unknown", sizeof(host_id)); 205 } 206 207 return 0; 208 } 209 210 /* Parse the argument given in the command line of the application */ 211 static int 212 proc_info_parse_args(int argc, char **argv) 213 { 214 int opt; 215 int option_index; 216 char *prgname = argv[0]; 217 static struct option long_option[] = { 218 {"stats", 0, NULL, 0}, 219 {"stats-reset", 0, NULL, 0}, 220 {"xstats", 0, NULL, 0}, 221 {"metrics", 0, NULL, 0}, 222 {"xstats-reset", 0, NULL, 0}, 223 {"xstats-name", required_argument, NULL, 1}, 224 {"collectd-format", 0, NULL, 0}, 225 {"xstats-ids", 1, NULL, 1}, 226 {"host-id", 0, NULL, 0}, 227 {"show-port", 0, NULL, 0}, 228 {"show-tm", 0, NULL, 0}, 229 {"show-crypto", 0, NULL, 0}, 230 {"show-ring", optional_argument, NULL, 0}, 231 {"show-mempool", optional_argument, NULL, 0}, 232 {"iter-mempool", required_argument, NULL, 0}, 233 {"dump-regs", required_argument, NULL, 0}, 234 {NULL, 0, 0, 0} 235 }; 236 237 if (argc == 1) 238 proc_info_usage(prgname); 239 240 /* Parse command line */ 241 while ((opt = getopt_long(argc, argv, "p:m", 242 long_option, &option_index)) != EOF) { 243 switch (opt) { 244 /* portmask */ 245 case 'p': 246 if (parse_portmask(optarg) < 0) { 247 proc_info_usage(prgname); 248 return -1; 249 } 250 break; 251 case 'm': 252 mem_info = 1; 253 break; 254 case 0: 255 /* Print stats */ 256 if (!strncmp(long_option[option_index].name, "stats", 257 MAX_LONG_OPT_SZ)) 258 enable_stats = 1; 259 /* Print xstats */ 260 else if (!strncmp(long_option[option_index].name, "xstats", 261 MAX_LONG_OPT_SZ)) 262 enable_xstats = 1; 263 else if (!strncmp(long_option[option_index].name, 264 "metrics", 265 MAX_LONG_OPT_SZ)) 266 enable_metrics = 1; 267 /* Reset stats */ 268 if (!strncmp(long_option[option_index].name, "stats-reset", 269 MAX_LONG_OPT_SZ)) 270 reset_stats = 1; 271 /* Reset xstats */ 272 else if (!strncmp(long_option[option_index].name, "xstats-reset", 273 MAX_LONG_OPT_SZ)) 274 reset_xstats = 1; 275 else if (!strncmp(long_option[option_index].name, 276 "show-port", MAX_LONG_OPT_SZ)) 277 enable_shw_port = 1; 278 else if (!strncmp(long_option[option_index].name, 279 "show-tm", MAX_LONG_OPT_SZ)) 280 enable_shw_tm = 1; 281 else if (!strncmp(long_option[option_index].name, 282 "show-crypto", MAX_LONG_OPT_SZ)) 283 enable_shw_crypto = 1; 284 else if (!strncmp(long_option[option_index].name, 285 "show-ring", MAX_LONG_OPT_SZ)) { 286 enable_shw_ring = 1; 287 ring_name = optarg; 288 } else if (!strncmp(long_option[option_index].name, 289 "show-mempool", MAX_LONG_OPT_SZ)) { 290 enable_shw_mempool = 1; 291 mempool_name = optarg; 292 } else if (!strncmp(long_option[option_index].name, 293 "iter-mempool", MAX_LONG_OPT_SZ)) { 294 enable_iter_mempool = 1; 295 mempool_iter_name = optarg; 296 } else if (!strncmp(long_option[option_index].name, 297 "dump-regs", MAX_LONG_OPT_SZ)) { 298 enable_dump_regs = 1; 299 dump_regs_file_prefix = optarg; 300 } 301 break; 302 case 1: 303 /* Print xstat single value given by name*/ 304 if (!strncmp(long_option[option_index].name, 305 "xstats-name", MAX_LONG_OPT_SZ)) { 306 enable_xstats_name = 1; 307 xstats_name = optarg; 308 printf("name:%s:%s\n", 309 long_option[option_index].name, 310 optarg); 311 } else if (!strncmp(long_option[option_index].name, 312 "xstats-ids", 313 MAX_LONG_OPT_SZ)) { 314 int ret = parse_xstats_ids(optarg, 315 xstats_ids, MAX_NB_XSTATS_IDS); 316 if (ret <= 0) { 317 printf("xstats-id list parse error.\n"); 318 return -1; 319 } 320 nb_xstats_ids = ret; 321 } 322 break; 323 default: 324 proc_info_usage(prgname); 325 return -1; 326 } 327 } 328 return 0; 329 } 330 331 static void 332 meminfo_display(void) 333 { 334 printf("----------- MEMORY_SEGMENTS -----------\n"); 335 rte_dump_physmem_layout(stdout); 336 printf("--------- END_MEMORY_SEGMENTS ---------\n"); 337 338 printf("------------ MEMORY_ZONES -------------\n"); 339 rte_memzone_dump(stdout); 340 printf("---------- END_MEMORY_ZONES -----------\n"); 341 342 printf("------------- TAIL_QUEUES -------------\n"); 343 rte_dump_tailq(stdout); 344 printf("---------- END_TAIL_QUEUES ------------\n"); 345 } 346 347 static void 348 nic_stats_display(uint16_t port_id) 349 { 350 struct rte_eth_stats stats; 351 uint8_t i; 352 353 static const char *nic_stats_border = "########################"; 354 355 rte_eth_stats_get(port_id, &stats); 356 printf("\n %s NIC statistics for port %-2d %s\n", 357 nic_stats_border, port_id, nic_stats_border); 358 359 printf(" RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64 360 " RX-bytes: %-10"PRIu64"\n", stats.ipackets, stats.ierrors, 361 stats.ibytes); 362 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf); 363 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64 364 " TX-bytes: %-10"PRIu64"\n", stats.opackets, stats.oerrors, 365 stats.obytes); 366 367 printf("\n"); 368 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 369 printf(" Stats reg %2d RX-packets: %-10"PRIu64 370 " RX-errors: %-10"PRIu64 371 " RX-bytes: %-10"PRIu64"\n", 372 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]); 373 } 374 375 printf("\n"); 376 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 377 printf(" Stats reg %2d TX-packets: %-10"PRIu64 378 " TX-bytes: %-10"PRIu64"\n", 379 i, stats.q_opackets[i], stats.q_obytes[i]); 380 } 381 382 printf(" %s############################%s\n", 383 nic_stats_border, nic_stats_border); 384 } 385 386 static void 387 nic_stats_clear(uint16_t port_id) 388 { 389 printf("\n Clearing NIC stats for port %d\n", port_id); 390 rte_eth_stats_reset(port_id); 391 printf("\n NIC statistics for port %d cleared\n", port_id); 392 } 393 394 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len, 395 const char *cnt_name) { 396 char *type_end = strrchr(cnt_name, '_'); 397 398 if ((type_end != NULL) && 399 (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) { 400 if (strncmp(type_end, "_errors", strlen("_errors")) == 0) 401 strlcpy(cnt_type, "if_rx_errors", cnt_type_len); 402 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) 403 strlcpy(cnt_type, "if_rx_dropped", cnt_type_len); 404 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) 405 strlcpy(cnt_type, "if_rx_octets", cnt_type_len); 406 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) 407 strlcpy(cnt_type, "if_rx_packets", cnt_type_len); 408 else if (strncmp(type_end, "_placement", 409 strlen("_placement")) == 0) 410 strlcpy(cnt_type, "if_rx_errors", cnt_type_len); 411 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0) 412 strlcpy(cnt_type, "if_rx_errors", cnt_type_len); 413 else 414 /* Does not fit obvious type: use a more generic one */ 415 strlcpy(cnt_type, "derive", cnt_type_len); 416 } else if ((type_end != NULL) && 417 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) { 418 if (strncmp(type_end, "_errors", strlen("_errors")) == 0) 419 strlcpy(cnt_type, "if_tx_errors", cnt_type_len); 420 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) 421 strlcpy(cnt_type, "if_tx_dropped", cnt_type_len); 422 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) 423 strlcpy(cnt_type, "if_tx_octets", cnt_type_len); 424 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) 425 strlcpy(cnt_type, "if_tx_packets", cnt_type_len); 426 else 427 /* Does not fit obvious type: use a more generic one */ 428 strlcpy(cnt_type, "derive", cnt_type_len); 429 } else if ((type_end != NULL) && 430 (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) { 431 if (strncmp(type_end, "_filters", strlen("_filters")) == 0) 432 strlcpy(cnt_type, "filter_result", cnt_type_len); 433 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0) 434 strlcpy(cnt_type, "errors", cnt_type_len); 435 } else if ((type_end != NULL) && 436 (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) { 437 if (strncmp(type_end, "_errors", strlen("_errors")) == 0) 438 strlcpy(cnt_type, "errors", cnt_type_len); 439 } else { 440 /* Does not fit obvious type, or strrchr error: */ 441 /* use a more generic type */ 442 strlcpy(cnt_type, "derive", cnt_type_len); 443 } 444 } 445 446 static void 447 nic_xstats_by_name_display(uint16_t port_id, char *name) 448 { 449 uint64_t id; 450 451 printf("###### NIC statistics for port %-2d, statistic name '%s':\n", 452 port_id, name); 453 454 if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0) 455 printf("%s: %"PRIu64"\n", name, id); 456 else 457 printf("Statistic not found...\n"); 458 459 } 460 461 static void 462 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len) 463 { 464 struct rte_eth_xstat_name *xstats_names; 465 uint64_t *values; 466 int ret, i; 467 static const char *nic_stats_border = "########################"; 468 469 values = malloc(sizeof(*values) * len); 470 if (values == NULL) { 471 printf("Cannot allocate memory for xstats\n"); 472 return; 473 } 474 475 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len); 476 if (xstats_names == NULL) { 477 printf("Cannot allocate memory for xstat names\n"); 478 free(values); 479 return; 480 } 481 482 if (len != rte_eth_xstats_get_names_by_id( 483 port_id, xstats_names, len, ids)) { 484 printf("Cannot get xstat names\n"); 485 goto err; 486 } 487 488 printf("###### NIC extended statistics for port %-2d #########\n", 489 port_id); 490 printf("%s############################\n", nic_stats_border); 491 ret = rte_eth_xstats_get_by_id(port_id, ids, values, len); 492 if (ret < 0 || ret > len) { 493 printf("Cannot get xstats\n"); 494 goto err; 495 } 496 497 for (i = 0; i < len; i++) 498 printf("%s: %"PRIu64"\n", 499 xstats_names[i].name, 500 values[i]); 501 502 printf("%s############################\n", nic_stats_border); 503 err: 504 free(values); 505 free(xstats_names); 506 } 507 508 static void 509 nic_xstats_display(uint16_t port_id) 510 { 511 struct rte_eth_xstat_name *xstats_names; 512 uint64_t *values; 513 int len, ret, i; 514 static const char *nic_stats_border = "########################"; 515 516 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL); 517 if (len < 0) { 518 printf("Cannot get xstats count\n"); 519 return; 520 } 521 values = malloc(sizeof(*values) * len); 522 if (values == NULL) { 523 printf("Cannot allocate memory for xstats\n"); 524 return; 525 } 526 527 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len); 528 if (xstats_names == NULL) { 529 printf("Cannot allocate memory for xstat names\n"); 530 free(values); 531 return; 532 } 533 if (len != rte_eth_xstats_get_names_by_id( 534 port_id, xstats_names, len, NULL)) { 535 printf("Cannot get xstat names\n"); 536 goto err; 537 } 538 539 printf("###### NIC extended statistics for port %-2d #########\n", 540 port_id); 541 printf("%s############################\n", 542 nic_stats_border); 543 ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len); 544 if (ret < 0 || ret > len) { 545 printf("Cannot get xstats\n"); 546 goto err; 547 } 548 549 for (i = 0; i < len; i++) { 550 if (enable_collectd_format) { 551 char counter_type[MAX_STRING_LEN]; 552 char buf[MAX_STRING_LEN]; 553 size_t n; 554 555 collectd_resolve_cnt_type(counter_type, 556 sizeof(counter_type), 557 xstats_names[i].name); 558 n = snprintf(buf, MAX_STRING_LEN, 559 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%" 560 PRIu64"\n", host_id, port_id, counter_type, 561 xstats_names[i].name, values[i]); 562 if (n > sizeof(buf) - 1) 563 n = sizeof(buf) - 1; 564 ret = write(stdout_fd, buf, n); 565 if (ret < 0) 566 goto err; 567 } else { 568 printf("%s: %"PRIu64"\n", xstats_names[i].name, 569 values[i]); 570 } 571 } 572 573 printf("%s############################\n", 574 nic_stats_border); 575 err: 576 free(values); 577 free(xstats_names); 578 } 579 580 static void 581 nic_xstats_clear(uint16_t port_id) 582 { 583 int ret; 584 585 printf("\n Clearing NIC xstats for port %d\n", port_id); 586 ret = rte_eth_xstats_reset(port_id); 587 if (ret != 0) { 588 printf("\n Error clearing xstats for port %d: %s\n", port_id, 589 strerror(-ret)); 590 return; 591 } 592 593 printf("\n NIC extended statistics for port %d cleared\n", port_id); 594 } 595 596 static void 597 metrics_display(int port_id) 598 { 599 struct rte_metric_value *metrics; 600 struct rte_metric_name *names; 601 int len, ret; 602 static const char *nic_stats_border = "########################"; 603 604 len = rte_metrics_get_names(NULL, 0); 605 if (len < 0) { 606 printf("Cannot get metrics count\n"); 607 return; 608 } 609 if (len == 0) { 610 printf("No metrics to display (none have been registered)\n"); 611 return; 612 } 613 614 metrics = rte_malloc("proc_info_metrics", 615 sizeof(struct rte_metric_value) * len, 0); 616 if (metrics == NULL) { 617 printf("Cannot allocate memory for metrics\n"); 618 return; 619 } 620 621 names = rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0); 622 if (names == NULL) { 623 printf("Cannot allocate memory for metrcis names\n"); 624 rte_free(metrics); 625 return; 626 } 627 628 if (len != rte_metrics_get_names(names, len)) { 629 printf("Cannot get metrics names\n"); 630 rte_free(metrics); 631 rte_free(names); 632 return; 633 } 634 635 if (port_id == RTE_METRICS_GLOBAL) 636 printf("###### Non port specific metrics #########\n"); 637 else 638 printf("###### metrics for port %-2d #########\n", port_id); 639 printf("%s############################\n", nic_stats_border); 640 ret = rte_metrics_get_values(port_id, metrics, len); 641 if (ret < 0 || ret > len) { 642 printf("Cannot get metrics values\n"); 643 rte_free(metrics); 644 rte_free(names); 645 return; 646 } 647 648 int i; 649 for (i = 0; i < len; i++) 650 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value); 651 652 printf("%s############################\n", nic_stats_border); 653 rte_free(metrics); 654 rte_free(names); 655 } 656 657 static void 658 show_security_context(uint16_t portid, bool inline_offload) 659 { 660 void *p_ctx; 661 const struct rte_security_capability *s_cap; 662 663 if (inline_offload) 664 p_ctx = rte_eth_dev_get_sec_ctx(portid); 665 else 666 p_ctx = rte_cryptodev_get_sec_ctx(portid); 667 668 if (p_ctx == NULL) 669 return; 670 671 printf(" - crypto context\n"); 672 printf("\t -- security context - %p\n", p_ctx); 673 printf("\t -- size %u\n", 674 rte_security_session_get_size(p_ctx)); 675 676 s_cap = rte_security_capabilities_get(p_ctx); 677 if (s_cap) { 678 printf("\t -- action (0x%x), protocol (0x%x)," 679 " offload flags (0x%x)\n", 680 s_cap->action, 681 s_cap->protocol, 682 s_cap->ol_flags); 683 printf("\t -- capabilities - oper type %x\n", 684 s_cap->crypto_capabilities->op); 685 } 686 } 687 688 static void 689 show_offloads(uint64_t offloads, 690 const char *(show_offload)(uint64_t)) 691 { 692 printf(" offloads :"); 693 while (offloads != 0) { 694 uint64_t offload_flag = 1ULL << __builtin_ctzll(offloads); 695 printf(" %s", show_offload(offload_flag)); 696 offloads &= ~offload_flag; 697 } 698 } 699 700 static void 701 show_port(void) 702 { 703 int i, ret, j, k; 704 705 snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD "); 706 STATS_BDR_STR(10, bdr_str); 707 708 for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 709 uint16_t mtu = 0; 710 struct rte_eth_link link; 711 struct rte_eth_dev_info dev_info; 712 struct rte_eth_rss_conf rss_conf; 713 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN]; 714 struct rte_eth_fc_conf fc_conf; 715 struct rte_ether_addr mac; 716 struct rte_eth_dev_owner owner; 717 718 /* Skip if port is not in mask */ 719 if ((enabled_port_mask & (1ul << i)) == 0) 720 continue; 721 722 /* Skip if port is unused */ 723 if (!rte_eth_dev_is_valid_port(i)) 724 continue; 725 726 memset(&rss_conf, 0, sizeof(rss_conf)); 727 728 snprintf(bdr_str, MAX_STRING_LEN, " Port %u ", i); 729 STATS_BDR_STR(5, bdr_str); 730 printf(" - generic config\n"); 731 732 ret = rte_eth_dev_info_get(i, &dev_info); 733 if (ret != 0) { 734 printf("Error during getting device info: %s\n", 735 strerror(-ret)); 736 return; 737 } 738 739 printf("\t -- driver %s device %s socket %d\n", 740 dev_info.driver_name, dev_info.device->name, 741 rte_eth_dev_socket_id(i)); 742 743 ret = rte_eth_dev_owner_get(i, &owner); 744 if (ret == 0 && owner.id != RTE_ETH_DEV_NO_OWNER) 745 printf("\t -- owner %#"PRIx64":%s\n", 746 owner.id, owner.name); 747 748 ret = rte_eth_link_get(i, &link); 749 if (ret < 0) { 750 printf("Link get failed (port %u): %s\n", 751 i, rte_strerror(-ret)); 752 } else { 753 rte_eth_link_to_str(link_status_text, 754 sizeof(link_status_text), 755 &link); 756 printf("\t%s\n", link_status_text); 757 } 758 759 ret = rte_eth_dev_flow_ctrl_get(i, &fc_conf); 760 if (ret == 0 && fc_conf.mode != RTE_FC_NONE) { 761 printf("\t -- flow control mode %s%s high %u low %u pause %u%s%s\n", 762 fc_conf.mode == RTE_FC_RX_PAUSE ? "rx " : 763 fc_conf.mode == RTE_FC_TX_PAUSE ? "tx " : 764 fc_conf.mode == RTE_FC_FULL ? "full" : "???", 765 fc_conf.autoneg ? " auto" : "", 766 fc_conf.high_water, 767 fc_conf.low_water, 768 fc_conf.pause_time, 769 fc_conf.send_xon ? " xon" : "", 770 fc_conf.mac_ctrl_frame_fwd ? " mac_ctrl" : ""); 771 } 772 773 ret = rte_eth_macaddr_get(i, &mac); 774 if (ret == 0) { 775 char ebuf[RTE_ETHER_ADDR_FMT_SIZE]; 776 777 rte_ether_format_addr(ebuf, sizeof(ebuf), &mac); 778 printf("\t -- mac %s\n", ebuf); 779 } 780 781 ret = rte_eth_promiscuous_get(i); 782 if (ret >= 0) 783 printf("\t -- promiscuous mode %s\n", 784 ret > 0 ? "enabled" : "disabled"); 785 786 ret = rte_eth_allmulticast_get(i); 787 if (ret >= 0) 788 printf("\t -- all multicast mode %s\n", 789 ret > 0 ? "enabled" : "disabled"); 790 791 ret = rte_eth_dev_get_mtu(i, &mtu); 792 if (ret == 0) 793 printf("\t -- mtu (%d)\n", mtu); 794 795 for (j = 0; j < dev_info.nb_rx_queues; j++) { 796 struct rte_eth_rxq_info queue_info; 797 int count; 798 799 ret = rte_eth_rx_queue_info_get(i, j, &queue_info); 800 if (ret != 0) 801 break; 802 803 if (j == 0) 804 printf(" - rx queue\n"); 805 806 printf("\t -- %d descriptors ", j); 807 count = rte_eth_rx_queue_count(i, j); 808 if (count >= 0) 809 printf("%d/", count); 810 printf("%u", queue_info.nb_desc); 811 812 if (queue_info.scattered_rx) 813 printf(" scattered"); 814 815 if (queue_info.conf.rx_drop_en) 816 printf(" drop_en"); 817 818 if (queue_info.conf.rx_deferred_start) 819 printf(" deferred_start"); 820 821 if (queue_info.rx_buf_size != 0) 822 printf(" rx buffer size %u", 823 queue_info.rx_buf_size); 824 825 printf(" mempool %s socket %d", 826 queue_info.mp->name, 827 queue_info.mp->socket_id); 828 829 if (queue_info.conf.offloads != 0) 830 show_offloads(queue_info.conf.offloads, rte_eth_dev_rx_offload_name); 831 832 printf("\n"); 833 } 834 835 for (j = 0; j < dev_info.nb_tx_queues; j++) { 836 struct rte_eth_txq_info queue_info; 837 838 ret = rte_eth_tx_queue_info_get(i, j, &queue_info); 839 if (ret != 0) 840 break; 841 842 if (j == 0) 843 printf(" - tx queue\n"); 844 845 printf("\t -- %d descriptors %d", 846 j, queue_info.nb_desc); 847 848 printf(" thresh %u/%u", 849 queue_info.conf.tx_rs_thresh, 850 queue_info.conf.tx_free_thresh); 851 852 if (queue_info.conf.tx_deferred_start) 853 printf(" deferred_start"); 854 855 if (queue_info.conf.offloads != 0) 856 show_offloads(queue_info.conf.offloads, rte_eth_dev_tx_offload_name); 857 printf("\n"); 858 } 859 860 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf); 861 if (ret == 0) { 862 if (rss_conf.rss_key) { 863 printf(" - RSS\n"); 864 printf("\t -- RSS len %u key (hex):", 865 rss_conf.rss_key_len); 866 for (k = 0; k < rss_conf.rss_key_len; k++) 867 printf(" %x", rss_conf.rss_key[k]); 868 printf("\t -- hf 0x%"PRIx64"\n", 869 rss_conf.rss_hf); 870 } 871 } 872 873 #ifdef RTE_LIB_SECURITY 874 show_security_context(i, true); 875 #endif 876 } 877 } 878 879 static void 880 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap) 881 { 882 if (cap == NULL) 883 return; 884 885 if (!is_leaf) { 886 printf("\t -- nonleaf sched max:\n" 887 "\t\t + children (%u)\n" 888 "\t\t + sp priorities (%u)\n" 889 "\t\t + wfq children per group (%u)\n" 890 "\t\t + wfq groups (%u)\n" 891 "\t\t + wfq weight (%u)\n", 892 cap->nonleaf.sched_n_children_max, 893 cap->nonleaf.sched_sp_n_priorities_max, 894 cap->nonleaf.sched_wfq_n_children_per_group_max, 895 cap->nonleaf.sched_wfq_n_groups_max, 896 cap->nonleaf.sched_wfq_weight_max); 897 } else { 898 printf("\t -- leaf cman support:\n" 899 "\t\t + wred pkt mode (%d)\n" 900 "\t\t + wred byte mode (%d)\n" 901 "\t\t + head drop (%d)\n" 902 "\t\t + wred context private (%d)\n" 903 "\t\t + wred context shared (%u)\n", 904 cap->leaf.cman_wred_packet_mode_supported, 905 cap->leaf.cman_wred_byte_mode_supported, 906 cap->leaf.cman_head_drop_supported, 907 cap->leaf.cman_wred_context_private_supported, 908 cap->leaf.cman_wred_context_shared_n_max); 909 } 910 } 911 912 static void 913 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap) 914 { 915 if (cap == NULL) 916 return; 917 918 if (!is_leaf) { 919 printf("\t -- shaper private: (%d) dual rate (%d)\n", 920 cap->nonleaf.shaper_private_supported, 921 cap->nonleaf.shaper_private_dual_rate_supported); 922 printf("\t -- shaper share: (%u)\n", 923 cap->nonleaf.shaper_shared_n_max); 924 printf("\t -- non leaf sched MAX:\n" 925 "\t\t + children (%u)\n" 926 "\t\t + sp (%u)\n" 927 "\t\t + wfq children per group (%u)\n" 928 "\t\t + wfq groups (%u)\n" 929 "\t\t + wfq weight (%u)\n", 930 cap->nonleaf.sched_n_children_max, 931 cap->nonleaf.sched_sp_n_priorities_max, 932 cap->nonleaf.sched_wfq_n_children_per_group_max, 933 cap->nonleaf.sched_wfq_n_groups_max, 934 cap->nonleaf.sched_wfq_weight_max); 935 } else { 936 printf("\t -- shaper private: (%d) dual rate (%d)\n", 937 cap->leaf.shaper_private_supported, 938 cap->leaf.shaper_private_dual_rate_supported); 939 printf("\t -- shaper share: (%u)\n", 940 cap->leaf.shaper_shared_n_max); 941 printf(" -- leaf cman support:\n" 942 "\t\t + wred pkt mode (%d)\n" 943 "\t\t + wred byte mode (%d)\n" 944 "\t\t + head drop (%d)\n" 945 "\t\t + wred context private (%d)\n" 946 "\t\t + wred context shared (%u)\n", 947 cap->leaf.cman_wred_packet_mode_supported, 948 cap->leaf.cman_wred_byte_mode_supported, 949 cap->leaf.cman_head_drop_supported, 950 cap->leaf.cman_wred_context_private_supported, 951 cap->leaf.cman_wred_context_shared_n_max); 952 } 953 } 954 955 static void 956 show_tm(void) 957 { 958 int ret = 0, check_for_leaf = 0, is_leaf = 0; 959 unsigned int j, k; 960 uint16_t i = 0; 961 962 snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD "); 963 STATS_BDR_STR(10, bdr_str); 964 965 RTE_ETH_FOREACH_DEV(i) { 966 struct rte_eth_dev_info dev_info; 967 struct rte_tm_capabilities cap; 968 struct rte_tm_error error; 969 struct rte_tm_node_capabilities capnode; 970 struct rte_tm_level_capabilities caplevel; 971 uint32_t n_leaf_nodes = 0; 972 973 memset(&cap, 0, sizeof(cap)); 974 memset(&error, 0, sizeof(error)); 975 976 ret = rte_eth_dev_info_get(i, &dev_info); 977 if (ret != 0) { 978 printf("Error during getting device (port %u) info: %s\n", 979 i, strerror(-ret)); 980 return; 981 } 982 983 printf(" - Generic for port (%u)\n" 984 "\t -- driver name %s\n" 985 "\t -- max vf (%u)\n" 986 "\t -- max tx queues (%u)\n" 987 "\t -- number of tx queues (%u)\n", 988 i, 989 dev_info.driver_name, 990 dev_info.max_vfs, 991 dev_info.max_tx_queues, 992 dev_info.nb_tx_queues); 993 994 ret = rte_tm_capabilities_get(i, &cap, &error); 995 if (ret) 996 continue; 997 998 printf(" - MAX: nodes (%u) levels (%u) children (%u)\n", 999 cap.n_nodes_max, 1000 cap.n_levels_max, 1001 cap.sched_n_children_max); 1002 1003 printf(" - identical nodes: non leaf (%d) leaf (%d)\n", 1004 cap.non_leaf_nodes_identical, 1005 cap.leaf_nodes_identical); 1006 1007 printf(" - Shaper MAX:\n" 1008 "\t -- total (%u)\n" 1009 "\t -- private (%u) private dual (%d)\n" 1010 "\t -- shared (%u) shared dual (%u)\n", 1011 cap.shaper_n_max, 1012 cap.shaper_private_n_max, 1013 cap.shaper_private_dual_rate_n_max, 1014 cap.shaper_shared_n_max, 1015 cap.shaper_shared_dual_rate_n_max); 1016 1017 printf(" - mark support:\n"); 1018 printf("\t -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n", 1019 cap.mark_vlan_dei_supported[RTE_COLOR_GREEN], 1020 cap.mark_vlan_dei_supported[RTE_COLOR_YELLOW], 1021 cap.mark_vlan_dei_supported[RTE_COLOR_RED]); 1022 printf("\t -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n", 1023 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_GREEN], 1024 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_YELLOW], 1025 cap.mark_ip_ecn_tcp_supported[RTE_COLOR_RED]); 1026 printf("\t -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n", 1027 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_GREEN], 1028 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_YELLOW], 1029 cap.mark_ip_ecn_sctp_supported[RTE_COLOR_RED]); 1030 printf("\t -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n", 1031 cap.mark_ip_dscp_supported[RTE_COLOR_GREEN], 1032 cap.mark_ip_dscp_supported[RTE_COLOR_YELLOW], 1033 cap.mark_ip_dscp_supported[RTE_COLOR_RED]); 1034 1035 printf(" - mask stats (0x%"PRIx64")" 1036 " dynamic update (0x%"PRIx64")\n", 1037 cap.stats_mask, 1038 cap.dynamic_update_mask); 1039 1040 printf(" - sched MAX:\n" 1041 "\t -- total (%u)\n" 1042 "\t -- sp levels (%u)\n" 1043 "\t -- wfq children per group (%u)\n" 1044 "\t -- wfq groups (%u)\n" 1045 "\t -- wfq weight (%u)\n", 1046 cap.sched_sp_n_priorities_max, 1047 cap.sched_sp_n_priorities_max, 1048 cap.sched_wfq_n_children_per_group_max, 1049 cap.sched_wfq_n_groups_max, 1050 cap.sched_wfq_weight_max); 1051 1052 printf(" - CMAN support:\n" 1053 "\t -- WRED mode: pkt (%d) byte (%d)\n" 1054 "\t -- head drop (%d)\n", 1055 cap.cman_wred_packet_mode_supported, 1056 cap.cman_wred_byte_mode_supported, 1057 cap.cman_head_drop_supported); 1058 printf("\t -- MAX WRED CONTEXT:" 1059 " total (%u) private (%u) shared (%u)\n", 1060 cap.cman_wred_context_n_max, 1061 cap.cman_wred_context_private_n_max, 1062 cap.cman_wred_context_shared_n_max); 1063 1064 for (j = 0; j < cap.n_nodes_max; j++) { 1065 memset(&capnode, 0, sizeof(capnode)); 1066 ret = rte_tm_node_capabilities_get(i, j, 1067 &capnode, &error); 1068 if (ret) 1069 continue; 1070 1071 check_for_leaf = 1; 1072 1073 printf(" NODE %u\n", j); 1074 printf("\t - shaper private: (%d) dual rate (%d)\n", 1075 capnode.shaper_private_supported, 1076 capnode.shaper_private_dual_rate_supported); 1077 printf("\t - shaper shared max: (%u)\n", 1078 capnode.shaper_shared_n_max); 1079 printf("\t - stats mask %"PRIx64"\n", 1080 capnode.stats_mask); 1081 1082 ret = rte_tm_node_type_get(i, j, &is_leaf, &error); 1083 if (ret) 1084 continue; 1085 1086 display_nodecap_info(is_leaf, &capnode); 1087 } 1088 1089 for (j = 0; j < cap.n_levels_max; j++) { 1090 memset(&caplevel, 0, sizeof(caplevel)); 1091 ret = rte_tm_level_capabilities_get(i, j, 1092 &caplevel, &error); 1093 if (ret) 1094 continue; 1095 1096 printf(" - Level %u\n", j); 1097 printf("\t -- node MAX: %u non leaf %u leaf %u\n", 1098 caplevel.n_nodes_max, 1099 caplevel.n_nodes_nonleaf_max, 1100 caplevel.n_nodes_leaf_max); 1101 printf("\t -- indetical: non leaf %u leaf %u\n", 1102 caplevel.non_leaf_nodes_identical, 1103 caplevel.leaf_nodes_identical); 1104 1105 for (k = 0; k < caplevel.n_nodes_max; k++) { 1106 ret = rte_tm_node_type_get(i, k, 1107 &is_leaf, &error); 1108 if (ret) 1109 continue; 1110 1111 display_levelcap_info(is_leaf, &caplevel); 1112 } 1113 } 1114 1115 if (check_for_leaf) { 1116 ret = rte_tm_get_number_of_leaf_nodes(i, 1117 &n_leaf_nodes, &error); 1118 if (ret == 0) 1119 printf(" - leaf nodes (%u)\n", n_leaf_nodes); 1120 } 1121 1122 for (j = 0; j < n_leaf_nodes; j++) { 1123 struct rte_tm_node_stats stats; 1124 memset(&stats, 0, sizeof(stats)); 1125 1126 ret = rte_tm_node_stats_read(i, j, 1127 &stats, &cap.stats_mask, 0, &error); 1128 if (ret) 1129 continue; 1130 1131 printf(" - STATS for node (%u)\n", j); 1132 printf(" -- pkts (%"PRIu64") bytes (%"PRIu64")\n", 1133 stats.n_pkts, stats.n_bytes); 1134 1135 ret = rte_tm_node_type_get(i, j, &is_leaf, &error); 1136 if (ret || (!is_leaf)) 1137 continue; 1138 1139 printf(" -- leaf queued:" 1140 " pkts (%"PRIu64") bytes (%"PRIu64")\n", 1141 stats.leaf.n_pkts_queued, 1142 stats.leaf.n_bytes_queued); 1143 printf(" - dropped:\n" 1144 "\t -- GREEN:" 1145 " pkts (%"PRIu64") bytes (%"PRIu64")\n" 1146 "\t -- YELLOW:" 1147 " pkts (%"PRIu64") bytes (%"PRIu64")\n" 1148 "\t -- RED:" 1149 " pkts (%"PRIu64") bytes (%"PRIu64")\n", 1150 stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN], 1151 stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN], 1152 stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW], 1153 stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW], 1154 stats.leaf.n_pkts_dropped[RTE_COLOR_RED], 1155 stats.leaf.n_bytes_dropped[RTE_COLOR_RED]); 1156 } 1157 } 1158 } 1159 1160 static void 1161 display_crypto_feature_info(uint64_t x) 1162 { 1163 if (x == 0) 1164 return; 1165 1166 printf("\t -- feature flags\n"); 1167 printf("\t\t + symmetric (%c), asymmetric (%c)\n" 1168 "\t\t + symmetric operation chaining (%c)\n", 1169 (x & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ? 'y' : 'n', 1170 (x & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) ? 'y' : 'n', 1171 (x & RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING) ? 'y' : 'n'); 1172 printf("\t\t + CPU: SSE (%c), AVX (%c), AVX2 (%c), AVX512 (%c)\n", 1173 (x & RTE_CRYPTODEV_FF_CPU_SSE) ? 'y' : 'n', 1174 (x & RTE_CRYPTODEV_FF_CPU_AVX) ? 'y' : 'n', 1175 (x & RTE_CRYPTODEV_FF_CPU_AVX2) ? 'y' : 'n', 1176 (x & RTE_CRYPTODEV_FF_CPU_AVX512) ? 'y' : 'n'); 1177 printf("\t\t + AESNI: CPU (%c), HW (%c)\n", 1178 (x & RTE_CRYPTODEV_FF_CPU_AESNI) ? 'y' : 'n', 1179 (x & RTE_CRYPTODEV_FF_HW_ACCELERATED) ? 'y' : 'n'); 1180 printf("\t\t + SECURITY OFFLOAD (%c)\n", 1181 (x & RTE_CRYPTODEV_FF_SECURITY) ? 'y' : 'n'); 1182 printf("\t\t + ARM: NEON (%c), CE (%c)\n", 1183 (x & RTE_CRYPTODEV_FF_CPU_NEON) ? 'y' : 'n', 1184 (x & RTE_CRYPTODEV_FF_CPU_ARM_CE) ? 'y' : 'n'); 1185 printf("\t -- buffer offload\n"); 1186 printf("\t\t + IN_PLACE_SGL (%c)\n", 1187 (x & RTE_CRYPTODEV_FF_IN_PLACE_SGL) ? 'y' : 'n'); 1188 printf("\t\t + OOP_SGL_IN_SGL_OUT (%c)\n", 1189 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT) ? 'y' : 'n'); 1190 printf("\t\t + OOP_SGL_IN_LB_OUT (%c)\n", 1191 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT) ? 'y' : 'n'); 1192 printf("\t\t + OOP_LB_IN_SGL_OUT (%c)\n", 1193 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT) ? 'y' : 'n'); 1194 printf("\t\t + OOP_LB_IN_LB_OUT (%c)\n", 1195 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT) ? 'y' : 'n'); 1196 } 1197 1198 static void 1199 show_crypto(void) 1200 { 1201 uint8_t crypto_dev_count = rte_cryptodev_count(), i; 1202 1203 snprintf(bdr_str, MAX_STRING_LEN, " show - CRYPTO PMD "); 1204 STATS_BDR_STR(10, bdr_str); 1205 1206 for (i = 0; i < crypto_dev_count; i++) { 1207 struct rte_cryptodev_info dev_info; 1208 struct rte_cryptodev_stats stats; 1209 1210 rte_cryptodev_info_get(i, &dev_info); 1211 1212 printf(" - device (%u)\n", i); 1213 printf("\t -- name (%s)\n" 1214 "\t -- driver (%s)\n" 1215 "\t -- id (%u) on socket (%d)\n" 1216 "\t -- queue pairs (%d)\n", 1217 rte_cryptodev_name_get(i), 1218 dev_info.driver_name, 1219 dev_info.driver_id, 1220 dev_info.device->numa_node, 1221 rte_cryptodev_queue_pair_count(i)); 1222 1223 display_crypto_feature_info(dev_info.feature_flags); 1224 1225 if (rte_cryptodev_stats_get(i, &stats) == 0) { 1226 printf("\t -- stats\n"); 1227 printf("\t\t + enqueue count (%"PRIu64")" 1228 " error (%"PRIu64")\n", 1229 stats.enqueued_count, 1230 stats.enqueue_err_count); 1231 printf("\t\t + dequeue count (%"PRIu64")" 1232 " error (%"PRIu64")\n", 1233 stats.dequeued_count, 1234 stats.dequeue_err_count); 1235 } 1236 1237 #ifdef RTE_LIB_SECURITY 1238 show_security_context(i, false); 1239 #endif 1240 } 1241 } 1242 1243 static void 1244 show_ring(char *name) 1245 { 1246 snprintf(bdr_str, MAX_STRING_LEN, " show - RING "); 1247 STATS_BDR_STR(10, bdr_str); 1248 1249 if (name != NULL) { 1250 struct rte_ring *ptr = rte_ring_lookup(name); 1251 if (ptr != NULL) { 1252 printf(" - Name (%s) on socket (%d)\n" 1253 " - flags:\n" 1254 "\t -- Single Producer Enqueue (%u)\n" 1255 "\t -- Single Consmer Dequeue (%u)\n", 1256 ptr->name, 1257 ptr->memzone->socket_id, 1258 ptr->flags & RING_F_SP_ENQ, 1259 ptr->flags & RING_F_SC_DEQ); 1260 printf(" - size (%u) mask (0x%x) capacity (%u)\n", 1261 ptr->size, 1262 ptr->mask, 1263 ptr->capacity); 1264 printf(" - count (%u) free count (%u)\n", 1265 rte_ring_count(ptr), 1266 rte_ring_free_count(ptr)); 1267 printf(" - full (%d) empty (%d)\n", 1268 rte_ring_full(ptr), 1269 rte_ring_empty(ptr)); 1270 1271 STATS_BDR_STR(50, ""); 1272 return; 1273 } 1274 } 1275 1276 rte_ring_list_dump(stdout); 1277 } 1278 1279 static void 1280 show_mempool(char *name) 1281 { 1282 snprintf(bdr_str, MAX_STRING_LEN, " show - MEMPOOL "); 1283 STATS_BDR_STR(10, bdr_str); 1284 1285 if (name != NULL) { 1286 struct rte_mempool *ptr = rte_mempool_lookup(name); 1287 if (ptr != NULL) { 1288 struct rte_mempool_ops *ops; 1289 uint64_t flags = ptr->flags; 1290 1291 ops = rte_mempool_get_ops(ptr->ops_index); 1292 printf(" - Name: %s on socket %d\n" 1293 " - flags:\n" 1294 "\t -- No spread (%c)\n" 1295 "\t -- No cache align (%c)\n" 1296 "\t -- SP put (%c), SC get (%c)\n" 1297 "\t -- Pool created (%c)\n" 1298 "\t -- No IOVA config (%c)\n", 1299 ptr->name, 1300 ptr->socket_id, 1301 (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n', 1302 (flags & MEMPOOL_F_NO_CACHE_ALIGN) ? 'y' : 'n', 1303 (flags & MEMPOOL_F_SP_PUT) ? 'y' : 'n', 1304 (flags & MEMPOOL_F_SC_GET) ? 'y' : 'n', 1305 (flags & MEMPOOL_F_POOL_CREATED) ? 'y' : 'n', 1306 (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); 1307 printf(" - Size %u Cache %u element %u\n" 1308 " - header %u trailer %u\n" 1309 " - private data size %u\n", 1310 ptr->size, 1311 ptr->cache_size, 1312 ptr->elt_size, 1313 ptr->header_size, 1314 ptr->trailer_size, 1315 ptr->private_data_size); 1316 printf(" - memezone - socket %d\n", 1317 ptr->mz->socket_id); 1318 printf(" - Count: avail (%u), in use (%u)\n", 1319 rte_mempool_avail_count(ptr), 1320 rte_mempool_in_use_count(ptr)); 1321 printf(" - ops_index %d ops_name %s\n", 1322 ptr->ops_index, ops ? ops->name : "NA"); 1323 1324 return; 1325 } 1326 } 1327 1328 rte_mempool_list_dump(stdout); 1329 } 1330 1331 static void 1332 mempool_itr_obj(struct rte_mempool *mp, void *opaque, 1333 void *obj, unsigned int obj_idx) 1334 { 1335 printf(" - obj_idx %u opaque %p obj %p\n", 1336 obj_idx, opaque, obj); 1337 1338 if (obj) 1339 rte_hexdump(stdout, " Obj Content", 1340 obj, (mp->elt_size > 256)?256:mp->elt_size); 1341 } 1342 1343 static void 1344 iter_mempool(char *name) 1345 { 1346 snprintf(bdr_str, MAX_STRING_LEN, " iter - MEMPOOL "); 1347 STATS_BDR_STR(10, bdr_str); 1348 1349 if (name != NULL) { 1350 struct rte_mempool *ptr = rte_mempool_lookup(name); 1351 if (ptr != NULL) { 1352 /* iterate each object */ 1353 uint32_t ret = rte_mempool_obj_iter(ptr, 1354 mempool_itr_obj, NULL); 1355 printf("\n - iterated %u objects\n", ret); 1356 return; 1357 } 1358 } 1359 } 1360 1361 static void 1362 dump_regs(char *file_prefix) 1363 { 1364 #define MAX_FILE_NAME_SZ (MAX_LONG_OPT_SZ + 10) 1365 char file_name[MAX_FILE_NAME_SZ]; 1366 struct rte_dev_reg_info reg_info; 1367 struct rte_eth_dev_info dev_info; 1368 unsigned char *buf_data; 1369 size_t buf_size; 1370 FILE *fp_regs; 1371 uint16_t i; 1372 int ret; 1373 1374 snprintf(bdr_str, MAX_STRING_LEN, " dump - Port REG"); 1375 STATS_BDR_STR(10, bdr_str); 1376 1377 RTE_ETH_FOREACH_DEV(i) { 1378 /* Skip if port is not in mask */ 1379 if ((enabled_port_mask & (1ul << i)) == 0) 1380 continue; 1381 1382 snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i); 1383 STATS_BDR_STR(5, bdr_str); 1384 1385 ret = rte_eth_dev_info_get(i, &dev_info); 1386 if (ret) { 1387 printf("Error getting device info: %d\n", ret); 1388 continue; 1389 } 1390 1391 memset(®_info, 0, sizeof(reg_info)); 1392 ret = rte_eth_dev_get_reg_info(i, ®_info); 1393 if (ret) { 1394 printf("Error getting device reg info: %d\n", ret); 1395 continue; 1396 } 1397 1398 buf_size = reg_info.length * reg_info.width; 1399 buf_data = malloc(buf_size); 1400 if (buf_data == NULL) { 1401 printf("Error allocating %zu bytes buffer\n", buf_size); 1402 continue; 1403 } 1404 1405 reg_info.data = buf_data; 1406 reg_info.length = 0; 1407 ret = rte_eth_dev_get_reg_info(i, ®_info); 1408 if (ret) { 1409 printf("Error getting regs from device: %d\n", ret); 1410 free(buf_data); 1411 continue; 1412 } 1413 1414 snprintf(file_name, MAX_FILE_NAME_SZ, "%s-port%u", 1415 file_prefix, i); 1416 fp_regs = fopen(file_name, "wb"); 1417 if (fp_regs == NULL) { 1418 printf("Error during opening '%s' for writing: %s\n", 1419 file_name, strerror(errno)); 1420 } else { 1421 size_t nr_written; 1422 1423 nr_written = fwrite(buf_data, 1, buf_size, fp_regs); 1424 if (nr_written != buf_size) 1425 printf("Error during writing %s: %s\n", 1426 file_prefix, strerror(errno)); 1427 else 1428 printf("Device (%s) regs dumped successfully, " 1429 "driver:%s version:0X%08X\n", 1430 dev_info.device->name, 1431 dev_info.driver_name, reg_info.version); 1432 1433 fclose(fp_regs); 1434 } 1435 1436 free(buf_data); 1437 } 1438 } 1439 1440 int 1441 main(int argc, char **argv) 1442 { 1443 int ret; 1444 int i; 1445 char c_flag[] = "-c1"; 1446 char n_flag[] = "-n4"; 1447 char mp_flag[] = "--proc-type=secondary"; 1448 char log_flag[] = "--log-level=6"; 1449 char *argp[argc + 4]; 1450 uint16_t nb_ports; 1451 1452 /* preparse app arguments */ 1453 ret = proc_info_preparse_args(argc, argv); 1454 if (ret < 0) { 1455 printf("Failed to parse arguments\n"); 1456 return -1; 1457 } 1458 1459 argp[0] = argv[0]; 1460 argp[1] = c_flag; 1461 argp[2] = n_flag; 1462 argp[3] = mp_flag; 1463 argp[4] = log_flag; 1464 1465 for (i = 1; i < argc; i++) 1466 argp[i + 4] = argv[i]; 1467 1468 argc += 4; 1469 1470 ret = rte_eal_init(argc, argp); 1471 if (ret < 0) 1472 rte_panic("Cannot init EAL\n"); 1473 1474 argc -= ret; 1475 argv += ret - 4; 1476 1477 if (!rte_eal_primary_proc_alive(NULL)) 1478 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n"); 1479 1480 /* parse app arguments */ 1481 ret = proc_info_parse_args(argc, argv); 1482 if (ret < 0) 1483 rte_exit(EXIT_FAILURE, "Invalid argument\n"); 1484 1485 if (mem_info) { 1486 meminfo_display(); 1487 return 0; 1488 } 1489 1490 nb_ports = rte_eth_dev_count_avail(); 1491 if (nb_ports == 0) 1492 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); 1493 1494 /* If no port mask was specified, then show non-owned ports */ 1495 if (enabled_port_mask == 0) { 1496 RTE_ETH_FOREACH_DEV(i) 1497 enabled_port_mask = 1ul << i; 1498 } 1499 1500 for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 1501 1502 /* Skip if port is not in mask */ 1503 if ((enabled_port_mask & (1ul << i)) == 0) 1504 continue; 1505 1506 /* Skip if port is unused */ 1507 if (!rte_eth_dev_is_valid_port(i)) 1508 continue; 1509 1510 if (enable_stats) 1511 nic_stats_display(i); 1512 else if (enable_xstats) 1513 nic_xstats_display(i); 1514 else if (reset_stats) 1515 nic_stats_clear(i); 1516 else if (reset_xstats) 1517 nic_xstats_clear(i); 1518 else if (enable_xstats_name) 1519 nic_xstats_by_name_display(i, xstats_name); 1520 else if (nb_xstats_ids > 0) 1521 nic_xstats_by_ids_display(i, xstats_ids, 1522 nb_xstats_ids); 1523 else if (enable_metrics) 1524 metrics_display(i); 1525 1526 } 1527 1528 /* print port independent stats */ 1529 if (enable_metrics) 1530 metrics_display(RTE_METRICS_GLOBAL); 1531 1532 /* show information for PMD */ 1533 if (enable_shw_port) 1534 show_port(); 1535 if (enable_shw_tm) 1536 show_tm(); 1537 if (enable_shw_crypto) 1538 show_crypto(); 1539 if (enable_shw_ring) 1540 show_ring(ring_name); 1541 if (enable_shw_mempool) 1542 show_mempool(mempool_name); 1543 if (enable_iter_mempool) 1544 iter_mempool(mempool_iter_name); 1545 if (enable_dump_regs) 1546 dump_regs(dump_regs_file_prefix); 1547 1548 RTE_ETH_FOREACH_DEV(i) 1549 rte_eth_dev_close(i); 1550 1551 ret = rte_eal_cleanup(); 1552 if (ret) 1553 printf("Error from rte_eal_cleanup(), %d\n", ret); 1554 1555 return 0; 1556 } 1557