vhost: assign poll group in vhost_session_start_done

Threads were assigned to sessions inside
vhost_session_send_event() so far, but even the doxygen
comments say that sessions would be assigned to the thread
which called vhost_session_start_done(). Currently, Vhost
uses only vhost_session_send_event() to schedule starting
the session on some thread, so the code ends up working.
We're about to remove vhost_session_send_event(), so move
the thread (poll group) assignment to start_done().

While here, publish the vhost_poll_group struct definition
via vhost_internal.h. As a replacement for
vhost_session_send_event() we would like to use
spdk_thread_send_msg() which a requires a thread object -
one of the struct fields inside vhost_poll_group.

The code for starting a session could look as follows:

pg = vhost_get_poll_group(cpumask);
spdk_thread_send_msg(pg->thread, cb);
...
cb:
  // start_pollers
  vhost_session_start_done(0);

Change-Id: I563f61509674768c1dea0b03767e9f39a9fb0069
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467228
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: Vitaliy Mysak <vitaliy.mysak@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-07-30 13:13:03 +02:00 committed by Changpeng Liu
parent fa282f6cb9
commit 2072d16e94
2 changed files with 21 additions and 8 deletions

View File

@ -43,12 +43,6 @@
#include "spdk_internal/memory.h" #include "spdk_internal/memory.h"
struct vhost_poll_group {
struct spdk_thread *thread;
unsigned ref;
TAILQ_ENTRY(vhost_poll_group) tailq;
};
static TAILQ_HEAD(, vhost_poll_group) g_poll_groups = TAILQ_HEAD_INITIALIZER(g_poll_groups); static TAILQ_HEAD(, vhost_poll_group) g_poll_groups = TAILQ_HEAD_INITIALIZER(g_poll_groups);
/* Temporary cpuset for poll group assignment */ /* Temporary cpuset for poll group assignment */
@ -893,11 +887,27 @@ vhost_get_poll_group(struct spdk_cpuset *cpumask)
return selected_pg; return selected_pg;
} }
static struct vhost_poll_group *
_get_current_poll_group(void)
{
struct vhost_poll_group *pg;
struct spdk_thread *cur_thread = spdk_get_thread();
TAILQ_FOREACH(pg, &g_poll_groups, tailq) {
if (pg->thread == cur_thread) {
return pg;
}
}
return NULL;
}
void void
vhost_session_start_done(struct spdk_vhost_session *vsession, int response) vhost_session_start_done(struct spdk_vhost_session *vsession, int response)
{ {
if (response == 0) { if (response == 0) {
vsession->started = true; vsession->started = true;
vsession->poll_group = _get_current_poll_group();
assert(vsession->poll_group != NULL); assert(vsession->poll_group != NULL);
assert(vsession->poll_group->ref < UINT_MAX); assert(vsession->poll_group->ref < UINT_MAX);
vsession->poll_group->ref++; vsession->poll_group->ref++;
@ -958,7 +968,6 @@ vhost_session_send_event(struct vhost_poll_group *pg,
ev_ctx.vsession_id = vsession->id; ev_ctx.vsession_id = vsession->id;
ev_ctx.cb_fn = cb_fn; ev_ctx.cb_fn = cb_fn;
vsession->poll_group = pg;
spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx); spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx);
pthread_mutex_unlock(&g_vhost_mutex); pthread_mutex_unlock(&g_vhost_mutex);

View File

@ -94,7 +94,11 @@
#define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \ #define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \
(1ULL << VIRTIO_F_NOTIFY_ON_EMPTY)) (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY))
struct vhost_poll_group; struct vhost_poll_group {
struct spdk_thread *thread;
unsigned ref;
TAILQ_ENTRY(vhost_poll_group) tailq;
};
struct spdk_vhost_virtqueue { struct spdk_vhost_virtqueue {
struct rte_vhost_vring vring; struct rte_vhost_vring vring;