app/testpmd: make txonly mode generate multiple flows
[dpdk.git] / app / test-pmd / testpmd.c
index a10bc40..40c873b 100644 (file)
@@ -217,6 +217,9 @@ uint8_t  tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
 /**< Split policy for packets to TX. */
 
+uint8_t txonly_multi_flow;
+/**< Whether multiple flows are generated in TXONLY mode. */
+
 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
 
@@ -469,6 +472,7 @@ uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
 struct vxlan_encap_conf vxlan_encap_conf = {
        .select_ipv4 = 1,
        .select_vlan = 0,
+       .select_tos_ttl = 0,
        .vni = "\x00\x00\x00",
        .udp_src = 0,
        .udp_dst = RTE_BE16(4789),
@@ -479,6 +483,8 @@ struct vxlan_encap_conf vxlan_encap_conf = {
        .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
                "\x00\x00\x00\x00\x00\x00\x11\x11",
        .vlan_tci = 0,
+       .ip_tos = 0,
+       .ip_ttl = 255,
        .eth_src = "\x00\x00\x00\x00\x00\x00",
        .eth_dst = "\xff\xff\xff\xff\xff\xff",
 };
@@ -649,28 +655,13 @@ calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
        return 0;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-       return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-       if (v == 0)
-               return 0;
-       v = rte_align64pow2(v);
-       return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
        /* as per mmap() manpage, all page sizes are log2 of page size
         * shifted by MAP_HUGE_SHIFT
         */
-       int log2 = log2_u64(page_sz);
+       int log2 = rte_log2_u64(page_sz);
 
        return (log2 << HUGE_SHIFT);
 }
@@ -1373,119 +1364,256 @@ pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
 
 static void
-fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
+fwd_stream_stats_display(streamid_t stream_id)
 {
-       struct rte_port *port;
-       uint8_t i;
+       struct fwd_stream *fs;
+       static const char *fwd_top_stats_border = "-------";
 
+       fs = fwd_streams[stream_id];
+       if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
+           (fs->fwd_dropped == 0))
+               return;
+       printf("\n  %s Forward Stats for RX Port=%2d/Queue=%2d -> "
+              "TX Port=%2d/Queue=%2d %s\n",
+              fwd_top_stats_border, fs->rx_port, fs->rx_queue,
+              fs->tx_port, fs->tx_queue, fwd_top_stats_border);
+       printf("  RX-packets: %-14"PRIu64" TX-packets: %-14"PRIu64
+              " TX-dropped: %-14"PRIu64,
+              fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
+
+       /* if checksum mode */
+       if (cur_fwd_eng == &csum_fwd_engine) {
+               printf("  RX- bad IP checksum: %-14"PRIu64
+                      "  Rx- bad L4 checksum: %-14"PRIu64
+                      " Rx- bad outer L4 checksum: %-14"PRIu64"\n",
+                       fs->rx_bad_ip_csum, fs->rx_bad_l4_csum,
+                       fs->rx_bad_outer_l4_csum);
+       } else {
+               printf("\n");
+       }
+
+#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
+       pkt_burst_stats_display("RX", &fs->rx_burst_stats);
+       pkt_burst_stats_display("TX", &fs->tx_burst_stats);
+#endif
+}
+
+void
+fwd_stats_display(void)
+{
        static const char *fwd_stats_border = "----------------------";
+       static const char *acc_stats_border = "+++++++++++++++";
+       struct {
+               struct fwd_stream *rx_stream;
+               struct fwd_stream *tx_stream;
+               uint64_t tx_dropped;
+               uint64_t rx_bad_ip_csum;
+               uint64_t rx_bad_l4_csum;
+               uint64_t rx_bad_outer_l4_csum;
+       } ports_stats[RTE_MAX_ETHPORTS];
+       uint64_t total_rx_dropped = 0;
+       uint64_t total_tx_dropped = 0;
+       uint64_t total_rx_nombuf = 0;
+       struct rte_eth_stats stats;
+#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
+       uint64_t fwd_cycles = 0;
+#endif
+       uint64_t total_recv = 0;
+       uint64_t total_xmit = 0;
+       struct rte_port *port;
+       streamid_t sm_id;
+       portid_t pt_id;
+       int i;
 
-       port = &ports[port_id];
-       printf("\n  %s Forward statistics for port %-2d %s\n",
-              fwd_stats_border, port_id, fwd_stats_border);
+       memset(ports_stats, 0, sizeof(ports_stats));
 
-       if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
-               printf("  RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
-                      "%-"PRIu64"\n",
-                      stats->ipackets, stats->imissed,
-                      (uint64_t) (stats->ipackets + stats->imissed));
+       for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
+               struct fwd_stream *fs = fwd_streams[sm_id];
 
-               if (cur_fwd_eng == &csum_fwd_engine)
-                       printf("  Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64"Bad-outer-l4csum: %-14"PRIu64"\n",
-                              port->rx_bad_ip_csum, port->rx_bad_l4_csum,
-                              port->rx_bad_outer_l4_csum);
-               if ((stats->ierrors + stats->rx_nombuf) > 0) {
-                       printf("  RX-error: %-"PRIu64"\n",  stats->ierrors);
-                       printf("  RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
+               if (cur_fwd_config.nb_fwd_streams >
+                   cur_fwd_config.nb_fwd_ports) {
+                       fwd_stream_stats_display(sm_id);
+               } else {
+                       ports_stats[fs->tx_port].tx_stream = fs;
+                       ports_stats[fs->rx_port].rx_stream = fs;
                }
 
-               printf("  TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
-                      "%-"PRIu64"\n",
-                      stats->opackets, port->tx_dropped,
-                      (uint64_t) (stats->opackets + port->tx_dropped));
-       }
-       else {
-               printf("  RX-packets:             %14"PRIu64"    RX-dropped:%14"PRIu64"    RX-total:"
-                      "%14"PRIu64"\n",
-                      stats->ipackets, stats->imissed,
-                      (uint64_t) (stats->ipackets + stats->imissed));
+               ports_stats[fs->tx_port].tx_dropped += fs->fwd_dropped;
 
-               if (cur_fwd_eng == &csum_fwd_engine)
-                       printf("  Bad-ipcsum:%14"PRIu64"    Bad-l4csum:%14"PRIu64"    Bad-outer-l4csum: %-14"PRIu64"\n",
-                              port->rx_bad_ip_csum, port->rx_bad_l4_csum,
-                              port->rx_bad_outer_l4_csum);
-               if ((stats->ierrors + stats->rx_nombuf) > 0) {
-                       printf("  RX-error:%"PRIu64"\n", stats->ierrors);
-                       printf("  RX-nombufs:             %14"PRIu64"\n",
-                              stats->rx_nombuf);
-               }
+               ports_stats[fs->rx_port].rx_bad_ip_csum += fs->rx_bad_ip_csum;
+               ports_stats[fs->rx_port].rx_bad_l4_csum += fs->rx_bad_l4_csum;
+               ports_stats[fs->rx_port].rx_bad_outer_l4_csum +=
+                               fs->rx_bad_outer_l4_csum;
 
-               printf("  TX-packets:             %14"PRIu64"    TX-dropped:%14"PRIu64"    TX-total:"
-                      "%14"PRIu64"\n",
-                      stats->opackets, port->tx_dropped,
-                      (uint64_t) (stats->opackets + port->tx_dropped));
+#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
+               fwd_cycles += fs->core_cycles;
+#endif
        }
+       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
+               uint8_t j;
+
+               pt_id = fwd_ports_ids[i];
+               port = &ports[pt_id];
+
+               rte_eth_stats_get(pt_id, &stats);
+               stats.ipackets -= port->stats.ipackets;
+               stats.opackets -= port->stats.opackets;
+               stats.ibytes -= port->stats.ibytes;
+               stats.obytes -= port->stats.obytes;
+               stats.imissed -= port->stats.imissed;
+               stats.oerrors -= port->stats.oerrors;
+               stats.rx_nombuf -= port->stats.rx_nombuf;
+
+               total_recv += stats.ipackets;
+               total_xmit += stats.opackets;
+               total_rx_dropped += stats.imissed;
+               total_tx_dropped += ports_stats[pt_id].tx_dropped;
+               total_tx_dropped += stats.oerrors;
+               total_rx_nombuf  += stats.rx_nombuf;
+
+               printf("\n  %s Forward statistics for port %-2d %s\n",
+                      fwd_stats_border, pt_id, fwd_stats_border);
+
+               if (!port->rx_queue_stats_mapping_enabled &&
+                   !port->tx_queue_stats_mapping_enabled) {
+                       printf("  RX-packets: %-14"PRIu64
+                              " RX-dropped: %-14"PRIu64
+                              "RX-total: %-"PRIu64"\n",
+                              stats.ipackets, stats.imissed,
+                              stats.ipackets + stats.imissed);
+
+                       if (cur_fwd_eng == &csum_fwd_engine)
+                               printf("  Bad-ipcsum: %-14"PRIu64
+                                      " Bad-l4csum: %-14"PRIu64
+                                      "Bad-outer-l4csum: %-14"PRIu64"\n",
+                                      ports_stats[pt_id].rx_bad_ip_csum,
+                                      ports_stats[pt_id].rx_bad_l4_csum,
+                                      ports_stats[pt_id].rx_bad_outer_l4_csum);
+                       if (stats.ierrors + stats.rx_nombuf > 0) {
+                               printf("  RX-error: %-"PRIu64"\n",
+                                      stats.ierrors);
+                               printf("  RX-nombufs: %-14"PRIu64"\n",
+                                      stats.rx_nombuf);
+                       }
+
+                       printf("  TX-packets: %-14"PRIu64
+                              " TX-dropped: %-14"PRIu64
+                              "TX-total: %-"PRIu64"\n",
+                              stats.opackets, ports_stats[pt_id].tx_dropped,
+                              stats.opackets + ports_stats[pt_id].tx_dropped);
+               } else {
+                       printf("  RX-packets:             %14"PRIu64
+                              "    RX-dropped:%14"PRIu64
+                              "    RX-total:%14"PRIu64"\n",
+                              stats.ipackets, stats.imissed,
+                              stats.ipackets + stats.imissed);
+
+                       if (cur_fwd_eng == &csum_fwd_engine)
+                               printf("  Bad-ipcsum:%14"PRIu64
+                                      "    Bad-l4csum:%14"PRIu64
+                                      "    Bad-outer-l4csum: %-14"PRIu64"\n",
+                                      ports_stats[pt_id].rx_bad_ip_csum,
+                                      ports_stats[pt_id].rx_bad_l4_csum,
+                                      ports_stats[pt_id].rx_bad_outer_l4_csum);
+                       if ((stats.ierrors + stats.rx_nombuf) > 0) {
+                               printf("  RX-error:%"PRIu64"\n", stats.ierrors);
+                               printf("  RX-nombufs:             %14"PRIu64"\n",
+                                      stats.rx_nombuf);
+                       }
+
+                       printf("  TX-packets:             %14"PRIu64
+                              "    TX-dropped:%14"PRIu64
+                              "    TX-total:%14"PRIu64"\n",
+                              stats.opackets, ports_stats[pt_id].tx_dropped,
+                              stats.opackets + ports_stats[pt_id].tx_dropped);
+               }
 
 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
-       if (port->rx_stream)
-               pkt_burst_stats_display("RX",
-                       &port->rx_stream->rx_burst_stats);
-       if (port->tx_stream)
-               pkt_burst_stats_display("TX",
-                       &port->tx_stream->tx_burst_stats);
+               if (ports_stats[pt_id].rx_stream)
+                       pkt_burst_stats_display("RX",
+                               &ports_stats[pt_id].rx_stream->rx_burst_stats);
+               if (ports_stats[pt_id].tx_stream)
+                       pkt_burst_stats_display("TX",
+                               &ports_stats[pt_id].tx_stream->tx_burst_stats);
 #endif
 
-       if (port->rx_queue_stats_mapping_enabled) {
-               printf("\n");
-               for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
-                       printf("  Stats reg %2d RX-packets:%14"PRIu64
-                              "     RX-errors:%14"PRIu64
-                              "    RX-bytes:%14"PRIu64"\n",
-                              i, stats->q_ipackets[i], stats->q_errors[i], stats->q_ibytes[i]);
-               }
-               printf("\n");
-       }
-       if (port->tx_queue_stats_mapping_enabled) {
-               for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
-                       printf("  Stats reg %2d TX-packets:%14"PRIu64
-                              "                                 TX-bytes:%14"PRIu64"\n",
-                              i, stats->q_opackets[i], stats->q_obytes[i]);
+               if (port->rx_queue_stats_mapping_enabled) {
+                       printf("\n");
+                       for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
+                               printf("  Stats reg %2d RX-packets:%14"PRIu64
+                                      "     RX-errors:%14"PRIu64
+                                      "    RX-bytes:%14"PRIu64"\n",
+                                      j, stats.q_ipackets[j],
+                                      stats.q_errors[j], stats.q_ibytes[j]);
+                       }
+                       printf("\n");
+               }
+               if (port->tx_queue_stats_mapping_enabled) {
+                       for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
+                               printf("  Stats reg %2d TX-packets:%14"PRIu64
+                                      "                                 TX-bytes:%14"
+                                      PRIu64"\n",
+                                      j, stats.q_opackets[j],
+                                      stats.q_obytes[j]);
+                       }
                }
