app/testpmd: register a specific log type
[dpdk.git] / app / test-pmd / testpmd.c
index 4317a17..373ed2a 100644 (file)
@@ -57,7 +57,6 @@
 #include <rte_cycles.h>
 #include <rte_memory.h>
 #include <rte_memcpy.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_alarm.h>
@@ -92,6 +91,7 @@
 #include "testpmd.h"
 
 uint16_t verbose_level = 0; /**< Silent by default. */
+int testpmd_logtype; /**< Log type for testpmd logs */
 
 /* use master core for command line ? */
 uint8_t interactive = 0;
@@ -164,6 +164,10 @@ struct fwd_engine * fwd_engines[] = {
        &tx_only_engine,
        &csum_fwd_engine,
        &icmp_echo_engine,
+#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
+       &softnic_tm_engine,
+       &softnic_tm_bypass_engine,
+#endif
 #ifdef RTE_LIBRTE_IEEE1588
        &ieee1588_fwd_engine,
 #endif
@@ -180,6 +184,13 @@ uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
 uint32_t param_total_num_mbufs = 0;  /**< number of mbufs in all pools - if
                                       * specified on command-line. */
 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
+
+/*
+ * In container, it cannot terminate the process which running with 'stats-period'
+ * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
+ */
+uint8_t f_quit;
+
 /*
  * Configuration of packet segments used by the "txonly" processing engine.
  */
@@ -336,6 +347,7 @@ struct rte_eth_rxmode rx_mode = {
        .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
        .jumbo_frame    = 0, /**< Jumbo Frame Support disabled. */
        .hw_strip_crc   = 1, /**< CRC stripping by hardware enabled. */
+       .hw_timestamp   = 0, /**< HW timestamp enabled. */
 };
 
 struct rte_fdir_conf fdir_conf = {
@@ -372,6 +384,11 @@ struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_a
 uint16_t nb_tx_queue_stats_mappings = 0;
 uint16_t nb_rx_queue_stats_mappings = 0;
 
+/*
+ * Display zero values by default for xstats
+ */
+uint8_t xstats_hide_zero;
+
 unsigned int num_sockets = 0;
 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
@@ -386,7 +403,8 @@ struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
 
 /* Forward function declarations */
-static void map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port);
+static void map_port_queue_stats_mapping_registers(portid_t pi,
+                                                  struct rte_port *port);
 static void check_all_ports_link_status(uint32_t port_mask);
 static int eth_event_callback(portid_t port_id,
                              enum rte_eth_event_type type,
@@ -398,6 +416,9 @@ static int eth_event_callback(portid_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -461,9 +482,10 @@ static void
 set_default_fwd_ports_config(void)
 {
        portid_t pt_id;
+       int i = 0;
 
-       for (pt_id = 0; pt_id < nb_ports; pt_id++)
-               fwd_ports_ids[pt_id] = pt_id;
+       RTE_ETH_FOREACH_DEV(pt_id)
+               fwd_ports_ids[i++] = pt_id;
 
        nb_cfg_ports = nb_ports;
        nb_fwd_ports = nb_ports;
@@ -491,7 +513,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
        mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
        mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
 
-       RTE_LOG(INFO, USER1,
+       TESTPMD_LOG(INFO,
                "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
                pool_name, nb_mbuf, mbuf_seg_size, socket_id);
 
@@ -557,6 +579,7 @@ init_config(void)
        lcoreid_t  lc_id;
        uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
        struct rte_gro_param gro_param;
+       uint32_t gso_types;
 
        memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -641,6 +664,8 @@ init_config(void)
 
        init_port_config();
 
+       gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+               DEV_TX_OFFLOAD_GRE_TNL_TSO;
        /*
         * Records which Mbuf pool to use by each logical core, if needed.
         */
@@ -651,6 +676,13 @@ init_config(void)
                if (mbp == NULL)
                        mbp = mbuf_pool_find(0);
                fwd_lcores[lc_id]->mbp = mbp;
+               /* initialize GSO context */
+               fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+               fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+               fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+               fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+                       ETHER_CRC_LEN;
+               fwd_lcores[lc_id]->gso_ctx.flag = 0;
        }
 
        /* Configuration of packet forwarding streams. */
@@ -1338,14 +1370,14 @@ stop_packet_forwarding(void)
 void
 dev_set_link_up(portid_t pid)
 {
-       if (rte_eth_dev_set_link_up((uint8_t)pid) < 0)
+       if (rte_eth_dev_set_link_up(pid) < 0)
                printf("\nSet link up fail.\n");
 }
 
 void
 dev_set_link_down(portid_t pid)
 {
-       if (rte_eth_dev_set_link_down((uint8_t)pid) < 0)
+       if (rte_eth_dev_set_link_down(pid) < 0)
                printf("\nSet link down fail.\n");
 }
 
@@ -1758,7 +1790,7 @@ attach_port(char *identifier)
 }
 
 void
-detach_port(uint8_t port_id)
+detach_port(portid_t port_id)
 {
        char name[RTE_ETH_NAME_MAX_LEN];
 
@@ -1773,7 +1805,7 @@ detach_port(uint8_t port_id)
                port_flow_flush(port_id);
 
        if (rte_eth_dev_detach(port_id, name)) {
-               RTE_LOG(ERR, USER1, "Failed to detach port '%s'\n", name);
+               TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
                return;
        }
 
@@ -1873,7 +1905,7 @@ static void
 rmv_event_callback(void *arg)
 {
        struct rte_eth_dev *dev;
-       uint8_t port_id = (intptr_t)arg;
+       portid_t port_id = (intptr_t)arg;
 
        RTE_ETH_VALID_PORTID_OR_RET(port_id);
        dev = &rte_eth_devices[port_id];
@@ -1882,7 +1914,7 @@ rmv_event_callback(void *arg)
        close_port(port_id);
        printf("removing device %s\n", dev->device->name);
        if (rte_eal_dev_detach(dev->device))
-               RTE_LOG(ERR, USER1, "Failed to detach device %s\n",
+               TESTPMD_LOG(ERR, "Failed to detach device %s\n",
                        dev->device->name);
 }
 
@@ -1928,7 +1960,7 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
 }
 
 static int
-set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
+set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
 {
        uint16_t i;
        int diag;
@@ -1951,7 +1983,7 @@ set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
 }
 
 static int
-set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
+set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
 {
        uint16_t i;
        int diag;
@@ -1974,7 +2006,7 @@ set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
 }
 
 static void
-map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port)
+map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
 {
        int diag = 0;
 
@@ -2088,6 +2120,17 @@ init_port_config(void)
                    (rte_eth_devices[pid].data->dev_flags &
                     RTE_ETH_DEV_INTR_RMV))
                        port->dev_conf.intr_conf.rmv = 1;
+
+#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
+               /* Detect softnic port */
+               if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
+                       port->softnic_enable = 1;
+                       memset(&port->softport, 0, sizeof(struct softnic_port));
+
+                       if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
+                               port->softport.tm_flag = 1;
+               }
+#endif
        }
 }
 
