diff mbox

[ovs-dev,v12,1/6] netdev-dpdk: Restore thread affinity after DPDK init

Message ID 1461699769-8496-2-git-send-email-aconole@redhat.com
State Superseded
Headers show

Commit Message

Aaron Conole April 26, 2016, 7:42 p.m. UTC
When the DPDK init function is called, it changes the executing thread's
CPU affinity to a single core specified in -c. This will result in the
userspace bridge configuration thread being rebound, even if that is not
the intent.

This change fixes that behavior by rebinding to the original thread
affinity after calling dpdk_init().

Co-authored-by: Kevin Traynor <kevin.traynor@intel.com>
Signed-off-by: Kevin Traynor <kevin.traynor@intel.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
Tested-by: RobertX Wojciechowicz <robertx.wojciechowicz@intel.com>
Tested-by: Sean K Mooney <sean.k.mooney@intel.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
---
Previous: http://openvswitch.org/pipermail/dev/2016-April/069026.html

v12:
* No change

 lib/netdev-dpdk.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 208c5f5..c4b6476 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2763,6 +2763,9 @@  dpdk_init(int argc, char **argv)
     int result;
     int base = 0;
     char *pragram_name = argv[0];
+    int err;
+    int isset;
+    cpu_set_t cpuset;
 
     if (argc < 2 || strcmp(argv[1], "--dpdk"))
         return 0;
@@ -2804,6 +2807,14 @@  dpdk_init(int argc, char **argv)
         base = 2;
     }
 
+    /* Get the main thread affinity */
+    CPU_ZERO(&cpuset);
+    err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+    if (err) {
+        VLOG_ERR("Thread getaffinity error %d.", err);
+        return err;
+    }
+
     /* Keep the program name argument as this is needed for call to
      * rte_eal_init()
      */
@@ -2815,6 +2826,13 @@  dpdk_init(int argc, char **argv)
         ovs_abort(result, "Cannot init EAL");
     }
 
+    /* Set the main thread affinity back to pre rte_eal_init() value */
+    err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+    if (err) {
+        VLOG_ERR("Thread setaffinity error %d", err);
+        return err;
+    }
+
     rte_memzone_dump(stdout);
     rte_eal_init_ret = 0;