From c4f8bff2b3d5327c906aa385242a079cf43a25b3 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 9 Mar 2022 10:26:13 -0700 Subject: [PATCH] fio_plugin/bdev: Use thread context space for spdk_fio_thread Instead of allocating this separately, use the thread context area. Signed-off-by: Ben Walker Change-Id: I2d5f4d223b15ff663e57f52237b3cc4dab43c291 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11865 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- examples/bdev/fio_plugin/fio_plugin.c | 28 ++++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 5660bb71f..bc99fc943 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -133,23 +133,20 @@ static int spdk_fio_init_thread(struct thread_data *td) { struct spdk_fio_thread *fio_thread; + struct spdk_thread *thread; - fio_thread = calloc(1, sizeof(*fio_thread)); - if (!fio_thread) { - SPDK_ERRLOG("failed to allocate thread local context\n"); - return -1; - } - - fio_thread->td = td; - td->io_ops_data = fio_thread; - - fio_thread->thread = spdk_thread_create("fio_thread", NULL); - if (!fio_thread->thread) { - free(fio_thread); + thread = spdk_thread_create("fio_thread", NULL); + if (!thread) { SPDK_ERRLOG("failed to allocate thread\n"); return -1; } - spdk_set_thread(fio_thread->thread); + + fio_thread = spdk_thread_get_ctx(thread); + fio_thread->td = td; + fio_thread->thread = thread; + td->io_ops_data = fio_thread; + + spdk_set_thread(thread); fio_thread->iocq_size = td->o.iodepth; fio_thread->iocq = calloc(fio_thread->iocq_size, sizeof(struct io_u *)); @@ -302,7 +299,7 @@ spdk_init_thread_poll(void *arg) #endif } - spdk_thread_lib_init(NULL, 0); + spdk_thread_lib_init(NULL, sizeof(struct spdk_fio_thread)); /* Create an SPDK thread temporarily */ rc = spdk_fio_init_thread(&td); @@ -387,9 +384,8 @@ spdk_init_thread_poll(void *arg) TAILQ_FOREACH_SAFE(thread, &g_threads, link, tmp) { if (spdk_thread_is_exited(thread->thread)) { TAILQ_REMOVE(&g_threads, thread, link); - spdk_thread_destroy(thread->thread); free(thread->iocq); - free(thread); + spdk_thread_destroy(thread->thread); } else { spdk_thread_poll(thread->thread, 0, 0); }