void port_infos_display(struct cmdline *cl, portid_t port_id) { struct ether_addr mac_addr; struct rte_eth_link link; int vlan_offload; static const char *info_border = "====================="; rte_eth_link_get_nowait(port_id, &link); cmdline_printf(cl, "\n%s Infos for port %-2d %s\n", info_border, port_id, info_border); rte_eth_macaddr_get(port_id, &mac_addr); print_ethaddr(cl, "MAC address: ", &mac_addr); cmdline_printf(cl, "\nLink status: %s\n", (link.link_status) ? ("up") : ("down")); cmdline_printf(cl, "Link speed: %u Mbps\n", (unsigned)link.link_speed); cmdline_printf(cl, "Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex")); cmdline_printf(cl, "Promiscuous mode: %s\n", rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled"); cmdline_printf(cl, "Allmulticast mode: %s\n", rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled"); vlan_offload = rte_eth_dev_get_vlan_offload(port_id); if (vlan_offload >= 0) { cmdline_printf(cl, "VLAN offload: \n"); if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD) cmdline_printf(cl, " strip on \n"); else cmdline_printf(cl, " strip off \n"); if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD) cmdline_printf(cl, " filter on \n"); else cmdline_printf(cl, " filter off \n"); if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) cmdline_printf(cl, " qinq(extend) on \n"); else cmdline_printf(cl, " qinq(extend) off \n"); } }
static int dpdk_main(int port_id, int argc, char* argv[]) { struct rte_eth_dev_info dev_info; unsigned nb_queues; FILE* lfile; uint8_t core_id; int ret; printf("In dpdk_main\n"); // Open the log file lfile = fopen("./vrouter.log", "w"); // Program the rte log rte_openlog_stream(lfile); ret = rte_eal_init(argc, argv); if (ret < 0) { log_crit( "Invalid EAL parameters\n"); return -1; } log_info( "Programming cmd rings now!\n"); rx_event_fd = (int *) malloc(sizeof(int *) * rte_lcore_count()); if (!rx_event_fd) { log_crit("Failed to allocate memory for rx event fd arrays\n"); return -ENOMEM; } rte_eth_macaddr_get(port_id, &port_eth_addr); log_info("Port%d: MAC Address: ", port_id); print_ethaddr(&port_eth_addr); /* Determine the number of RX/TX pairs supported by NIC */ rte_eth_dev_info_get(port_id, &dev_info); dev_info.pci_dev->intr_handle.type = RTE_INTR_HANDLE_VFIO_MSIX; dev_info.pci_dev->intr_handle.max_intr = dev_info.max_rx_queues + dev_info.max_tx_queues; ret = rte_intr_efd_enable(&dev_info.pci_dev->intr_handle, dev_info.max_rx_queues); if (ret < 0) { rte_exit(EXIT_FAILURE, "Failed to enable rx interrupts\n"); } ret = rte_intr_enable(&dev_info.pci_dev->intr_handle); if (ret < 0) { rte_exit(EXIT_FAILURE, "Failed to enable interrupts\n"); } ret = rte_eth_dev_configure(port_id, dev_info.max_rx_queues, dev_info.max_tx_queues, &port_conf); if (ret < 0) { rte_exit(EXIT_FAILURE, "Failed to configure ethernet device\n"); } /* For each RX/TX pair */ nb_queues = dev_info.max_tx_queues; for (core_id = 0; core_id < nb_queues; core_id++) { char s[64]; if (rte_lcore_is_enabled(core_id) == 0) continue; /* NUMA socket number */ unsigned socketid = rte_lcore_to_socket_id(core_id); if (socketid >= NB_SOCKETS) { log_crit( "Socket %d of lcore %u is out of range %d\n", socketid, core_id, NB_SOCKETS); return -EBADF; } /* Create memory pool */ if (pktmbuf_pool[socketid] == NULL) { log_info("Creating mempool on %d of ~%lx bytes\n", socketid, NB_MBUF * MBUF_SIZE); printf("Creating mempool on %d of ~%lx bytes\n", socketid, NB_MBUF * MBUF_SIZE); snprintf(s, sizeof(s), "mbuf_pool_%d", socketid); pktmbuf_pool[socketid] = rte_mempool_create(s, NB_MBUF, MBUF_SIZE, MEMPOOL_CACHE_SIZE, PKTMBUF_PRIV_SZ, rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, socketid, 0); if (!pktmbuf_pool[socketid]) { log_crit( "Cannot init mbuf pool on socket %d\n", socketid); return -ENOMEM; } } /* Setup the TX queue */ ret = rte_eth_tx_queue_setup(port_id, core_id, RTE_TX_DESC_DEFAULT, socketid, &tx_conf); if (ret < 0) { log_crit( "Cannot initialize TX queue (%d)\n", core_id); return -ENODEV; } /* Setup the RX queue */ ret = rte_eth_rx_queue_setup(port_id, core_id, RTE_RX_DESC_DEFAULT, socketid, &rx_conf, pktmbuf_pool[socketid]); if (ret < 0) { log_crit( "Cannot initialize RX queue (%d)\n", core_id); return -ENODEV; } /* Create the event fds for event notification */ lcore_cmd_event_fd[core_id] = eventfd(0, 0); } // Start the eth device ret = rte_eth_dev_start(port_id); if (ret < 0) { log_crit( "rte_eth_dev_start: err=%d, port=%d\n", ret, core_id); return -ENODEV; } // Put the device in promiscuous mode rte_eth_promiscuous_enable(port_id); // Wait for link up //check_all_ports_link_status(1, 1u << port_id); log_info( "Starting engines on every core\n"); rte_eal_mp_remote_launch(engine_loop, &dev_info, CALL_MASTER); return 0; }
static int test_pmd_perf(void) { uint16_t nb_ports, num, nb_lcores, slave_id = (uint16_t)-1; uint16_t nb_rxd = MAX_TRAFFIC_BURST; uint16_t nb_txd = MAX_TRAFFIC_BURST; uint16_t portid; uint16_t nb_rx_queue = 1, nb_tx_queue = 1; int socketid = -1; int ret; printf("Start PMD RXTX cycles cost test.\n"); signal(SIGUSR1, signal_handler); signal(SIGUSR2, signal_handler); nb_ports = rte_eth_dev_count(); if (nb_ports < NB_ETHPORTS_USED) { printf("At least %u port(s) used for perf. test\n", NB_ETHPORTS_USED); return -1; } if (nb_ports > RTE_MAX_ETHPORTS) nb_ports = RTE_MAX_ETHPORTS; nb_lcores = rte_lcore_count(); memset(lcore_conf, 0, sizeof(lcore_conf)); init_lcores(); init_mbufpool(NB_MBUF); if (sc_flag == SC_CONTINUOUS) { nb_rxd = RTE_TEST_RX_DESC_DEFAULT; nb_txd = RTE_TEST_TX_DESC_DEFAULT; } printf("CONFIG RXD=%d TXD=%d\n", nb_rxd, nb_txd); reset_count(); num = 0; for (portid = 0; portid < nb_ports; portid++) { if (socketid == -1) { socketid = rte_eth_dev_socket_id(portid); slave_id = alloc_lcore(socketid); if (slave_id == (uint16_t)-1) { printf("No avail lcore to run test\n"); return -1; } printf("Performance test runs on lcore %u socket %u\n", slave_id, socketid); } if (socketid != rte_eth_dev_socket_id(portid)) { printf("Skip port %d\n", portid); continue; } /* port configure */ ret = rte_eth_dev_configure(portid, nb_rx_queue, nb_tx_queue, &port_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%d\n", ret, portid); rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); printf("Port %u ", portid); print_ethaddr("Address:", &ports_eth_addr[portid]); printf("\n"); /* tx queue setup */ ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, socketid, &tx_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, " "port=%d\n", ret, portid); /* rx queue steup */ ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, socketid, &rx_conf, mbufpool[socketid]); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=%d," "port=%d\n", ret, portid); /* Start device */ stop = 0; ret = rte_eth_dev_start(portid); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", ret, portid); /* always eanble promiscuous */ rte_eth_promiscuous_enable(portid); lcore_conf[slave_id].portlist[num++] = portid; lcore_conf[slave_id].nb_ports++; } check_all_ports_link_status(nb_ports, RTE_PORT_ALL); if (tx_burst == NULL) { tx_burst = (struct rte_mbuf **) rte_calloc_socket("tx_buff", MAX_TRAFFIC_BURST * nb_ports, sizeof(void *), RTE_CACHE_LINE_SIZE, socketid); if (!tx_burst) return -1; } init_traffic(mbufpool[socketid], tx_burst, MAX_TRAFFIC_BURST * nb_ports); printf("Generate %d packets @socket %d\n", MAX_TRAFFIC_BURST * nb_ports, socketid); if (sc_flag == SC_CONTINUOUS) { /* do both rxtx by default */ if (NULL == do_measure) do_measure = measure_rxtx; rte_eal_remote_launch(main_loop, NULL, slave_id); if (rte_eal_wait_lcore(slave_id) < 0) return -1; } else if (sc_flag == SC_BURST_POLL_FIRST || sc_flag == SC_BURST_XMIT_FIRST) if (exec_burst(sc_flag, slave_id) < 0) return -1; /* port tear down */ for (portid = 0; portid < nb_ports; portid++) { if (socketid != rte_eth_dev_socket_id(portid)) continue; rte_eth_dev_stop(portid); } return 0; }