Commit 0d845de7 authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

fio_plugin/bdev: Assign spdk_threads created by SPDK modules to the init


thread

This allows SPDK modules to spawn spdk_threads and they'll get correctly
polled.

Change-Id: Ie5cadc130aeaa475eb44c0ea55b9a25dfeb29552
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11866


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent c4f8bff2
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -129,13 +129,36 @@ static TAILQ_HEAD(, spdk_fio_thread) g_threads = TAILQ_HEAD_INITIALIZER(g_thread
/* Default polling timeout (ns) */
#define SPDK_FIO_POLLING_TIMEOUT 1000000000ULL

static __thread bool g_internal_thread = false;

static int
spdk_fio_schedule_thread(struct spdk_thread *thread)
{
	struct spdk_fio_thread *fio_thread;

	if (g_internal_thread) {
		/* Do nothing. */
		return 0;
	}

	fio_thread = spdk_thread_get_ctx(thread);

	pthread_mutex_lock(&g_init_mtx);
	TAILQ_INSERT_TAIL(&g_threads, fio_thread, link);
	pthread_mutex_unlock(&g_init_mtx);

	return 0;
}

static int
spdk_fio_init_thread(struct thread_data *td)
{
	struct spdk_fio_thread *fio_thread;
	struct spdk_thread *thread;

	g_internal_thread = true;
	thread = spdk_thread_create("fio_thread", NULL);
	g_internal_thread = false;
	if (!thread) {
		SPDK_ERRLOG("failed to allocate thread\n");
		return -1;
@@ -299,7 +322,7 @@ spdk_init_thread_poll(void *arg)
#endif
	}

	spdk_thread_lib_init(NULL, sizeof(struct spdk_fio_thread));
	spdk_thread_lib_init(spdk_fio_schedule_thread, sizeof(struct spdk_fio_thread));

	/* Create an SPDK thread temporarily */
	rc = spdk_fio_init_thread(&td);