lib/vhost: use contructor to initalize g_dpdk_sem
Using contructor/destructor to handle g_dpdk_sem will help later in the series when splitting vhost fini between vhost.c and virtio abstraction. Otherwise multiple callbacks would be needed during vhost fini. Ex. spdk_vhost_fini -> vhost_user_fini to stop the sessions -> -> back to spdk_vhost_fini to remove vhost devices -> -> vhost_user_fini to destroy the g_dpdk_sem g_dpdk_sem will only be used from rte_vhost_user.c. Until all references are moved, it is placed in vhost_internal. Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I0505b906621f0eb0cb1226f96a3b6cf49f66778f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11055 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
parent
26dfb9a9fa
commit
c144d3669c
@ -47,6 +47,22 @@
|
|||||||
#include "spdk_internal/vhost_user.h"
|
#include "spdk_internal/vhost_user.h"
|
||||||
|
|
||||||
char g_vhost_user_dev_dirname[PATH_MAX] = "";
|
char g_vhost_user_dev_dirname[PATH_MAX] = "";
|
||||||
|
sem_t g_dpdk_sem;
|
||||||
|
|
||||||
|
static void __attribute__((constructor))
|
||||||
|
_vhost_user_sem_init(void)
|
||||||
|
{
|
||||||
|
if (sem_init(&g_dpdk_sem, 0, 0) != 0) {
|
||||||
|
SPDK_ERRLOG("Failed to initialize semaphore for rte_vhost pthread.\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __attribute__((destructor))
|
||||||
|
_vhost_user_sem_destroy(void)
|
||||||
|
{
|
||||||
|
sem_destroy(&g_dpdk_sem);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
vhost_session_mem_region_calc(uint64_t *previous_start, uint64_t *start, uint64_t *end,
|
vhost_session_mem_region_calc(uint64_t *previous_start, uint64_t *start, uint64_t *end,
|
||||||
|
@ -51,13 +51,6 @@ static struct spdk_thread *g_vhost_init_thread;
|
|||||||
|
|
||||||
static spdk_vhost_fini_cb g_fini_cpl_cb;
|
static spdk_vhost_fini_cb g_fini_cpl_cb;
|
||||||
|
|
||||||
/**
|
|
||||||
* DPDK calls our callbacks synchronously but the work those callbacks
|
|
||||||
* perform needs to be async. Luckily, all DPDK callbacks are called on
|
|
||||||
* a DPDK-internal pthread, so we'll just wait on a semaphore in there.
|
|
||||||
*/
|
|
||||||
static sem_t g_dpdk_sem;
|
|
||||||
|
|
||||||
/** Return code for the current DPDK callback */
|
/** Return code for the current DPDK callback */
|
||||||
static int g_dpdk_response;
|
static int g_dpdk_response;
|
||||||
|
|
||||||
@ -1524,8 +1517,8 @@ spdk_vhost_init(spdk_vhost_init_cb init_cb)
|
|||||||
if (g_vhost_user_dev_dirname[0] == '\0') {
|
if (g_vhost_user_dev_dirname[0] == '\0') {
|
||||||
if (getcwd(g_vhost_user_dev_dirname, sizeof(g_vhost_user_dev_dirname) - 1) == NULL) {
|
if (getcwd(g_vhost_user_dev_dirname, sizeof(g_vhost_user_dev_dirname) - 1) == NULL) {
|
||||||
SPDK_ERRLOG("getcwd failed (%d): %s\n", errno, spdk_strerror(errno));
|
SPDK_ERRLOG("getcwd failed (%d): %s\n", errno, spdk_strerror(errno));
|
||||||
ret = -1;
|
init_cb(-1);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(g_vhost_user_dev_dirname);
|
len = strlen(g_vhost_user_dev_dirname);
|
||||||
@ -1535,18 +1528,10 @@ spdk_vhost_init(spdk_vhost_init_cb init_cb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sem_init(&g_dpdk_sem, 0, 0);
|
|
||||||
if (ret != 0) {
|
|
||||||
SPDK_ERRLOG("Failed to initialize semaphore for rte_vhost pthread.\n");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_cpuset_zero(&g_vhost_core_mask);
|
spdk_cpuset_zero(&g_vhost_core_mask);
|
||||||
SPDK_ENV_FOREACH_CORE(i) {
|
SPDK_ENV_FOREACH_CORE(i) {
|
||||||
spdk_cpuset_set_cpu(&g_vhost_core_mask, i, true);
|
spdk_cpuset_set_cpu(&g_vhost_core_mask, i, true);
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
init_cb(ret);
|
init_cb(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1565,9 +1550,6 @@ vhost_fini(void *arg1)
|
|||||||
}
|
}
|
||||||
spdk_vhost_unlock();
|
spdk_vhost_unlock();
|
||||||
|
|
||||||
/* All devices are removed now. */
|
|
||||||
sem_destroy(&g_dpdk_sem);
|
|
||||||
|
|
||||||
g_fini_cpl_cb();
|
g_fini_cpl_cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,13 @@
|
|||||||
|
|
||||||
extern bool g_packed_ring_recovery;
|
extern bool g_packed_ring_recovery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DPDK calls our callbacks synchronously but the work those callbacks
|
||||||
|
* perform needs to be async. Luckily, all DPDK callbacks are called on
|
||||||
|
* a DPDK-internal pthread, so we'll just wait on a semaphore in there.
|
||||||
|
*/
|
||||||
|
extern sem_t g_dpdk_sem;
|
||||||
|
|
||||||
#define SPDK_VHOST_MAX_VQUEUES 256
|
#define SPDK_VHOST_MAX_VQUEUES 256
|
||||||
#define SPDK_VHOST_MAX_VQ_SIZE 1024
|
#define SPDK_VHOST_MAX_VQ_SIZE 1024
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user