DPDK need to set _lcore_id for using multiple core.

Signed-off-by: Pravin B Shelar <pshe...@nicira.com>
---
Moved thread affinity function to dpdk.
---
 lib/dpif-netdev.c |    2 ++
 lib/netdev-dpdk.c |   20 ++++++++++++++++++++
 lib/netdev-dpdk.h |    2 ++
 3 files changed, 24 insertions(+)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index d11c0d1..72d0168 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -43,6 +43,7 @@
 #include "list.h"
 #include "meta-flow.h"
 #include "netdev.h"
+#include "netdev-dpdk.h"
 #include "netdev-vport.h"
 #include "netlink.h"
 #include "odp-execute.h"
@@ -1864,6 +1865,7 @@ pmd_thread_main(void *f_)
     poll_cnt = 0;
     poll_list = NULL;
 
+    pmd_thread_setaffinity_cpu(f->id);
 reload:
     poll_cnt = pmd_load_queues(f, &poll_list, poll_cnt);
     atomic_read(&f->change_seq, &port_seq);
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index da38d1b..4fe88b3 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -1199,3 +1199,23 @@ netdev_dpdk_register(void)
 {
     netdev_register_provider(&netdev_dpdk_class);
 }
+
+int
+pmd_thread_setaffinity_cpu(int cpu)
+{
+    cpu_set_t cpuset;
+    int err;
+
+    CPU_ZERO(&cpuset);
+    CPU_SET(cpu, &cpuset);
+    err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+    if (err) {
+        VLOG_ERR("Thread affinity error %d",err);
+        return err;
+    }
+#ifdef DPDK_NETDEV
+    RTE_PER_LCORE(_lcore_id) = cpu;
+#endif
+
+    return 0;
+}
diff --git a/lib/netdev-dpdk.h b/lib/netdev-dpdk.h
index 7897110..d9ffdb6 100644
--- a/lib/netdev-dpdk.h
+++ b/lib/netdev-dpdk.h
@@ -21,12 +21,14 @@
 int dpdk_init(int argc, char **argv);
 void netdev_dpdk_register(void);
 void free_dpdk_buf(struct ofpbuf *);
+int pmd_thread_setaffinity_cpu(int cpu);
 
 #else
 
 #define dpdk_init(arg1, arg2) (0)
 #define netdev_dpdk_register() 
 #define free_dpdk_buf(arg) 
+#define pmd_thread_setaffinity_cpu(c) (0)
 
 #endif /* DPDK_NETDEV */
 #endif
-- 
1.7.9.5

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

Reply via email to