4 * Copyright(c) 2010-2014 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.
39 #include <rte_cycles.h>
40 #include <rte_ethdev.h>
41 #include <rte_byteorder.h>
42 #include <rte_atomic.h>
43 #include <rte_malloc.h>
44 #include "packet_burst_generator.h"
47 #define NB_ETHPORTS_USED (1)
48 #define NB_SOCKETS (2)
49 #define MEMPOOL_CACHE_SIZE 250
50 #define MAX_PKT_BURST (32)
51 #define RTE_TEST_RX_DESC_DEFAULT (128)
52 #define RTE_TEST_TX_DESC_DEFAULT (512)
53 #define RTE_PORT_ALL (~(uint8_t)0x0)
55 /* how long test would take at full line rate */
56 #define RTE_TEST_DURATION (2)
59 * RX and TX Prefetch, Host, and Write-back threshold values should be
60 * carefully set for optimal performance. Consult the network
61 * controller's datasheet and supporting DPDK documentation for guidance
62 * on how these parameters should be set.
64 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
65 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
66 #define RX_WTHRESH 0 /**< Default values of RX write-back threshold reg. */
69 * These default values are optimized for use with the Intel(R) 82599 10 GbE
70 * Controller and the DPDK ixgbe PMD. Consider using other values for other
71 * network controllers and/or network drivers.
73 #define TX_PTHRESH 32 /**< Default values of TX prefetch threshold reg. */
74 #define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */
75 #define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */
77 #define MAX_TRAFFIC_BURST 2048
79 #define NB_MBUF RTE_MAX( \
80 (unsigned)(nb_ports*nb_rx_queue*nb_rxd + \
81 nb_ports*nb_lcores*MAX_PKT_BURST + \
82 nb_ports*nb_tx_queue*nb_txd + \
83 nb_lcores*MEMPOOL_CACHE_SIZE + \
84 nb_ports*MAX_TRAFFIC_BURST), \
88 static struct rte_mempool
*mbufpool
[NB_SOCKETS
];
89 /* ethernet addresses of ports */
90 static struct ether_addr ports_eth_addr
[RTE_MAX_ETHPORTS
];
92 static struct rte_eth_conf port_conf
= {
94 .mq_mode
= ETH_MQ_RX_NONE
,
95 .max_rx_pkt_len
= ETHER_MAX_LEN
,
97 .header_split
= 0, /**< Header Split disabled */
98 .hw_ip_checksum
= 0, /**< IP checksum offload enabled */
99 .hw_vlan_filter
= 0, /**< VLAN filtering disabled */
100 .hw_vlan_strip
= 0, /**< VLAN strip enabled. */
101 .hw_vlan_extend
= 0, /**< Extended VLAN disabled. */
102 .jumbo_frame
= 0, /**< Jumbo Frame Support disabled */
103 .hw_strip_crc
= 1, /**< CRC stripped by hardware */
104 .enable_scatter
= 0, /**< scatter rx disabled */
107 .mq_mode
= ETH_MQ_TX_NONE
,
109 .lpbk_mode
= 1, /* enable loopback */
112 static struct rte_eth_rxconf rx_conf
= {
114 .pthresh
= RX_PTHRESH
,
115 .hthresh
= RX_HTHRESH
,
116 .wthresh
= RX_WTHRESH
,
118 .rx_free_thresh
= 32,
121 static struct rte_eth_txconf tx_conf
= {
123 .pthresh
= TX_PTHRESH
,
124 .hthresh
= TX_HTHRESH
,
125 .wthresh
= TX_WTHRESH
,
127 .tx_free_thresh
= 32, /* Use PMD default values */
128 .tx_rs_thresh
= 32, /* Use PMD default values */
129 .txq_flags
= (ETH_TXQ_FLAGS_NOMULTSEGS
|
130 ETH_TXQ_FLAGS_NOVLANOFFL
|
131 ETH_TXQ_FLAGS_NOXSUMSCTP
|
132 ETH_TXQ_FLAGS_NOXSUMUDP
|
133 ETH_TXQ_FLAGS_NOXSUMTCP
)
146 uint8_t portlist
[RTE_MAX_ETHPORTS
];
147 } __rte_cache_aligned
;
149 struct lcore_conf lcore_conf
[RTE_MAX_LCORE
];
151 static uint64_t link_mbps
;
159 static uint32_t sc_flag
;
161 /* Check the link status of all ports in up to 3s, and print them finally */
163 check_all_ports_link_status(uint8_t port_num
, uint32_t port_mask
)
165 #define CHECK_INTERVAL 100 /* 100ms */
166 #define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */
167 uint8_t portid
, count
, all_ports_up
, print_flag
= 0;
168 struct rte_eth_link link
;
170 printf("Checking link statuses...\n");
172 for (count
= 0; count
<= MAX_CHECK_TIME
; count
++) {
174 for (portid
= 0; portid
< port_num
; portid
++) {
175 if ((port_mask
& (1 << portid
)) == 0)
177 memset(&link
, 0, sizeof(link
));
178 rte_eth_link_get_nowait(portid
, &link
);
179 /* print link status if flag set */
180 if (print_flag
== 1) {
181 if (link
.link_status
) {
182 printf("Port %d Link Up - speed %u "
183 "Mbps - %s\n", (uint8_t)portid
,
184 (unsigned)link
.link_speed
,
185 (link
.link_duplex
== ETH_LINK_FULL_DUPLEX
) ?
186 ("full-duplex") : ("half-duplex\n"));
188 link_mbps
= link
.link_speed
;
190 printf("Port %d Link Down\n",
194 /* clear all_ports_up flag if any link down */
195 if (link
.link_status
== ETH_LINK_DOWN
) {
200 /* after finally printing all link status, get out */
204 if (all_ports_up
== 0) {
206 rte_delay_ms(CHECK_INTERVAL
);
209 /* set the print_flag if all ports up or timeout */
210 if (all_ports_up
== 1 || count
== (MAX_CHECK_TIME
- 1))
216 print_ethaddr(const char *name
, const struct ether_addr
*eth_addr
)
218 char buf
[ETHER_ADDR_FMT_SIZE
];
219 ether_format_addr(buf
, ETHER_ADDR_FMT_SIZE
, eth_addr
);
220 printf("%s%s", name
, buf
);
224 init_traffic(struct rte_mempool
*mp
,
225 struct rte_mbuf
**pkts_burst
, uint32_t burst_size
)
227 struct ether_hdr pkt_eth_hdr
;
228 struct ipv4_hdr pkt_ipv4_hdr
;
229 struct udp_hdr pkt_udp_hdr
;
231 static uint8_t src_mac
[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF };
232 static uint8_t dst_mac
[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA };
235 initialize_eth_header(&pkt_eth_hdr
,
236 (struct ether_addr
*)src_mac
,
237 (struct ether_addr
*)dst_mac
, ETHER_TYPE_IPv4
, 0, 0);
239 pktlen
= initialize_ipv4_header(&pkt_ipv4_hdr
,
240 IPV4_ADDR(10, 0, 0, 1),
241 IPV4_ADDR(10, 0, 0, 2), 26);
242 printf("IPv4 pktlen %u\n", pktlen
);
244 pktlen
= initialize_udp_header(&pkt_udp_hdr
, 0, 0, 18);
246 printf("UDP pktlen %u\n", pktlen
);
248 return generate_packet_burst(mp
, pkts_burst
, &pkt_eth_hdr
,
250 &pkt_udp_hdr
, burst_size
,
251 PACKET_BURST_GEN_PKT_LEN
, 1);
259 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
260 lcore_conf
[lcore_id
].socketid
=
261 rte_lcore_to_socket_id(lcore_id
);
262 if (rte_lcore_is_enabled(lcore_id
) == 0) {
263 lcore_conf
[lcore_id
].status
= LCORE_INVALID
;
266 lcore_conf
[lcore_id
].status
= LCORE_AVAIL
;
272 init_mbufpool(unsigned nb_mbuf
)
278 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
279 if (rte_lcore_is_enabled(lcore_id
) == 0)
282 socketid
= rte_lcore_to_socket_id(lcore_id
);
283 if (socketid
>= NB_SOCKETS
) {
284 rte_exit(EXIT_FAILURE
,
285 "Socket %d of lcore %u is out of range %d\n",
286 socketid
, lcore_id
, NB_SOCKETS
);
288 if (mbufpool
[socketid
] == NULL
) {
289 snprintf(s
, sizeof(s
), "mbuf_pool_%d", socketid
);
291 rte_pktmbuf_pool_create(s
, nb_mbuf
,
292 MEMPOOL_CACHE_SIZE
, 0,
293 RTE_MBUF_DEFAULT_BUF_SIZE
, socketid
);
294 if (mbufpool
[socketid
] == NULL
)
295 rte_exit(EXIT_FAILURE
,
296 "Cannot init mbuf pool on socket %d\n",
299 printf("Allocated mbuf pool on socket %d\n",
307 alloc_lcore(uint16_t socketid
)
311 for (lcore_id
= 0; lcore_id
< RTE_MAX_LCORE
; lcore_id
++) {
312 if (LCORE_AVAIL
!= lcore_conf
[lcore_id
].status
||
313 lcore_conf
[lcore_id
].socketid
!= socketid
||
314 lcore_id
== rte_get_master_lcore())
316 lcore_conf
[lcore_id
].status
= LCORE_USED
;
317 lcore_conf
[lcore_id
].nb_ports
= 0;
324 volatile uint64_t stop
;
338 stats_display(uint8_t port_id
)
340 struct rte_eth_stats stats
;
341 rte_eth_stats_get(port_id
, &stats
);
343 printf(" RX-packets: %-10"PRIu64
" RX-missed: %-10"PRIu64
" RX-bytes: "
345 stats
.ipackets
, stats
.imissed
, stats
.ibytes
);
346 printf(" RX-errors: %-10"PRIu64
" RX-nombuf: %-10"PRIu64
"\n",
347 stats
.ierrors
, stats
.rx_nombuf
);
348 printf(" TX-packets: %-10"PRIu64
" TX-errors: %-10"PRIu64
" TX-bytes: "
350 stats
.opackets
, stats
.oerrors
, stats
.obytes
);
354 signal_handler(int signum
)
356 /* USR1 signal, stop testing */
357 if (signum
== SIGUSR1
) {
358 printf("Force Stop!\n");
362 /* USR2 signal, print stats */
363 if (signum
== SIGUSR2
)
367 struct rte_mbuf
**tx_burst
;
369 uint64_t (*do_measure
)(struct lcore_conf
*conf
,
370 struct rte_mbuf
*pkts_burst
[],
371 uint64_t total_pkts
);
374 measure_rxtx(struct lcore_conf
*conf
,
375 struct rte_mbuf
*pkts_burst
[],
378 unsigned i
, portid
, nb_rx
, nb_tx
;
379 uint64_t prev_tsc
, cur_tsc
;
381 prev_tsc
= rte_rdtsc();
383 while (likely(!stop
)) {
384 for (i
= 0; i
< conf
->nb_ports
; i
++) {
385 portid
= conf
->portlist
[i
];
386 nb_rx
= rte_eth_rx_burst((uint8_t) portid
, 0,
387 pkts_burst
, MAX_PKT_BURST
);
388 if (unlikely(nb_rx
== 0)) {
394 nb_tx
= rte_eth_tx_burst(portid
, 0, pkts_burst
, nb_rx
);
395 if (unlikely(nb_tx
< nb_rx
)) {
396 drop
+= (nb_rx
- nb_tx
);
398 rte_pktmbuf_free(pkts_burst
[nb_tx
]);
399 } while (++nb_tx
< nb_rx
);
402 if (unlikely(count
>= total_pkts
))
406 cur_tsc
= rte_rdtsc();
408 return cur_tsc
- prev_tsc
;
412 measure_rxonly(struct lcore_conf
*conf
,
413 struct rte_mbuf
*pkts_burst
[],
416 unsigned i
, portid
, nb_rx
, nb_tx
;
417 uint64_t diff_tsc
, cur_tsc
;
420 while (likely(!stop
)) {
421 for (i
= 0; i
< conf
->nb_ports
; i
++) {
422 portid
= conf
->portlist
[i
];
424 cur_tsc
= rte_rdtsc();
425 nb_rx
= rte_eth_rx_burst((uint8_t) portid
, 0,
426 pkts_burst
, MAX_PKT_BURST
);
427 if (unlikely(nb_rx
== 0)) {
431 diff_tsc
+= rte_rdtsc() - cur_tsc
;
434 nb_tx
= rte_eth_tx_burst(portid
, 0, pkts_burst
, nb_rx
);
435 if (unlikely(nb_tx
< nb_rx
)) {
436 drop
+= (nb_rx
- nb_tx
);
438 rte_pktmbuf_free(pkts_burst
[nb_tx
]);
439 } while (++nb_tx
< nb_rx
);
442 if (unlikely(count
>= total_pkts
))
450 measure_txonly(struct lcore_conf
*conf
,
451 struct rte_mbuf
*pkts_burst
[],
454 unsigned i
, portid
, nb_rx
, nb_tx
;
455 uint64_t diff_tsc
, cur_tsc
;
457 printf("do tx measure\n");
459 while (likely(!stop
)) {
460 for (i
= 0; i
< conf
->nb_ports
; i
++) {
461 portid
= conf
->portlist
[i
];
462 nb_rx
= rte_eth_rx_burst((uint8_t) portid
, 0,
463 pkts_burst
, MAX_PKT_BURST
);
464 if (unlikely(nb_rx
== 0)) {
471 cur_tsc
= rte_rdtsc();
472 nb_tx
= rte_eth_tx_burst(portid
, 0, pkts_burst
, nb_rx
);
473 if (unlikely(nb_tx
< nb_rx
)) {
474 drop
+= (nb_rx
- nb_tx
);
476 rte_pktmbuf_free(pkts_burst
[nb_tx
]);
477 } while (++nb_tx
< nb_rx
);
479 diff_tsc
+= rte_rdtsc() - cur_tsc
;
481 if (unlikely(count
>= total_pkts
))
488 /* main processing loop */
490 main_loop(__rte_unused
void *args
)
492 #define PACKET_SIZE 64
494 #define MAC_PREAMBLE 8
495 struct rte_mbuf
*pkts_burst
[MAX_PKT_BURST
];
497 unsigned i
, portid
, nb_rx
= 0, nb_tx
= 0;
498 struct lcore_conf
*conf
;
501 uint64_t packets_per_second
, total_packets
;
503 lcore_id
= rte_lcore_id();
504 conf
= &lcore_conf
[lcore_id
];
505 if (conf
->status
!= LCORE_USED
)
508 pkt_per_port
= MAX_TRAFFIC_BURST
;
511 for (i
= 0; i
< conf
->nb_ports
; i
++) {
512 int num
= pkt_per_port
;
513 portid
= conf
->portlist
[i
];
514 printf("inject %d packet to port %d\n", num
, portid
);
516 nb_tx
= RTE_MIN(MAX_PKT_BURST
, num
);
517 nb_tx
= rte_eth_tx_burst(portid
, 0,
518 &tx_burst
[idx
], nb_tx
);
523 printf("Total packets inject to prime ports = %u\n", idx
);
525 packets_per_second
= (link_mbps
* 1000 * 1000) /
526 ((PACKET_SIZE
+ FRAME_GAP
+ MAC_PREAMBLE
) * CHAR_BIT
);
527 printf("Each port will do %"PRIu64
" packets per second\n",
530 total_packets
= RTE_TEST_DURATION
* conf
->nb_ports
* packets_per_second
;
531 printf("Test will stop after at least %"PRIu64
" packets received\n",
534 diff_tsc
= do_measure(conf
, pkts_burst
, total_packets
);
536 for (i
= 0; i
< conf
->nb_ports
; i
++) {
537 portid
= conf
->portlist
[i
];
538 int nb_free
= pkt_per_port
;
540 nb_rx
= rte_eth_rx_burst((uint8_t) portid
, 0,
541 pkts_burst
, MAX_PKT_BURST
);
543 while (nb_tx
< nb_rx
)
544 rte_pktmbuf_free(pkts_burst
[nb_tx
++]);
546 } while (nb_free
!= 0);
547 printf("free %d mbuf left in port %u\n", pkt_per_port
, portid
);
553 printf("%"PRIu64
" packet, %"PRIu64
" drop, %"PRIu64
" idle\n",
555 printf("Result: %"PRIu64
" cycles per packet\n", diff_tsc
/ count
);
560 rte_atomic64_t start
;
563 poll_burst(void *args
)
565 #define MAX_IDLE (10000)
567 struct rte_mbuf
**pkts_burst
;
568 uint64_t diff_tsc
, cur_tsc
;
569 uint16_t next
[RTE_MAX_ETHPORTS
];
570 struct lcore_conf
*conf
;
571 uint32_t pkt_per_port
= *((uint32_t *)args
);
572 unsigned i
, portid
, nb_rx
= 0;
574 uint64_t timeout
= MAX_IDLE
;
576 lcore_id
= rte_lcore_id();
577 conf
= &lcore_conf
[lcore_id
];
578 if (conf
->status
!= LCORE_USED
)
581 total
= pkt_per_port
* conf
->nb_ports
;
582 printf("start to receive total expect %"PRIu64
"\n", total
);
584 pkts_burst
= (struct rte_mbuf
**)
585 rte_calloc_socket("poll_burst",
586 total
, sizeof(void *),
587 RTE_CACHE_LINE_SIZE
, conf
->socketid
);
591 for (i
= 0; i
< conf
->nb_ports
; i
++) {
592 portid
= conf
->portlist
[i
];
593 next
[portid
] = i
* pkt_per_port
;
596 while (!rte_atomic64_read(&start
))
599 cur_tsc
= rte_rdtsc();
601 for (i
= 0; i
< conf
->nb_ports
; i
++) {
602 portid
= conf
->portlist
[i
];
603 nb_rx
= rte_eth_rx_burst((uint8_t) portid
, 0,
604 &pkts_burst
[next
[portid
]],
606 if (unlikely(nb_rx
== 0)) {
608 if (unlikely(timeout
== 0))
612 next
[portid
] += nb_rx
;
617 diff_tsc
= rte_rdtsc() - cur_tsc
;
619 printf("%"PRIu64
" packets lost, IDLE %"PRIu64
" times\n",
620 total
, MAX_IDLE
- timeout
);
623 total
= pkt_per_port
* conf
->nb_ports
- total
;
624 for (i
= 0; i
< total
; i
++)
625 rte_pktmbuf_free(pkts_burst
[i
]);
627 rte_free(pkts_burst
);
630 return diff_tsc
/ total
;
636 exec_burst(uint32_t flags
, int lcore
)
638 unsigned i
, portid
, nb_tx
= 0;
639 struct lcore_conf
*conf
;
640 uint32_t pkt_per_port
;
644 conf
= &lcore_conf
[lcore
];
646 pkt_per_port
= MAX_TRAFFIC_BURST
;
649 rte_atomic64_init(&start
);
651 /* start polling thread, but not actually poll yet */
652 rte_eal_remote_launch(poll_burst
,
653 (void *)&pkt_per_port
, lcore
);
655 /* Only when polling first */
656 if (flags
== SC_BURST_POLL_FIRST
)
657 rte_atomic64_set(&start
, 1);
661 nb_tx
= RTE_MIN(MAX_PKT_BURST
, num
);
662 for (i
= 0; i
< conf
->nb_ports
; i
++) {
663 portid
= conf
->portlist
[i
];
664 rte_eth_tx_burst(portid
, 0,
665 &tx_burst
[idx
], nb_tx
);
673 /* only when polling second */
674 if (flags
== SC_BURST_XMIT_FIRST
)
675 rte_atomic64_set(&start
, 1);
677 /* wait for polling finished */
678 diff_tsc
= rte_eal_wait_lcore(lcore
);
680 printf("exec_burst: Failed to measure cycles per packet\n");
684 printf("Result: %d cycles per packet\n", diff_tsc
);
692 uint16_t nb_ports
, num
, nb_lcores
, slave_id
= (uint16_t)-1;
693 uint16_t nb_rxd
= MAX_TRAFFIC_BURST
;
694 uint16_t nb_txd
= MAX_TRAFFIC_BURST
;
696 uint16_t nb_rx_queue
= 1, nb_tx_queue
= 1;
700 printf("Start PMD RXTX cycles cost test.\n");
702 signal(SIGUSR1
, signal_handler
);
703 signal(SIGUSR2
, signal_handler
);
705 nb_ports
= rte_eth_dev_count();
706 if (nb_ports
< NB_ETHPORTS_USED
) {
707 printf("At least %u port(s) used for perf. test\n",
712 nb_lcores
= rte_lcore_count();
714 memset(lcore_conf
, 0, sizeof(lcore_conf
));
717 init_mbufpool(NB_MBUF
);
719 if (sc_flag
== SC_CONTINUOUS
) {
720 nb_rxd
= RTE_TEST_RX_DESC_DEFAULT
;
721 nb_txd
= RTE_TEST_TX_DESC_DEFAULT
;
723 printf("CONFIG RXD=%d TXD=%d\n", nb_rxd
, nb_txd
);
727 for (portid
= 0; portid
< nb_ports
; portid
++) {
728 if (socketid
== -1) {
729 socketid
= rte_eth_dev_socket_id(portid
);
730 slave_id
= alloc_lcore(socketid
);
731 if (slave_id
== (uint16_t)-1) {
732 printf("No avail lcore to run test\n");
735 printf("Performance test runs on lcore %u socket %u\n",
739 if (socketid
!= rte_eth_dev_socket_id(portid
)) {
740 printf("Skip port %d\n", portid
);
745 ret
= rte_eth_dev_configure(portid
, nb_rx_queue
,
746 nb_tx_queue
, &port_conf
);
748 rte_exit(EXIT_FAILURE
,
749 "Cannot configure device: err=%d, port=%d\n",
752 rte_eth_macaddr_get(portid
, &ports_eth_addr
[portid
]);
753 printf("Port %u ", portid
);
754 print_ethaddr("Address:", &ports_eth_addr
[portid
]);
758 ret
= rte_eth_tx_queue_setup(portid
, 0, nb_txd
,
761 rte_exit(EXIT_FAILURE
,
762 "rte_eth_tx_queue_setup: err=%d, "
763 "port=%d\n", ret
, portid
);
766 ret
= rte_eth_rx_queue_setup(portid
, 0, nb_rxd
,
770 rte_exit(EXIT_FAILURE
, "rte_eth_rx_queue_setup: err=%d,"
771 "port=%d\n", ret
, portid
);
775 ret
= rte_eth_dev_start(portid
);
777 rte_exit(EXIT_FAILURE
,
778 "rte_eth_dev_start: err=%d, port=%d\n",
781 /* always eanble promiscuous */
782 rte_eth_promiscuous_enable(portid
);
784 lcore_conf
[slave_id
].portlist
[num
++] = portid
;
785 lcore_conf
[slave_id
].nb_ports
++;
787 check_all_ports_link_status(nb_ports
, RTE_PORT_ALL
);
789 if (tx_burst
== NULL
) {
790 tx_burst
= (struct rte_mbuf
**)
791 rte_calloc_socket("tx_buff",
792 MAX_TRAFFIC_BURST
* nb_ports
,
794 RTE_CACHE_LINE_SIZE
, socketid
);
799 init_traffic(mbufpool
[socketid
],
800 tx_burst
, MAX_TRAFFIC_BURST
* nb_ports
);
802 printf("Generate %d packets @socket %d\n",
803 MAX_TRAFFIC_BURST
* nb_ports
, socketid
);
805 if (sc_flag
== SC_CONTINUOUS
) {
806 /* do both rxtx by default */
807 if (NULL
== do_measure
)
808 do_measure
= measure_rxtx
;
810 rte_eal_remote_launch(main_loop
, NULL
, slave_id
);
812 if (rte_eal_wait_lcore(slave_id
) < 0)
814 } else if (sc_flag
== SC_BURST_POLL_FIRST
||
815 sc_flag
== SC_BURST_XMIT_FIRST
)
816 if (exec_burst(sc_flag
, slave_id
) < 0)
820 for (portid
= 0; portid
< nb_ports
; portid
++) {
821 if (socketid
!= rte_eth_dev_socket_id(portid
))
824 rte_eth_dev_stop(portid
);
831 test_set_rxtx_conf(cmdline_fixed_string_t mode
)
833 printf("mode switch to %s\n", mode
);
835 if (!strcmp(mode
, "vector")) {
837 tx_conf
.txq_flags
= 0xf01;
838 tx_conf
.tx_rs_thresh
= 32;
839 tx_conf
.tx_free_thresh
= 32;
840 port_conf
.rxmode
.hw_ip_checksum
= 0;
841 port_conf
.rxmode
.enable_scatter
= 0;
843 } else if (!strcmp(mode
, "scalar")) {
844 /* bulk alloc rx, full-featured tx */
845 tx_conf
.txq_flags
= 0;
846 tx_conf
.tx_rs_thresh
= 32;
847 tx_conf
.tx_free_thresh
= 32;
848 port_conf
.rxmode
.hw_ip_checksum
= 1;
849 port_conf
.rxmode
.enable_scatter
= 0;
851 } else if (!strcmp(mode
, "hybrid")) {
852 /* bulk alloc rx, vector tx
853 * when vec macro not define,
854 * using the same rx/tx as scalar
856 tx_conf
.txq_flags
= 0xf01;
857 tx_conf
.tx_rs_thresh
= 32;
858 tx_conf
.tx_free_thresh
= 32;
859 port_conf
.rxmode
.hw_ip_checksum
= 1;
860 port_conf
.rxmode
.enable_scatter
= 0;
862 } else if (!strcmp(mode
, "full")) {
863 /* full feature rx,tx pair */
864 tx_conf
.txq_flags
= 0x0; /* must condition */
865 tx_conf
.tx_rs_thresh
= 32;
866 tx_conf
.tx_free_thresh
= 32;
867 port_conf
.rxmode
.hw_ip_checksum
= 0;
868 port_conf
.rxmode
.enable_scatter
= 1; /* must condition */
876 test_set_rxtx_anchor(cmdline_fixed_string_t type
)
878 printf("type switch to %s\n", type
);
880 if (!strcmp(type
, "rxtx")) {
881 do_measure
= measure_rxtx
;
883 } else if (!strcmp(type
, "rxonly")) {
884 do_measure
= measure_rxonly
;
886 } else if (!strcmp(type
, "txonly")) {
887 do_measure
= measure_txonly
;
895 test_set_rxtx_sc(cmdline_fixed_string_t type
)
897 printf("stream control switch to %s\n", type
);
899 if (!strcmp(type
, "continuous")) {
900 sc_flag
= SC_CONTINUOUS
;
902 } else if (!strcmp(type
, "poll_before_xmit")) {
903 sc_flag
= SC_BURST_POLL_FIRST
;
905 } else if (!strcmp(type
, "poll_after_xmit")) {
906 sc_flag
= SC_BURST_XMIT_FIRST
;
913 REGISTER_TEST_COMMAND(pmd_perf_autotest
, test_pmd_perf
);