The user has control over the DPDK internal lcore coremask, but this
parameter can be autofilled with a bit more intelligence. If the user
does not fill this parameter in, we use the lowest set bit in the
current task CPU affinity. Otherwise, we will reassign the current
thread to the specified lcore mask, in addition to the dpdk lcore
threads.

Signed-off-by: Aaron Conole <acon...@redhat.com>
Tested-by: Sean K Mooney <sean.k.moo...@intel.com>
Tested-by: RobertX Wojciechowicz <robertx.wojciechow...@intel.com>
Tested-by: Kevin Traynor <kevin.tray...@intel.com>
Acked-by: Panu Matilainen <pmati...@redhat.com>
Acked-by: Kevin Traynor <kevin.tray...@intel.com>
Acked-by: Flavio Leitner <f...@sysclose.org>
---
v2:
* Fix a conditional branch coding standard issue
* When lcore coremask is set, do not reset the affinities as
  suggested by Kevin Traynor

v3:
* Fixed grow_argv calls
* Fixed an error in argc assignment after 'break;' introduced
  in v2
* Switched to using xstrdup

v4->v7:
* No change

v8:
* Assign the lcore only when resetting the affinity.

v9,v10:
* No change

v11:
* Minor refactors due to previous changes
* Cleanups suggested by Daniele

 lib/netdev-dpdk.c | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 397a3fa..af5f765 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2792,7 +2792,6 @@ construct_dpdk_options(const struct ovsrec_open_vswitch 
*ovs_cfg,
         {"dpdk-mem-channels", "-n", false, NULL},
         {"dpdk-hugepage-dir", "--huge-dir", false, NULL},
     };
-
     int i, ret = initial_size;
 
     /*First, construct from the flat-options (non-mutex)*/
@@ -2873,9 +2872,10 @@ construct_dpdk_mutex_options(const struct 
ovsrec_open_vswitch *ovs_cfg,
 }
 
 static int
-get_dpdk_args(const struct ovsrec_open_vswitch *ovs_cfg, char ***argv)
+get_dpdk_args(const struct ovsrec_open_vswitch *ovs_cfg, char ***argv,
+              int argc)
 {
-    int i = construct_dpdk_options(ovs_cfg, argv, 1);
+    int i = construct_dpdk_options(ovs_cfg, argv, argc);
     i = construct_dpdk_mutex_options(ovs_cfg, argv, i);
     return i;
 }
@@ -2899,7 +2899,8 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
 {
     char **argv = NULL;
     int result;
-    int argc;
+    int argc, argc_tmp;
+    bool auto_determine = true;
     int err;
     cpu_set_t cpuset;
 #ifndef VHOST_CUSE
@@ -2941,9 +2942,34 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
         VLOG_ERR("Thread getaffinity error %d.", err);
     }
 
-    argv = grow_argv(&argv, 0, 1);
+    argv = grow_argv(&argv, argc, 1);
     argv[0] = xstrdup(ovs_get_program_name());
-    argc = get_dpdk_args(ovs_cfg, &argv);
+    argc_tmp = get_dpdk_args(ovs_cfg, &argv, argc);
+
+    while (argc_tmp != argc) {
+        if (!strcmp("-c", argv[argc]) || !strcmp("-l", argv[argc])) {
+            auto_determine = false;
+            break;
+        }
+        argc++;
+    }
+    argc = argc_tmp;
+
+    /**
+     * NOTE: This is an unsophisticated mechanism for determining the DPDK
+     * lcore for the DPDK Master.
+     */
+    if (auto_determine) {
+        int i;
+        for (i = 0; i < CPU_SETSIZE; i++) {
+            if (CPU_ISSET(i, &cpuset)) {
+                argv = grow_argv(&argv, argc, 2);
+                argv[argc++] = xstrdup("-c");
+                argv[argc++] = xasprintf("0x%08llX", (1ULL<<i));
+                i = CPU_SETSIZE;
+            }
+        }
+    }
 
     argv = grow_argv(&argv, argc, 1);
     argv[argc] = 0;
@@ -2957,7 +2983,7 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
     }
 
     /* Set the main thread affinity back to pre rte_eal_init() value */
-    if (!err) {
+    if (auto_determine) {
         err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
                                      &cpuset);
         if (err) {
-- 
2.5.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to