diff mbox

[ovs-dev,RFC,13/13] dpdk: Late initialization.

Message ID 20161005012224.107729-14-diproiettod@vmware.com
State RFC
Headers show

Commit Message

Daniele Di Proietto Oct. 5, 2016, 1:22 a.m. UTC
With this commit, we allow the user to set other_config:dpdk-init=true
after the process is started.  This makes it easier to start Open
vSwitch with DPDK using standard init scripts without restarting the
service.

This is still far from ideal, because initializing DPDK might still
abort the process (e.g. if there not enough memory), so the user must
check the status of the process after setting dpdk-init to true.

Nonetheless, I think this is an improvement, because it doesn't require
restarting the whole unit.

CC: Aaron Conole <aconole@redhat.com>
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
---
 lib/dpdk-stub.c         |  8 ++++----
 lib/dpdk.c              | 30 ++++++++++++++++++++----------
 tests/ofproto-macros.at |  2 +-
 3 files changed, 25 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c
index 42196c4..b6ae6f6 100644
--- a/lib/dpdk-stub.c
+++ b/lib/dpdk-stub.c
@@ -27,13 +27,13 @@  VLOG_DEFINE_THIS_MODULE(dpdk);
 void
 dpdk_init(const struct smap *ovs_other_config)
 {
-    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+    if (smap_get_bool(ovs_other_config, "dpdk-init", false)) {
+        static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
 
-    if (ovsthread_once_start(&once)) {
-        if (smap_get_bool(ovs_other_config, "dpdk-init", false)) {
+        if (ovsthread_once_start(&once)) {
             VLOG_ERR("DPDK not supported in this copy of Open vSwitch.");
+            ovsthread_once_done(&once);
         }
-        ovsthread_once_done(&once);
     }
 }
 
diff --git a/lib/dpdk.c b/lib/dpdk.c
index caea0f4..9d0708a 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -270,12 +270,6 @@  dpdk_init__(const struct smap *ovs_other_config)
     cpu_set_t cpuset;
     char *sock_dir_subcomponent;
 
-    if (!smap_get_bool(ovs_other_config, "dpdk-init", false)) {
-        VLOG_INFO("DPDK Disabled - to change this requires a restart.\n");
-        return;
-    }
-
-    VLOG_INFO("DPDK Enabled, initializing");
     if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()),
                             NAME_MAX, ovs_other_config,
                             &sock_dir_subcomponent)) {
@@ -409,11 +403,27 @@  dpdk_init__(const struct smap *ovs_other_config)
 void
 dpdk_init(const struct smap *ovs_other_config)
 {
-    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+    static bool enabled = false;
+
+    if (enabled || !ovs_other_config) {
+        return;
+    }
+
+    if (smap_get_bool(ovs_other_config, "dpdk-init", false)) {
+        static struct ovsthread_once once_enable = OVSTHREAD_ONCE_INITIALIZER;
 
-    if (ovs_other_config && ovsthread_once_start(&once)) {
-        dpdk_init__(ovs_other_config);
-        ovsthread_once_done(&once);
+        if (ovsthread_once_start(&once_enable)) {
+            VLOG_INFO("DPDK Enabled - initializing...");
+            dpdk_init__(ovs_other_config);
+            VLOG_INFO("DPDK Enabled - initialized");
+            ovsthread_once_done(&once_enable);
+        }
+    } else {
+        static struct ovsthread_once once_disable = OVSTHREAD_ONCE_INITIALIZER;
+        if (ovsthread_once_start(&once_disable)) {
+            VLOG_INFO("DPDK Disabled - Use other_config:dpdk-init to enable");
+            ovsthread_once_done(&once_disable);
+        }
     }
 }
 
diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index 92ab9ab..ef97256 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -331,7 +331,7 @@  m4_define([_OVS_VSWITCHD_START],
 /ofproto|INFO|using datapath ID/d
 /netdev_linux|INFO|.*device has unknown hardware address family/d
 /ofproto|INFO|datapath ID changed to fedcba9876543210/d
-/dpdk|INFO|DPDK Disabled - to change this requires a restart./d']])
+/dpdk|INFO|DPDK Disabled - Use other_config:dpdk-init to enable/d']])
 ])
 
 # OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override],