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) {