From: Intel Date: Wed, 19 Dec 2012 23:00:00 +0000 (+0100) Subject: examples: update link status checks X-Git-Tag: spdx-start~11313 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=d3641ae86313ac8da51faeff980022ebe18bd2bd;p=dpdk.git examples: update link status checks Signed-off-by: Intel --- diff --git a/examples/exception_path/main.c b/examples/exception_path/main.c index 646065ced3..3070e660dc 100644 --- a/examples/exception_path/main.c +++ b/examples/exception_path/main.c @@ -72,6 +72,7 @@ #include #include #include +#include /* Macros for printing using RTE_LOG */ #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 @@ -446,7 +447,6 @@ parse_args(int argc, char **argv) static void init_port(uint8_t port) { - struct rte_eth_link link; int ret; /* Initialise device and RX/TX queues */ @@ -472,19 +472,64 @@ init_port(uint8_t port) if (ret < 0) FATAL_ERROR("Could not start port%u (%d)", (unsigned)port, ret); - /* Everything is setup and started, print link status */ - rte_eth_link_get(port, &link); - if (link.link_status) - PRINT_INFO(" link up - %u Mbit/s - %s", - (unsigned)link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex")); - else - PRINT_INFO(" link down"); - rte_eth_promiscuous_enable(port); } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + /* Initialise ports/queues etc. and start main loop on each core */ int main(int argc, char** argv) @@ -550,6 +595,7 @@ main(int argc, char** argv) } init_port(port); } + check_all_ports_link_status(nb_sys_ports, ports_mask); /* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); diff --git a/examples/ipv4_frag/main.c b/examples/ipv4_frag/main.c index a790d936b4..cc1e51b64c 100644 --- a/examples/ipv4_frag/main.c +++ b/examples/ipv4_frag/main.c @@ -512,11 +512,65 @@ print_ethaddr(const char *name, struct ether_addr *eth_addr) eth_addr->addr_bytes[5]); } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + int MAIN(int argc, char **argv) { struct lcore_queue_conf *qconf; - struct rte_eth_link link; int ret; unsigned nb_ports, i; uint16_t queueid = 0; @@ -651,21 +705,12 @@ MAIN(int argc, char **argv) printf("done: "); - /* get link status */ - rte_eth_link_get(portid, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (uint32_t) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - } else { - printf(" Link Down\n"); - } - /* Set port in promiscuous mode */ rte_eth_promiscuous_enable(portid); } + check_all_ports_link_status((uint8_t)nb_ports, enabled_port_mask); + /* create the LPM table */ l3fwd_lpm = rte_lpm_create("L3FWD_LPM", SOCKET0, L3FWD_LPM_MAX_RULES, 0); if (l3fwd_lpm == NULL) diff --git a/examples/ipv4_multicast/main.c b/examples/ipv4_multicast/main.c index 356bb6439b..fddd11f03f 100644 --- a/examples/ipv4_multicast/main.c +++ b/examples/ipv4_multicast/main.c @@ -655,11 +655,65 @@ init_mcast_hash(void) return 0; } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + int MAIN(int argc, char **argv) { struct lcore_queue_conf *qconf; - struct rte_eth_link link; int ret; uint16_t queueid; unsigned lcore_id = 0, rx_lcore_id = 0;; @@ -793,22 +847,10 @@ MAIN(int argc, char **argv) rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", ret, portid); - printf("done: "); - - /* get link status */ - rte_eth_link_get(portid, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (uint32_t) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - rte_eth_promiscuous_enable(portid); - rte_eth_allmulticast_enable(portid); - } else { - printf(" Link Down\n"); - } + printf("done:\n"); } + check_all_ports_link_status(nb_ports, enabled_port_mask); /* initialize the multicast hash */ int retval = init_mcast_hash(); diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 5ed37b80f6..7948e3a6b2 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -530,12 +530,66 @@ l2fwd_parse_args(int argc, char **argv) return ret; } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + int MAIN(int argc, char **argv) { struct lcore_queue_conf *qconf; struct rte_eth_dev_info dev_info; - struct rte_eth_link link; int ret; unsigned int nb_ports, nb_lcores; unsigned portid, last_port, queueid = 0; @@ -700,18 +754,7 @@ MAIN(int argc, char **argv) "err=%d, port=%u\n", ret, portid); - printf("done: "); - - /* get link status */ - rte_eth_link_get((uint8_t) portid, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (unsigned) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - } else { - printf(" Link Down\n"); - } + printf("done: \n"); rte_eth_promiscuous_enable((uint8_t)portid); @@ -728,6 +771,8 @@ MAIN(int argc, char **argv) memset(&port_statistics, 0, sizeof(port_statistics)); } + check_all_ports_link_status((uint8_t)nb_ports, l2fwd_enabled_port_mask); + /* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(lcore_id) { @@ -737,3 +782,4 @@ MAIN(int argc, char **argv) return 0; } + diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 6ca4ab290f..cbfdff6c5e 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -940,11 +940,65 @@ init_mem(void) return 0; } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + int MAIN(int argc, char **argv) { struct lcore_conf *qconf; - struct rte_eth_link link; int ret; unsigned nb_ports; uint16_t queueid; @@ -1086,18 +1140,6 @@ MAIN(int argc, char **argv) rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", ret, portid); - printf("done: Port %d ", portid); - - /* get link status */ - rte_eth_link_get(portid, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (unsigned) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - } else { - printf(" Link Down\n"); - } /* * If enabled, put device in promiscuous mode. * This allows IO forwarding mode to forward packets @@ -1108,6 +1150,8 @@ MAIN(int argc, char **argv) rte_eth_promiscuous_enable(portid); } + check_all_ports_link_status((uint8_t)nb_ports, enabled_port_mask); + /* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(lcore_id) { diff --git a/examples/link_status_interrupt/main.c b/examples/link_status_interrupt/main.c index b6a46223d7..9a8bed154f 100644 --- a/examples/link_status_interrupt/main.c +++ b/examples/link_status_interrupt/main.c @@ -568,7 +568,7 @@ lsi_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param) printf("\n\nIn registered callback...\n"); printf("Event type: %s\n", type == RTE_ETH_EVENT_INTR_LSC ? "LSC interrupt" : "unknown event"); - rte_eth_link_get(port_id, &link); + rte_eth_link_get_nowait(port_id, &link); if (link.link_status) { printf("Port %d Link Up - speed %u Mbps - %s\n\n", port_id, (unsigned)link.link_speed, @@ -578,12 +578,66 @@ lsi_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param) printf("Port %d Link Down\n\n", port_id); } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + int MAIN(int argc, char **argv) { struct lcore_queue_conf *qconf; struct rte_eth_dev_info dev_info; - struct rte_eth_link link; int ret; unsigned int nb_ports, nb_lcores; unsigned portid, portid_last = 0, queueid = 0; @@ -748,19 +802,7 @@ MAIN(int argc, char **argv) if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%u\n", ret, portid); - - printf("done: "); - - /* get link status */ - rte_eth_link_get((uint8_t) portid, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (unsigned) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - } else { - printf(" Link Down\n"); - } + printf("done:\n"); printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n", portid, @@ -775,6 +817,8 @@ MAIN(int argc, char **argv) memset(&port_statistics, 0, sizeof(port_statistics)); } + check_all_ports_link_status((uint8_t)nb_ports, lsi_enabled_port_mask); + /* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch(lsi_launch_one_lcore, NULL, CALL_MASTER); RTE_LCORE_FOREACH_SLAVE(lcore_id) { diff --git a/examples/load_balancer/init.c b/examples/load_balancer/init.c index ea4f6f407f..b95b8a3bd0 100644 --- a/examples/load_balancer/init.c +++ b/examples/load_balancer/init.c @@ -379,6 +379,66 @@ app_init_rings_tx(void) } } +/* 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) +{ +#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; + struct rte_eth_link link; + uint32_t n_rx_queues, n_tx_queues; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + n_rx_queues = app_get_nic_rx_queues_per_port(portid); + n_tx_queues = app.nic_tx_port_mask[portid]; + if ((n_rx_queues == 0) && (n_tx_queues == 0)) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + static void app_init_nics(void) { @@ -398,7 +458,6 @@ app_init_nics(void) /* Init NIC ports and queues, then start the ports */ for (port = 0; port < APP_MAX_NIC_PORTS; port ++) { - struct rte_eth_link link; struct rte_mempool *pool; uint32_t n_rx_queues, n_tx_queues; @@ -473,18 +532,9 @@ app_init_nics(void) if (ret < 0) { rte_panic("Cannot start port %d (%d)\n", port, ret); } - - /* Get link status */ - rte_eth_link_get(port, &link); - if (link.link_status) { - printf("Port %u is UP (%u Mbps)\n", - (uint32_t) port, - (unsigned) link.link_speed); - } else { - printf("Port %u is DOWN\n", - (uint32_t) port); - } } + + check_all_ports_link_status(APP_MAX_NIC_PORTS, (~0x0)); } void diff --git a/examples/multi_process/client_server_mp/mp_server/init.c b/examples/multi_process/client_server_mp/mp_server/init.c index 6e08a0b14e..9f5382cefc 100644 --- a/examples/multi_process/client_server_mp/mp_server/init.c +++ b/examples/multi_process/client_server_mp/mp_server/init.c @@ -65,6 +65,7 @@ #include #include #include +#include #include "common.h" #include "init_drivers.h" @@ -171,7 +172,6 @@ init_port(uint8_t port_num) const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT; const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT; - struct rte_eth_link link; uint16_t q; int retval; @@ -201,19 +201,8 @@ init_port(uint8_t port_num) retval = rte_eth_dev_start(port_num); if (retval < 0) return retval; - printf( "done: "); + printf( "done: \n"); - /* get link status */ - rte_eth_link_get(port_num, &link); - if (link.link_status) { - printf(" Link Up - speed %u Mbps - %s\n", - (uint32_t) link.link_speed, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - } - else{ - printf(" Link Down\n"); - } return 0; } @@ -244,6 +233,61 @@ init_shm_rings(void) return 0; } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + /** * Main init function for the multi-process server app, * calls subfunctions to do each stage of the initialisation. @@ -296,6 +340,8 @@ init(int argc, char *argv[]) (unsigned)i); } + check_all_ports_link_status(ports->num_ports, (~0x0)); + /* initialise the client queues/rings for inter-eu comms */ init_shm_rings(); diff --git a/examples/multi_process/symmetric_mp/main.c b/examples/multi_process/symmetric_mp/main.c index bfd253b944..abf8309431 100644 --- a/examples/multi_process/symmetric_mp/main.c +++ b/examples/multi_process/symmetric_mp/main.c @@ -76,6 +76,7 @@ #include #include #include +#include #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 @@ -233,22 +234,6 @@ smp_parse_args(int argc, char **argv) return (ret); } -/* Queries the link status of a port and prints it to screen */ -static void -report_link_status(uint8_t port) -{ - /* get link status */ - struct rte_eth_link link; - rte_eth_link_get(port, &link); - if (link.link_status) - printf("Port %u: Link Up - %u Gbps - %s\n", (unsigned)port, - (unsigned) link.link_speed / 1000, - (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); - else - printf("Port %u: Link Down\n", (unsigned)port); -} - /* * Initialises a given port using global settings and with the rx buffers * coming from the mbuf_pool passed as parameter @@ -400,6 +385,61 @@ lcore_main(void *arg __rte_unused) } } +/* 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) +{ +#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; + struct rte_eth_link link; + + printf("\nChecking link status"); + fflush(stdout); + for (count = 0; count <= MAX_CHECK_TIME; count++) { + all_ports_up = 1; + for (portid = 0; portid < port_num; portid++) { + if ((port_mask & (1 << portid)) == 0) + continue; + memset(&link, 0, sizeof(link)); + rte_eth_link_get_nowait(portid, &link); + /* 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, + (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? + ("full-duplex") : ("half-duplex\n")); + else + printf("Port %d Link Down\n", + (uint8_t)portid); + continue; + } + /* clear all_ports_up flag if any link down */ + if (link.link_status == 0) { + all_ports_up = 0; + break; + } + } + /* after finally printing all link status, get out */ + if (print_flag == 1) + break; + + if (all_ports_up == 0) { + printf("."); + fflush(stdout); + rte_delay_ms(CHECK_INTERVAL); + } + + /* set the print_flag if all ports up or timeout */ + if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { + print_flag = 1; + printf("done\n"); + } + } +} + /* Main function. * Performs initialisation and then calls the lcore_main on each core * to do the packet-processing work. @@ -452,9 +492,11 @@ main(int argc, char **argv) if(proc_type == RTE_PROC_PRIMARY) if (smp_port_init(ports[i], mp, (uint16_t)num_procs) < 0) rte_exit(EXIT_FAILURE, "Error initialising ports\n"); - report_link_status(ports[i]); } + if (proc_type == RTE_PROC_PRIMARY) + check_all_ports_link_status((uint8_t)num_ports, (~0x0)); + assign_ports_to_cores(); RTE_LOG(INFO, APP, "Finished Process Init.\n");