+
+               printf("  %s--------------------------------%s\n",
+                      fwd_stats_border, fwd_stats_border);
        }
 
-       printf("  %s--------------------------------%s\n",
-              fwd_stats_border, fwd_stats_border);
+       printf("\n  %s Accumulated forward statistics for all ports"
+              "%s\n",
+              acc_stats_border, acc_stats_border);
+       printf("  RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
+              "%-"PRIu64"\n"
+              "  TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
+              "%-"PRIu64"\n",
+              total_recv, total_rx_dropped, total_recv + total_rx_dropped,
+              total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
+       if (total_rx_nombuf > 0)
+               printf("  RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
+       printf("  %s++++++++++++++++++++++++++++++++++++++++++++++"
+              "%s\n",
+              acc_stats_border, acc_stats_border);
+#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
+       if (total_recv > 0)
+               printf("\n  CPU cycles/packet=%u (total cycles="
+                      "%"PRIu64" / total RX packets=%"PRIu64")\n",
+                      (unsigned int)(fwd_cycles / total_recv),
+                      fwd_cycles, total_recv);
+#endif
 }
 
-static void
-fwd_stream_stats_display(streamid_t stream_id)
+void
+fwd_stats_reset(void)
 {
-       struct fwd_stream *fs;
-       static const char *fwd_top_stats_border = "-------";
-
-       fs = fwd_streams[stream_id];
-       if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
-           (fs->fwd_dropped == 0))
-               return;
-       printf("\n  %s Forward Stats for RX Port=%2d/Queue=%2d -> "
-              "TX Port=%2d/Queue=%2d %s\n",
-              fwd_top_stats_border, fs->rx_port, fs->rx_queue,
-              fs->tx_port, fs->tx_queue, fwd_top_stats_border);
-       printf("  RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
-              fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
+       streamid_t sm_id;
+       portid_t pt_id;
+       int i;
 
-       /* if checksum mode */
-       if (cur_fwd_eng == &csum_fwd_engine) {
-              printf("  RX- bad IP checksum: %-14u  Rx- bad L4 checksum: "
-                       "%-14u Rx- bad outer L4 checksum: %-14u\n",
-                       fs->rx_bad_ip_csum, fs->rx_bad_l4_csum,
-                       fs->rx_bad_outer_l4_csum);
+       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
+               pt_id = fwd_ports_ids[i];
+               rte_eth_stats_get(pt_id, &ports[pt_id].stats);
        }
+       for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
+               struct fwd_stream *fs = fwd_streams[sm_id];
+
+               fs->rx_packets = 0;
+               fs->tx_packets = 0;
+               fs->fwd_dropped = 0;
+               fs->rx_bad_ip_csum = 0;
+               fs->rx_bad_l4_csum = 0;
+               fs->rx_bad_outer_l4_csum = 0;
 
 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
-       pkt_burst_stats_display("RX", &fs->rx_burst_stats);
-       pkt_burst_stats_display("TX", &fs->tx_burst_stats);
+               memset(&fs->rx_burst_stats, 0, sizeof(fs->rx_burst_stats));
+               memset(&fs->tx_burst_stats, 0, sizeof(fs->tx_burst_stats));
+#endif
+#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
+               fs->core_cycles = 0;
 #endif
+       }
 }
 
 static void
