X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fpacket_ordering%2Fmain.c;h=b5fc6c54be56e1527a0a9b7049207f042b6b1480;hb=d74fab8e7cc36acaf2abf83888809fd1e40c932a;hp=97a58ddaf3a2849a383060c0a72c1fe5ed7e8685;hpb=867a6c66ecf3d88e76367254e79bb9e7b936a830;p=dpdk.git diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c index 97a58ddaf3..b5fc6c54be 100644 --- a/examples/packet_ordering/main.c +++ b/examples/packet_ordering/main.c @@ -31,15 +31,12 @@ unsigned int portmask; unsigned int disable_reorder; +unsigned int insight_worker; volatile uint8_t quit_signal; static struct rte_mempool *mbuf_pool; -static struct rte_eth_conf port_conf_default = { - .rxmode = { - .ignore_offload_bitfield = 1, - }, -}; +static struct rte_eth_conf port_conf_default; struct worker_thread_args { struct rte_ring *ring_in; @@ -75,6 +72,14 @@ volatile struct app_stats { } tx __rte_cache_aligned; } app_stats; +/* per worker lcore stats */ +struct wkr_stats_per { + uint64_t deq_pkts; + uint64_t enq_pkts; + uint64_t enq_failed_pkts; +} __rte_cache_aligned; + +static struct wkr_stats_per wkr_stats[RTE_MAX_LCORE] = { {0} }; /** * Get the last enabled lcore ID * @@ -138,10 +143,7 @@ parse_portmask(const char *portmask) /* parse hexadecimal string */ pm = strtoul(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) - return -1; - - if (pm == 0) - return -1; + return 0; return pm; } @@ -156,6 +158,7 @@ parse_args(int argc, char **argv) char *prgname = argv[0]; static struct option lgopts[] = { {"disable-reorder", 0, 0, 0}, + {"insight-worker", 0, 0, 0}, {NULL, 0, 0, 0} }; @@ -179,6 +182,11 @@ parse_args(int argc, char **argv) printf("reorder disabled\n"); disable_reorder = 1; } + if (!strcmp(lgopts[option_index].name, + "insight-worker")) { + printf("print all worker statistics\n"); + insight_worker = 1; + } break; default: print_usage(prgname); @@ -211,11 +219,10 @@ flush_tx_error_callback(struct rte_mbuf **unsent, uint16_t count, static inline int free_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) { - const uint8_t nb_ports = rte_eth_dev_count(); - unsigned port_id; + uint16_t port_id; /* initialize buffers for all ports */ - for (port_id = 0; port_id < nb_ports; port_id++) { + RTE_ETH_FOREACH_DEV(port_id) { /* skip ports that are not enabled */ if ((portmask & (1 << port_id)) == 0) continue; @@ -228,12 +235,11 @@ free_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) { static inline int configure_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) { - const uint8_t nb_ports = rte_eth_dev_count(); - unsigned port_id; + uint16_t port_id; int ret; /* initialize buffers for all ports */ - for (port_id = 0; port_id < nb_ports; port_id++) { + RTE_ETH_FOREACH_DEV(port_id) { /* skip ports that are not enabled */ if ((portmask & (1 << port_id)) == 0) continue; @@ -261,9 +267,8 @@ configure_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) static inline int configure_eth_port(uint16_t port_id) { - struct ether_addr addr; + struct rte_ether_addr addr; const uint16_t rxRings = 1, txRings = 1; - const uint8_t nb_ports = rte_eth_dev_count(); int ret; uint16_t q; uint16_t nb_rxd = RX_DESC_PER_QUEUE; @@ -272,10 +277,16 @@ configure_eth_port(uint16_t port_id) struct rte_eth_txconf txconf; struct rte_eth_conf port_conf = port_conf_default; - if (port_id > nb_ports) + if (!rte_eth_dev_is_valid_port(port_id)) return -1; - rte_eth_dev_info_get(port_id, &dev_info); + ret = rte_eth_dev_info_get(port_id, &dev_info); + if (ret != 0) { + printf("Error during getting device (port %u) info: %s\n", + port_id, strerror(-ret)); + return ret; + } + if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; @@ -296,7 +307,6 @@ configure_eth_port(uint16_t port_id) } txconf = dev_info.default_txconf; - txconf.txq_flags = ETH_TXQ_FLAGS_IGNORE; txconf.offloads = port_conf.txmode.offloads; for (q = 0; q < txRings; q++) { ret = rte_eth_tx_queue_setup(port_id, q, nb_txd, @@ -309,7 +319,13 @@ configure_eth_port(uint16_t port_id) if (ret < 0) return ret; - rte_eth_macaddr_get(port_id, &addr); + ret = rte_eth_macaddr_get(port_id, &addr); + if (ret != 0) { + printf("Failed to get MAC address (port %u): %s\n", + port_id, rte_strerror(-ret)); + return ret; + } + printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", port_id, @@ -317,7 +333,9 @@ configure_eth_port(uint16_t port_id) addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); - rte_eth_promiscuous_enable(port_id); + ret = rte_eth_promiscuous_enable(port_id); + if (ret != 0) + return ret; return 0; } @@ -325,9 +343,13 @@ configure_eth_port(uint16_t port_id) static void print_stats(void) { - const uint8_t nb_ports = rte_eth_dev_count(); - unsigned i; + uint16_t i; struct rte_eth_stats eth_stats; + unsigned int lcore_id, last_lcore_id, master_lcore_id, end_w_lcore_id; + + last_lcore_id = get_last_lcore_id(); + master_lcore_id = rte_get_master_lcore(); + end_w_lcore_id = get_previous_lcore_id(last_lcore_id); printf("\nRX thread stats:\n"); printf(" - Pkts rxd: %"PRIu64"\n", @@ -335,6 +357,26 @@ print_stats(void) printf(" - Pkts enqd to workers ring: %"PRIu64"\n", app_stats.rx.enqueue_pkts); + for (lcore_id = 0; lcore_id <= end_w_lcore_id; lcore_id++) { + if (insight_worker + && rte_lcore_is_enabled(lcore_id) + && lcore_id != master_lcore_id) { + printf("\nWorker thread stats on core [%u]:\n", + lcore_id); + printf(" - Pkts deqd from workers ring: %"PRIu64"\n", + wkr_stats[lcore_id].deq_pkts); + printf(" - Pkts enqd to tx ring: %"PRIu64"\n", + wkr_stats[lcore_id].enq_pkts); + printf(" - Pkts enq to tx failed: %"PRIu64"\n", + wkr_stats[lcore_id].enq_failed_pkts); + } + + app_stats.wkr.dequeue_pkts += wkr_stats[lcore_id].deq_pkts; + app_stats.wkr.enqueue_pkts += wkr_stats[lcore_id].enq_pkts; + app_stats.wkr.enqueue_failed_pkts += + wkr_stats[lcore_id].enq_failed_pkts; + } + printf("\nWorker thread stats:\n"); printf(" - Pkts deqd from workers ring: %"PRIu64"\n", app_stats.wkr.dequeue_pkts); @@ -355,7 +397,7 @@ print_stats(void) printf(" - Pkts tx failed w/o reorder: %"PRIu64"\n", app_stats.tx.early_pkts_tx_failed_woro); - for (i = 0; i < nb_ports; i++) { + RTE_ETH_FOREACH_DEV(i) { rte_eth_stats_get(i, ð_stats); printf("\nPort %u stats:\n", i); printf(" - Pkts in: %"PRIu64"\n", eth_stats.ipackets); @@ -383,7 +425,6 @@ int_handler(int sig_num) static int rx_thread(struct rte_ring *ring_out) { - const uint8_t nb_ports = rte_eth_dev_count(); uint32_t seqn = 0; uint16_t i, ret = 0; uint16_t nb_rx_pkts; @@ -395,7 +436,7 @@ rx_thread(struct rte_ring *ring_out) while (!quit_signal) { - for (port_id = 0; port_id < nb_ports; port_id++) { + RTE_ETH_FOREACH_DEV(port_id) { if ((portmask & (1 << port_id)) != 0) { /* receive packets */ @@ -435,20 +476,21 @@ rx_thread(struct rte_ring *ring_out) static int worker_thread(void *args_ptr) { - const uint8_t nb_ports = rte_eth_dev_count(); + const uint16_t nb_ports = rte_eth_dev_count_avail(); uint16_t i, ret = 0; uint16_t burst_size = 0; struct worker_thread_args *args; struct rte_mbuf *burst_buffer[MAX_PKTS_BURST] = { NULL }; struct rte_ring *ring_in, *ring_out; const unsigned xor_val = (nb_ports > 1); + unsigned int core_id = rte_lcore_id(); args = (struct worker_thread_args *) args_ptr; ring_in = args->ring_in; ring_out = args->ring_out; RTE_LOG(INFO, REORDERAPP, "%s() started on lcore %u\n", __func__, - rte_lcore_id()); + core_id); while (!quit_signal) { @@ -458,7 +500,7 @@ worker_thread(void *args_ptr) if (unlikely(burst_size == 0)) continue; - __sync_fetch_and_add(&app_stats.wkr.dequeue_pkts, burst_size); + wkr_stats[core_id].deq_pkts += burst_size; /* just do some operation on mbuf */ for (i = 0; i < burst_size;) @@ -467,11 +509,10 @@ worker_thread(void *args_ptr) /* enqueue the modified mbufs to workers_to_tx ring */ ret = rte_ring_enqueue_burst(ring_out, (void *)burst_buffer, burst_size, NULL); - __sync_fetch_and_add(&app_stats.wkr.enqueue_pkts, ret); + wkr_stats[core_id].enq_pkts += ret; if (unlikely(ret < burst_size)) { /* Return the mbufs to their respective pool, dropping packets */ - __sync_fetch_and_add(&app_stats.wkr.enqueue_failed_pkts, - (int)burst_size - ret); + wkr_stats[core_id].enq_failed_pkts += burst_size - ret; pktmbuf_free_bulk(&burst_buffer[ret], burst_size - ret); } } @@ -631,7 +672,7 @@ main(int argc, char **argv) /* Initialize EAL */ ret = rte_eal_init(argc, argv); if (ret < 0) - return -1; + rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n"); argc -= ret; argv += ret; @@ -639,7 +680,7 @@ main(int argc, char **argv) /* Parse the application specific arguments */ ret = parse_args(argc, argv); if (ret < 0) - return -1; + rte_exit(EXIT_FAILURE, "Invalid packet_ordering arguments\n"); /* Check if we have enought cores */ if (rte_lcore_count() < 3) @@ -649,7 +690,7 @@ main(int argc, char **argv) "1 lcore for packet TX\n" "and at least 1 lcore for worker threads\n"); - nb_ports = rte_eth_dev_count(); + nb_ports = rte_eth_dev_count_avail(); if (nb_ports == 0) rte_exit(EXIT_FAILURE, "Error: no ethernet ports detected\n"); if (nb_ports != 1 && (nb_ports & 1)) @@ -665,7 +706,7 @@ main(int argc, char **argv) nb_ports_available = nb_ports; /* initialize all ports */ - for (port_id = 0; port_id < nb_ports; port_id++) { + RTE_ETH_FOREACH_DEV(port_id) { /* skip ports that are not enabled */ if ((portmask & (1 << port_id)) == 0) { printf("\nSkipping disabled port %d\n", port_id);