2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 08:15:25 +00:00

dpdk: Use ovs-numa provided functions to manage thread affinity.

This allows to decrease code duplication and avoid using Linux-specific
functions (this might be useful in the future if we'll try to allow
running OvS+DPDK on FreeBSD).

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Acked-by: William Tu <u9012063@gmail.com>
This commit is contained in:
Ilya Maximets
2019-08-13 14:28:26 +03:00
parent 1276e3db89
commit 15d8655b1f

View File

@@ -275,7 +275,7 @@ dpdk_init__(const struct smap *ovs_other_config)
int result; int result;
bool auto_determine = true; bool auto_determine = true;
int err = 0; int err = 0;
cpu_set_t cpuset; struct ovs_numa_dump *affinity = NULL;
struct svec args = SVEC_EMPTY_INITIALIZER; struct svec args = SVEC_EMPTY_INITIALIZER;
log_stream = fopencookie(NULL, "w+", dpdk_log_func); log_stream = fopencookie(NULL, "w+", dpdk_log_func);
@@ -357,22 +357,22 @@ dpdk_init__(const struct smap *ovs_other_config)
* lcore for the DPDK Master. * lcore for the DPDK Master.
*/ */
if (auto_determine) { if (auto_determine) {
const struct ovs_numa_info_core *core;
int cpu = 0; int cpu = 0;
/* Get the main thread affinity */ /* Get the main thread affinity */
CPU_ZERO(&cpuset); affinity = ovs_numa_thread_getaffinity_dump();
err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), if (affinity) {
&cpuset); cpu = INT_MAX;
if (!err) { FOR_EACH_CORE_ON_DUMP (core, affinity) {
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { if (cpu > core->core_id) {
if (CPU_ISSET(cpu, &cpuset)) { cpu = core->core_id;
break;
} }
} }
} else { } else {
/* User did not set dpdk-lcore-mask and unable to get current /* User did not set dpdk-lcore-mask and unable to get current
* thread affintity - default to core #0 */ * thread affintity - default to core #0 */
VLOG_ERR("Thread getaffinity error %d. Using core #0", err); VLOG_ERR("Thread getaffinity failed. Using core #0");
} }
svec_add(&args, "-l"); svec_add(&args, "-l");
svec_add_nocopy(&args, xasprintf("%d", cpu)); svec_add_nocopy(&args, xasprintf("%d", cpu));
@@ -403,12 +403,9 @@ dpdk_init__(const struct smap *ovs_other_config)
svec_destroy(&args); svec_destroy(&args);
/* Set the main thread affinity back to pre rte_eal_init() value */ /* Set the main thread affinity back to pre rte_eal_init() value */
if (auto_determine && !err) { if (affinity) {
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), ovs_numa_thread_setaffinity_dump(affinity);
&cpuset); ovs_numa_dump_destroy(affinity);
if (err) {
VLOG_ERR("Thread setaffinity error %d", err);
}
} }
if (result < 0) { if (result < 0) {