DPDK need to set _lcore_id for using multiple core.
Signed-off-by: Pravin B Shelar <[email protected]>
---
lib/dpif-netdev.c | 1 +
lib/ovs-thread.c | 22 ++++++++++++++++++++++
lib/ovs-thread.h | 2 ++
3 files changed, 25 insertions(+)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index bf7549d..8e5449a 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1778,6 +1778,7 @@ pmd_thread_main(void *f_)
poll_cnt = 0;
poll_list = NULL;
+ xpthread_setaffinity_np_cpu(pthread_self(), f->id);
reload:
poll_cnt = pmd_load_queues(f, &poll_list, poll_cnt);
atomic_read(&f->change_seq, &port_seq);
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 76cbbd3..7cbde22 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include "compiler.h"
#include "hash.h"
+#include "netdev-dpdk.h"
#include "poll-loop.h"
#include "socket-util.h"
#include "util.h"
@@ -288,6 +289,27 @@ xpthread_create(pthread_t *threadp, pthread_attr_t *attr,
ovs_abort(error, "pthread_create failed");
}
}
+
+int
+xpthread_setaffinity_np_cpu(pthread_t thread, 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\n",err);
+ return err;
+ }
+#ifdef DPDK_NETDEV
+ RTE_PER_LCORE(_lcore_id) = cpu;
+#endif
+
+ return 0;
+}
+
bool
ovsthread_once_start__(struct ovsthread_once *once)
diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h
index d3bd538..1e5eda2 100644
--- a/lib/ovs-thread.h
+++ b/lib/ovs-thread.h
@@ -158,6 +158,8 @@ void xpthread_setspecific(pthread_key_t, const void *);
void xpthread_create(pthread_t *, pthread_attr_t *, void *(*)(void *), void *);
void xpthread_join(pthread_t, void **);
+int xpthread_setaffinity_np_cpu(pthread_t thread, int cpu);
+
/* Per-thread data.
*
--
1.7.9.5
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev