This commit moves the code that sets the pmd threads affinity from netdev-dpdk to ovs-numa. There's one small part left in netdev-dpdk, to set the lcore_id.
Now dpif-netdev will call both modules (ovs-numa and netdev-dpdk) when starting a pmd thread. This change will allow having a dummy implementation of the set affinity call, for testing purposes. Signed-off-by: Daniele Di Proietto <diproiet...@vmware.com> --- lib/dpif-netdev.c | 3 ++- lib/netdev-dpdk.c | 16 ++-------------- lib/netdev-dpdk.h | 8 ++++---- lib/ovs-numa.c | 20 ++++++++++++++++++++ lib/ovs-numa.h | 1 + 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 61a939a..fcfd22e 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2839,7 +2839,8 @@ pmd_thread_main(void *f_) /* Stores the pmd thread's 'pmd' to 'per_pmd_key'. */ ovsthread_setspecific(pmd->dp->per_pmd_key, pmd); - pmd_thread_setaffinity_cpu(pmd->core_id); + ovs_numa_thread_setaffinity_core(pmd->core_id); + dpdk_set_lcore_id(pmd->core_id); poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list); reload: emc_cache_init(&pmd->flow_cache); diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 22891b2..19d355f 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -3502,24 +3502,12 @@ netdev_dpdk_register(void) #endif } -int -pmd_thread_setaffinity_cpu(unsigned cpu) +void +dpdk_set_lcore_id(unsigned 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; - } /* NON_PMD_CORE_ID is reserved for use by non pmd threads. */ ovs_assert(cpu != NON_PMD_CORE_ID); RTE_PER_LCORE(_lcore_id) = cpu; - - return 0; } static bool diff --git a/lib/netdev-dpdk.h b/lib/netdev-dpdk.h index ee748e0..80bb834 100644 --- a/lib/netdev-dpdk.h +++ b/lib/netdev-dpdk.h @@ -25,7 +25,7 @@ struct smap; void netdev_dpdk_register(void); void free_dpdk_buf(struct dp_packet *); -int pmd_thread_setaffinity_cpu(unsigned cpu); +void dpdk_set_lcore_id(unsigned cpu); #else @@ -45,10 +45,10 @@ free_dpdk_buf(struct dp_packet *buf OVS_UNUSED) /* Nothing */ } -static inline int -pmd_thread_setaffinity_cpu(unsigned cpu OVS_UNUSED) +static inline void +dpdk_set_lcore_id(unsigned cpu OVS_UNUSED) { - return 0; + /* Nothing */ } #endif /* DPDK_NETDEV */ diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c index 461d734..7bb2bcc 100644 --- a/lib/ovs-numa.c +++ b/lib/ovs-numa.c @@ -473,3 +473,23 @@ ovs_numa_set_cpu_mask(const char *cmask) core->available = false; } } + +int ovs_numa_thread_setaffinity_core(unsigned core_id) +{ +#ifdef __linux__ + cpu_set_t cpuset; + int err; + + CPU_ZERO(&cpuset); + CPU_SET(core_id, &cpuset); + err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + if (err) { + VLOG_ERR("Thread affinity error %d",err); + return err; + } + + return 0; +#else /* !__linux__ */ + return EOPNOTSUPP; +#endif /* __linux__ */ +} diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h index c2619d1..5b3444b 100644 --- a/lib/ovs-numa.h +++ b/lib/ovs-numa.h @@ -54,6 +54,7 @@ unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id); void ovs_numa_unpin_core(unsigned core_id); struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id); void ovs_numa_dump_destroy(struct ovs_numa_dump *); +int ovs_numa_thread_setaffinity_core(unsigned core_id); #define FOR_EACH_CORE_ON_NUMA(ITER, DUMP) \ LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump) -- 2.8.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev