lib/vhost: set g_vhost_core_mask to all cores rather than threads

spdk_vhost_init() relies on having a thread on each reactor.
Every vhost controller could be created on the same core and
even passing --cpumask when creating would not affect it.

This has happened before, see patch (7cc83b62).

This patch modifies the g_vhost_core_mask to match the actual
cores in use.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I42a07c5f99690bfa4ecd2a5b9b7b04d1aa7d2800
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6188
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Tomasz Zawadzki 2021-01-29 14:04:48 -05:00
parent b74363bcdf
commit ce9efeda3a

View File

@ -926,26 +926,6 @@ vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
return 0;
}
static void
vhost_setup_core_mask(void *ctx)
{
struct spdk_thread *thread = spdk_get_thread();
spdk_cpuset_or(&g_vhost_core_mask, spdk_thread_get_cpumask(thread));
}
static void
vhost_setup_core_mask_done(void *ctx)
{
spdk_vhost_init_cb init_cb = ctx;
if (spdk_cpuset_count(&g_vhost_core_mask) == 0) {
init_cb(-ECHILD);
return;
}
init_cb(0);
}
static void
vhost_dev_thread_exit(void *arg1)
{
@ -1573,7 +1553,8 @@ void
spdk_vhost_init(spdk_vhost_init_cb init_cb)
{
size_t len;
int ret;
uint32_t i;
int ret = 0;
g_vhost_init_thread = spdk_get_thread();
assert(g_vhost_init_thread != NULL);
@ -1600,12 +1581,9 @@ spdk_vhost_init(spdk_vhost_init_cb init_cb)
}
spdk_cpuset_zero(&g_vhost_core_mask);
/* iterate threads instead of using SPDK_ENV_FOREACH_CORE to ensure that threads are really
* created.
*/
spdk_for_each_thread(vhost_setup_core_mask, init_cb, vhost_setup_core_mask_done);
return;
SPDK_ENV_FOREACH_CORE(i) {
spdk_cpuset_set_cpu(&g_vhost_core_mask, i, true);
}
out:
init_cb(ret);
}