diff mbox

[ovs-dev,v3] dpdk: Late initialization.

Message ID 20170110031702.123066-1-diproiettod@vmware.com
State Accepted
Headers show

Commit Message

Daniele Di Proietto Jan. 10, 2017, 3:17 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>
---
v3: Set 'enable' after dpdk_init__()
---
 lib/dpdk-stub.c         |  8 ++++----
 lib/dpdk.c              | 31 +++++++++++++++++++++----------
 tests/ofproto-macros.at |  2 +-
 3 files changed, 26 insertions(+), 15 deletions(-)

Comments

Aaron Conole Jan. 10, 2017, 2:54 p.m. UTC | #1
Daniele Di Proietto <diproiettod@vmware.com> writes:

> 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>
> ---

Acked-by: Aaron Conole <aconole@redhat.com>
Daniele Di Proietto Jan. 11, 2017, 6:59 a.m. UTC | #2
On 10/01/2017 06:54, "Aaron Conole" <aconole@redhat.com> wrote:

>Daniele Di Proietto <diproiettod@vmware.com> writes:
>
>> 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>
>> ---
>
>Acked-by: Aaron Conole <aconole@redhat.com>

Thanks for reviewing this, applied to master
diff mbox

Patch

diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c
index bd981bb90..daef7291f 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 ee4360b22..9ae249141 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -273,12 +273,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)) {
@@ -413,11 +407,28 @@  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);
+            enabled = true;
+            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 5477777b8..faff5b0a8 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],