4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/types.h>
45 #include <sys/queue.h>
52 #include <rte_common.h>
53 #include <rte_byteorder.h>
55 #include <rte_debug.h>
56 #include <rte_cycles.h>
57 #include <rte_memory.h>
58 #include <rte_memcpy.h>
59 #include <rte_memzone.h>
60 #include <rte_launch.h>
61 #include <rte_tailq.h>
63 #include <rte_per_lcore.h>
64 #include <rte_lcore.h>
65 #include <rte_atomic.h>
66 #include <rte_branch_prediction.h>
68 #include <rte_mempool.h>
69 #include <rte_malloc.h>
71 #include <rte_interrupts.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
79 uint16_t verbose_level = 0; /**< Silent by default. */
81 /* use master core for command line ? */
82 uint8_t interactive = 0;
85 * NUMA support configuration.
86 * When set, the NUMA support attempts to dispatch the allocation of the
87 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
88 * probed ports among the CPU sockets 0 and 1.
89 * Otherwise, all memory is allocated from CPU socket 0.
91 uint8_t numa_support = 0; /**< No numa support by default */
94 * Record the Ethernet address of peer target ports to which packets are
96 * Must be instanciated with the ethernet addresses of peer traffic generator
99 struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
100 portid_t nb_peer_eth_addrs = 0;
103 * Probed Target Environment.
105 struct rte_port *ports; /**< For all probed ethernet ports. */
106 portid_t nb_ports; /**< Number of probed ethernet ports. */
107 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
108 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
111 * Test Forwarding Configuration.
112 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
113 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
115 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
116 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
117 portid_t nb_cfg_ports; /**< Number of configured ports. */
118 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
120 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
121 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
123 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
124 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
127 * Forwarding engines.
129 struct fwd_engine * fwd_engines[] = {
135 #ifdef RTE_LIBRTE_IEEE1588
136 &ieee1588_fwd_engine,
141 struct fwd_config cur_fwd_config;
142 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
144 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
147 * Configuration of packet segments used by the "txonly" processing engine.
149 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
150 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
151 TXONLY_DEF_PACKET_LEN,
153 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
155 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
156 uint16_t mb_mempool_cache = DEF_PKT_BURST; /**< Size of mbuf mempool cache. */
159 * Ethernet Ports Configuration.
161 int promiscuous_on = 1; /**< Ports set in promiscuous mode by default. */
164 * Configurable number of RX/TX queues.
166 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
167 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
170 * Configurable number of RX/TX ring descriptors.
172 #define RTE_TEST_RX_DESC_DEFAULT 128
173 #define RTE_TEST_TX_DESC_DEFAULT 512
174 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
175 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
178 * Configurable values of RX and TX ring threshold registers.
180 #define RX_PTHRESH 8 /**< Default value of RX prefetch threshold register. */
181 #define RX_HTHRESH 8 /**< Default value of RX host threshold register. */
182 #define RX_WTHRESH 4 /**< Default value of RX write-back threshold register. */
184 #define TX_PTHRESH 36 /**< Default value of TX prefetch threshold register. */
185 #define TX_HTHRESH 0 /**< Default value of TX host threshold register. */
186 #define TX_WTHRESH 0 /**< Default value of TX write-back threshold register. */
188 struct rte_eth_thresh rx_thresh = {
189 .pthresh = RX_PTHRESH,
190 .hthresh = RX_HTHRESH,
191 .wthresh = RX_WTHRESH,
194 struct rte_eth_thresh tx_thresh = {
195 .pthresh = TX_PTHRESH,
196 .hthresh = TX_HTHRESH,
197 .wthresh = TX_WTHRESH,
201 * Configurable value of RX free threshold.
203 uint16_t rx_free_thresh = 0; /* Immediately free RX descriptors by default. */
206 * Configurable value of TX free threshold.
208 uint16_t tx_free_thresh = 0; /* Use default values. */
211 * Configurable value of TX RS bit threshold.
213 uint16_t tx_rs_thresh = 0; /* Use default values. */
216 * Receive Side Scaling (RSS) configuration.
218 uint16_t rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6; /* RSS IP by default. */
221 * Port topology configuration
223 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
226 * Ethernet device configuration.
228 struct rte_eth_rxmode rx_mode = {
229 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
231 .header_split = 0, /**< Header Split disabled. */
232 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
233 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
234 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
235 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
238 struct rte_fdir_conf fdir_conf = {
239 .mode = RTE_FDIR_MODE_NONE,
240 .pballoc = RTE_FDIR_PBALLOC_64K,
241 .status = RTE_FDIR_REPORT_STATUS,
242 .flexbytes_offset = 0x6,
246 static volatile int test_done = 1; /* stop packet forwarding when set to 1. */
249 * Setup default configuration.
252 set_default_fwd_lcores_config(void)
258 for (i = 0; i < RTE_MAX_LCORE; i++) {
259 if (! rte_lcore_is_enabled(i))
261 if (i == rte_get_master_lcore())
263 fwd_lcores_cpuids[nb_lc++] = i;
265 nb_lcores = (lcoreid_t) nb_lc;
266 nb_cfg_lcores = nb_lcores;
271 set_def_peer_eth_addrs(void)
275 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
276 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
277 peer_eth_addrs[i].addr_bytes[5] = i;
282 set_default_fwd_ports_config(void)
286 for (pt_id = 0; pt_id < nb_ports; pt_id++)
287 fwd_ports_ids[pt_id] = pt_id;
289 nb_cfg_ports = nb_ports;
290 nb_fwd_ports = nb_ports;
294 set_def_fwd_config(void)
296 set_default_fwd_lcores_config();
297 set_def_peer_eth_addrs();
298 set_default_fwd_ports_config();
302 * Configuration initialisation done once at init time.
304 struct mbuf_ctor_arg {
305 uint16_t seg_buf_offset; /**< offset of data in data segment of mbuf. */
306 uint16_t seg_buf_size; /**< size of data segment in mbuf. */
309 struct mbuf_pool_ctor_arg {
310 uint16_t seg_buf_size; /**< size of data segment in mbuf. */
314 testpmd_mbuf_ctor(struct rte_mempool *mp,
317 __attribute__((unused)) unsigned i)
319 struct mbuf_ctor_arg *mb_ctor_arg;
322 mb_ctor_arg = (struct mbuf_ctor_arg *) opaque_arg;
323 mb = (struct rte_mbuf *) raw_mbuf;
326 mb->buf_addr = (void *) ((char *)mb + mb_ctor_arg->seg_buf_offset);
327 mb->buf_physaddr = (uint64_t) (rte_mempool_virt2phy(mp, mb) +
328 mb_ctor_arg->seg_buf_offset);
329 mb->buf_len = mb_ctor_arg->seg_buf_size;
330 mb->type = RTE_MBUF_PKT;
332 mb->pkt.data = (char *) mb->buf_addr + RTE_PKTMBUF_HEADROOM;
336 mb->pkt.vlan_tci = 0;
337 mb->pkt.hash.rss = 0;
341 testpmd_mbuf_pool_ctor(struct rte_mempool *mp,
344 struct mbuf_pool_ctor_arg *mbp_ctor_arg;
345 struct rte_pktmbuf_pool_private *mbp_priv;
347 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
348 printf("%s(%s) private_data_size %d < %d\n",
349 __func__, mp->name, (int) mp->private_data_size,
350 (int) sizeof(struct rte_pktmbuf_pool_private));
353 mbp_ctor_arg = (struct mbuf_pool_ctor_arg *) opaque_arg;
354 mbp_priv = (struct rte_pktmbuf_pool_private *)
355 ((char *)mp + sizeof(struct rte_mempool));
356 mbp_priv->mbuf_data_room_size = mbp_ctor_arg->seg_buf_size;
360 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
361 unsigned int socket_id)
363 char pool_name[RTE_MEMPOOL_NAMESIZE];
364 struct rte_mempool *rte_mp;
365 struct mbuf_pool_ctor_arg mbp_ctor_arg;
366 struct mbuf_ctor_arg mb_ctor_arg;
369 mbp_ctor_arg.seg_buf_size = (uint16_t) (RTE_PKTMBUF_HEADROOM +
371 mb_ctor_arg.seg_buf_offset =
372 (uint16_t) CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf));
373 mb_ctor_arg.seg_buf_size = mbp_ctor_arg.seg_buf_size;
374 mb_size = mb_ctor_arg.seg_buf_offset + mb_ctor_arg.seg_buf_size;
375 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
376 rte_mp = rte_mempool_create(pool_name, nb_mbuf, (unsigned) mb_size,
377 (unsigned) mb_mempool_cache,
378 sizeof(struct rte_pktmbuf_pool_private),
379 testpmd_mbuf_pool_ctor, &mbp_ctor_arg,
380 testpmd_mbuf_ctor, &mb_ctor_arg,
382 if (rte_mp == NULL) {
383 rte_exit(EXIT_FAILURE, "Creation of mbuf pool for socket %u failed\n",
391 struct rte_port *port;
392 struct rte_mempool *mbp;
393 unsigned int nb_mbuf_per_pool;
398 /* Configuration of logical cores. */
399 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
400 sizeof(struct fwd_lcore *) * nb_lcores,
402 if (fwd_lcores == NULL) {
403 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) failed\n",
406 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
407 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
408 sizeof(struct fwd_lcore),
410 if (fwd_lcores[lc_id] == NULL) {
411 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) failed\n");
413 fwd_lcores[lc_id]->cpuid_idx = lc_id;
417 * Create pools of mbuf.
418 * If NUMA support is disabled, create a single pool of mbuf in
420 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
422 nb_mbuf_per_pool = nb_rxd + (nb_lcores * mb_mempool_cache) +
423 nb_txd + MAX_PKT_BURST;
425 nb_mbuf_per_pool = nb_mbuf_per_pool * (nb_ports >> 1);
426 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
427 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 1);
429 nb_mbuf_per_pool = (nb_mbuf_per_pool * nb_ports);
430 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
434 * Records which Mbuf pool to use by each logical core, if needed.
436 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
437 mbp = mbuf_pool_find(rte_lcore_to_socket_id(lc_id));
439 mbp = mbuf_pool_find(0);
440 fwd_lcores[lc_id]->mbp = mbp;
443 /* Configuration of Ethernet ports. */
444 ports = rte_zmalloc("testpmd: ports",
445 sizeof(struct rte_port) * nb_ports,
448 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d struct rte_port) failed\n",
452 for (pt_id = 0; pt_id < nb_ports; pt_id++, port++) {
453 rte_eth_dev_info_get(pt_id, &port->dev_info);
454 if (nb_rxq > port->dev_info.max_rx_queues) {
455 rte_exit(EXIT_FAILURE, "Port %d: max RX queues %d < nb_rxq %d\n",
457 (int) port->dev_info.max_rx_queues,
460 if (nb_txq > port->dev_info.max_tx_queues) {
461 rte_exit(EXIT_FAILURE, "Port %d: max TX queues %d < nb_txq %d\n",
463 (int) port->dev_info.max_tx_queues,
468 port->socket_id = (pt_id < (nb_ports >> 1)) ? 0 : 1;
473 /* Configuration of packet forwarding streams. */
474 nb_fwd_streams = (streamid_t) (nb_ports * nb_rxq);
475 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
476 sizeof(struct fwd_stream *) * nb_fwd_streams,
478 if (fwd_streams == NULL) {
479 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_stream *)) failed\n",
482 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
483 fwd_streams[sm_id] = rte_zmalloc("testpmd: struct fwd_stream",
484 sizeof(struct fwd_stream),
486 if (fwd_streams[sm_id] == NULL) {
487 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_stream) failed\n");
492 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
494 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
496 unsigned int total_burst;
497 unsigned int nb_burst;
498 unsigned int burst_stats[3];
499 uint16_t pktnb_stats[3];
501 int burst_percent[3];
504 * First compute the total number of packet bursts and the
505 * two highest numbers of bursts of the same number of packets.
508 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
509 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
510 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
511 nb_burst = pbs->pkt_burst_spread[nb_pkt];
514 total_burst += nb_burst;
515 if (nb_burst > burst_stats[0]) {
516 burst_stats[1] = burst_stats[0];
517 pktnb_stats[1] = pktnb_stats[0];
518 burst_stats[0] = nb_burst;
519 pktnb_stats[0] = nb_pkt;
522 if (total_burst == 0)
524 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
525 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
526 burst_percent[0], (int) pktnb_stats[0]);
527 if (burst_stats[0] == total_burst) {
531 if (burst_stats[0] + burst_stats[1] == total_burst) {
532 printf(" + %d%% of %d pkts]\n",
533 100 - burst_percent[0], pktnb_stats[1]);
536 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
537 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
538 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
539 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
542 printf(" + %d%% of %d pkts + %d%% of others]\n",
543 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
545 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
548 fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
550 struct rte_port *port;
552 static const char *fwd_stats_border = "----------------------";
554 port = &ports[port_id];
555 printf("\n %s Forward statistics for port %-2d %s\n",
556 fwd_stats_border, port_id, fwd_stats_border);
557 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
559 stats->ipackets, stats->ierrors,
560 (uint64_t) (stats->ipackets + stats->ierrors));
562 if (cur_fwd_eng == &csum_fwd_engine)
563 printf(" Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
564 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
566 printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
568 stats->opackets, port->tx_dropped,
569 (uint64_t) (stats->opackets + port->tx_dropped));
571 if (stats->rx_nombuf > 0)
572 printf(" RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
573 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
575 pkt_burst_stats_display("RX", &port->rx_stream->rx_burst_stats);
577 pkt_burst_stats_display("TX", &port->tx_stream->tx_burst_stats);
580 if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
581 printf(" Fdirmiss: %-14"PRIu64" Fdirmatch: %-14"PRIu64"\n",
585 printf(" %s--------------------------------%s\n",
586 fwd_stats_border, fwd_stats_border);
590 fwd_stream_stats_display(streamid_t stream_id)
592 struct fwd_stream *fs;
593 static const char *fwd_top_stats_border = "-------";
595 fs = fwd_streams[stream_id];
596 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
597 (fs->fwd_dropped == 0))
599 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
600 "TX Port=%2d/Queue=%2d %s\n",
601 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
602 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
603 printf(" RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
604 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
606 /* if checksum mode */
607 if (cur_fwd_eng == &csum_fwd_engine) {
608 printf(" RX- bad IP checksum: %-14u Rx- bad L4 checksum: %-14u\n",
609 fs->rx_bad_ip_csum, fs->rx_bad_l4_csum);
612 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
613 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
614 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
619 flush_all_rx_queues(void)
621 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
628 for (j = 0; j < 2; j++) {
629 for (rxp = 0; rxp < nb_ports; rxp++) {
630 for (rxq = 0; rxq < nb_rxq; rxq++) {
632 nb_rx = rte_eth_rx_burst(rxp, rxq,
635 for (i = 0; i < nb_rx; i++)
636 rte_pktmbuf_free(pkts_burst[i]);
640 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
645 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
647 struct fwd_stream **fsm;
651 fsm = &fwd_streams[fc->stream_idx];
652 nb_fs = fc->stream_nb;
654 for (sm_id = 0; sm_id < nb_fs; sm_id++)
655 (*pkt_fwd)(fsm[sm_id]);
656 } while (! fc->stopped);
660 start_pkt_forward_on_core(void *fwd_arg)
662 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
663 cur_fwd_config.fwd_eng->packet_fwd);
668 * Run the TXONLY packet forwarding engine to send a single burst of packets.
669 * Used to start communication flows in network loopback test configurations.
672 run_one_txonly_burst_on_core(void *fwd_arg)
674 struct fwd_lcore *fwd_lc;
675 struct fwd_lcore tmp_lcore;
677 fwd_lc = (struct fwd_lcore *) fwd_arg;
679 tmp_lcore.stopped = 1;
680 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
685 * Launch packet forwarding:
686 * - Setup per-port forwarding context.
687 * - launch logical cores with their forwarding configuration.
690 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
692 port_fwd_begin_t port_fwd_begin;
697 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
698 if (port_fwd_begin != NULL) {
699 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
700 (*port_fwd_begin)(fwd_ports_ids[i]);
702 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
703 lc_id = fwd_lcores_cpuids[i];
704 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
705 fwd_lcores[i]->stopped = 0;
706 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
707 fwd_lcores[i], lc_id);
709 printf("launch lcore %u failed - diag=%d\n",
716 * Launch packet forwarding configuration.
719 start_packet_forwarding(int with_tx_first)
721 port_fwd_begin_t port_fwd_begin;
722 port_fwd_end_t port_fwd_end;
723 struct rte_port *port;
728 if (test_done == 0) {
729 printf("Packet forwarding already started\n");
733 flush_all_rx_queues();
735 rxtx_config_display();
737 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
738 pt_id = fwd_ports_ids[i];
739 port = &ports[pt_id];
740 rte_eth_stats_get(pt_id, &port->stats);
741 port->tx_dropped = 0;
743 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
744 fwd_streams[sm_id]->rx_packets = 0;
745 fwd_streams[sm_id]->tx_packets = 0;
746 fwd_streams[sm_id]->fwd_dropped = 0;
747 fwd_streams[sm_id]->rx_bad_ip_csum = 0;
748 fwd_streams[sm_id]->rx_bad_l4_csum = 0;
750 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
751 memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
752 sizeof(fwd_streams[sm_id]->rx_burst_stats));
753 memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
754 sizeof(fwd_streams[sm_id]->tx_burst_stats));
756 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
757 fwd_streams[sm_id]->core_cycles = 0;
761 port_fwd_begin = tx_only_engine.port_fwd_begin;
762 if (port_fwd_begin != NULL) {
763 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
764 (*port_fwd_begin)(fwd_ports_ids[i]);
766 launch_packet_forwarding(run_one_txonly_burst_on_core);
767 rte_eal_mp_wait_lcore();
768 port_fwd_end = tx_only_engine.port_fwd_end;
769 if (port_fwd_end != NULL) {
770 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
771 (*port_fwd_end)(fwd_ports_ids[i]);
774 launch_packet_forwarding(start_pkt_forward_on_core);
778 stop_packet_forwarding(void)
780 struct rte_eth_stats stats;
781 struct rte_port *port;
782 port_fwd_end_t port_fwd_end;
789 uint64_t total_rx_dropped;
790 uint64_t total_tx_dropped;
791 uint64_t total_rx_nombuf;
793 uint64_t rx_bad_ip_csum;
794 uint64_t rx_bad_l4_csum;
795 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
798 static const char *acc_stats_border = "+++++++++++++++";
801 printf("Packet forwarding not started\n");
804 printf("Telling cores to stop...");
805 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
806 fwd_lcores[lc_id]->stopped = 1;
807 printf("\nWaiting for lcores to finish...\n");
808 rte_eal_mp_wait_lcore();
809 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
810 if (port_fwd_end != NULL) {
811 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
812 pt_id = fwd_ports_ids[i];
813 (*port_fwd_end)(pt_id);
816 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
819 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
820 if (cur_fwd_config.nb_fwd_streams >
821 cur_fwd_config.nb_fwd_ports) {
822 fwd_stream_stats_display(sm_id);
823 ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
824 ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
826 ports[fwd_streams[sm_id]->tx_port].tx_stream =
828 ports[fwd_streams[sm_id]->rx_port].rx_stream =
831 tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
832 tx_dropped = (uint64_t) (tx_dropped +
833 fwd_streams[sm_id]->fwd_dropped);
834 ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
836 rx_bad_ip_csum = ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
837 rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
838 fwd_streams[sm_id]->rx_bad_ip_csum);
839 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum = rx_bad_ip_csum;
841 rx_bad_l4_csum = ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
842 rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
843 fwd_streams[sm_id]->rx_bad_l4_csum);
844 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum = rx_bad_l4_csum;
846 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
847 fwd_cycles = (uint64_t) (fwd_cycles +
848 fwd_streams[sm_id]->core_cycles);
853 total_rx_dropped = 0;
854 total_tx_dropped = 0;
856 for (i = 0; i < ((cur_fwd_config.nb_fwd_ports + 1) & ~0x1); i++) {
857 pt_id = fwd_ports_ids[i];
859 port = &ports[pt_id];
860 rte_eth_stats_get(pt_id, &stats);
861 stats.ipackets -= port->stats.ipackets;
862 port->stats.ipackets = 0;
863 stats.opackets -= port->stats.opackets;
864 port->stats.opackets = 0;
865 stats.ibytes -= port->stats.ibytes;
866 port->stats.ibytes = 0;
867 stats.obytes -= port->stats.obytes;
868 port->stats.obytes = 0;
869 stats.ierrors -= port->stats.ierrors;
870 port->stats.ierrors = 0;
871 stats.oerrors -= port->stats.oerrors;
872 port->stats.oerrors = 0;
873 stats.rx_nombuf -= port->stats.rx_nombuf;
874 port->stats.rx_nombuf = 0;
875 stats.fdirmatch -= port->stats.fdirmatch;
876 port->stats.rx_nombuf = 0;
877 stats.fdirmiss -= port->stats.fdirmiss;
878 port->stats.rx_nombuf = 0;
880 total_recv += stats.ipackets;
881 total_xmit += stats.opackets;
882 total_rx_dropped += stats.ierrors;
883 total_tx_dropped += port->tx_dropped;
884 total_rx_nombuf += stats.rx_nombuf;
886 fwd_port_stats_display(pt_id, &stats);
888 printf("\n %s Accumulated forward statistics for all ports"
890 acc_stats_border, acc_stats_border);
891 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
893 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
895 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
896 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
897 if (total_rx_nombuf > 0)
898 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
899 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
901 acc_stats_border, acc_stats_border);
902 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
904 printf("\n CPU cycles/packet=%u (total cycles="
905 "%"PRIu64" / total RX packets=%"PRIu64")\n",
906 (unsigned int)(fwd_cycles / total_recv),
907 fwd_cycles, total_recv);
918 for (pt_id = 0; pt_id < nb_ports; pt_id++) {
919 printf("Stopping port %d...", pt_id);
921 rte_eth_dev_close(pt_id);
927 typedef void (*cmd_func_t)(void);
928 struct pmd_test_command {
929 const char *cmd_name;
933 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
936 fatal_init_error(const char *func_name, uint8_t port_id, int diag)
938 rte_panic("%s(port_id=%d) failed - diag=%d\n",
939 func_name, port_id, diag);
945 struct rte_eth_link link;
946 struct rte_eth_conf port_conf = {
951 struct rte_eth_rxconf rx_conf;
952 struct rte_eth_txconf tx_conf;
953 struct rte_port *port;
954 unsigned int sock_id;
959 port_conf.rxmode = rx_mode;
960 port_conf.fdir_conf = fdir_conf;
962 if (nb_rxq > 0) { /* configure RSS */
963 port_conf.rx_adv_conf.rss_conf.rss_key = NULL;
964 /* use default hash key */
965 port_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf;
967 port_conf.rx_adv_conf.rss_conf.rss_hf = 0;
968 rx_conf.rx_thresh = rx_thresh;
969 rx_conf.rx_free_thresh = rx_free_thresh;
970 tx_conf.tx_thresh = tx_thresh;
971 tx_conf.tx_rs_thresh = tx_rs_thresh;
972 tx_conf.tx_free_thresh = tx_free_thresh;
974 for (pi = 0; pi < nb_ports; pi++) {
976 memcpy(&port->dev_conf, &port_conf, sizeof(port_conf));
977 sock_id = port->socket_id;
978 printf("Initializing port %d... ", pi);
980 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq, &port_conf);
982 fatal_init_error("rte_eth_dev_configure", pi, diag);
985 rte_eth_macaddr_get(pi, &port->eth_addr);
986 for (qi = 0; qi < nb_txq; qi++) {
987 diag = rte_eth_tx_queue_setup(pi, qi, nb_txd,
991 fatal_init_error("rte_eth_tx_queue_setup",
996 for (qi = 0; qi < nb_rxq; qi++) {
997 diag = rte_eth_rx_queue_setup(pi, qi, nb_rxd, sock_id,
999 mbuf_pool_find(sock_id));
1001 fatal_init_error("rte_eth_rx_queue_setup",
1008 diag = rte_eth_dev_start(pi);
1010 fatal_init_error("rte_eth_dev_start", pi, diag);
1014 rte_eth_link_get(pi, &link);
1015 if (link.link_status) {
1016 printf(" Link Up - speed %u Mbps - %s\n",
1017 (unsigned) link.link_speed,
1018 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1019 ("full-duplex") : ("half-duplex\n"));
1021 printf(" Link Down\n");
1025 * If enabled, put device in promiscuous mode.
1026 * This allows the PMD test in IO forwarding mode to forward
1027 * packets to itself through 2 cross-connected ports of the
1031 rte_eth_promiscuous_enable(pi);
1035 #ifdef RTE_EXEC_ENV_BAREMETAL
1040 main(int argc, char** argv)
1044 diag = rte_eal_init(argc, argv);
1046 rte_panic("Cannot init EAL\n");
1048 #ifdef RTE_LIBRTE_IGB_PMD
1049 if (rte_igb_pmd_init())
1050 rte_panic("Cannot init igb PMD\n");
1052 #ifdef RTE_LIBRTE_IXGBE_PMD
1053 if (rte_ixgbe_pmd_init())
1054 rte_panic("Cannot init ixgbe PMD\n");
1056 if (rte_ixgbevf_pmd_init())
1057 rte_panic("Cannot init ixgbevf PMD\n");
1060 if (rte_eal_pci_probe())
1061 rte_panic("Cannot probe PCI\n");
1063 nb_ports = (portid_t) rte_eth_dev_count();
1065 rte_exit(EXIT_FAILURE, "No probed ethernet devices - check that "
1066 "CONFIG_RTE_LIBRTE_IGB_PMD=y and that "
1067 "CONFIG_RTE_LIBRTE_IXGBE_PMD=y in your "
1068 "configuration file\n");
1070 set_def_fwd_config();
1072 rte_panic("Empty set of forwarding logical cores - check the "
1073 "core mask supplied in the command parameters\n");
1078 launch_args_parse(argc, argv);
1080 if (nb_rxq > nb_txq)
1081 printf("Warning: nb_rxq=%d enables RSS configuration, "
1082 "but nb_txq=%d will prevent to fully test it.\n",
1089 if (interactive == 1)
1095 printf("No commandline core given, start packet forwarding\n");
1096 start_packet_forwarding(0);
1097 printf("Press enter to exit\n");
1098 rc = read(0, &c, 1);