examples: update link status checks
authorIntel <intel.com>
Wed, 19 Dec 2012 23:00:00 +0000 (00:00 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 25 Jul 2013 13:57:45 +0000 (15:57 +0200)
Signed-off-by: Intel
examples/exception_path/main.c
examples/ipv4_frag/main.c
examples/ipv4_multicast/main.c
examples/l2fwd/main.c
examples/l3fwd/main.c
examples/link_status_interrupt/main.c
examples/load_balancer/init.c
examples/multi_process/client_server_mp/mp_server/init.c
examples/multi_process/symmetric_mp/main.c

index 646065c..3070e66 100644 (file)
@@ -72,6 +72,7 @@
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 /* 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);
index a790d93..cc1e51b 100644 (file)
@@ -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)
index 356bb64..fddd11f 100644 (file)
@@ -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();
index 5ed37b8..7948e3a 100644 (file)
@@ -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;
 }
+
index 6ca4ab2..cbfdff6 100644 (file)
@@ -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) {
index b6a4622..9a8bed1 100644 (file)
@@ -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) {
index ea4f6f4..b95b8a3 100644 (file)
@@ -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
index 6e08a0b..9f5382c 100644 (file)
@@ -65,6 +65,7 @@
 #include <rte_hash_crc.h>
 #include <rte_fbk_hash.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #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();
 
index bfd253b..abf8309 100644 (file)
@@ -76,6 +76,7 @@
 #include <rte_memcpy.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #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");