@@ -1643,7 +1771,6 @@ start_packet_forwarding(int with_tx_first)
        struct rte_port *port;
        unsigned int i;
        portid_t   pt_id;
-       streamid_t sm_id;
 
        if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
                rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
@@ -1694,32 +1821,12 @@ start_packet_forwarding(int with_tx_first)
        pkt_fwd_config_display(&cur_fwd_config);
        rxtx_config_display();
 
+       fwd_stats_reset();
        for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
                pt_id = fwd_ports_ids[i];
                port = &ports[pt_id];
-               rte_eth_stats_get(pt_id, &port->stats);
-               port->tx_dropped = 0;
-
                map_port_queue_stats_mapping_registers(pt_id, port);
        }
-       for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
-               fwd_streams[sm_id]->rx_packets = 0;
-               fwd_streams[sm_id]->tx_packets = 0;
-               fwd_streams[sm_id]->fwd_dropped = 0;
-               fwd_streams[sm_id]->rx_bad_ip_csum = 0;
-               fwd_streams[sm_id]->rx_bad_l4_csum = 0;
-               fwd_streams[sm_id]->rx_bad_outer_l4_csum = 0;
-
-#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
-               memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
-                      sizeof(fwd_streams[sm_id]->rx_burst_stats));
-               memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
-                      sizeof(fwd_streams[sm_id]->tx_burst_stats));
-#endif
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-               fwd_streams[sm_id]->core_cycles = 0;
-#endif
-       }
        if (with_tx_first) {
                port_fwd_begin = tx_only_engine.port_fwd_begin;
                if (port_fwd_begin != NULL) {
@@ -1743,26 +1850,10 @@ start_packet_forwarding(int with_tx_first)
 void
 stop_packet_forwarding(void)
 {
-       struct rte_eth_stats stats;
-       struct rte_port *port;
-       port_fwd_end_t  port_fwd_end;
+       port_fwd_end_t port_fwd_end;
+       lcoreid_t lc_id;
+       portid_t pt_id;
        int i;
-       portid_t   pt_id;
-       streamid_t sm_id;
-       lcoreid_t  lc_id;
-       uint64_t total_recv;
-       uint64_t total_xmit;
-       uint64_t total_rx_dropped;
-       uint64_t total_tx_dropped;
-       uint64_t total_rx_nombuf;
-       uint64_t tx_dropped;
-       uint64_t rx_bad_ip_csum;
-       uint64_t rx_bad_l4_csum;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       uint64_t fwd_cycles;
-#endif
-
-       static const char *acc_stats_border = "+++++++++++++++";
 
        if (test_done) {
                printf("Packet forwarding not started\n");
@@ -1780,103 +1871,9 @@ stop_packet_forwarding(void)
                        (*port_fwd_end)(pt_id);
                }
        }
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       fwd_cycles = 0;
-#endif
-       for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
-               if (cur_fwd_config.nb_fwd_streams >
-                   cur_fwd_config.nb_fwd_ports) {
-                       fwd_stream_stats_display(sm_id);
-                       ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
-                       ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
-               } else {
-                       ports[fwd_streams[sm_id]->tx_port].tx_stream =
-                               fwd_streams[sm_id];
-                       ports[fwd_streams[sm_id]->rx_port].rx_stream =
-                               fwd_streams[sm_id];
-               }
-               tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
-               tx_dropped = (uint64_t) (tx_dropped +
-                                        fwd_streams[sm_id]->fwd_dropped);
-               ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
-
-               rx_bad_ip_csum =
-                       ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
-               rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
-                                        fwd_streams[sm_id]->rx_bad_ip_csum);
-               ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum =
-                                                       rx_bad_ip_csum;
-
-               rx_bad_l4_csum =
-                       ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
-               rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
-                                        fwd_streams[sm_id]->rx_bad_l4_csum);
-               ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum =
-                                                       rx_bad_l4_csum;
-
-               ports[fwd_streams[sm_id]->rx_port].rx_bad_outer_l4_csum +=
-                               fwd_streams[sm_id]->rx_bad_outer_l4_csum;
-
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-               fwd_cycles = (uint64_t) (fwd_cycles +
-                                        fwd_streams[sm_id]->core_cycles);
-#endif
-       }
-       total_recv = 0;
-       total_xmit = 0;
-       total_rx_dropped = 0;
-       total_tx_dropped = 0;
-       total_rx_nombuf  = 0;
-       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
-               pt_id = fwd_ports_ids[i];
-
-               port = &ports[pt_id];
-               rte_eth_stats_get(pt_id, &stats);
-               stats.ipackets -= port->stats.ipackets;
-               port->stats.ipackets = 0;
-               stats.opackets -= port->stats.opackets;
-               port->stats.opackets = 0;
-               stats.ibytes   -= port->stats.ibytes;
-               port->stats.ibytes = 0;
-               stats.obytes   -= port->stats.obytes;
-               port->stats.obytes = 0;
-               stats.imissed  -= port->stats.imissed;
-               port->stats.imissed = 0;
-               stats.oerrors  -= port->stats.oerrors;
-               port->stats.oerrors = 0;
-               stats.rx_nombuf -= port->stats.rx_nombuf;
-               port->stats.rx_nombuf = 0;
 
