netdev-dpdk: Use multiple core for dpdk IO.
authorPravin <pshelar@nicira.com>
Fri, 21 Mar 2014 05:07:44 +0000 (22:07 -0700)
committerPravin B Shelar <pshelar@nicira.com>
Fri, 21 Mar 2014 18:48:28 +0000 (11:48 -0700)
DPDK need to set _lcore_id for using multiple core.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Thomas Graf <tgraf@redhat.com>
lib/dpif-netdev.c
lib/netdev-dpdk.c
lib/netdev-dpdk.h

index d1097e9..4d04629 100644 (file)
@@ -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);
index 520d642..f6adf87 100644 (file)
@@ -1196,3 +1196,21 @@ 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;
+    }
+    RTE_PER_LCORE(_lcore_id) = cpu;
+
+    return 0;
+}
index 5449a6b..55984e8 100644 (file)
 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