Message ID | 1512734667-23202-5-git-send-email-bhanuprakash.bodireddy@intel.com |
---|---|
State | Changes Requested |
Headers | show |
Series | Add OVS DPDK keep-alive functionality. | expand |
LGTM, Tested-by: Antonio Fischetti <antonio.fischetti@intel.com> Acked-by: Antonio Fischetti <antonio.fischetti@intel.com> > -----Original Message----- > From: ovs-dev-bounces@openvswitch.org [mailto:ovs-dev- > bounces@openvswitch.org] On Behalf Of Bhanuprakash Bodireddy > Sent: Friday, December 8, 2017 12:04 PM > To: dev@openvswitch.org > Subject: [ovs-dev] [PATCH v6 4/8] keepalive: Retrieve PMD status > periodically. > > 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.bodireddy@intel.com> > --- > lib/dpif-netdev.c | 1 + > lib/keepalive.c | 63 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > lib/keepalive.h | 1 + > 3 files changed, 65 insertions(+) > > diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c > index 9021906..e9fa3c1 100644 > --- a/lib/dpif-netdev.c > +++ b/lib/dpif-netdev.c > @@ -1039,6 +1039,7 @@ ovs_keepalive(void *f_) > /* Dispatch heartbeats only if pmd[s] exist. */ > if (hb_enable) { > dispatch_heartbeats(); > + get_ka_stats(); > } > > xnanosleep(interval * 1000 * 1000); > diff --git a/lib/keepalive.c b/lib/keepalive.c > index 0e4b2b6..7d3dbad 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,65 @@ 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_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 cbc2387..2bae8f1 100644 > --- a/lib/keepalive.h > +++ b/lib/keepalive.h > @@ -100,6 +100,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 > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 9021906..e9fa3c1 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1039,6 +1039,7 @@ ovs_keepalive(void *f_) /* Dispatch heartbeats only if pmd[s] exist. */ if (hb_enable) { dispatch_heartbeats(); + get_ka_stats(); } xnanosleep(interval * 1000 * 1000); diff --git a/lib/keepalive.c b/lib/keepalive.c index 0e4b2b6..7d3dbad 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,65 @@ 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_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 cbc2387..2bae8f1 100644 --- a/lib/keepalive.h +++ b/lib/keepalive.h @@ -100,6 +100,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);
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.bodireddy@intel.com> --- lib/dpif-netdev.c | 1 + lib/keepalive.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/keepalive.h | 1 + 3 files changed, 65 insertions(+)