thread: Eliminate function pointers in spdk_allocate_thread

These are no longer used by anything.

Change-Id: I0db6bc88e4dc945ff4f64df2ac410e1d00a669c1
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/437601
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2018-12-17 15:22:17 -07:00 committed by Darek Stojaczyk
parent 11654a6065
commit 6728c4f4c0
9 changed files with 13 additions and 58 deletions

View File

@ -104,7 +104,7 @@ spdk_fio_init_thread(struct thread_data *td)
fio_thread->td = td; fio_thread->td = td;
td->io_ops_data = fio_thread; td->io_ops_data = fio_thread;
fio_thread->thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "fio_thread"); fio_thread->thread = spdk_allocate_thread("fio_thread");
if (!fio_thread->thread) { if (!fio_thread->thread) {
free(fio_thread); free(fio_thread);
SPDK_ERRLOG("failed to allocate thread\n"); SPDK_ERRLOG("failed to allocate thread\n");

View File

@ -178,27 +178,13 @@ void spdk_thread_lib_fini(void);
/** /**
* Initializes the calling thread for I/O channel allocation. * Initializes the calling thread for I/O channel allocation.
* *
* \param msg_fn A function that may be called from any thread and is passed a function
* pointer (spdk_msg_fn) that must be called on the same thread that spdk_allocate_thread
* was called from.
* DEPRECATED. Only used in tests. Pass NULL for this parameter.
* \param start_poller_fn Function to be called to start a poller for the thread.
* DEPRECATED. Only used in tests. Pass NULL for this parameter.
* \param stop_poller_fn Function to be called to stop a poller for the thread.
* DEPRECATED. Only used in tests. Pass NULL for this parameter.
* \param thread_ctx Context that will be passed to msg_fn, start_poller_fn, and stop_poller_fn.
* DEPRECATED. Only used in tests. Pass NULL for this parameter.
* \param name Human-readable name for the thread; can be retrieved with spdk_thread_get_name(). * \param name Human-readable name for the thread; can be retrieved with spdk_thread_get_name().
* The string is copied, so the pointed-to data only needs to be valid during the * The string is copied, so the pointed-to data only needs to be valid during the
* spdk_allocate_thread() call. May be NULL to specify no name. * spdk_allocate_thread() call. May be NULL to specify no name.
* *
* \return a pointer to the allocated thread on success or NULL on failure.. * \return a pointer to the allocated thread on success or NULL on failure..
*/ */
struct spdk_thread *spdk_allocate_thread(spdk_thread_pass_msg msg_fn, struct spdk_thread *spdk_allocate_thread(const char *name);
spdk_start_poller start_poller_fn,
spdk_stop_poller stop_poller_fn,
void *thread_ctx,
const char *name);
/** /**
* Release any resources related to the calling thread for I/O channel allocation. * Release any resources related to the calling thread for I/O channel allocation.

View File

@ -291,7 +291,7 @@ _spdk_reactor_run(void *arg)
char thread_name[32]; char thread_name[32];
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore); snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, thread_name); thread = spdk_allocate_thread(thread_name);
if (!thread) { if (!thread) {
return -1; return -1;
} }

View File

@ -584,7 +584,7 @@ void SpdkInitializeThread(void)
struct spdk_thread *thread; struct spdk_thread *thread;
if (g_fs != NULL) { if (g_fs != NULL) {
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "spdk_rocksdb"); thread = spdk_allocate_thread("spdk_rocksdb");
spdk_set_thread(thread); spdk_set_thread(thread);
g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs); g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs);
} }

View File

@ -103,10 +103,6 @@ struct spdk_poller {
}; };
struct spdk_thread { struct spdk_thread {
spdk_thread_pass_msg msg_fn;
spdk_start_poller start_poller_fn;
spdk_stop_poller stop_poller_fn;
void *thread_ctx;
TAILQ_HEAD(, spdk_io_channel) io_channels; TAILQ_HEAD(, spdk_io_channel) io_channels;
TAILQ_ENTRY(spdk_thread) tailq; TAILQ_ENTRY(spdk_thread) tailq;
char *name; char *name;
@ -184,10 +180,7 @@ spdk_thread_lib_fini(void)
} }
struct spdk_thread * struct spdk_thread *
spdk_allocate_thread(spdk_thread_pass_msg msg_fn, spdk_allocate_thread(const char *name)
spdk_start_poller start_poller_fn,
spdk_stop_poller stop_poller_fn,
void *thread_ctx, const char *name)
{ {
struct spdk_thread *thread; struct spdk_thread *thread;
@ -197,22 +190,12 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
return NULL; return NULL;
} }
if ((start_poller_fn != NULL && stop_poller_fn == NULL) ||
(start_poller_fn == NULL && stop_poller_fn != NULL)) {
SPDK_ERRLOG("start_poller_fn and stop_poller_fn must either both be NULL or both be non-NULL\n");
return NULL;
}
thread = calloc(1, sizeof(*thread)); thread = calloc(1, sizeof(*thread));
if (!thread) { if (!thread) {
SPDK_ERRLOG("Unable to allocate memory for thread\n"); SPDK_ERRLOG("Unable to allocate memory for thread\n");
return NULL; return NULL;
} }
thread->msg_fn = msg_fn;
thread->start_poller_fn = start_poller_fn;
thread->stop_poller_fn = stop_poller_fn;
thread->thread_ctx = thread_ctx;
TAILQ_INIT(&thread->io_channels); TAILQ_INIT(&thread->io_channels);
TAILQ_INIT(&thread->active_pollers); TAILQ_INIT(&thread->active_pollers);
TAILQ_INIT(&thread->timer_pollers); TAILQ_INIT(&thread->timer_pollers);
@ -479,11 +462,6 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx
return; return;
} }
if (thread->msg_fn) {
thread->msg_fn(fn, ctx, thread->thread_ctx);
return;
}
msg = spdk_mempool_get(g_spdk_msg_mempool); msg = spdk_mempool_get(g_spdk_msg_mempool);
if (!msg) { if (!msg) {
assert(false); assert(false);
@ -516,10 +494,6 @@ spdk_poller_register(spdk_poller_fn fn,
return NULL; return NULL;
} }
if (thread->start_poller_fn) {
return thread->start_poller_fn(thread->thread_ctx, fn, arg, period_microseconds);
}
poller = calloc(1, sizeof(*poller)); poller = calloc(1, sizeof(*poller));
if (poller == NULL) { if (poller == NULL) {
SPDK_ERRLOG("Poller memory allocation failed\n"); SPDK_ERRLOG("Poller memory allocation failed\n");
@ -568,11 +542,6 @@ spdk_poller_unregister(struct spdk_poller **ppoller)
return; return;
} }
if (thread->stop_poller_fn) {
thread->stop_poller_fn(poller, thread->thread_ctx);
return;
}
if (poller->state == SPDK_POLLER_STATE_RUNNING) { if (poller->state == SPDK_POLLER_STATE_RUNNING) {
/* /*
* We are being called from the poller_fn, so set the state to unregistered * We are being called from the poller_fn, so set the state to unregistered

View File

@ -87,7 +87,7 @@ allocate_threads(int num_threads)
for (i = 0; i < g_ut_num_threads; i++) { for (i = 0; i < g_ut_num_threads; i++) {
set_thread(i); set_thread(i);
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, NULL); thread = spdk_allocate_thread(NULL);
assert(thread != NULL); assert(thread != NULL);
g_ut_threads[i].thread = thread; g_ut_threads[i].thread = thread;
} }

View File

@ -374,7 +374,7 @@ spdk_thread(void *arg)
struct spdk_thread *thread; struct spdk_thread *thread;
struct ut_request *req; struct ut_request *req;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "thread1"); thread = spdk_allocate_thread("thread1");
spdk_set_thread(thread); spdk_set_thread(thread);
while (1) { while (1) {
@ -428,7 +428,7 @@ int main(int argc, char **argv)
return CU_get_error(); return CU_get_error();
} }
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "thread0"); thread = spdk_allocate_thread("thread0");
spdk_set_thread(thread); spdk_set_thread(thread);
pthread_create(&spdk_tid, NULL, spdk_thread, NULL); pthread_create(&spdk_tid, NULL, spdk_thread, NULL);

View File

@ -204,7 +204,7 @@ test_nvmf_tcp_create(void)
struct spdk_nvmf_tcp_transport *ttransport; struct spdk_nvmf_tcp_transport *ttransport;
struct spdk_nvmf_transport_opts opts; struct spdk_nvmf_transport_opts opts;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, NULL); thread = spdk_allocate_thread(NULL);
SPDK_CU_ASSERT_FATAL(thread != NULL); SPDK_CU_ASSERT_FATAL(thread != NULL);
spdk_set_thread(thread); spdk_set_thread(thread);
@ -276,7 +276,7 @@ test_nvmf_tcp_destroy(void)
struct spdk_nvmf_transport *transport; struct spdk_nvmf_transport *transport;
struct spdk_nvmf_transport_opts opts; struct spdk_nvmf_transport_opts opts;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, NULL); thread = spdk_allocate_thread(NULL);
SPDK_CU_ASSERT_FATAL(thread != NULL); SPDK_CU_ASSERT_FATAL(thread != NULL);
spdk_set_thread(thread); spdk_set_thread(thread);
@ -304,7 +304,7 @@ test_nvmf_tcp_poll_group_create(void)
struct spdk_nvmf_transport_poll_group *group; struct spdk_nvmf_transport_poll_group *group;
struct spdk_thread *thread; struct spdk_thread *thread;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, NULL); thread = spdk_allocate_thread(NULL);
SPDK_CU_ASSERT_FATAL(thread != NULL); SPDK_CU_ASSERT_FATAL(thread != NULL);
spdk_set_thread(thread); spdk_set_thread(thread);

View File

@ -345,7 +345,7 @@ thread_name(void)
const char *name; const char *name;
/* Create thread with no name, which automatically generates one */ /* Create thread with no name, which automatically generates one */
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, NULL); thread = spdk_allocate_thread(NULL);
spdk_set_thread(thread); spdk_set_thread(thread);
thread = spdk_get_thread(); thread = spdk_get_thread();
SPDK_CU_ASSERT_FATAL(thread != NULL); SPDK_CU_ASSERT_FATAL(thread != NULL);
@ -354,7 +354,7 @@ thread_name(void)
spdk_free_thread(); spdk_free_thread();
/* Create thread named "test_thread" */ /* Create thread named "test_thread" */
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "test_thread"); thread = spdk_allocate_thread("test_thread");
spdk_set_thread(thread); spdk_set_thread(thread);
thread = spdk_get_thread(); thread = spdk_get_thread();
SPDK_CU_ASSERT_FATAL(thread != NULL); SPDK_CU_ASSERT_FATAL(thread != NULL);