[ovs-dev,v3,09/19] keepalive: Retrieve PMD status periodically.

Submitted by Bhanuprakash Bodireddy on Aug. 4, 2017, 8:07 a.m.

Details

Message ID 1501834086-31829-10-git-send-email-bhanuprakash.bodireddy@intel.com
State New
Headers show

Commit Message

Bhanuprakash Bodireddy Aug. 4, 2017, 8:07 a.m.
This commit implements APIs to retrieve the PMD thread status and return
the status in the below format for each PMD thread.

  Format: pmdid="status,core id,last_seen_timestamp"
  eg:     pmd62="ALIVE,2,9220698256784207"
          pmd63="GONE,3,9220698256786231"

The status is periodically retrieved by keepalive thread and stored in
keepalive_stats struc which later shall be retrieved by vswitchd thread.
In case of four PMD threads the status is as below:

   "pmd62"="ALIVE,0,9220698256784207"
   "pmd63"="ALIVE,1,9220698256784913"
   "pmd64"="ALIVE,2,9220698256785902"
   "pmd65"="ALIVE,3,9220698256786231"

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 lib/dpif-netdev.c |  1 +
 lib/keepalive.c   | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/keepalive.h   |  1 +
 3 files changed, 75 insertions(+)

Patch hide | download patch | download mbox

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 009ee24..65db5fd 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -991,6 +991,7 @@  ovs_keepalive(void *f_)
         int n_pmds = cmap_count(&dp->poll_threads) - 1;
         if (n_pmds > 0) {
             dispatch_heartbeats();
+            get_ka_stats();
         }
 
         xusleep(get_ka_interval() * 1000);
diff --git a/lib/keepalive.c b/lib/keepalive.c
index 3022789..509a0d1 100644
--- a/lib/keepalive.c
+++ b/lib/keepalive.c
@@ -24,6 +24,7 @@ 
 #include "keepalive.h"
 #include "lib/vswitch-idl.h"
 #include "openvswitch/vlog.h"
+#include "ovs-thread.h"
 #include "process.h"
 
 VLOG_DEFINE_THIS_MODULE(keepalive);
@@ -33,6 +34,9 @@  static bool ka_init_status = ka_init_failure; /* Keepalive initialization */
 static uint32_t keepalive_timer_interval;     /* keepalive timer interval */
 static struct keepalive_info *ka_info = NULL;
 
+static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
+static struct smap *keepalive_stats OVS_GUARDED_BY(mutex);
+
 inline bool
 ka_is_enabled(void)
 {
@@ -266,6 +270,75 @@  keepalive_info_create(void)
     return ka_info;
 }
 
+static void
+get_pmd_status(struct smap *ka_pmd_stats)
+    OVS_REQUIRES(ka_info->proclist_mutex)
+{
+    if (OVS_UNLIKELY(!ka_info)) {
+        return;
+    }
+
+    struct ka_process_info *pinfo, *pinfo_next;
+    HMAP_FOR_EACH_SAFE (pinfo, pinfo_next, node, &ka_info->process_list) {
+        int core_id = pinfo->core_id;
+        char *state = NULL;
+        if (pinfo->core_state == KA_STATE_UNUSED ||
+               pinfo->core_state == KA_STATE_SLEEP ) {
+            continue;
+        }
+
+        switch (pinfo->core_state) {
+        case KA_STATE_ALIVE:
+            state = "ALIVE";
+            break;
+        case KA_STATE_MISSING:
+            state = "MISSING";
+            break;
+        case KA_STATE_DEAD:
+            state = "DEAD";
+            break;
+        case KA_STATE_GONE:
+            state = "GONE";
+            break;
+        case KA_STATE_DOZING:
+            state = "DOZING";
+            break;
+        case KA_STATE_SLEEP:
+            state = "SLEEP";
+            break;
+        case KA_STATE_CHECK:
+            state = "HEALTH_CHECK_RUNNING";
+            break;
+        case KA_STATE_UNUSED:
+            break;
+        }
+
+        smap_add_format(ka_pmd_stats, pinfo->name, "%s,%d,%ld",
+                        state, core_id, pinfo->core_last_seen_times);
+    }
+}
+
+void
+get_ka_stats(void)
+{
+    struct smap *ka_pmd_stats;
+    ka_pmd_stats = xmalloc(sizeof *ka_pmd_stats);
+    smap_init(ka_pmd_stats);
+
+    ovs_mutex_lock(&ka_info->proclist_mutex);
+    get_pmd_status(ka_pmd_stats);
+    ovs_mutex_unlock(&ka_info->proclist_mutex);
+
+    ovs_mutex_lock(&mutex);
+    if (keepalive_stats) {
+        smap_destroy(keepalive_stats);
+        free(keepalive_stats);
+        keepalive_stats = NULL;
+    }
+    keepalive_stats = ka_pmd_stats;
+    ovs_mutex_unlock(&mutex);
+}
+
 static int
 ka_init__(void)
 {
diff --git a/lib/keepalive.h b/lib/keepalive.h
index 31ee34c..b18f6e0 100644
--- a/lib/keepalive.h
+++ b/lib/keepalive.h
@@ -100,6 +100,7 @@  uint32_t get_ka_interval(void);
 int get_ka_init_status(void);
 int ka_alloc_portstats(unsigned, int);
 void ka_destroy_portstats(void);
+void get_ka_stats(void);
 
 void dispatch_heartbeats(void);
 #endif /* keepalive.h */