app/flow-perf: support meter action
[dpdk.git] / examples / l3fwd / main.c
index c95b165..bb49e5f 100644 (file)
@@ -48,7 +48,7 @@
 #include "l3fwd.h"
 #include "l3fwd_event.h"
 
-#define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
+#define MAX_TX_QUEUE_PER_PORT RTE_MAX_LCORE
 #define MAX_RX_QUEUE_PER_PORT 128
 
 #define MAX_LCORE_PARAMS 1024
@@ -340,10 +340,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;
 }
@@ -810,6 +807,7 @@ check_all_ports_link_status(uint32_t port_mask)
        uint8_t count, all_ports_up, print_flag = 0;
        struct rte_eth_link link;
        int ret;
+       char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
 
        printf("\nChecking link status");
        fflush(stdout);
@@ -833,14 +831,10 @@ check_all_ports_link_status(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\n", portid,
+                                      link_status_text);
                                continue;
                        }
                        /* clear all_ports_up flag if any link down */
@@ -1092,8 +1086,6 @@ l3fwd_poll_resource_setup(void)
                                ret, portid);
                }
        }
-
-
 }
 
 static inline int
@@ -1114,8 +1106,9 @@ l3fwd_service_enable(uint32_t service_id)
        /* Get the core which has least number of services running. */
        while (slcore_count--) {
                /* Reset default mapping */
-               rte_service_map_lcore_set(service_id,
-                               slcore_array[slcore_count], 0);
+               if (rte_service_map_lcore_set(service_id,
+                               slcore_array[slcore_count], 0) != 0)
+                       return -ENOENT;
                service_count = rte_service_lcore_count_services(
                                slcore_array[slcore_count]);
                if (service_count < min_service_count) {
@@ -1191,7 +1184,7 @@ main(int argc, char **argv)
        uint16_t queueid, portid;
        unsigned int lcore_id;
        uint8_t queue;
-       int ret;
+       int i, ret;
 
        /* init EAL */
        ret = rte_eal_init(argc, argv);
@@ -1279,22 +1272,48 @@ main(int argc, char **argv)
 
        ret = 0;
        /* launch per-lcore init on every lcore */
-       rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MASTER);
-       RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-               if (rte_eal_wait_lcore(lcore_id) < 0) {
-                       ret = -1;
-                       break;
+       rte_eal_mp_remote_launch(l3fwd_lkp.main_loop, NULL, CALL_MAIN);
+       if (evt_rsrc->enabled) {
+               for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++)
+                       rte_event_eth_rx_adapter_stop(
+                                       evt_rsrc->rx_adptr.rx_adptr[i]);
+               for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++)
+                       rte_event_eth_tx_adapter_stop(
+                                       evt_rsrc->tx_adptr.tx_adptr[i]);
+
+               RTE_ETH_FOREACH_DEV(portid) {
+                       if ((enabled_port_mask & (1 << portid)) == 0)
+                               continue;
+                       ret = rte_eth_dev_stop(portid);
+                       if (ret != 0)
+                               printf("rte_eth_dev_stop: err=%d, port=%u\n",
+                                      ret, portid);
                }
-       }
 
-       /* stop ports */
-       RTE_ETH_FOREACH_DEV(portid) {
-               if ((enabled_port_mask & (1 << portid)) == 0)
-                       continue;
-               printf("Closing port %d...", portid);
-               rte_eth_dev_stop(portid);
-               rte_eth_dev_close(portid);
-               printf(" Done\n");
+               rte_eal_mp_wait_lcore();
+               RTE_ETH_FOREACH_DEV(portid) {
+                       if ((enabled_port_mask & (1 << portid)) == 0)
+                               continue;
+                       rte_eth_dev_close(portid);
+               }
+
+               rte_event_dev_stop(evt_rsrc->event_d_id);
+               rte_event_dev_close(evt_rsrc->event_d_id);
+
+       } else {
+               rte_eal_mp_wait_lcore();
+
+               RTE_ETH_FOREACH_DEV(portid) {
+                       if ((enabled_port_mask & (1 << portid)) == 0)
+                               continue;
+                       printf("Closing port %d...", portid);
+                       ret = rte_eth_dev_stop(portid);
+                       if (ret != 0)
+                               printf("rte_eth_dev_stop: err=%d, port=%u\n",
+                                      ret, portid);
+                       rte_eth_dev_close(portid);
+                       printf(" Done\n");
+               }
        }
        printf("Bye...\n");