X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fl2fwd-keepalive%2Fmain.c;h=2f543d31d3aa779410829840bccc4cce4d411950;hb=ff5d5b01f8f21a87387042843b8494bc2d82b1cd;hp=5fdbdef2d299fe25f26719b4787b3a9a6d0b0a45;hpb=91e89e477eda7b310a0cfcee115b04d0543f15e4;p=dpdk.git diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c index 5fdbdef2d2..2f543d31d3 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -158,7 +157,7 @@ print_stats(__attribute__((unused)) struct rte_timer *ptr_timer, __attribute__((unused)) void *ptr_data) { uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; - unsigned portid; + uint16_t portid; total_packets_dropped = 0; total_packets_tx = 0; @@ -300,7 +299,7 @@ l2fwd_main_loop(void) for (i = 0; i < qconf->n_rx_port; i++) { portid = qconf->rx_port_list[i]; - nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, + nb_rx = rte_eth_rx_burst(portid, 0, pkts_burst, MAX_PKT_BURST); port_statistics[portid].rx += nb_rx; @@ -480,11 +479,12 @@ l2fwd_parse_args(int argc, char **argv) /* Check the link status of all ports in up to 9s, and print them finally */ static void -check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) +check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) { #define CHECK_INTERVAL 100 /* 100ms */ #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ - uint8_t portid, count, all_ports_up, print_flag = 0; + uint16_t portid; + uint8_t count, all_ports_up, print_flag = 0; struct rte_eth_link link; printf("\nChecking link status"); @@ -499,14 +499,13 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) /* print link status if flag set */ if (print_flag == 1) { if (link.link_status) - printf("Port %d Link Up - speed %u " - "Mbps - %s\n", (uint8_t)portid, - (unsigned)link.link_speed, + printf( + "Port%d Link Up. Speed %u Mbps - %s\n", + portid, link.link_speed, (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n")); else - printf("Port %d Link Down\n", - (uint8_t)portid); + printf("Port %d Link Down\n", portid); continue; } /* clear all_ports_up flag if any link down */ @@ -561,12 +560,13 @@ main(int argc, char **argv) struct lcore_queue_conf *qconf; struct rte_eth_dev_info dev_info; int ret; - uint8_t nb_ports; - uint8_t nb_ports_available; - uint8_t portid, last_port; + uint16_t nb_ports; + uint16_t nb_ports_available; + uint16_t portid, last_port; unsigned lcore_id, rx_lcore_id; unsigned nb_ports_in_mask = 0; struct sigaction signal_handler; + struct rte_keepalive_shm *ka_shm; memset(&signal_handler, 0, sizeof(signal_handler)); terminate_signal_received = 0; @@ -653,7 +653,7 @@ main(int argc, char **argv) qconf->rx_port_list[qconf->n_rx_port] = portid; qconf->n_rx_port++; printf("Lcore %u: RX port %u\n", - rx_lcore_id, (unsigned) portid); + rx_lcore_id, portid); } nb_ports_available = nb_ports; @@ -662,19 +662,25 @@ main(int argc, char **argv) for (portid = 0; portid < nb_ports; portid++) { /* skip ports that are not enabled */ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) { - printf("Skipping disabled port %u\n", - (unsigned) portid); + printf("Skipping disabled port %u\n", portid); nb_ports_available--; continue; } /* init port */ - printf("Initializing port %u... ", (unsigned) portid); + printf("Initializing port %u... ", portid); fflush(stdout); ret = rte_eth_dev_configure(portid, 1, 1, &port_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", - ret, (unsigned) portid); + ret, portid); + + ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, + &nb_txd); + if (ret < 0) + rte_exit(EXIT_FAILURE, + "Cannot adjust number of descriptors: err=%d, port=%u\n", + ret, portid); rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]); @@ -687,7 +693,7 @@ main(int argc, char **argv) if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n", - ret, (unsigned) portid); + ret, portid); /* init one TX queue on each port */ fflush(stdout); @@ -697,7 +703,7 @@ main(int argc, char **argv) if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n", - ret, (unsigned) portid); + ret, portid); /* Initialize TX buffers */ tx_buffer[portid] = rte_zmalloc_socket("tx_buffer", @@ -705,7 +711,7 @@ main(int argc, char **argv) rte_eth_dev_socket_id(portid)); if (tx_buffer[portid] == NULL) rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n", - (unsigned) portid); + portid); rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST); @@ -713,21 +719,22 @@ main(int argc, char **argv) rte_eth_tx_buffer_count_callback, &port_statistics[portid].dropped); if (ret < 0) - rte_exit(EXIT_FAILURE, "Cannot set error callback for " - "tx buffer on port %u\n", (unsigned) portid); + rte_exit(EXIT_FAILURE, + "Cannot set error callback for tx buffer on port %u\n", + portid); /* Start device */ ret = rte_eth_dev_start(portid); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n", - ret, (unsigned) portid); + ret, portid); rte_eth_promiscuous_enable(portid); printf("Port %u, MAC address: " "%02X:%02X:%02X:%02X:%02X:%02X\n\n", - (unsigned) portid, + portid, l2fwd_ports_eth_addr[portid].addr_bytes[0], l2fwd_ports_eth_addr[portid].addr_bytes[1], l2fwd_ports_eth_addr[portid].addr_bytes[2], @@ -751,9 +758,8 @@ main(int argc, char **argv) rte_timer_subsystem_init(); rte_timer_init(&stats_timer); + ka_shm = NULL; if (check_period > 0) { - struct rte_keepalive_shm *ka_shm; - ka_shm = rte_keepalive_shm_create(); if (ka_shm == NULL) rte_exit(EXIT_FAILURE, @@ -813,5 +819,7 @@ main(int argc, char **argv) return -1; } + if (ka_shm != NULL) + rte_keepalive_shm_cleanup(ka_shm); return 0; }