From 8e68dfd99f90e7d9c079d1f9f3af14ce76af76a9 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Thu, 8 Aug 2019 14:08:03 +0200 Subject: [PATCH] rte_vhost: unaffinitize the thread inside rte_vhost API function We used to call rte_vhost_driver_start() under spdk_call_unaffinitized() because that function could spawn a new pthread and we didn't want to to be pinned to the one single cpu of the current SPDK reactor. New DPDK versions (>= 19.05) already unaffinitize the pthread by themselves, so our spdk_call_unaffinitized() was only required for the legacy, internal rte_vhost fork in SPDK. To clean up SPDK code, move the un-affinitization down to the rte_vhost fork. Change-Id: I53836517e9ec2ff366b509f00e1403845e3c3172 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466746 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/rte_vhost/socket.c | 17 ++++++++++++++++- lib/vhost/vhost.c | 19 +------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/rte_vhost/socket.c b/lib/rte_vhost/socket.c index 1d69e630e..2b2716a5d 100644 --- a/lib/rte_vhost/socket.c +++ b/lib/rte_vhost/socket.c @@ -809,8 +809,23 @@ rte_vhost_driver_start(const char *path) return -1; if (fdset_tid == 0) { - int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch, + rte_cpuset_t orig_cpuset; + rte_cpuset_t tmp_cpuset; + long num_cores, i; + int ret; + + CPU_ZERO(&tmp_cpuset); + num_cores = sysconf(_SC_NPROCESSORS_CONF); + /* Create a mask containing all CPUs */ + for (i = 0; i < num_cores; i++) { + CPU_SET(i, &tmp_cpuset); + } + + rte_thread_get_affinity(&orig_cpuset); + rte_thread_set_affinity(&tmp_cpuset); + ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch, &vhost_user.fdset); + rte_thread_set_affinity(&orig_cpuset); if (ret < 0) RTE_LOG(ERR, VHOST_CONFIG, "failed to create fdset handling thread"); diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index c07b14664..8d46240e9 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -670,18 +670,6 @@ vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask) return 0; } -static void * -_start_rte_driver(void *arg) -{ - char *path = arg; - - if (rte_vhost_driver_start(path) != 0) { - return NULL; - } - - return path; -} - int vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, const struct spdk_vhost_dev_backend *backend) @@ -783,12 +771,7 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma vhost_dev_install_rte_compat_hooks(vdev); - /* The following might start a POSIX thread that polls for incoming - * socket connections and calls backend->start/stop_device. These backend - * callbacks are also protected by the global SPDK vhost mutex, so we're - * safe with not initializing the vdev just yet. - */ - if (spdk_call_unaffinitized(_start_rte_driver, path) == NULL) { + if (rte_vhost_driver_start(path) != 0) { SPDK_ERRLOG("Failed to start vhost driver for controller %s (%d): %s\n", name, errno, spdk_strerror(errno)); rte_vhost_driver_unregister(path);