Commit 2072d16e authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Changpeng Liu
Browse files

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: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467228


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
parent fa282f6c
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -43,12 +43,6 @@

#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);

/* Temporary cpuset for poll group assignment */
@@ -893,11 +887,27 @@ vhost_get_poll_group(struct spdk_cpuset *cpumask)
	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
vhost_session_start_done(struct spdk_vhost_session *vsession, int response)
{
	if (response == 0) {
		vsession->started = true;
		vsession->poll_group = _get_current_poll_group();
		assert(vsession->poll_group != NULL);
		assert(vsession->poll_group->ref < UINT_MAX);
		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.cb_fn = cb_fn;

	vsession->poll_group = pg;
	spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx);
	pthread_mutex_unlock(&g_vhost_mutex);

+5 −1
Original line number Diff line number Diff line
@@ -94,7 +94,11 @@
#define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \
	(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 rte_vhost_vring vring;