app/testpmd: support multi-process
[dpdk.git] / app / proc-info / main.c
index d2624e0..a8e928f 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <inttypes.h>
@@ -12,6 +13,7 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <unistd.h>
+#include <strings.h>
 
 #include <rte_eal.h>
 #include <rte_common.h>
@@ -46,7 +48,7 @@
        STATS_BDR_FMT, s, w, STATS_BDR_FMT)
 
 /**< mask of enabled ports */
-static uint32_t enabled_port_mask;
+static unsigned long enabled_port_mask;
 /**< Enable stats. */
 static uint32_t enable_stats;
 /**< Enable xstats. */
@@ -92,6 +94,9 @@ static char *mempool_name;
 /**< Enable iter mempool. */
 static uint32_t enable_iter_mempool;
 static char *mempool_iter_name;
+/**< Enable dump regs. */
+static uint32_t enable_dump_regs;
+static char *dump_regs_file_prefix;
 
 /**< display usage */
 static void
@@ -117,7 +122,8 @@ proc_info_usage(const char *prgname)
                "  --show-crypto: to display crypto information\n"
                "  --show-ring[=name]: to display ring information\n"
                "  --show-mempool[=name]: to display mempool information\n"
-               "  --iter-mempool=name: iterate mempool elements to display content\n",
+               "  --iter-mempool=name: iterate mempool elements to display content\n"
+               "  --dump-regs=file-prefix: dump registers to file with the file-prefix\n",
                prgname);
 }
 
@@ -128,23 +134,17 @@ static int
 parse_portmask(const char *portmask)
 {
        char *end = NULL;
-       unsigned long pm;
 
        errno = 0;
 
        /* parse hexadecimal string */
-       pm = strtoul(portmask, &end, 16);
-       if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
-               (errno != 0)) {
-               printf("%s ERROR parsing the port mask\n", __func__);
+       enabled_port_mask = strtoul(portmask, &end, 16);
+       if (portmask[0] == '\0' || end == NULL || *end != '\0' || errno != 0) {
+               fprintf(stderr, "Invalid portmask '%s'\n", portmask);
                return -1;
        }
 
-       if (pm == 0)
-               return -1;
-
-       return pm;
-
+       return 0;
 }
 
 /*
@@ -230,6 +230,7 @@ proc_info_parse_args(int argc, char **argv)
                {"show-ring", optional_argument, NULL, 0},
                {"show-mempool", optional_argument, NULL, 0},
                {"iter-mempool", required_argument, NULL, 0},
+               {"dump-regs", required_argument, NULL, 0},
                {NULL, 0, 0, 0}
        };
 
@@ -242,9 +243,7 @@ proc_info_parse_args(int argc, char **argv)
                switch (opt) {
                /* portmask */
                case 'p':
-                       enabled_port_mask = parse_portmask(optarg);
-                       if (enabled_port_mask == 0) {
-                               printf("invalid portmask\n");
+                       if (parse_portmask(optarg) < 0) {
                                proc_info_usage(prgname);
                                return -1;
                        }
@@ -294,6 +293,10 @@ proc_info_parse_args(int argc, char **argv)
                                        "iter-mempool", MAX_LONG_OPT_SZ)) {
                                enable_iter_mempool = 1;
                                mempool_iter_name = optarg;
+                       } else if (!strncmp(long_option[option_index].name,
+                                       "dump-regs", MAX_LONG_OPT_SZ)) {
+                               enable_dump_regs = 1;
+                               dump_regs_file_prefix = optarg;
                        }
                        break;
                case 1:
