examples: add eal cleanup to examples
[dpdk.git] / examples / link_status_interrupt / main.c
index a0b75d9..d8ff5f1 100644 (file)
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
@@ -133,7 +132,7 @@ print_stats(void)
                link_get_err = rte_eth_link_get_nowait(portid, &link);
                printf("\nStatistics for port %u ------------------------------"
                           "\nLink status: %25s"
-                          "\nLink speed: %26u"
+                          "\nLink speed: %26s"
                           "\nLink duplex: %25s"
                           "\nPackets sent: %24"PRIu64
                           "\nPackets received: %20"PRIu64
@@ -141,8 +140,8 @@ print_stats(void)
                           portid,
                           link_get_err < 0 ? "Link get failed" :
                           (link.link_status ? "Link up" : "Link down"),
-                          link_get_err < 0 ? 0 :
-                                       (unsigned int)link.link_speed,
+                          link_get_err < 0 ? "0" :
+                          rte_eth_link_speed_to_str(link.link_speed),
                           link_get_err < 0 ? "Link get failed" :
                           (link.link_duplex == ETH_LINK_FULL_DUPLEX ? \
                                        "full-duplex" : "half-duplex"),
@@ -162,6 +161,8 @@ print_stats(void)
                   total_packets_rx,
                   total_packets_dropped);
        printf("\n====================================================\n");
+
+       fflush(stdout);
 }
 
 static void
@@ -253,8 +254,8 @@ lsi_main_loop(void)
                                /* if timer has reached its timeout */
                                if (unlikely(timer_tsc >= (uint64_t) timer_period)) {
 
-                                       /* do this only on master core */
-                                       if (lcore_id == rte_get_master_lcore()) {
+                                       /* do this only on main core */
+                                       if (lcore_id == rte_get_main_lcore()) {
                                                print_stats();
                                                /* reset the timer */
                                                timer_tsc = 0;
@@ -286,7 +287,7 @@ lsi_main_loop(void)
 }
 
 static int
-lsi_launch_one_lcore(__attribute__((unused)) void *dummy)
+lsi_launch_one_lcore(__rte_unused void *dummy)
 {
        lsi_main_loop();
        return 0;
@@ -312,10 +313,7 @@ lsi_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;
 }
@@ -443,6 +441,7 @@ lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param,
 {
        struct rte_eth_link link;
        int ret;
+       char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
 
        RTE_SET_USED(param);
        RTE_SET_USED(ret_param);
@@ -455,13 +454,8 @@ lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param,
                       port_id, rte_strerror(-ret));
                return ret;
        }
-       if (link.link_status) {
-               printf("Port %d Link Up - speed %u Mbps - %s\n\n",
-                               port_id, (unsigned)link.link_speed,
-                       (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                               ("full-duplex") : ("half-duplex"));
-       } else
-               printf("Port %d Link Down\n\n", port_id);
+       rte_eth_link_to_str(link_status_text, sizeof(link_status_text), &link);
+       printf("Port %d %s\n\n", port_id, link_status_text);
 
        return 0;
 }
@@ -476,6 +470,7 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask)
        uint16_t portid;
        struct rte_eth_link link;
        int ret;
+       char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
 
        printf("\nChecking link status");
        fflush(stdout);
@@ -495,14 +490,10 @@ check_all_ports_link_status(uint16_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",
-                                               portid, link.link_speed,
-                               (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
-                                       ("full-duplex") : ("half-duplex\n"));
-                               else
-                                       printf("Port %d Link Down\n", portid);
+                               rte_eth_link_to_str(link_status_text,
+                                       sizeof(link_status_text), &link);
+                               printf("Port %d %s", portid,
+                                      link_status_text);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
@@ -657,8 +648,12 @@ main(int argc, char **argv)
                rte_eth_dev_callback_register(portid,
                        RTE_ETH_EVENT_INTR_LSC, lsi_event_callback, NULL);
 
-               rte_eth_macaddr_get(portid,
+               ret = rte_eth_macaddr_get(portid,
                                    &lsi_ports_eth_addr[portid]);
+               if (ret < 0)
+                       rte_exit(EXIT_FAILURE,
+                                "rte_eth_macaddr_get: err=%d, port=%u\n",
+                                ret, (unsigned int)portid);
 
                /* init one RX queue */
                fflush(stdout);
@@ -729,11 +724,14 @@ main(int argc, char **argv)
        check_all_ports_link_status(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) {
+       rte_eal_mp_remote_launch(lsi_launch_one_lcore, NULL, CALL_MAIN);
+       RTE_LCORE_FOREACH_WORKER(lcore_id) {
                if (rte_eal_wait_lcore(lcore_id) < 0)
                        return -1;
        }
 
+       /* clean up the EAL */
+       rte_eal_cleanup();
+
        return 0;
 }