@@ -2155,8 +2198,8 @@ get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
                                1 << (i % vmdq_rx_conf->nb_queue_pools);
                }
                for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
-                       vmdq_rx_conf->dcb_tc[i] = i;
-                       vmdq_tx_conf->dcb_tc[i] = i;
+                       vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
+                       vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
                }
 
                /* set DCB mode of RX and TX of multiple queues */
@@ -2321,6 +2364,8 @@ signal_handler(int signum)
                rte_latencystats_uninit();
 #endif
                force_quit();
+               /* Set flag to indicate the force termination. */
+               f_quit = 1;
                /* exit with the expected status */
                signal(signum, SIG_DFL);
                kill(getpid(), signum);
@@ -2340,8 +2385,13 @@ main(int argc, char** argv)
        if (diag < 0)
                rte_panic("Cannot init EAL\n");
 
+       testpmd_logtype = rte_log_register("testpmd");
+       if (testpmd_logtype < 0)
+               rte_panic("Cannot register log type");
+       rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
+
        if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
-               RTE_LOG(NOTICE, USER1, "mlockall() failed with error \"%s\"\n",
+               TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
                        strerror(errno));
        }
 
@@ -2352,7 +2402,7 @@ main(int argc, char** argv)
 
        nb_ports = (portid_t) rte_eth_dev_count();
        if (nb_ports == 0)
-               RTE_LOG(WARNING, EAL, "No probed ethernet devices\n");
+               TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
 
        /* allocate port structures, and init them */
        init_port();
@@ -2443,6 +2493,8 @@ main(int argc, char** argv)
                char c;
                int rc;
 
+               f_quit = 0;
+
                printf("No commandline core given, start packet forwarding\n");
                start_packet_forwarding(tx_first);
                if (stats_period != 0) {
@@ -2452,7 +2504,7 @@ main(int argc, char** argv)
                        /* Convert to number of cycles */
                        timer_period = stats_period * rte_get_timer_hz();
 
-                       while (1) {
+                       while (f_quit == 0) {
                                cur_time = rte_get_timer_cycles();
                                diff_time += cur_time - prev_time;