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(epoch)" eg: pmd62="ALIVE,2,1503333332575" pmd63="GONE,3,1503333332525" 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,1503333332575" "pmd63"="ALIVE,1,1503333332575" "pmd64"="ALIVE,2,1503333332575" "pmd65"="ALIVE,3,1503333332575" Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodire...@intel.com> --- lib/dpif-netdev.c | 1 + lib/keepalive.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/keepalive.h | 1 + 3 files changed, 68 insertions(+) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index fd0ce61..56a3422 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1038,6 +1038,7 @@ ovs_keepalive(void *f_) /* Dispatch heartbeats only if pmd[s] exist. */ if (hb_enable) { dispatch_heartbeats(); + get_ka_stats(); } xnanosleep(interval); diff --git a/lib/keepalive.c b/lib/keepalive.c index 3067e73..fe81919 100644 --- a/lib/keepalive.c +++ b/lib/keepalive.c @@ -19,6 +19,7 @@ #include "keepalive.h" #include "lib/vswitch-idl.h" #include "openvswitch/vlog.h" +#include "ovs-thread.h" #include "process.h" #include "seq.h" #include "timeval.h" @@ -29,6 +30,9 @@ static bool keepalive_enable = false; /* Keepalive disabled by default. */ static uint32_t keepalive_timer_interval; /* keepalive timer interval. */ static struct keepalive_info ka_info; +static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; +static struct smap *keepalive_stats OVS_GUARDED_BY(mutex); + /* Returns true if state update is allowed, false otherwise. */ static bool ka_can_update_state(void) @@ -284,6 +288,68 @@ ka_mark_pmd_thread_sleep(int tid) } } +static void +get_pmd_status(struct smap *ka_pmd_stats) + OVS_REQUIRES(ka_info.proclist_mutex) +{ + struct ka_process_info *pinfo, *pinfo_next; + HMAP_FOR_EACH_SAFE (pinfo, pinfo_next, node, &ka_info.process_list) { + char *state = NULL; + if (pinfo->state == KA_STATE_UNUSED) { + continue; + } + + switch (pinfo->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_UNUSED: + break; + default: + OVS_NOT_REACHED(); + } + + smap_add_format(ka_pmd_stats, pinfo->name, "%s,%d,%ld", + state, pinfo->core_id, pinfo->last_seen_time); + } +} + +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); +} + /* Dispatch heartbeats from 'ovs_keepalive' thread. */ void dispatch_heartbeats(void) diff --git a/lib/keepalive.h b/lib/keepalive.h index 392a701..6e6ec68 100644 --- a/lib/keepalive.h +++ b/lib/keepalive.h @@ -102,6 +102,7 @@ void ka_free_cached_threads(void); void ka_cache_registered_threads(void); void ka_mark_pmd_thread_alive(int); void ka_mark_pmd_thread_sleep(int); +void get_ka_stats(void); void dispatch_heartbeats(void); void ka_init(const struct smap *); void ka_destroy(void); -- 2.4.11 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev