@@ -48,3 +48,33 @@ dpdk_get_vhost_sock_dir(void)
{
return NULL;
}
+
+void
+dpdk_ka_register_core(unsigned core_id OVS_UNUSED)
+{
+ /* Nothing */
+}
+
+void
+dpdk_ka_get_tid(unsigned core_idx OVS_UNUSED)
+{
+ /* Nothing */
+}
+
+bool
+dpdk_is_ka_enabled(void)
+{
+ return false;
+}
+
+void
+ka_mark_core_alive(void)
+{
+ /* Nothing */
+}
+
+void
+ka_mark_core_sleep(void)
+{
+ /* Nothing */
+}
@@ -15,6 +15,7 @@
*/
#include <config.h>
+#include <stdbool.h>
#include "dpdk.h"
#include <stdio.h>
@@ -22,6 +23,7 @@
#include <sys/stat.h>
#include <getopt.h>
+#include <rte_keepalive.h>
#include <rte_log.h>
#include <rte_memzone.h>
#ifdef DPDK_PDUMP
@@ -42,6 +44,10 @@ static FILE *log_stream = NULL; /* Stream for DPDK log redirection */
static char *vhost_sock_dir = NULL; /* Location of vhost-user sockets */
+bool keepalive_enable = false; /* KeepAlive disabled by default */
+static uint32_t keepalive_timer_interval; /* keepalive timer interval */
+static const char *keepalive_shm_blk = NULL;
+
static int
process_vhost_flags(char *flag, const char *default_val, int size,
const struct smap *ovs_other_config,
@@ -67,6 +73,36 @@ process_vhost_flags(char *flag, const char *default_val, int size,
return changed;
}
+/* Retrieve and return the keepalive timer interval from OVSDB. */
+static uint32_t
+get_ka_timer_interval(const struct smap *ovs_other_config)
+{
+#define OVS_KEEPALIVE_TIMEOUT 100 /* Default timeout set to 100ms */
+ uint32_t ka_interval;
+
+ /* Timer granularity in milliseconds
+ * Defaults to OVS_KEEPALIVE_TIMEOUT(ms) if not set */
+ ka_interval = smap_get_int(ovs_other_config, "keepalive-interval",
+ OVS_KEEPALIVE_TIMEOUT);
+
+ VLOG_INFO("KeepAlive timer interval set to %"PRIu32" (ms)\n", ka_interval);
+ return ka_interval;
+}
+
+static const char *
+get_ka_shm_block(const struct smap *ovs_other_config)
+{
+/* Shared mem block. */
+#define OVS_KEEPALIVE_SHM_NAME /dpdk_keepalive_shm_name
+ keepalive_shm_blk = smap_get(ovs_other_config, "keepalive-shm-name");
+ if (!keepalive_shm_blk) {
+ keepalive_shm_blk = OVS_STRINGIZE(OVS_KEEPALIVE_SHM_NAME);
+ }
+
+ VLOG_INFO("KeepAlive shared memory block: %s\n", keepalive_shm_blk);
+ return keepalive_shm_blk;
+}
+
static char **
grow_argv(char ***argv, size_t cur_siz, size_t grow_by)
{
@@ -432,6 +468,14 @@ dpdk_init__(const struct smap *ovs_other_config)
/* We are called from the main thread here */
RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID;
+ if (smap_get_bool(ovs_other_config, "keepalive", false)) {
+ keepalive_enable = true;
+ VLOG_INFO("OvS-DPDK KeepAlive enabled\n");
+
+ keepalive_timer_interval = get_ka_timer_interval(ovs_other_config);
+ keepalive_shm_blk = get_ka_shm_block(ovs_other_config);
+ }
+
#ifdef DPDK_PDUMP
VLOG_INFO("DPDK pdump packet capture enabled");
err = rte_pdump_init(ovs_rundir());
@@ -489,3 +533,51 @@ dpdk_set_lcore_id(unsigned cpu)
ovs_assert(cpu != NON_PMD_CORE_ID);
RTE_PER_LCORE(_lcore_id) = cpu;
}
+
+/* Return 'true' if KA enabled, otherwise 'false'. */
+inline bool
+dpdk_is_ka_enabled(void)
+{
+ return keepalive_enable;
+}
+
+/* Return the Keepalive timer interval. */
+uint32_t
+dpdk_get_ka_interval(void)
+{
+ return keepalive_timer_interval;
+}
+
+/* Return the Keepalive shared memory block name. */
+const char *
+dpdk_get_ka_shm(void)
+{
+ return keepalive_shm_blk;
+}
+
+/* Register Packet processing core 'core_id' for liveness checks. */
+void
+dpdk_ka_register_core(unsigned core_id)
+{
+ if (dpdk_is_ka_enabled()) {
+ rte_keepalive_register_core(rte_global_keepalive_info, core_id);
+ }
+}
+
+/* Mark Packet processing core alive. */
+void
+ka_mark_core_alive(void)
+{
+ if (dpdk_is_ka_enabled()) {
+ rte_keepalive_mark_alive(rte_global_keepalive_info);
+ }
+}
+
+/* Mark packet processing core as idle. */
+void
+ka_mark_core_sleep(void)
+{
+ if (dpdk_is_ka_enabled()) {
+ rte_keepalive_mark_sleep(rte_global_keepalive_info);
+ }
+}
@@ -26,6 +26,9 @@
#else
+#include <stdint.h>
+#include <stdbool.h>
+
#define NON_PMD_CORE_ID UINT32_MAX
#endif /* DPDK_NETDEV */
@@ -35,5 +38,11 @@ struct smap;
void dpdk_init(const struct smap *ovs_other_config);
void dpdk_set_lcore_id(unsigned cpu);
const char *dpdk_get_vhost_sock_dir(void);
-
+uint32_t dpdk_get_ka_interval(void);
+bool dpdk_is_ka_enabled(void);
+void dpdk_ka_register_core(unsigned core_id);
+void ka_mark_core_alive(void);
+void ka_mark_core_sleep(void);
+const char *dpdk_get_ka_shm(void);
+void dpdk_ka_get_tid(unsigned core_id);
#endif /* dpdk.h */
Introduce helper functions in 'dpdk' module that are needed for keepalive functionality. Also add dummy functions in 'dpdk-stub' module that are needed when DPDK is not available. Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com> --- lib/dpdk-stub.c | 30 +++++++++++++++++++ lib/dpdk.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/dpdk.h | 11 ++++++- 3 files changed, 132 insertions(+), 1 deletion(-)