1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2a9de470cSBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 3a9de470cSBruce Richardson */ 4a9de470cSBruce Richardson 5a9de470cSBruce Richardson 6a9de470cSBruce Richardson #include <stdio.h> 7a9de470cSBruce Richardson #include <inttypes.h> 8a9de470cSBruce Richardson #include <signal.h> 9a9de470cSBruce Richardson #include <unistd.h> 10a9de470cSBruce Richardson #include <rte_cycles.h> 11a9de470cSBruce Richardson #include <rte_ethdev.h> 12a9de470cSBruce Richardson #include <rte_byteorder.h> 13a9de470cSBruce Richardson #include <rte_malloc.h> 14a9de470cSBruce Richardson #include "packet_burst_generator.h" 15a9de470cSBruce Richardson #include "test.h" 16a9de470cSBruce Richardson 17a9de470cSBruce Richardson #define NB_ETHPORTS_USED (1) 18a9de470cSBruce Richardson #define NB_SOCKETS (2) 19a9de470cSBruce Richardson #define MEMPOOL_CACHE_SIZE 250 20a9de470cSBruce Richardson #define MAX_PKT_BURST (32) 214ed89049SDavid Marchand #define RX_DESC_DEFAULT (1024) 224ed89049SDavid Marchand #define TX_DESC_DEFAULT (1024) 23a9de470cSBruce Richardson #define RTE_PORT_ALL (~(uint16_t)0x0) 24a9de470cSBruce Richardson 25a9de470cSBruce Richardson /* how long test would take at full line rate */ 26a9de470cSBruce Richardson #define RTE_TEST_DURATION (2) 27a9de470cSBruce Richardson 28a9de470cSBruce Richardson /* 29a9de470cSBruce Richardson * RX and TX Prefetch, Host, and Write-back threshold values should be 30a9de470cSBruce Richardson * carefully set for optimal performance. Consult the network 31a9de470cSBruce Richardson * controller's datasheet and supporting DPDK documentation for guidance 32a9de470cSBruce Richardson * on how these parameters should be set. 33a9de470cSBruce Richardson */ 34a9de470cSBruce Richardson #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */ 35a9de470cSBruce Richardson #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */ 36a9de470cSBruce Richardson #define RX_WTHRESH 0 /**< Default values of RX write-back threshold reg. */ 37a9de470cSBruce Richardson 38a9de470cSBruce Richardson /* 39a9de470cSBruce Richardson * These default values are optimized for use with the Intel(R) 82599 10 GbE 40a9de470cSBruce Richardson * Controller and the DPDK ixgbe PMD. Consider using other values for other 41a9de470cSBruce Richardson * network controllers and/or network drivers. 42a9de470cSBruce Richardson */ 43a9de470cSBruce Richardson #define TX_PTHRESH 32 /**< Default values of TX prefetch threshold reg. */ 44a9de470cSBruce Richardson #define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */ 45a9de470cSBruce Richardson #define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */ 46a9de470cSBruce Richardson 47a9de470cSBruce Richardson #define MAX_TRAFFIC_BURST 2048 48a9de470cSBruce Richardson 49a9de470cSBruce Richardson #define NB_MBUF RTE_MAX( \ 50a9de470cSBruce Richardson (unsigned)(nb_ports*nb_rx_queue*nb_rxd + \ 51a9de470cSBruce Richardson nb_ports*nb_lcores*MAX_PKT_BURST + \ 52a9de470cSBruce Richardson nb_ports*nb_tx_queue*nb_txd + \ 53a9de470cSBruce Richardson nb_lcores*MEMPOOL_CACHE_SIZE + \ 54a9de470cSBruce Richardson nb_ports*MAX_TRAFFIC_BURST), \ 55a9de470cSBruce Richardson (unsigned)8192) 56a9de470cSBruce Richardson 57a9de470cSBruce Richardson 58a9de470cSBruce Richardson static struct rte_mempool *mbufpool[NB_SOCKETS]; 59a9de470cSBruce Richardson /* ethernet addresses of ports */ 606d13ea8eSOlivier Matz static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; 61a9de470cSBruce Richardson 62a9de470cSBruce Richardson static struct rte_eth_conf port_conf = { 63a9de470cSBruce Richardson .rxmode = { 64295968d1SFerruh Yigit .mq_mode = RTE_ETH_MQ_RX_NONE, 65a9de470cSBruce Richardson }, 66a9de470cSBruce Richardson .txmode = { 67295968d1SFerruh Yigit .mq_mode = RTE_ETH_MQ_TX_NONE, 68a9de470cSBruce Richardson }, 69a9de470cSBruce Richardson .lpbk_mode = 1, /* enable loopback */ 70a9de470cSBruce Richardson }; 71a9de470cSBruce Richardson 72a9de470cSBruce Richardson static struct rte_eth_rxconf rx_conf = { 73a9de470cSBruce Richardson .rx_thresh = { 74a9de470cSBruce Richardson .pthresh = RX_PTHRESH, 75a9de470cSBruce Richardson .hthresh = RX_HTHRESH, 76a9de470cSBruce Richardson .wthresh = RX_WTHRESH, 77a9de470cSBruce Richardson }, 78a9de470cSBruce Richardson .rx_free_thresh = 32, 79a9de470cSBruce Richardson }; 80a9de470cSBruce Richardson 81a9de470cSBruce Richardson static struct rte_eth_txconf tx_conf = { 82a9de470cSBruce Richardson .tx_thresh = { 83a9de470cSBruce Richardson .pthresh = TX_PTHRESH, 84a9de470cSBruce Richardson .hthresh = TX_HTHRESH, 85a9de470cSBruce Richardson .wthresh = TX_WTHRESH, 86a9de470cSBruce Richardson }, 87a9de470cSBruce Richardson .tx_free_thresh = 32, /* Use PMD default values */ 88a9de470cSBruce Richardson .tx_rs_thresh = 32, /* Use PMD default values */ 89a9de470cSBruce Richardson }; 90a9de470cSBruce Richardson 91a9de470cSBruce Richardson enum { 92a9de470cSBruce Richardson LCORE_INVALID = 0, 93a9de470cSBruce Richardson LCORE_AVAIL, 94a9de470cSBruce Richardson LCORE_USED, 95a9de470cSBruce Richardson }; 96a9de470cSBruce Richardson 97a9de470cSBruce Richardson struct lcore_conf { 98a9de470cSBruce Richardson uint8_t status; 99a9de470cSBruce Richardson uint8_t socketid; 100a9de470cSBruce Richardson uint16_t nb_ports; 101a9de470cSBruce Richardson uint16_t portlist[RTE_MAX_ETHPORTS]; 102a9de470cSBruce Richardson } __rte_cache_aligned; 103a9de470cSBruce Richardson 104a9de470cSBruce Richardson struct lcore_conf lcore_conf[RTE_MAX_LCORE]; 105a9de470cSBruce Richardson 106a9de470cSBruce Richardson static uint64_t link_mbps; 107a9de470cSBruce Richardson 108a9de470cSBruce Richardson enum { 109a9de470cSBruce Richardson SC_CONTINUOUS = 0, 110a9de470cSBruce Richardson SC_BURST_POLL_FIRST, 111a9de470cSBruce Richardson SC_BURST_XMIT_FIRST, 112a9de470cSBruce Richardson }; 113a9de470cSBruce Richardson 114a9de470cSBruce Richardson static uint32_t sc_flag; 115a9de470cSBruce Richardson 116a9de470cSBruce Richardson /* Check the link status of all ports in up to 3s, and print them finally */ 117a9de470cSBruce Richardson static void 118a9de470cSBruce Richardson check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) 119a9de470cSBruce Richardson { 120a9de470cSBruce Richardson #define CHECK_INTERVAL 100 /* 100ms */ 121a9de470cSBruce Richardson #define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */ 122a9de470cSBruce Richardson uint16_t portid; 123a9de470cSBruce Richardson uint8_t count, all_ports_up, print_flag = 0; 124a9de470cSBruce Richardson struct rte_eth_link link; 125844949ecSIgor Romanov int ret; 126ba5509a6SIvan Dyukov char link_status[RTE_ETH_LINK_MAX_STR_LEN]; 127a9de470cSBruce Richardson 128a9de470cSBruce Richardson printf("Checking link statuses...\n"); 129a9de470cSBruce Richardson fflush(stdout); 130a9de470cSBruce Richardson for (count = 0; count <= MAX_CHECK_TIME; count++) { 131a9de470cSBruce Richardson all_ports_up = 1; 132a9de470cSBruce Richardson for (portid = 0; portid < port_num; portid++) { 133a9de470cSBruce Richardson if ((port_mask & (1 << portid)) == 0) 134a9de470cSBruce Richardson continue; 135a9de470cSBruce Richardson memset(&link, 0, sizeof(link)); 136844949ecSIgor Romanov ret = rte_eth_link_get_nowait(portid, &link); 137844949ecSIgor Romanov if (ret < 0) { 138844949ecSIgor Romanov all_ports_up = 0; 139844949ecSIgor Romanov if (print_flag == 1) 140844949ecSIgor Romanov printf("Port %u link get failed: %s\n", 141844949ecSIgor Romanov portid, rte_strerror(-ret)); 142844949ecSIgor Romanov continue; 143844949ecSIgor Romanov } 144844949ecSIgor Romanov 145a9de470cSBruce Richardson /* print link status if flag set */ 146a9de470cSBruce Richardson if (print_flag == 1) { 147ba5509a6SIvan Dyukov if (link.link_status && link_mbps == 0) 148a9de470cSBruce Richardson link_mbps = link.link_speed; 149ba5509a6SIvan Dyukov 150ba5509a6SIvan Dyukov rte_eth_link_to_str(link_status, 151ba5509a6SIvan Dyukov sizeof(link_status), &link); 152ba5509a6SIvan Dyukov printf("Port %d %s\n", portid, link_status); 153a9de470cSBruce Richardson continue; 154a9de470cSBruce Richardson } 155a9de470cSBruce Richardson /* clear all_ports_up flag if any link down */ 156295968d1SFerruh Yigit if (link.link_status == RTE_ETH_LINK_DOWN) { 157a9de470cSBruce Richardson all_ports_up = 0; 158a9de470cSBruce Richardson break; 159a9de470cSBruce Richardson } 160a9de470cSBruce Richardson } 161a9de470cSBruce Richardson /* after finally printing all link status, get out */ 162a9de470cSBruce Richardson if (print_flag == 1) 163a9de470cSBruce Richardson break; 164a9de470cSBruce Richardson 165a9de470cSBruce Richardson if (all_ports_up == 0) { 166a9de470cSBruce Richardson fflush(stdout); 167a9de470cSBruce Richardson rte_delay_ms(CHECK_INTERVAL); 168a9de470cSBruce Richardson } 169a9de470cSBruce Richardson 170a9de470cSBruce Richardson /* set the print_flag if all ports up or timeout */ 171a9de470cSBruce Richardson if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) 172a9de470cSBruce Richardson print_flag = 1; 173a9de470cSBruce Richardson } 174a9de470cSBruce Richardson } 175a9de470cSBruce Richardson 176a9de470cSBruce Richardson static void 1776d13ea8eSOlivier Matz print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 178a9de470cSBruce Richardson { 17935b2d13fSOlivier Matz char buf[RTE_ETHER_ADDR_FMT_SIZE]; 18035b2d13fSOlivier Matz rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 181a9de470cSBruce Richardson printf("%s%s", name, buf); 182a9de470cSBruce Richardson } 183a9de470cSBruce Richardson 184a9de470cSBruce Richardson static int 185a9de470cSBruce Richardson init_traffic(struct rte_mempool *mp, 186a9de470cSBruce Richardson struct rte_mbuf **pkts_burst, uint32_t burst_size) 187a9de470cSBruce Richardson { 1886d13ea8eSOlivier Matz struct rte_ether_hdr pkt_eth_hdr; 189a7c528e5SOlivier Matz struct rte_ipv4_hdr pkt_ipv4_hdr; 190e73e3547SOlivier Matz struct rte_udp_hdr pkt_udp_hdr; 191a9de470cSBruce Richardson uint32_t pktlen; 192a9de470cSBruce Richardson static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF }; 193a9de470cSBruce Richardson static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA }; 194a9de470cSBruce Richardson 195a9de470cSBruce Richardson 196a9de470cSBruce Richardson initialize_eth_header(&pkt_eth_hdr, 1976d13ea8eSOlivier Matz (struct rte_ether_addr *)src_mac, 1980c9da755SDavid Marchand (struct rte_ether_addr *)dst_mac, RTE_ETHER_TYPE_IPV4, 0, 0); 199a9de470cSBruce Richardson 200a9de470cSBruce Richardson pktlen = initialize_ipv4_header(&pkt_ipv4_hdr, 201a9de470cSBruce Richardson IPV4_ADDR(10, 0, 0, 1), 202a9de470cSBruce Richardson IPV4_ADDR(10, 0, 0, 2), 26); 203a9de470cSBruce Richardson printf("IPv4 pktlen %u\n", pktlen); 204a9de470cSBruce Richardson 205a9de470cSBruce Richardson pktlen = initialize_udp_header(&pkt_udp_hdr, 0, 0, 18); 206a9de470cSBruce Richardson 207a9de470cSBruce Richardson printf("UDP pktlen %u\n", pktlen); 208a9de470cSBruce Richardson 209a9de470cSBruce Richardson return generate_packet_burst(mp, pkts_burst, &pkt_eth_hdr, 210a9de470cSBruce Richardson 0, &pkt_ipv4_hdr, 1, 211a9de470cSBruce Richardson &pkt_udp_hdr, burst_size, 212a9de470cSBruce Richardson PACKET_BURST_GEN_PKT_LEN, 1); 213a9de470cSBruce Richardson } 214a9de470cSBruce Richardson 215a9de470cSBruce Richardson static int 216a9de470cSBruce Richardson init_lcores(void) 217a9de470cSBruce Richardson { 218a9de470cSBruce Richardson unsigned lcore_id; 219a9de470cSBruce Richardson 220a9de470cSBruce Richardson for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 221a9de470cSBruce Richardson lcore_conf[lcore_id].socketid = 222a9de470cSBruce Richardson rte_lcore_to_socket_id(lcore_id); 223a9de470cSBruce Richardson if (rte_lcore_is_enabled(lcore_id) == 0) { 224a9de470cSBruce Richardson lcore_conf[lcore_id].status = LCORE_INVALID; 225a9de470cSBruce Richardson continue; 226a9de470cSBruce Richardson } else 227a9de470cSBruce Richardson lcore_conf[lcore_id].status = LCORE_AVAIL; 228a9de470cSBruce Richardson } 229a9de470cSBruce Richardson return 0; 230a9de470cSBruce Richardson } 231a9de470cSBruce Richardson 232a9de470cSBruce Richardson static int 233a9de470cSBruce Richardson init_mbufpool(unsigned nb_mbuf) 234a9de470cSBruce Richardson { 235a9de470cSBruce Richardson int socketid; 236a9de470cSBruce Richardson unsigned lcore_id; 237a9de470cSBruce Richardson char s[64]; 238a9de470cSBruce Richardson 239a9de470cSBruce Richardson for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 240a9de470cSBruce Richardson if (rte_lcore_is_enabled(lcore_id) == 0) 241a9de470cSBruce Richardson continue; 242a9de470cSBruce Richardson 243a9de470cSBruce Richardson socketid = rte_lcore_to_socket_id(lcore_id); 244a9de470cSBruce Richardson if (socketid >= NB_SOCKETS) { 245a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, 246a9de470cSBruce Richardson "Socket %d of lcore %u is out of range %d\n", 247a9de470cSBruce Richardson socketid, lcore_id, NB_SOCKETS); 248a9de470cSBruce Richardson } 249a9de470cSBruce Richardson if (mbufpool[socketid] == NULL) { 250a9de470cSBruce Richardson snprintf(s, sizeof(s), "mbuf_pool_%d", socketid); 251a9de470cSBruce Richardson mbufpool[socketid] = 252a9de470cSBruce Richardson rte_pktmbuf_pool_create(s, nb_mbuf, 253a9de470cSBruce Richardson MEMPOOL_CACHE_SIZE, 0, 254a9de470cSBruce Richardson RTE_MBUF_DEFAULT_BUF_SIZE, socketid); 255a9de470cSBruce Richardson if (mbufpool[socketid] == NULL) 256a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, 257a9de470cSBruce Richardson "Cannot init mbuf pool on socket %d\n", 258a9de470cSBruce Richardson socketid); 259a9de470cSBruce Richardson else 260a9de470cSBruce Richardson printf("Allocated mbuf pool on socket %d\n", 261a9de470cSBruce Richardson socketid); 262a9de470cSBruce Richardson } 263a9de470cSBruce Richardson } 264a9de470cSBruce Richardson return 0; 265a9de470cSBruce Richardson } 266a9de470cSBruce Richardson 267a9de470cSBruce Richardson static uint16_t 268011c617cSOlivier Matz alloc_lcore(int socketid) 269a9de470cSBruce Richardson { 270a9de470cSBruce Richardson unsigned lcore_id; 271a9de470cSBruce Richardson 272a9de470cSBruce Richardson for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 273a9de470cSBruce Richardson if (LCORE_AVAIL != lcore_conf[lcore_id].status || 274011c617cSOlivier Matz (socketid != SOCKET_ID_ANY && 275011c617cSOlivier Matz lcore_conf[lcore_id].socketid != socketid) || 276cb056611SStephen Hemminger lcore_id == rte_get_main_lcore()) 277a9de470cSBruce Richardson continue; 278a9de470cSBruce Richardson lcore_conf[lcore_id].status = LCORE_USED; 279a9de470cSBruce Richardson lcore_conf[lcore_id].nb_ports = 0; 280a9de470cSBruce Richardson return lcore_id; 281a9de470cSBruce Richardson } 282a9de470cSBruce Richardson 283a9de470cSBruce Richardson return (uint16_t)-1; 284a9de470cSBruce Richardson } 285a9de470cSBruce Richardson 286a9de470cSBruce Richardson static volatile uint64_t stop; 287a9de470cSBruce Richardson static uint64_t count; 288a9de470cSBruce Richardson static uint64_t drop; 289a9de470cSBruce Richardson static uint64_t idle; 290a9de470cSBruce Richardson 291a9de470cSBruce Richardson static void 292a9de470cSBruce Richardson reset_count(void) 293a9de470cSBruce Richardson { 294a9de470cSBruce Richardson count = 0; 295a9de470cSBruce Richardson drop = 0; 296a9de470cSBruce Richardson idle = 0; 297a9de470cSBruce Richardson } 298a9de470cSBruce Richardson 299987d40a0SJie Zhou #ifndef RTE_EXEC_ENV_WINDOWS 300a9de470cSBruce Richardson static void 301a9de470cSBruce Richardson stats_display(uint16_t port_id) 302a9de470cSBruce Richardson { 303a9de470cSBruce Richardson struct rte_eth_stats stats; 304a9de470cSBruce Richardson rte_eth_stats_get(port_id, &stats); 305a9de470cSBruce Richardson 306a9de470cSBruce Richardson printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 307a9de470cSBruce Richardson "%-"PRIu64"\n", 308a9de470cSBruce Richardson stats.ipackets, stats.imissed, stats.ibytes); 309a9de470cSBruce Richardson printf(" RX-errors: %-10"PRIu64" RX-nombuf: %-10"PRIu64"\n", 310a9de470cSBruce Richardson stats.ierrors, stats.rx_nombuf); 311a9de470cSBruce Richardson printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 312a9de470cSBruce Richardson "%-"PRIu64"\n", 313a9de470cSBruce Richardson stats.opackets, stats.oerrors, stats.obytes); 314a9de470cSBruce Richardson } 315a9de470cSBruce Richardson 316a9de470cSBruce Richardson static void 317a9de470cSBruce Richardson signal_handler(int signum) 318a9de470cSBruce Richardson { 319a9de470cSBruce Richardson /* USR1 signal, stop testing */ 320a9de470cSBruce Richardson if (signum == SIGUSR1) { 321a9de470cSBruce Richardson stop = 1; 322a9de470cSBruce Richardson } 323a9de470cSBruce Richardson 324a9de470cSBruce Richardson /* USR2 signal, print stats */ 325a9de470cSBruce Richardson if (signum == SIGUSR2) 326a9de470cSBruce Richardson stats_display(0); 327a9de470cSBruce Richardson } 328987d40a0SJie Zhou #endif 329a9de470cSBruce Richardson 330a9de470cSBruce Richardson struct rte_mbuf **tx_burst; 331a9de470cSBruce Richardson 332a9de470cSBruce Richardson uint64_t (*do_measure)(struct lcore_conf *conf, 333a9de470cSBruce Richardson struct rte_mbuf *pkts_burst[], 334a9de470cSBruce Richardson uint64_t total_pkts); 335a9de470cSBruce Richardson 336a9de470cSBruce Richardson static uint64_t 337a9de470cSBruce Richardson measure_rxtx(struct lcore_conf *conf, 338a9de470cSBruce Richardson struct rte_mbuf *pkts_burst[], 339a9de470cSBruce Richardson uint64_t total_pkts) 340a9de470cSBruce Richardson { 341a9de470cSBruce Richardson unsigned i, portid, nb_rx, nb_tx; 342a9de470cSBruce Richardson uint64_t prev_tsc, cur_tsc; 343a9de470cSBruce Richardson 344a9de470cSBruce Richardson prev_tsc = rte_rdtsc(); 345a9de470cSBruce Richardson 346a9de470cSBruce Richardson while (likely(!stop)) { 347a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 348a9de470cSBruce Richardson portid = conf->portlist[i]; 349a9de470cSBruce Richardson nb_rx = rte_eth_rx_burst(portid, 0, 350a9de470cSBruce Richardson pkts_burst, MAX_PKT_BURST); 351a9de470cSBruce Richardson if (unlikely(nb_rx == 0)) { 352a9de470cSBruce Richardson idle++; 353a9de470cSBruce Richardson continue; 354a9de470cSBruce Richardson } 355a9de470cSBruce Richardson 356a9de470cSBruce Richardson count += nb_rx; 357a9de470cSBruce Richardson nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); 358a9de470cSBruce Richardson if (unlikely(nb_tx < nb_rx)) { 359a9de470cSBruce Richardson drop += (nb_rx - nb_tx); 360a9de470cSBruce Richardson do { 361a9de470cSBruce Richardson rte_pktmbuf_free(pkts_burst[nb_tx]); 362a9de470cSBruce Richardson } while (++nb_tx < nb_rx); 363a9de470cSBruce Richardson } 364a9de470cSBruce Richardson } 365a9de470cSBruce Richardson if (unlikely(count >= total_pkts)) 366a9de470cSBruce Richardson break; 367a9de470cSBruce Richardson } 368a9de470cSBruce Richardson 369a9de470cSBruce Richardson cur_tsc = rte_rdtsc(); 370a9de470cSBruce Richardson 371a9de470cSBruce Richardson return cur_tsc - prev_tsc; 372a9de470cSBruce Richardson } 373a9de470cSBruce Richardson 374a9de470cSBruce Richardson static uint64_t 375a9de470cSBruce Richardson measure_rxonly(struct lcore_conf *conf, 376a9de470cSBruce Richardson struct rte_mbuf *pkts_burst[], 377a9de470cSBruce Richardson uint64_t total_pkts) 378a9de470cSBruce Richardson { 379a9de470cSBruce Richardson unsigned i, portid, nb_rx, nb_tx; 380a9de470cSBruce Richardson uint64_t diff_tsc, cur_tsc; 381a9de470cSBruce Richardson 382a9de470cSBruce Richardson diff_tsc = 0; 383a9de470cSBruce Richardson while (likely(!stop)) { 384a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 385a9de470cSBruce Richardson portid = conf->portlist[i]; 386a9de470cSBruce Richardson 387a9de470cSBruce Richardson cur_tsc = rte_rdtsc(); 388a9de470cSBruce Richardson nb_rx = rte_eth_rx_burst(portid, 0, 389a9de470cSBruce Richardson pkts_burst, MAX_PKT_BURST); 390a9de470cSBruce Richardson if (unlikely(nb_rx == 0)) { 391a9de470cSBruce Richardson idle++; 392a9de470cSBruce Richardson continue; 393a9de470cSBruce Richardson } 394a9de470cSBruce Richardson diff_tsc += rte_rdtsc() - cur_tsc; 395a9de470cSBruce Richardson 396a9de470cSBruce Richardson count += nb_rx; 397a9de470cSBruce Richardson nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); 398a9de470cSBruce Richardson if (unlikely(nb_tx < nb_rx)) { 399a9de470cSBruce Richardson drop += (nb_rx - nb_tx); 400a9de470cSBruce Richardson do { 401a9de470cSBruce Richardson rte_pktmbuf_free(pkts_burst[nb_tx]); 402a9de470cSBruce Richardson } while (++nb_tx < nb_rx); 403a9de470cSBruce Richardson } 404a9de470cSBruce Richardson } 405a9de470cSBruce Richardson if (unlikely(count >= total_pkts)) 406a9de470cSBruce Richardson break; 407a9de470cSBruce Richardson } 408a9de470cSBruce Richardson 409a9de470cSBruce Richardson return diff_tsc; 410a9de470cSBruce Richardson } 411a9de470cSBruce Richardson 412a9de470cSBruce Richardson static uint64_t 413a9de470cSBruce Richardson measure_txonly(struct lcore_conf *conf, 414a9de470cSBruce Richardson struct rte_mbuf *pkts_burst[], 415a9de470cSBruce Richardson uint64_t total_pkts) 416a9de470cSBruce Richardson { 417a9de470cSBruce Richardson unsigned i, portid, nb_rx, nb_tx; 418a9de470cSBruce Richardson uint64_t diff_tsc, cur_tsc; 419a9de470cSBruce Richardson 420a9de470cSBruce Richardson printf("do tx measure\n"); 421a9de470cSBruce Richardson diff_tsc = 0; 422a9de470cSBruce Richardson while (likely(!stop)) { 423a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 424a9de470cSBruce Richardson portid = conf->portlist[i]; 425a9de470cSBruce Richardson nb_rx = rte_eth_rx_burst(portid, 0, 426a9de470cSBruce Richardson pkts_burst, MAX_PKT_BURST); 427a9de470cSBruce Richardson if (unlikely(nb_rx == 0)) { 428a9de470cSBruce Richardson idle++; 429a9de470cSBruce Richardson continue; 430a9de470cSBruce Richardson } 431a9de470cSBruce Richardson 432a9de470cSBruce Richardson count += nb_rx; 433a9de470cSBruce Richardson 434a9de470cSBruce Richardson cur_tsc = rte_rdtsc(); 435a9de470cSBruce Richardson nb_tx = rte_eth_tx_burst(portid, 0, pkts_burst, nb_rx); 436a9de470cSBruce Richardson if (unlikely(nb_tx < nb_rx)) { 437a9de470cSBruce Richardson drop += (nb_rx - nb_tx); 438a9de470cSBruce Richardson do { 439a9de470cSBruce Richardson rte_pktmbuf_free(pkts_burst[nb_tx]); 440a9de470cSBruce Richardson } while (++nb_tx < nb_rx); 441a9de470cSBruce Richardson } 442a9de470cSBruce Richardson diff_tsc += rte_rdtsc() - cur_tsc; 443a9de470cSBruce Richardson } 444a9de470cSBruce Richardson if (unlikely(count >= total_pkts)) 445a9de470cSBruce Richardson break; 446a9de470cSBruce Richardson } 447a9de470cSBruce Richardson 448a9de470cSBruce Richardson return diff_tsc; 449a9de470cSBruce Richardson } 450a9de470cSBruce Richardson 451a9de470cSBruce Richardson /* main processing loop */ 452a9de470cSBruce Richardson static int 453a9de470cSBruce Richardson main_loop(__rte_unused void *args) 454a9de470cSBruce Richardson { 455a9de470cSBruce Richardson #define PACKET_SIZE 64 456a9de470cSBruce Richardson #define FRAME_GAP 12 457a9de470cSBruce Richardson #define MAC_PREAMBLE 8 45836edf3ccSRakesh Kudurumalla #define MAX_RETRY_COUNT 5 459a9de470cSBruce Richardson struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; 460a9de470cSBruce Richardson unsigned lcore_id; 461a9de470cSBruce Richardson unsigned i, portid, nb_rx = 0, nb_tx = 0; 462a9de470cSBruce Richardson struct lcore_conf *conf; 463a9de470cSBruce Richardson int pkt_per_port; 464a9de470cSBruce Richardson uint64_t diff_tsc; 465a9de470cSBruce Richardson uint64_t packets_per_second, total_packets; 46636edf3ccSRakesh Kudurumalla int retry_cnt = 0; 46736edf3ccSRakesh Kudurumalla int free_pkt = 0; 468a9de470cSBruce Richardson 469a9de470cSBruce Richardson lcore_id = rte_lcore_id(); 470a9de470cSBruce Richardson conf = &lcore_conf[lcore_id]; 471a9de470cSBruce Richardson if (conf->status != LCORE_USED) 472a9de470cSBruce Richardson return 0; 473a9de470cSBruce Richardson 474a9de470cSBruce Richardson pkt_per_port = MAX_TRAFFIC_BURST; 475a9de470cSBruce Richardson 476a9de470cSBruce Richardson int idx = 0; 477a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 478a9de470cSBruce Richardson int num = pkt_per_port; 479a9de470cSBruce Richardson portid = conf->portlist[i]; 480a9de470cSBruce Richardson printf("inject %d packet to port %d\n", num, portid); 481a9de470cSBruce Richardson while (num) { 482a9de470cSBruce Richardson nb_tx = RTE_MIN(MAX_PKT_BURST, num); 483a9de470cSBruce Richardson nb_tx = rte_eth_tx_burst(portid, 0, 484a9de470cSBruce Richardson &tx_burst[idx], nb_tx); 48536edf3ccSRakesh Kudurumalla if (nb_tx == 0) 48636edf3ccSRakesh Kudurumalla retry_cnt++; 487a9de470cSBruce Richardson num -= nb_tx; 488a9de470cSBruce Richardson idx += nb_tx; 48936edf3ccSRakesh Kudurumalla if (retry_cnt == MAX_RETRY_COUNT) { 49036edf3ccSRakesh Kudurumalla retry_cnt = 0; 49136edf3ccSRakesh Kudurumalla break; 492a9de470cSBruce Richardson } 493a9de470cSBruce Richardson } 49436edf3ccSRakesh Kudurumalla } 49536edf3ccSRakesh Kudurumalla for (free_pkt = idx; free_pkt < (MAX_TRAFFIC_BURST * conf->nb_ports); 49636edf3ccSRakesh Kudurumalla free_pkt++) 49736edf3ccSRakesh Kudurumalla rte_pktmbuf_free(tx_burst[free_pkt]); 498a9de470cSBruce Richardson printf("Total packets inject to prime ports = %u\n", idx); 499a9de470cSBruce Richardson 500a9de470cSBruce Richardson packets_per_second = (link_mbps * 1000 * 1000) / 501a9de470cSBruce Richardson ((PACKET_SIZE + FRAME_GAP + MAC_PREAMBLE) * CHAR_BIT); 502a9de470cSBruce Richardson printf("Each port will do %"PRIu64" packets per second\n", 503a9de470cSBruce Richardson packets_per_second); 504a9de470cSBruce Richardson 505a9de470cSBruce Richardson total_packets = RTE_TEST_DURATION * conf->nb_ports * packets_per_second; 506a9de470cSBruce Richardson printf("Test will stop after at least %"PRIu64" packets received\n", 507a9de470cSBruce Richardson + total_packets); 508a9de470cSBruce Richardson 509a9de470cSBruce Richardson diff_tsc = do_measure(conf, pkts_burst, total_packets); 510a9de470cSBruce Richardson 511a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 512a9de470cSBruce Richardson portid = conf->portlist[i]; 513a9de470cSBruce Richardson int nb_free = 0; 514a9de470cSBruce Richardson uint64_t timeout = 10000; 515a9de470cSBruce Richardson do { /* dry out */ 516a9de470cSBruce Richardson nb_rx = rte_eth_rx_burst(portid, 0, 517a9de470cSBruce Richardson pkts_burst, MAX_PKT_BURST); 518a9de470cSBruce Richardson nb_tx = 0; 519a9de470cSBruce Richardson while (nb_tx < nb_rx) 520a9de470cSBruce Richardson rte_pktmbuf_free(pkts_burst[nb_tx++]); 521a9de470cSBruce Richardson nb_free += nb_rx; 522a9de470cSBruce Richardson 523a9de470cSBruce Richardson if (unlikely(nb_rx == 0)) 524a9de470cSBruce Richardson timeout--; 525a9de470cSBruce Richardson } while (nb_free != pkt_per_port && timeout != 0); 526a9de470cSBruce Richardson printf("free %d (expected %d) mbuf left in port %u\n", nb_free, 527a9de470cSBruce Richardson pkt_per_port, portid); 528a9de470cSBruce Richardson } 529a9de470cSBruce Richardson 530a9de470cSBruce Richardson if (count == 0) 531a9de470cSBruce Richardson return -1; 532a9de470cSBruce Richardson 533a9de470cSBruce Richardson printf("%"PRIu64" packet, %"PRIu64" drop, %"PRIu64" idle\n", 534a9de470cSBruce Richardson count, drop, idle); 535a9de470cSBruce Richardson printf("Result: %"PRIu64" cycles per packet\n", diff_tsc / count); 536a9de470cSBruce Richardson 537a9de470cSBruce Richardson return 0; 538a9de470cSBruce Richardson } 539a9de470cSBruce Richardson 540a598afbaSJoyce Kong static uint64_t start; 541a9de470cSBruce Richardson 542a9de470cSBruce Richardson static inline int 543a9de470cSBruce Richardson poll_burst(void *args) 544a9de470cSBruce Richardson { 545a9de470cSBruce Richardson #define MAX_IDLE (10000) 546a9de470cSBruce Richardson unsigned lcore_id; 547a9de470cSBruce Richardson struct rte_mbuf **pkts_burst; 548a9de470cSBruce Richardson uint64_t diff_tsc, cur_tsc; 549a9de470cSBruce Richardson uint16_t next[RTE_MAX_ETHPORTS]; 550a9de470cSBruce Richardson struct lcore_conf *conf; 551a9de470cSBruce Richardson uint32_t pkt_per_port = *((uint32_t *)args); 552a9de470cSBruce Richardson unsigned i, portid, nb_rx = 0; 553a9de470cSBruce Richardson uint64_t total; 554a9de470cSBruce Richardson uint64_t timeout = MAX_IDLE; 555a9de470cSBruce Richardson int num[RTE_MAX_ETHPORTS]; 556a9de470cSBruce Richardson 557a9de470cSBruce Richardson lcore_id = rte_lcore_id(); 558a9de470cSBruce Richardson conf = &lcore_conf[lcore_id]; 559a9de470cSBruce Richardson if (conf->status != LCORE_USED) 560a9de470cSBruce Richardson return 0; 561a9de470cSBruce Richardson 562a9de470cSBruce Richardson total = pkt_per_port * conf->nb_ports; 563a9de470cSBruce Richardson printf("start to receive total expect %"PRIu64"\n", total); 564a9de470cSBruce Richardson 565a9de470cSBruce Richardson pkts_burst = (struct rte_mbuf **) 566a9de470cSBruce Richardson rte_calloc_socket("poll_burst", 567a9de470cSBruce Richardson total, sizeof(void *), 568a9de470cSBruce Richardson RTE_CACHE_LINE_SIZE, conf->socketid); 569a9de470cSBruce Richardson if (!pkts_burst) 570a9de470cSBruce Richardson return -1; 571a9de470cSBruce Richardson 572a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 573a9de470cSBruce Richardson portid = conf->portlist[i]; 574a9de470cSBruce Richardson next[portid] = i * pkt_per_port; 575a9de470cSBruce Richardson num[portid] = pkt_per_port; 576a9de470cSBruce Richardson } 577a9de470cSBruce Richardson 578a598afbaSJoyce Kong rte_wait_until_equal_64(&start, 1, __ATOMIC_ACQUIRE); 579a9de470cSBruce Richardson 580a9de470cSBruce Richardson cur_tsc = rte_rdtsc(); 581a9de470cSBruce Richardson while (total) { 582a9de470cSBruce Richardson for (i = 0; i < conf->nb_ports; i++) { 583a9de470cSBruce Richardson portid = conf->portlist[i]; 584a9de470cSBruce Richardson nb_rx = rte_eth_rx_burst(portid, 0, 585a9de470cSBruce Richardson &pkts_burst[next[portid]], 586a9de470cSBruce Richardson RTE_MIN(MAX_PKT_BURST, num[portid])); 587a9de470cSBruce Richardson if (unlikely(nb_rx == 0)) { 588a9de470cSBruce Richardson timeout--; 589a9de470cSBruce Richardson if (unlikely(timeout == 0)) 590a9de470cSBruce Richardson goto timeout; 591a9de470cSBruce Richardson continue; 592a9de470cSBruce Richardson } 593a9de470cSBruce Richardson next[portid] += nb_rx; 594a9de470cSBruce Richardson num[portid] -= nb_rx; 595a9de470cSBruce Richardson total -= nb_rx; 596a9de470cSBruce Richardson } 597a9de470cSBruce Richardson } 598a9de470cSBruce Richardson timeout: 599a9de470cSBruce Richardson diff_tsc = rte_rdtsc() - cur_tsc; 600a9de470cSBruce Richardson 601a9de470cSBruce Richardson printf("%"PRIu64" packets lost, IDLE %"PRIu64" times\n", 602a9de470cSBruce Richardson total, MAX_IDLE - timeout); 603a9de470cSBruce Richardson /* clean up */ 604a9de470cSBruce Richardson total = pkt_per_port * conf->nb_ports - total; 605a9de470cSBruce Richardson for (i = 0; i < total; i++) 606a9de470cSBruce Richardson rte_pktmbuf_free(pkts_burst[i]); 607a9de470cSBruce Richardson 608a9de470cSBruce Richardson rte_free(pkts_burst); 609a9de470cSBruce Richardson 610a9de470cSBruce Richardson if (total > 0) 611a9de470cSBruce Richardson return diff_tsc / total; 612a9de470cSBruce Richardson else 613a9de470cSBruce Richardson return -1; 614a9de470cSBruce Richardson } 615a9de470cSBruce Richardson 616a9de470cSBruce Richardson static int 617a9de470cSBruce Richardson exec_burst(uint32_t flags, int lcore) 618a9de470cSBruce Richardson { 61958325f09SAlvin Zhang unsigned int portid, nb_tx = 0; 620a9de470cSBruce Richardson struct lcore_conf *conf; 621a9de470cSBruce Richardson uint32_t pkt_per_port; 62258325f09SAlvin Zhang int num, i, idx = 0; 623a9de470cSBruce Richardson int diff_tsc; 624a9de470cSBruce Richardson 625a9de470cSBruce Richardson conf = &lcore_conf[lcore]; 626a9de470cSBruce Richardson 627a9de470cSBruce Richardson pkt_per_port = MAX_TRAFFIC_BURST; 628a9de470cSBruce Richardson num = pkt_per_port * conf->nb_ports; 629a9de470cSBruce Richardson 630a598afbaSJoyce Kong /* only when polling first */ 631a598afbaSJoyce Kong if (flags == SC_BURST_POLL_FIRST) 632a598afbaSJoyce Kong __atomic_store_n(&start, 1, __ATOMIC_RELAXED); 633a598afbaSJoyce Kong else 634a598afbaSJoyce Kong __atomic_store_n(&start, 0, __ATOMIC_RELAXED); 635a9de470cSBruce Richardson 636a598afbaSJoyce Kong /* start polling thread 637a598afbaSJoyce Kong * if in POLL_FIRST mode, poll once launched; 638a598afbaSJoyce Kong * otherwise, not actually poll yet 639a598afbaSJoyce Kong */ 640a9de470cSBruce Richardson rte_eal_remote_launch(poll_burst, 641a9de470cSBruce Richardson (void *)&pkt_per_port, lcore); 642a9de470cSBruce Richardson 643a9de470cSBruce Richardson /* start xmit */ 64458325f09SAlvin Zhang i = 0; 645a9de470cSBruce Richardson while (num) { 646a9de470cSBruce Richardson nb_tx = RTE_MIN(MAX_PKT_BURST, num); 647a9de470cSBruce Richardson portid = conf->portlist[i]; 64858325f09SAlvin Zhang nb_tx = rte_eth_tx_burst(portid, 0, &tx_burst[idx], nb_tx); 649a9de470cSBruce Richardson idx += nb_tx; 650a9de470cSBruce Richardson num -= nb_tx; 65158325f09SAlvin Zhang i = (i >= conf->nb_ports - 1) ? 0 : (i + 1); 652a9de470cSBruce Richardson } 653a9de470cSBruce Richardson 654987d40a0SJie Zhou rte_delay_us(5 * US_PER_S); 655a9de470cSBruce Richardson 656a9de470cSBruce Richardson /* only when polling second */ 657a9de470cSBruce Richardson if (flags == SC_BURST_XMIT_FIRST) 658a598afbaSJoyce Kong __atomic_store_n(&start, 1, __ATOMIC_RELEASE); 659a9de470cSBruce Richardson 660a9de470cSBruce Richardson /* wait for polling finished */ 661a9de470cSBruce Richardson diff_tsc = rte_eal_wait_lcore(lcore); 662a9de470cSBruce Richardson if (diff_tsc < 0) { 663a9de470cSBruce Richardson printf("exec_burst: Failed to measure cycles per packet\n"); 664a9de470cSBruce Richardson return -1; 665a9de470cSBruce Richardson } 666a9de470cSBruce Richardson 667a9de470cSBruce Richardson printf("Result: %d cycles per packet\n", diff_tsc); 668a9de470cSBruce Richardson 669a9de470cSBruce Richardson return 0; 670a9de470cSBruce Richardson } 671a9de470cSBruce Richardson 672a9de470cSBruce Richardson static int 673a9de470cSBruce Richardson test_pmd_perf(void) 674a9de470cSBruce Richardson { 675cb056611SStephen Hemminger uint16_t nb_ports, num, nb_lcores, worker_id = (uint16_t)-1; 676a9de470cSBruce Richardson uint16_t nb_rxd = MAX_TRAFFIC_BURST; 677a9de470cSBruce Richardson uint16_t nb_txd = MAX_TRAFFIC_BURST; 678a9de470cSBruce Richardson uint16_t portid; 679a9de470cSBruce Richardson uint16_t nb_rx_queue = 1, nb_tx_queue = 1; 680a9de470cSBruce Richardson int socketid = -1; 681a9de470cSBruce Richardson int ret; 682a9de470cSBruce Richardson 683a9de470cSBruce Richardson printf("Start PMD RXTX cycles cost test.\n"); 684a9de470cSBruce Richardson 685987d40a0SJie Zhou #ifndef RTE_EXEC_ENV_WINDOWS 686a9de470cSBruce Richardson signal(SIGUSR1, signal_handler); 687a9de470cSBruce Richardson signal(SIGUSR2, signal_handler); 688987d40a0SJie Zhou #endif 689a9de470cSBruce Richardson 690a9de470cSBruce Richardson nb_ports = rte_eth_dev_count_avail(); 691a9de470cSBruce Richardson if (nb_ports < NB_ETHPORTS_USED) { 692a9de470cSBruce Richardson printf("At least %u port(s) used for perf. test\n", 693a9de470cSBruce Richardson NB_ETHPORTS_USED); 694a9de470cSBruce Richardson return -1; 695a9de470cSBruce Richardson } 696a9de470cSBruce Richardson 697a9de470cSBruce Richardson nb_lcores = rte_lcore_count(); 698a9de470cSBruce Richardson 699a9de470cSBruce Richardson memset(lcore_conf, 0, sizeof(lcore_conf)); 700a9de470cSBruce Richardson init_lcores(); 701a9de470cSBruce Richardson 702a9de470cSBruce Richardson init_mbufpool(NB_MBUF); 703a9de470cSBruce Richardson 704a9de470cSBruce Richardson if (sc_flag == SC_CONTINUOUS) { 7054ed89049SDavid Marchand nb_rxd = RX_DESC_DEFAULT; 7064ed89049SDavid Marchand nb_txd = TX_DESC_DEFAULT; 707a9de470cSBruce Richardson } 708a9de470cSBruce Richardson printf("CONFIG RXD=%d TXD=%d\n", nb_rxd, nb_txd); 709a9de470cSBruce Richardson 710a9de470cSBruce Richardson reset_count(); 711a9de470cSBruce Richardson num = 0; 712a9de470cSBruce Richardson RTE_ETH_FOREACH_DEV(portid) { 713a9de470cSBruce Richardson if (socketid == -1) { 714011c617cSOlivier Matz worker_id = alloc_lcore(rte_eth_dev_socket_id(portid)); 715cb056611SStephen Hemminger if (worker_id == (uint16_t)-1) { 716a9de470cSBruce Richardson printf("No avail lcore to run test\n"); 717a9de470cSBruce Richardson return -1; 718a9de470cSBruce Richardson } 719011c617cSOlivier Matz socketid = rte_lcore_to_socket_id(worker_id); 720a9de470cSBruce Richardson printf("Performance test runs on lcore %u socket %u\n", 721cb056611SStephen Hemminger worker_id, socketid); 722a9de470cSBruce Richardson } 723a9de470cSBruce Richardson 724011c617cSOlivier Matz if (socketid != rte_eth_dev_socket_id(portid) && 725011c617cSOlivier Matz rte_eth_dev_socket_id(portid) != SOCKET_ID_ANY) { 726a9de470cSBruce Richardson printf("Skip port %d\n", portid); 727a9de470cSBruce Richardson continue; 728a9de470cSBruce Richardson } 729a9de470cSBruce Richardson 730a9de470cSBruce Richardson /* port configure */ 731a9de470cSBruce Richardson ret = rte_eth_dev_configure(portid, nb_rx_queue, 732a9de470cSBruce Richardson nb_tx_queue, &port_conf); 733a9de470cSBruce Richardson if (ret < 0) 734a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, 735a9de470cSBruce Richardson "Cannot configure device: err=%d, port=%d\n", 736a9de470cSBruce Richardson ret, portid); 737a9de470cSBruce Richardson 7386fcf8586SIgor Romanov ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); 7396fcf8586SIgor Romanov if (ret < 0) 7406fcf8586SIgor Romanov rte_exit(EXIT_FAILURE, 7416fcf8586SIgor Romanov "Cannot get mac address: err=%d, port=%d\n", 7426fcf8586SIgor Romanov ret, portid); 7436fcf8586SIgor Romanov 744a9de470cSBruce Richardson printf("Port %u ", portid); 745a9de470cSBruce Richardson print_ethaddr("Address:", &ports_eth_addr[portid]); 746a9de470cSBruce Richardson printf("\n"); 747a9de470cSBruce Richardson 748a9de470cSBruce Richardson /* tx queue setup */ 749a9de470cSBruce Richardson ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, 750a9de470cSBruce Richardson socketid, &tx_conf); 751a9de470cSBruce Richardson if (ret < 0) 752a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, 753a9de470cSBruce Richardson "rte_eth_tx_queue_setup: err=%d, " 754a9de470cSBruce Richardson "port=%d\n", ret, portid); 755a9de470cSBruce Richardson 756a9de470cSBruce Richardson /* rx queue steup */ 757a9de470cSBruce Richardson ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, 758a9de470cSBruce Richardson socketid, &rx_conf, 759a9de470cSBruce Richardson mbufpool[socketid]); 760a9de470cSBruce Richardson if (ret < 0) 761a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=%d," 762a9de470cSBruce Richardson "port=%d\n", ret, portid); 763a9de470cSBruce Richardson 764a9de470cSBruce Richardson /* Start device */ 765a9de470cSBruce Richardson stop = 0; 766a9de470cSBruce Richardson ret = rte_eth_dev_start(portid); 767a9de470cSBruce Richardson if (ret < 0) 768a9de470cSBruce Richardson rte_exit(EXIT_FAILURE, 769a9de470cSBruce Richardson "rte_eth_dev_start: err=%d, port=%d\n", 770a9de470cSBruce Richardson ret, portid); 771a9de470cSBruce Richardson 7724a6672c2SStephen Hemminger /* always enable promiscuous */ 77370e51a0eSIvan Ilchenko ret = rte_eth_promiscuous_enable(portid); 77470e51a0eSIvan Ilchenko if (ret != 0) 77570e51a0eSIvan Ilchenko rte_exit(EXIT_FAILURE, 77670e51a0eSIvan Ilchenko "rte_eth_promiscuous_enable: err=%s, port=%d\n", 77770e51a0eSIvan Ilchenko rte_strerror(-ret), portid); 778a9de470cSBruce Richardson 779cb056611SStephen Hemminger lcore_conf[worker_id].portlist[num++] = portid; 780cb056611SStephen Hemminger lcore_conf[worker_id].nb_ports++; 781a9de470cSBruce Richardson } 782a9de470cSBruce Richardson check_all_ports_link_status(nb_ports, RTE_PORT_ALL); 783a9de470cSBruce Richardson 784a9de470cSBruce Richardson if (tx_burst == NULL) { 785a9de470cSBruce Richardson tx_burst = (struct rte_mbuf **) 786a9de470cSBruce Richardson rte_calloc_socket("tx_buff", 787a9de470cSBruce Richardson MAX_TRAFFIC_BURST * nb_ports, 788a9de470cSBruce Richardson sizeof(void *), 789a9de470cSBruce Richardson RTE_CACHE_LINE_SIZE, socketid); 790a9de470cSBruce Richardson if (!tx_burst) 791a9de470cSBruce Richardson return -1; 792a9de470cSBruce Richardson } 793a9de470cSBruce Richardson 794a9de470cSBruce Richardson init_traffic(mbufpool[socketid], 795a9de470cSBruce Richardson tx_burst, MAX_TRAFFIC_BURST * nb_ports); 796a9de470cSBruce Richardson 797a9de470cSBruce Richardson printf("Generate %d packets @socket %d\n", 798a9de470cSBruce Richardson MAX_TRAFFIC_BURST * nb_ports, socketid); 799a9de470cSBruce Richardson 800a9de470cSBruce Richardson if (sc_flag == SC_CONTINUOUS) { 801a9de470cSBruce Richardson /* do both rxtx by default */ 802a9de470cSBruce Richardson if (NULL == do_measure) 803a9de470cSBruce Richardson do_measure = measure_rxtx; 804a9de470cSBruce Richardson 805cb056611SStephen Hemminger rte_eal_remote_launch(main_loop, NULL, worker_id); 806a9de470cSBruce Richardson 807cb056611SStephen Hemminger if (rte_eal_wait_lcore(worker_id) < 0) 808a9de470cSBruce Richardson return -1; 809a9de470cSBruce Richardson } else if (sc_flag == SC_BURST_POLL_FIRST || 810a9de470cSBruce Richardson sc_flag == SC_BURST_XMIT_FIRST) 811cb056611SStephen Hemminger if (exec_burst(sc_flag, worker_id) < 0) 812a9de470cSBruce Richardson return -1; 813a9de470cSBruce Richardson 814a9de470cSBruce Richardson /* port tear down */ 815a9de470cSBruce Richardson RTE_ETH_FOREACH_DEV(portid) { 816a9de470cSBruce Richardson if (socketid != rte_eth_dev_socket_id(portid)) 817a9de470cSBruce Richardson continue; 818a9de470cSBruce Richardson 8190ead65afSIvan Ilchenko ret = rte_eth_dev_stop(portid); 8200ead65afSIvan Ilchenko if (ret != 0) 8210ead65afSIvan Ilchenko printf("rte_eth_dev_stop: err=%s, port=%u\n", 8220ead65afSIvan Ilchenko rte_strerror(-ret), portid); 823a9de470cSBruce Richardson } 824a9de470cSBruce Richardson 825a9de470cSBruce Richardson return 0; 826a9de470cSBruce Richardson } 827a9de470cSBruce Richardson 828a9de470cSBruce Richardson int 829a9de470cSBruce Richardson test_set_rxtx_conf(cmdline_fixed_string_t mode) 830a9de470cSBruce Richardson { 831a9de470cSBruce Richardson printf("mode switch to %s\n", mode); 832a9de470cSBruce Richardson 833a9de470cSBruce Richardson if (!strcmp(mode, "vector")) { 834a9de470cSBruce Richardson /* vector rx, tx */ 835a9de470cSBruce Richardson tx_conf.tx_rs_thresh = 32; 836a9de470cSBruce Richardson tx_conf.tx_free_thresh = 32; 837a9de470cSBruce Richardson return 0; 838a9de470cSBruce Richardson } else if (!strcmp(mode, "scalar")) { 839a9de470cSBruce Richardson /* bulk alloc rx, full-featured tx */ 840a9de470cSBruce Richardson tx_conf.tx_rs_thresh = 32; 841a9de470cSBruce Richardson tx_conf.tx_free_thresh = 32; 842295968d1SFerruh Yigit port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM; 843a9de470cSBruce Richardson return 0; 844a9de470cSBruce Richardson } else if (!strcmp(mode, "hybrid")) { 845a9de470cSBruce Richardson /* bulk alloc rx, vector tx 846a9de470cSBruce Richardson * when vec macro not define, 847a9de470cSBruce Richardson * using the same rx/tx as scalar 848a9de470cSBruce Richardson */ 849a9de470cSBruce Richardson tx_conf.tx_rs_thresh = 32; 850a9de470cSBruce Richardson tx_conf.tx_free_thresh = 32; 851295968d1SFerruh Yigit port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_CHECKSUM; 852a9de470cSBruce Richardson return 0; 853a9de470cSBruce Richardson } else if (!strcmp(mode, "full")) { 854a9de470cSBruce Richardson /* full feature rx,tx pair */ 855a9de470cSBruce Richardson tx_conf.tx_rs_thresh = 32; 856a9de470cSBruce Richardson tx_conf.tx_free_thresh = 32; 857295968d1SFerruh Yigit port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_SCATTER; 858a9de470cSBruce Richardson return 0; 859a9de470cSBruce Richardson } 860a9de470cSBruce Richardson 861a9de470cSBruce Richardson return -1; 862a9de470cSBruce Richardson } 863a9de470cSBruce Richardson 864a9de470cSBruce Richardson int 865a9de470cSBruce Richardson test_set_rxtx_anchor(cmdline_fixed_string_t type) 866a9de470cSBruce Richardson { 867a9de470cSBruce Richardson printf("type switch to %s\n", type); 868a9de470cSBruce Richardson 869a9de470cSBruce Richardson if (!strcmp(type, "rxtx")) { 870a9de470cSBruce Richardson do_measure = measure_rxtx; 871a9de470cSBruce Richardson return 0; 872a9de470cSBruce Richardson } else if (!strcmp(type, "rxonly")) { 873a9de470cSBruce Richardson do_measure = measure_rxonly; 874a9de470cSBruce Richardson return 0; 875a9de470cSBruce Richardson } else if (!strcmp(type, "txonly")) { 876a9de470cSBruce Richardson do_measure = measure_txonly; 877a9de470cSBruce Richardson return 0; 878a9de470cSBruce Richardson } 879a9de470cSBruce Richardson 880a9de470cSBruce Richardson return -1; 881a9de470cSBruce Richardson } 882a9de470cSBruce Richardson 883a9de470cSBruce Richardson int 884a9de470cSBruce Richardson test_set_rxtx_sc(cmdline_fixed_string_t type) 885a9de470cSBruce Richardson { 886a9de470cSBruce Richardson printf("stream control switch to %s\n", type); 887a9de470cSBruce Richardson 888a9de470cSBruce Richardson if (!strcmp(type, "continuous")) { 889a9de470cSBruce Richardson sc_flag = SC_CONTINUOUS; 890a9de470cSBruce Richardson return 0; 891a9de470cSBruce Richardson } else if (!strcmp(type, "poll_before_xmit")) { 892a9de470cSBruce Richardson sc_flag = SC_BURST_POLL_FIRST; 893a9de470cSBruce Richardson return 0; 894a9de470cSBruce Richardson } else if (!strcmp(type, "poll_after_xmit")) { 895a9de470cSBruce Richardson sc_flag = SC_BURST_XMIT_FIRST; 896a9de470cSBruce Richardson return 0; 897a9de470cSBruce Richardson } 898a9de470cSBruce Richardson 899a9de470cSBruce Richardson return -1; 900a9de470cSBruce Richardson } 901a9de470cSBruce Richardson 902*e0a8442cSBruce Richardson REGISTER_PERF_TEST(pmd_perf_autotest, test_pmd_perf); 903