examples/l3fwd-power: add Rx interrupt timeout
authorAnatoly Burakov <anatoly.burakov@intel.com>
Thu, 7 May 2020 10:46:28 +0000 (11:46 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 11 May 2020 19:33:42 +0000 (21:33 +0200)
Currently, thread waiting on an interrupt does not have a timeout, so
it will not ever wake up until traffic arrives. This means that, when
time comes to exit the application, it will not quit unless there
happens to be traffic coming in and waking up the thread from sleep.

Fix it so that the interrupt thread sleeps for 10ms before waking up
and attempting to poll again. Additionally, remove the log message
to avoid spamming about entering interrupt mode.

Fixes: 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Cc: stable@dpdk.org
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: David Hunt <david.hunt@intel.com>
Tested-by: Lihong Ma <lihongx.ma@intel.com>
examples/l3fwd-power/main.c

index 13fd72d..48b9c85 100644 (file)
@@ -824,17 +824,24 @@ power_freq_scaleup_heuristic(unsigned lcore_id,
 static int
 sleep_until_rx_interrupt(int num)
 {
+       /*
+        * we want to track when we are woken up by traffic so that we can go
+        * back to sleep again without log spamming.
+        */
+       static bool timeout;
        struct rte_epoll_event event[num];
        int n, i;
        uint16_t port_id;
        uint8_t queue_id;
        void *data;
 
-       RTE_LOG(INFO, L3FWD_POWER,
-               "lcore %u sleeps until interrupt triggers\n",
-               rte_lcore_id());
+       if (!timeout) {
+               RTE_LOG(INFO, L3FWD_POWER,
+                               "lcore %u sleeps until interrupt triggers\n",
+                               rte_lcore_id());
+       }
 
-       n = rte_epoll_wait(RTE_EPOLL_PER_THREAD, event, num, -1);
+       n = rte_epoll_wait(RTE_EPOLL_PER_THREAD, event, num, 10);
        for (i = 0; i < n; i++) {
                data = event[i].epdata.data;
                port_id = ((uintptr_t)data) >> CHAR_BIT;
@@ -845,6 +852,7 @@ sleep_until_rx_interrupt(int num)
                        " port %d queue %d\n",
                        rte_lcore_id(), port_id, queue_id);
        }
+       timeout = n == 0;
 
        return 0;
 }
@@ -1307,7 +1315,8 @@ start_rx:
                                        /**
                                         * start receiving packets immediately
                                         */
-                                       goto start_rx;
+                                       if (likely(!is_done()))
+                                               goto start_rx;
                                }
                        }
                        stats[lcore_id].sleep_time += lcore_idle_hint;