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