@@ -308,14 +311,13 @@ proc_info_parse_args(int argc, char **argv)
                        } else if (!strncmp(long_option[option_index].name,
                                        "xstats-ids",
                                        MAX_LONG_OPT_SZ))       {
-                               nb_xstats_ids = parse_xstats_ids(optarg,
+                               int ret = parse_xstats_ids(optarg,
                                                xstats_ids, MAX_NB_XSTATS_IDS);
-
-                               if (nb_xstats_ids <= 0) {
+                               if (ret <= 0) {
                                        printf("xstats-id list parse error.\n");
                                        return -1;
                                }
-
+                               nb_xstats_ids = ret;
                        }
                        break;
                default:
@@ -427,11 +429,9 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
        } else if ((type_end != NULL) &&
                   (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
                if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
-                       strlcpy(cnt_type, "operations", cnt_type_len);
+                       strlcpy(cnt_type, "filter_result", cnt_type_len);
                else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
                        strlcpy(cnt_type, "errors", cnt_type_len);
-               else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
-                       strlcpy(cnt_type, "filter_result", cnt_type_len);
        } else if ((type_end != NULL) &&
                   (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
                if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
@@ -655,11 +655,16 @@ metrics_display(int port_id)
 }
 
 static void
-show_security_context(uint16_t portid)
+show_security_context(uint16_t portid, bool inline_offload)
 {
-       void *p_ctx = rte_eth_dev_get_sec_ctx(portid);
+       void *p_ctx;
        const struct rte_security_capability *s_cap;
 
+       if (inline_offload)
+               p_ctx = rte_eth_dev_get_sec_ctx(portid);
+       else
+               p_ctx = rte_cryptodev_get_sec_ctx(portid);
+
        if (p_ctx == NULL)
                return;
 
@@ -695,13 +700,12 @@ show_offloads(uint64_t offloads,
 static void
 show_port(void)
 {
-       uint16_t i = 0;
-       int ret = 0, j, k;
+       int i, ret, j, k;
 
        snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD ");
        STATS_BDR_STR(10, bdr_str);
 
-       RTE_ETH_FOREACH_DEV(i) {
+       for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
                uint16_t mtu = 0;
                struct rte_eth_link link;
                struct rte_eth_dev_info dev_info;
@@ -709,6 +713,15 @@ show_port(void)
                char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
                struct rte_eth_fc_conf fc_conf;
                struct rte_ether_addr mac;
+               struct rte_eth_dev_owner owner;
+
+               /* Skip if port is not in mask */
+               if ((enabled_port_mask & (1ul << i)) == 0)
+                       continue;
+
+               /* Skip if port is unused */
+               if (!rte_eth_dev_is_valid_port(i))
+                       continue;
 
                memset(&rss_conf, 0, sizeof(rss_conf));
 
@@ -727,6 +740,11 @@ show_port(void)
                       dev_info.driver_name, dev_info.device->name,
                       rte_eth_dev_socket_id(i));
 
+               ret = rte_eth_dev_owner_get(i, &owner);
+               if (ret == 0 && owner.id != RTE_ETH_DEV_NO_OWNER)
+                       printf("\t --  owner %#"PRIx64":%s\n",
+                              owner.id, owner.name);
+
                ret = rte_eth_link_get(i, &link);
                if (ret < 0) {
                        printf("Link get failed (port %u): %s\n",
@@ -853,7 +871,7 @@ show_port(void)
                }
 
 #ifdef RTE_LIB_SECURITY
-               show_security_context(i);
+               show_security_context(i, true);
 #endif
        }
 }
@@ -1204,7 +1222,6 @@ show_crypto(void)
 
                display_crypto_feature_info(dev_info.feature_flags);
 
-               memset(&stats, 0, sizeof(0));
                if (rte_cryptodev_stats_get(i, &stats) == 0) {
                        printf("\t  -- stats\n");
                        printf("\t\t  + enqueue count (%"PRIu64")"
@@ -1217,8 +1234,8 @@ show_crypto(void)
                               stats.dequeue_err_count);
                }
 
-#ifdef RTE_LIBRTE_SECURITY
-               show_security_context(i);
+#ifdef RTE_LIB_SECURITY
+               show_security_context(i, false);
 #endif
        }
 }
@@ -1262,8 +1279,6 @@ show_ring(char *name)
 static void
 show_mempool(char *name)
 {
-       uint64_t flags = 0;
-
        snprintf(bdr_str, MAX_STRING_LEN, " show - MEMPOOL ");
        STATS_BDR_STR(10, bdr_str);
 
@@ -1271,8 +1286,8 @@ show_mempool(char *name)
                struct rte_mempool *ptr = rte_mempool_lookup(name);
                if (ptr != NULL) {
                        struct rte_mempool_ops *ops;
+                       uint64_t flags = ptr->flags;
 
-                       flags = ptr->flags;
                        ops = rte_mempool_get_ops(ptr->ops_index);
                        printf("  - Name: %s on socket %d\n"
                                "  - flags:\n"
@@ -1343,6 +1358,85 @@ iter_mempool(char *name)
        }
 }
 
+static void
+dump_regs(char *file_prefix)
+{
+#define MAX_FILE_NAME_SZ (MAX_LONG_OPT_SZ + 10)
+       char file_name[MAX_FILE_NAME_SZ];
+       struct rte_dev_reg_info reg_info;
+       struct rte_eth_dev_info dev_info;
+       unsigned char *buf_data;
+       size_t buf_size;
+       FILE *fp_regs;
+       uint16_t i;
+       int ret;
+
+       snprintf(bdr_str, MAX_STRING_LEN, " dump - Port REG");
+       STATS_BDR_STR(10, bdr_str);
+
+       RTE_ETH_FOREACH_DEV(i) {
+               /* Skip if port is not in mask */
+               if ((enabled_port_mask & (1ul << i)) == 0)
+                       continue;
+
+               snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i);
+               STATS_BDR_STR(5, bdr_str);
+
+               ret = rte_eth_dev_info_get(i, &dev_info);
+               if (ret) {
+                       printf("Error getting device info: %d\n", ret);
+                       continue;
+               }
+
+               memset(&reg_info, 0, sizeof(reg_info));
+               ret = rte_eth_dev_get_reg_info(i, &reg_info);
+               if (ret) {
+                       printf("Error getting device reg info: %d\n", ret);
+                       continue;
+               }
+
+               buf_size = reg_info.length * reg_info.width;
+               buf_data = malloc(buf_size);
+               if (buf_data == NULL) {
+                       printf("Error allocating %zu bytes buffer\n", buf_size);
+                       continue;
+               }
+
+               reg_info.data = buf_data;
+               reg_info.length = 0;
+               ret = rte_eth_dev_get_reg_info(i, &reg_info);
+               if (ret) {
+                       printf("Error getting regs from device: %d\n", ret);
+                       free(buf_data);
+                       continue;
+               }
+
+               snprintf(file_name, MAX_FILE_NAME_SZ, "%s-port%u",
+                               file_prefix, i);
+               fp_regs = fopen(file_name, "wb");
+               if (fp_regs == NULL) {
+                       printf("Error during opening '%s' for writing: %s\n",
+                                       file_name, strerror(errno));
+               } else {
+                       size_t nr_written;
+
+                       nr_written = fwrite(buf_data, 1, buf_size, fp_regs);
+                       if (nr_written != buf_size)
+                               printf("Error during writing %s: %s\n",
+                                               file_prefix, strerror(errno));
+                       else
+                               printf("Device (%s) regs dumped successfully, "
+                                       "driver:%s version:0X%08X\n",
+                                       dev_info.device->name,
+                                       dev_info.driver_name, reg_info.version);
+
+                       fclose(fp_regs);
+               }
+
+               free(buf_data);
+       }
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1397,28 +1491,38 @@ main(int argc, char **argv)
        if (nb_ports == 0)
                rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
 
-       /* If no port mask was specified*/
-       if (enabled_port_mask == 0)
-               enabled_port_mask = 0xffff;
+       /* If no port mask was specified, then show non-owned ports */
+       if (enabled_port_mask == 0) {
+               RTE_ETH_FOREACH_DEV(i)
+                       enabled_port_mask = 1ul << i;
+       }
+
+       for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+
+               /* Skip if port is not in mask */
+               if ((enabled_port_mask & (1ul << i)) == 0)
+                       continue;
+
+               /* Skip if port is unused */
+               if (!rte_eth_dev_is_valid_port(i))
+                       continue;
+
+               if (enable_stats)
+                       nic_stats_display(i);
+               else if (enable_xstats)
+                       nic_xstats_display(i);
+               else if (reset_stats)
+                       nic_stats_clear(i);
+               else if (reset_xstats)
+                       nic_xstats_clear(i);
+               else if (enable_xstats_name)
+                       nic_xstats_by_name_display(i, xstats_name);
+               else if (nb_xstats_ids > 0)
+                       nic_xstats_by_ids_display(i, xstats_ids,
+                                                 nb_xstats_ids);
+               else if (enable_metrics)
+                       metrics_display(i);
 
-       RTE_ETH_FOREACH_DEV(i) {
-               if (enabled_port_mask & (1 << i)) {
-                       if (enable_stats)
-                               nic_stats_display(i);
-                       else if (enable_xstats)
-                               nic_xstats_display(i);
-                       else if (reset_stats)
-                               nic_stats_clear(i);
-                       else if (reset_xstats)
-                               nic_xstats_clear(i);
-                       else if (enable_xstats_name)
-                               nic_xstats_by_name_display(i, xstats_name);
-                       else if (nb_xstats_ids > 0)
-                               nic_xstats_by_ids_display(i, xstats_ids,
-                                               nb_xstats_ids);
-                       else if (enable_metrics)
-                               metrics_display(i);
-               }
        }
 
        /* print port independent stats */
@@ -1438,6 +1542,8 @@ main(int argc, char **argv)
                show_mempool(mempool_name);
        if (enable_iter_mempool)
                iter_mempool(mempool_iter_name);
+       if (enable_dump_regs)
+               dump_regs(dump_regs_file_prefix);
 
        RTE_ETH_FOREACH_DEV(i)
                rte_eth_dev_close(i);