From 1068e22da526348f7a58d8d0ef2b467a923777a9 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 15 Jan 2019 13:45:59 -0700 Subject: [PATCH] thread: spdk_free_thread now takes a thread parameter Instead of implicitly grabbing the thread from the thread local variable, make it explicit. Change-Id: I733fad06181439e12b1e71a4829b84e7b64e2468 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/440595 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Darek Stojaczyk Chandler-Test-Pool: SPDK Automated Test System --- examples/bdev/fio_plugin/fio_plugin.c | 2 +- include/spdk/thread.h | 9 ++++++--- lib/event/reactor.c | 2 +- lib/thread/thread.c | 15 +++++---------- test/common/lib/ut_multithread.c | 3 ++- .../lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 6 ++---- test/unit/lib/nvmf/tcp.c/tcp_ut.c | 6 +++--- test/unit/lib/thread/thread.c/thread_ut.c | 4 ++-- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index c7aa0ae8b..4307f327e 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -143,7 +143,7 @@ spdk_fio_cleanup_thread(struct spdk_fio_thread *fio_thread) spdk_set_thread(fio_thread->thread); - spdk_free_thread(); + spdk_free_thread(fio_thread->thread); free(fio_thread->iocq); free(fio_thread); } diff --git a/include/spdk/thread.h b/include/spdk/thread.h index c53903b51..13c6b9c10 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -199,12 +199,15 @@ void spdk_thread_lib_fini(void); struct spdk_thread *spdk_allocate_thread(const char *name); /** - * Release any resources related to the calling thread for I/O channel allocation. + * Release any resources related to the given thread and destroy it. Execution + * continues on the current system thread after returning. * - * All I/O channel references related to the calling thread must be released using + * \param thread The thread to destroy. + * + * All I/O channel references associated with the thread must be released using * spdk_put_io_channel() prior to calling this function. */ -void spdk_free_thread(void); +void spdk_free_thread(struct spdk_thread *thread); /** * Perform one iteration worth of processing on the thread. This includes diff --git a/lib/event/reactor.c b/lib/event/reactor.c index b53a21a6f..e9b528b69 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -355,7 +355,7 @@ _spdk_reactor_run(void *arg) spdk_set_thread(thread); _spdk_reactor_context_switch_monitor_stop(reactor, NULL); - spdk_free_thread(); + spdk_free_thread(thread); return 0; } diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 11592f43c..9e5cb8e12 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -234,19 +234,16 @@ spdk_set_thread(struct spdk_thread *thread) } void -spdk_free_thread(void) +spdk_free_thread(struct spdk_thread *thread) { - struct spdk_thread *thread; struct spdk_io_channel *ch; - thread = _get_thread(); - if (!thread) { - SPDK_ERRLOG("No thread allocated\n"); - return; - } - SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Freeing thread %s\n", thread->name); + if (tls_thread == thread) { + tls_thread = NULL; + } + TAILQ_FOREACH(ch, &thread->io_channels, tailq) { SPDK_ERRLOG("thread %s still has channel for io_device %s\n", thread->name, ch->dev->name); @@ -265,8 +262,6 @@ spdk_free_thread(void) } free(thread); - - tls_thread = NULL; } static inline uint32_t diff --git a/test/common/lib/ut_multithread.c b/test/common/lib/ut_multithread.c index c559751ce..82bf3f26b 100644 --- a/test/common/lib/ut_multithread.c +++ b/test/common/lib/ut_multithread.c @@ -103,7 +103,8 @@ free_threads(void) for (i = 0; i < g_ut_num_threads; i++) { set_thread(i); - spdk_free_thread(); + spdk_free_thread(g_ut_threads[i].thread); + g_ut_threads[i].thread = NULL; } g_ut_num_threads = 0; diff --git a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index 2caa65509..0bb1472d8 100644 --- a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -364,7 +364,7 @@ fs_delete_file_without_close(void) static void terminate_spdk_thread(void *arg) { - spdk_free_thread(); + spdk_free_thread(spdk_get_thread()); pthread_exit(NULL); } @@ -395,8 +395,6 @@ spdk_thread(void *arg) spdk_set_thread(thread); } - spdk_free_thread(); - return NULL; } @@ -440,6 +438,6 @@ int main(int argc, char **argv) free(g_dev_buffer); send_request(terminate_spdk_thread, NULL); pthread_join(spdk_tid, NULL); - spdk_free_thread(); + spdk_free_thread(thread); return num_failures; } diff --git a/test/unit/lib/nvmf/tcp.c/tcp_ut.c b/test/unit/lib/nvmf/tcp.c/tcp_ut.c index ed431bee8..e95040529 100644 --- a/test/unit/lib/nvmf/tcp.c/tcp_ut.c +++ b/test/unit/lib/nvmf/tcp.c/tcp_ut.c @@ -266,7 +266,7 @@ test_nvmf_tcp_create(void) transport = spdk_nvmf_tcp_create(&opts); CU_ASSERT_PTR_NULL(transport); - spdk_free_thread(); + spdk_free_thread(thread); } static void @@ -294,7 +294,7 @@ test_nvmf_tcp_destroy(void) /* destroy transport */ CU_ASSERT(spdk_nvmf_tcp_destroy(transport) == 0); - spdk_free_thread(); + spdk_free_thread(thread); } static void @@ -313,7 +313,7 @@ test_nvmf_tcp_poll_group_create(void) CU_ASSERT_PTR_NOT_NULL(group); spdk_nvmf_tcp_poll_group_destroy(group); - spdk_free_thread(); + spdk_free_thread(thread); } static void diff --git a/test/unit/lib/thread/thread.c/thread_ut.c b/test/unit/lib/thread/thread.c/thread_ut.c index 9d999a19b..63d4e7a74 100644 --- a/test/unit/lib/thread/thread.c/thread_ut.c +++ b/test/unit/lib/thread/thread.c/thread_ut.c @@ -351,7 +351,7 @@ thread_name(void) SPDK_CU_ASSERT_FATAL(thread != NULL); name = spdk_thread_get_name(thread); CU_ASSERT(name != NULL); - spdk_free_thread(); + spdk_free_thread(thread); /* Create thread named "test_thread" */ thread = spdk_allocate_thread("test_thread"); @@ -361,7 +361,7 @@ thread_name(void) name = spdk_thread_get_name(thread); SPDK_CU_ASSERT_FATAL(name != NULL); CU_ASSERT(strcmp(name, "test_thread") == 0); - spdk_free_thread(); + spdk_free_thread(thread); } static uint64_t device1;