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