examples/l2fwd-event: check function errors
[dpdk.git] / examples / l3fwd-power / main.c
index 99c1208..d049d8a 100644 (file)
@@ -184,8 +184,8 @@ enum busy_rate {
  * reference CYCLES to be used to
  * measure core busyness based on poll count
  */
-#define MIN_CYCLES 1500000ULL
-#define MAX_CYCLES 2500000ULL
+#define MIN_CYCLES  1500000ULL
+#define MAX_CYCLES 22000000ULL
 
 /* (500ms) */
 #define TELEMETRY_INTERVALS_PER_SEC 2
@@ -880,7 +880,9 @@ sleep_until_rx_interrupt(int num)
                port_id = ((uintptr_t)data) >> CHAR_BIT;
                queue_id = ((uintptr_t)data) &
                        RTE_LEN2MASK(CHAR_BIT, uint8_t);
+               rte_spinlock_lock(&(locks[port_id]));
                rte_eth_dev_rx_intr_disable(port_id, queue_id);
+               rte_spinlock_unlock(&(locks[port_id]));
                RTE_LOG(INFO, L3FWD_POWER,
                        "lcore %u is waked up from rx interrupt on"
                        " port %d queue %d\n",
@@ -1034,7 +1036,7 @@ main_telemetry_loop(__attribute__((unused)) void *dummy)
                                br = FULL;
                        } else if (diff_tsc > MIN_CYCLES &&
                                        diff_tsc < MAX_CYCLES) {
-                               br = PARTIAL;
+                               br = (diff_tsc * 100) / MAX_CYCLES;
                        } else {
                                br = ZERO;
                        }
@@ -1970,6 +1972,7 @@ check_all_ports_link_status(uint32_t port_mask)
        uint8_t count, all_ports_up, print_flag = 0;
        uint16_t portid;
        struct rte_eth_link link;
+       int ret;
 
        printf("\nChecking link status");
        fflush(stdout);
@@ -1979,7 +1982,14 @@ check_all_ports_link_status(uint32_t port_mask)
                        if ((port_mask & (1 << portid)) == 0)
                                continue;
                        memset(&link, 0, sizeof(link));
-                       rte_eth_link_get_nowait(portid, &link);
+                       ret = rte_eth_link_get_nowait(portid, &link);
+                       if (ret < 0) {
+                               all_ports_up = 0;
+                               if (print_flag == 1)
+                                       printf("Port %u link get failed: %s\n",
+                                               portid, rte_strerror(-ret));
+                               continue;
+                       }
                        /* print link status if flag set */
                        if (print_flag == 1) {
                                if (link.link_status)
@@ -2100,9 +2110,16 @@ update_telemetry(__attribute__((unused)) struct rte_timer *tim,
                rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
        }
 
-       values[0] = round(app_eps/count);
-       values[1] = round(app_fps/count);
-       values[2] = round(app_br/count);
+       if (count > 0) {
+               values[0] = app_eps/count;
+               values[1] = app_fps/count;
+               values[2] = app_br/count;
+       } else {
+               values[0] = 0;
+               values[1] = 0;
+               values[2] = 0;
+       }
+
        ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
                                        values, RTE_DIM(values));
        if (ret < 0)
@@ -2250,7 +2267,12 @@ main(int argc, char **argv)
                printf("Initializing port %d ... ", portid );
                fflush(stdout);
 
-               rte_eth_dev_info_get(portid, &dev_info);
+               ret = rte_eth_dev_info_get(portid, &dev_info);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Error during getting device (port %u) info: %s\n",
+                               portid, strerror(-ret));
+
                dev_rxq_num = dev_info.max_rx_queues;
                dev_txq_num = dev_info.max_tx_queues;
 
@@ -2268,7 +2290,13 @@ main(int argc, char **argv)
                /* If number of Rx queue is 0, no need to enable Rx interrupt */
                if (nb_rx_queue == 0)
                        local_port_conf.intr_conf.rxq = 0;
-               rte_eth_dev_info_get(portid, &dev_info);
+
+               ret = rte_eth_dev_info_get(portid, &dev_info);
+               if (ret != 0)
+                       rte_exit(EXIT_FAILURE,
+                               "Error during getting device (port %u) info: %s\n",
+                               portid, strerror(-ret));
+
                if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
                        local_port_conf.txmode.offloads |=
                                DEV_TX_OFFLOAD_MBUF_FAST_FREE;
@@ -2297,7 +2325,12 @@ main(int argc, char **argv)
                                 "Cannot adjust number of descriptors: err=%d, port=%d\n",
                                 ret, portid);
 
-               rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+               ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+               if (ret < 0)
+                       rte_exit(EXIT_FAILURE,
+                                "Cannot get MAC address: err=%d, port=%d\n",
+                                ret, portid);
+
                print_ethaddr(" Address:", &ports_eth_addr[portid]);
                printf(", ");
 
@@ -2378,13 +2411,9 @@ main(int argc, char **argv)
                /* init RX queues */
                for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
                        struct rte_eth_rxconf rxq_conf;
-                       struct rte_eth_dev *dev;
-                       struct rte_eth_conf *conf;
 
                        portid = qconf->rx_queue_list[queue].port_id;
                        queueid = qconf->rx_queue_list[queue].queue_id;
-                       dev = &rte_eth_devices[portid];
-                       conf = &dev->data->dev_conf;
 
                        if (numa_on)
                                socketid = \
@@ -2395,9 +2424,14 @@ main(int argc, char **argv)
                        printf("rxq=%d,%d,%d ", portid, queueid, socketid);
                        fflush(stdout);
 
-                       rte_eth_dev_info_get(portid, &dev_info);
+                       ret = rte_eth_dev_info_get(portid, &dev_info);
+                       if (ret != 0)
+                               rte_exit(EXIT_FAILURE,
+                                       "Error during getting device (port %u) info: %s\n",
+                                       portid, strerror(-ret));
+
                        rxq_conf = dev_info.default_rxconf;
-                       rxq_conf.offloads = conf->rxmode.offloads;
+                       rxq_conf.offloads = port_conf.rxmode.offloads;
                        ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
                                socketid, &rxq_conf,
                                pktmbuf_pool[socketid]);
@@ -2434,8 +2468,13 @@ main(int argc, char **argv)
                 * to itself through 2 cross-connected  ports of the
                 * target machine.
                 */
-               if (promiscuous_on)
-                       rte_eth_promiscuous_enable(portid);
+               if (promiscuous_on) {
+                       ret = rte_eth_promiscuous_enable(portid);
+                       if (ret != 0)
+                               rte_exit(EXIT_FAILURE,
+                                       "rte_eth_promiscuous_enable: err=%s, port=%u\n",
+                                       rte_strerror(-ret), portid);
+               }
                /* initialize spinlock for each port */
                rte_spinlock_init(&(locks[portid]));
        }