[ovs-dev] [RFC PATCH v2 06/19] dpif-netdev: Register packet processing cores to KA framework.

Bhanuprakash Bodireddy bhanuprakash.bodireddy at intel.com
Mon Jun 12 16:49:34 UTC 2017


This commit registers the packet processing PMD cores to keepalive
framework. Only PMDs that have rxqs mapped will be registered and
actively monitored by KA framework.

This commit spawns a keepalive thread that will dispatch heartbeats to
PMD cores. The pmd threads respond to heartbeats by marking themselves
alive. As long as PMD responds to heartbeats it is considered 'healthy'.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy at intel.com>
---
 lib/dpif-netdev.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 2f224db..2607b9a 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -48,6 +48,7 @@
 #include "fat-rwlock.h"
 #include "flow.h"
 #include "hmapx.h"
+#include "keepalive.h"
 #include "latch.h"
 #include "netdev.h"
 #include "netdev-vport.h"
@@ -969,6 +970,62 @@ sorted_poll_thread_list(struct dp_netdev *dp,
     *n = k;
 }
 
+static void *
+ovs_keepalive(void *f_)
+{
+    struct dp_netdev *dp = f_;
+
+    pthread_detach(pthread_self());
+
+    for (;;) {
+        ovsrcu_quiesce_start();
+        usleep(get_ka_interval() * 1000);
+        ovsrcu_quiesce_end();
+    }
+
+    return NULL;
+}
+
+static void
+ka_thread_start(struct dp_netdev *dp)
+{
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+
+    if (ovsthread_once_start(&once)) {
+        ovs_thread_create("ovs_keepalive", ovs_keepalive, dp);
+
+        ovsthread_once_done(&once);
+    }
+}
+
+static void
+ka_register_datapath_threads(struct dp_netdev *dp)
+{
+    int ka_init = get_ka_init_status();
+    VLOG_DBG("Keepalive: Was initialization successful? [%s]",
+                ka_init ? "Success" : "Failure");
+    if (!ka_init) {
+        return;
+    }
+
+    ka_thread_start(dp);
+
+    struct dp_netdev_pmd_thread *pmd;
+    CMAP_FOR_EACH(pmd, node, &dp->poll_threads) {
+        /* Skip PMD thread with no rxqs mapping. */
+        if (!hmap_count(&pmd->poll_list)) {
+            continue;
+        }
+
+        /*  Register only PMD threads. */
+        if (pmd->core_id != NON_PMD_CORE_ID) {
+            ka_register_pmd_thread(pmd->core_id);
+            VLOG_DBG("Registered PMD thread Core [%d] to KA framework",
+                      pmd->core_id);
+        }
+    }
+}
+
 static void
 dpif_netdev_pmd_info(struct unixctl_conn *conn, int argc, const char *argv[],
                      void *aux)
@@ -3539,6 +3596,9 @@ reconfigure_datapath(struct dp_netdev *dp)
 
     /* Reload affected pmd threads. */
     reload_affected_pmds(dp);
+
+    /* Register datapath threads for KA monitoring. */
+    ka_register_datapath_threads(dp);
 }
 
 /* Returns true if one of the netdevs in 'dp' requires a reconfiguration */
@@ -3736,6 +3796,9 @@ reload:
                                        poll_list[i].port_no);
         }
 
+        /* Mark PMD thread alive. */
+        ka_mark_pmd_thread_alive();
+
         if (lc++ > 1024) {
             bool reload;
 
@@ -3766,6 +3829,8 @@ reload:
         goto reload;
     }
 
+    ka_unregister_pmd_thread(pmd->core_id);
+
     free(poll_list);
     pmd_free_cached_ports(pmd);
     return NULL;
-- 
2.4.11



More information about the dev mailing list