examples/ioat: add option to control stats print interval
[dpdk.git] / examples / ioat / ioatfwd.c
index 887cdf3..995ba7b 100644 (file)
@@ -25,6 +25,8 @@
 #define CMD_LINE_OPT_COPY_TYPE "copy-type"
 #define CMD_LINE_OPT_RING_SIZE "ring-size"
 #define CMD_LINE_OPT_BATCH_SIZE "dma-batch-size"
+#define CMD_LINE_OPT_FRAME_SIZE "max-frame-size"
+#define CMD_LINE_OPT_STATS_INTERVAL "stats-interval"
 
 /* configurable number of RX/TX ring descriptors */
 #define RX_DEFAULT_RINGSIZE 1024
@@ -94,6 +96,9 @@ static copy_mode_t copy_mode = COPY_MODE_IOAT_NUM;
  */
 static unsigned short ring_size = 2048;
 
+/* interval, in seconds, between stats prints */
+static unsigned short stats_interval = 1;
+
 /* global transmission config */
 struct rxtx_transmission_config cfg;
 
@@ -104,6 +109,7 @@ static uint16_t nb_txd = TX_DEFAULT_RINGSIZE;
 static volatile bool force_quit;
 
 static uint32_t ioat_batch_sz = MAX_PKT_BURST;
+static uint32_t max_frame_size = RTE_ETHER_MAX_LEN;
 
 /* ethernet addresses of ports */
 static struct rte_ether_addr ioat_ports_eth_addr[RTE_MAX_ETHPORTS];
@@ -150,15 +156,15 @@ print_total_stats(struct total_statistics *ts)
                "\nTotal packets Tx: %24"PRIu64" [pps]"
                "\nTotal packets Rx: %24"PRIu64" [pps]"
                "\nTotal packets dropped: %19"PRIu64" [pps]",
-               ts->total_packets_tx,
-               ts->total_packets_rx,
-               ts->total_packets_dropped);
+               ts->total_packets_tx / stats_interval,
+               ts->total_packets_rx / stats_interval,
+               ts->total_packets_dropped / stats_interval);
 
        if (copy_mode == COPY_MODE_IOAT_NUM) {
                printf("\nTotal IOAT successful enqueues: %8"PRIu64" [enq/s]"
                        "\nTotal IOAT failed enqueues: %12"PRIu64" [enq/s]",
-                       ts->total_successful_enqueues,
-                       ts->total_failed_enqueues);
+                       ts->total_successful_enqueues / stats_interval,
+                       ts->total_failed_enqueues / stats_interval);
        }
 
        printf("\n====================================================\n");
@@ -246,10 +252,10 @@ print_stats(char *prgname)
        memset(&ts, 0, sizeof(struct total_statistics));
 
        while (!force_quit) {
-               /* Sleep for 1 second each round - init sleep allows reading
+               /* Sleep for "stats_interval" seconds each round - init sleep allows reading
                 * messages from app startup.
                 */
-               sleep(1);
+               sleep(stats_interval);
 
                /* Clear screen and move to top left */
                printf("%s%s", clr, topLeft);
@@ -604,6 +610,7 @@ ioat_usage(const char *prgname)
 {
        printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
                "  -b --dma-batch-size: number of requests per DMA batch\n"
+               "  -f --max-frame-size: max frame size\n"
                "  -p --portmask: hexadecimal bitmask of ports to configure\n"
                "  -q NQ: number of RX queues per port (default is 1)\n"
                "  --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
@@ -611,7 +618,8 @@ ioat_usage(const char *prgname)
                "       - The source MAC address is replaced by the TX port MAC address\n"
                "       - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n"
                "  -c --copy-type CT: type of copy: sw|hw\n"
-               "  -s --ring-size RS: size of IOAT rawdev ring for hardware copy mode or rte_ring for software copy mode\n",
+               "  -s --ring-size RS: size of IOAT rawdev ring for hardware copy mode or rte_ring for software copy mode\n"
+               "  -i --stats-interval SI: interval, in seconds, between stats prints (default is 1)\n",
                        prgname);
 }
 
@@ -647,9 +655,11 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
        static const char short_options[] =
                "b:"  /* dma batch size */
                "c:"  /* copy type (sw|hw) */
+               "f:"  /* max frame size */
                "p:"  /* portmask */
                "q:"  /* number of RX queues per port */
                "s:"  /* ring size */
+               "i:"  /* interval, in seconds, between stats prints */
                ;
 
        static const struct option lgopts[] = {
@@ -660,6 +670,8 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
                {CMD_LINE_OPT_COPY_TYPE, required_argument, NULL, 'c'},
                {CMD_LINE_OPT_RING_SIZE, required_argument, NULL, 's'},
                {CMD_LINE_OPT_BATCH_SIZE, required_argument, NULL, 'b'},
+               {CMD_LINE_OPT_FRAME_SIZE, required_argument, NULL, 'f'},
+               {CMD_LINE_OPT_STATS_INTERVAL, required_argument, NULL, 'i'},
                {NULL, 0, 0, 0}
        };
 
@@ -684,6 +696,15 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
                                return -1;
                        }
                        break;
+               case 'f':
+                       max_frame_size = atoi(optarg);
+                       if (max_frame_size > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
+                               printf("Invalid max frame size, %s.\n", optarg);
+                               ioat_usage(prgname);
+                               return -1;
+                       }
+                       break;
+
                /* portmask */
                case 'p':
                        ioat_enabled_port_mask = ioat_parse_portmask(optarg);
@@ -724,6 +745,14 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
                        }
                        break;
 
+               case 'i':
+                       stats_interval = atoi(optarg);
+                       if (stats_interval == 0) {
+                               printf("Invalid stats interval, setting to 1\n");
+                               stats_interval = 1;     /* set to default */
+                       }
+                       break;
+
                /* long options */
                case 0:
                        break;
@@ -879,6 +908,9 @@ port_init(uint16_t portid, struct rte_mempool *mbuf_pool, uint16_t nb_queues)
        struct rte_eth_dev_info dev_info;
        int ret, i;
 
+       if (max_frame_size > local_port_conf.rxmode.mtu)
+               local_port_conf.rxmode.mtu = max_frame_size;
+
        /* Skip ports that are not enabled */
        if ((ioat_enabled_port_mask & (1 << portid)) == 0) {
                printf("Skipping disabled port %u\n", portid);
@@ -989,6 +1021,7 @@ main(int argc, char **argv)
        uint16_t nb_ports, portid;
        uint32_t i;
        unsigned int nb_mbufs;
+       size_t sz;
 
        /* Init EAL. 8< */
        ret = rte_eal_init(argc, argv);
@@ -1018,9 +1051,10 @@ main(int argc, char **argv)
                MIN_POOL_SIZE);
 
        /* Create the mbuf pool */
+       sz = max_frame_size + RTE_PKTMBUF_HEADROOM;
+       sz = RTE_MAX(sz, (size_t)RTE_MBUF_DEFAULT_BUF_SIZE);
        ioat_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
-               MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
-               rte_socket_id());
+               MEMPOOL_CACHE_SIZE, 0, sz, rte_socket_id());
        if (ioat_pktmbuf_pool == NULL)
                rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
        /* >8 End of allocates mempool to hold the mbufs. */