From 154eb3399a82145ca22b78ebe690f942b08fe854 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 22 Feb 2019 08:58:46 -0500 Subject: [PATCH] thread: add spdk_thread_is_idle() This function add possibility to check if there are any scheduled operations on particular thread. Return from spdk_thread_poll() will be used as a way to load-balance and signify if any work was performed during the single iteration. A poller could return 0, but still be registered. This helps especially in fio_plugin that only checked active_pollers or messages via spdk_thread_poll(). Change-Id: Id6237278eb3b4bd4922b2abaa3c8ebd5e434d45d Signed-off-by: Tomasz Zawadzki Reviewed-on: https://review.gerrithub.io/c/445915 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Darek Stojaczyk --- CHANGELOG.md | 3 +++ examples/bdev/fio_plugin/fio_plugin.c | 8 ++++---- include/spdk/thread.h | 9 +++++++++ lib/thread/thread.c | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a3aeae2..41b280aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ strip_size. The strip_size rpc param is deprecated. Added spdk_thread_has_pollers() function to verify if there are any registered pollers to be run on the thread. +Added spdk_thread_is_idle() function to check if there are any scheduled operations +to be performed on the thread at given time. + ## v19.01: ### ocf bdev diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 96f029500..1fba71854 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -140,7 +140,9 @@ spdk_fio_cleanup_thread(struct spdk_fio_thread *fio_thread) { spdk_thread_send_msg(fio_thread->thread, spdk_fio_bdev_close_targets, fio_thread); - while (spdk_fio_poll_thread(fio_thread) > 0) {} + while (!spdk_thread_is_idle(fio_thread->thread)) { + spdk_fio_poll_thread(fio_thread); + } spdk_set_thread(fio_thread->thread); @@ -330,9 +332,7 @@ spdk_init_thread_poll(void *arg) do { spdk_fio_poll_thread(fio_thread); - } while (!done); - - while (spdk_fio_poll_thread(fio_thread) > 0) {}; + } while (!done && !spdk_thread_is_idle(fio_thread->thread)); spdk_fio_cleanup_thread(fio_thread); diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 2b864df42..26e589486 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -277,6 +277,15 @@ int spdk_thread_has_active_pollers(struct spdk_thread *thread); */ bool spdk_thread_has_pollers(struct spdk_thread *thread); +/** + * Returns whether there are scheduled operations to be run on the thread. + * + * \param thread The thread to check. + * + * \return true if there are no scheduled operations, false otherwise. + */ +bool spdk_thread_is_idle(struct spdk_thread *thread); + /** * Get count of allocated threads. */ diff --git a/lib/thread/thread.c b/lib/thread/thread.c index f4231bf44..33de40ab6 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -560,6 +560,17 @@ spdk_thread_has_pollers(struct spdk_thread *thread) return true; } +bool +spdk_thread_is_idle(struct spdk_thread *thread) +{ + if (spdk_ring_count(thread->messages) || + spdk_thread_has_pollers(thread)) { + return false; + } + + return true; +} + uint32_t spdk_thread_get_count(void) {