-               total_recv += stats.ipackets;
-               total_xmit += stats.opackets;
-               total_rx_dropped += stats.imissed;
-               total_tx_dropped += port->tx_dropped;
-               total_rx_nombuf  += stats.rx_nombuf;
-
-               fwd_port_stats_display(pt_id, &stats);
-       }
+       fwd_stats_display();
 
-       printf("\n  %s Accumulated forward statistics for all ports"
-              "%s\n",
-              acc_stats_border, acc_stats_border);
-       printf("  RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
-              "%-"PRIu64"\n"
-              "  TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
-              "%-"PRIu64"\n",
-              total_recv, total_rx_dropped, total_recv + total_rx_dropped,
-              total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
-       if (total_rx_nombuf > 0)
-               printf("  RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
-       printf("  %s++++++++++++++++++++++++++++++++++++++++++++++"
-              "%s\n",
-              acc_stats_border, acc_stats_border);
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       if (total_recv > 0)
-               printf("\n  CPU cycles/packet=%u (total cycles="
-                      "%"PRIu64" / total RX packets=%"PRIu64")\n",
-                      (unsigned int)(fwd_cycles / total_recv),
-                      fwd_cycles, total_recv);
-#endif
        printf("\nDone.\n");
        test_done = 1;
 }
@@ -2406,9 +2403,13 @@ pmd_test_exit(void)
        if (ports != NULL) {
                no_link_check = 1;
                RTE_ETH_FOREACH_DEV(pt_id) {
-                       printf("\nShutting down port %d...\n", pt_id);
+                       printf("\nStopping port %d...\n", pt_id);
                        fflush(stdout);
                        stop_port(pt_id);
+               }
+               RTE_ETH_FOREACH_DEV(pt_id) {
+                       printf("\nShutting down port %d...\n", pt_id);
+                       fflush(stdout);
                        close_port(pt_id);
 
                        /*
@@ -3054,6 +3055,8 @@ print_stats(void)
        printf("\nPort statistics ====================================");
        for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
                nic_stats_display(fwd_ports_ids[i]);
+
+       fflush(stdout);
 }
 
 static void
@@ -3133,7 +3136,7 @@ main(int argc, char** argv)
 #endif
 
        /* on FreeBSD, mlockall() is disabled by default */
-#ifdef RTE_EXEC_ENV_BSDAPP
+#ifdef RTE_EXEC_ENV_FREEBSD
        do_mlockall = 0;
 #else
        do_mlockall = 1;