Fix link speed when link is down at startup. 21/55421/4
authorXavier Simonart <xavier.simonart@intel.com>
Wed, 11 Apr 2018 14:15:55 +0000 (16:15 +0200)
committerPatrice Buriez <patrice.buriez@intel.com>
Tue, 17 Apr 2018 16:28:09 +0000 (16:28 +0000)
When link is down at startup, the link_speed returned by DPDK
is 0. This results in un-optimized latency estimates in gen and lat.
With this fix, lat and gen do nothing until link_speed is
properly initialized, and use the right link speed in the fast path.

Change-Id: Id2d14b6966ccfac7cc78db3c5a74e704b42edae7
Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
VNFs/DPPD-PROX/handle_gen.c
VNFs/DPPD-PROX/handle_lat.c

index 9bb34fc..89dbe9e 100644 (file)
@@ -641,6 +641,16 @@ static int handle_gen_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin
 
        int i, j;
 
+       // If link is down, link_speed is 0
+       if (unlikely(task->link_speed == 0)) {
+               if (task->port && task->port->link_speed != 0) {
+                       task->link_speed = task->port->link_speed * 125000L;
+                       plog_info("\tPort %u: link speed is %ld Mbps\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+               } else
+                       return 0;
+       }
+
        task_gen_update_config(task);
 
        if (task->pkt_count == 0) {
@@ -1145,11 +1155,17 @@ static void start(struct task_base *tbase)
        if (tbase->l3.tmaster) {
                register_all_ip_to_ctrl_plane(task);
        }
-       if (task->port && task->port->link_speed) {
-               // task->port->link->speed reports the link speed in Mbps e.g. 40k for a 40 Gbps NIC
-               // task->link_speed reported link speed in Bytes per sec.
+       if (task->port) {
+               // task->port->link_speed reports the link speed in Mbps e.g. 40k for a 40 Gbps NIC.
+               // task->link_speed reports link speed in Bytes per sec.
+               // It can be 0 if link is down, and must hence be updated in fast path.
                task->link_speed = task->port->link_speed * 125000L;
-               plog_info("\tGenerating at %ld Mbps\n", 8 * task->link_speed / 1000000);
+               if (task->link_speed)
+                       plog_info("\tPort %u: link speed is %ld Mbps\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+               else
+                       plog_info("\tPort %u: link speed is %ld Mbps - link might be down\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
        }
        /* TODO
           Handle the case when two tasks transmit to the same port
index 1fa4413..8cc5c32 100644 (file)
@@ -520,6 +520,16 @@ static int handle_lat_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin
 
        uint32_t pkt_rx_time, pkt_tx_time;
 
+       // If link is down, link_speed is 0
+       if (unlikely(task->link_speed == 0)) {
+               if (task->port && task->port->link_speed != 0) {
+                       task->link_speed = task->port->link_speed * 125000L;
+                       plog_info("\tPort %u: link speed is %ld Mbps\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+               } else
+                       return 0;
+       }
+
        if (n_pkts == 0) {
                task->begin = tbase->aux->tsc_rx.before;
                return 0;
@@ -688,11 +698,17 @@ static void lat_start(struct task_base *tbase)
 {
        struct task_lat *task = (struct task_lat *)tbase;
 
-       if (task->port && task->port->link_speed) {
-               // task->port->link->speed reports the link speed in Mbps e.g. 40k for a 40 Gbps NIC
-               // task->link_speed reported link speed in Bytes per sec.
+       if (task->port) {
+               // task->port->link_speed reports the link speed in Mbps e.g. 40k for a 40 Gbps NIC.
+               // task->link_speed reports link speed in Bytes per sec.
+               // It can be 0 if link is down, and must hence be updated in fast path.
                task->link_speed = task->port->link_speed * 125000L;
-               plog_info("\tReceiving at %lu Mbps\n", 8 * task->link_speed / 1000000);
+               if (task->link_speed)
+                       plog_info("\tPort %u: link speed is %ld Mbps\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+               else
+                       plog_info("\tPort %u: link speed is %ld Mbps - link might be down\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
        }
 }