From 85d70c03c56bf1c48e02eae86ff078918381ee2c Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 18 Nov 2022 17:57:07 +0000 Subject: [PATCH] thread: don't move to EXITED if there are pending messages At end of spdk_thread_poll(), if thread is in EXITING state, we call thread_exit() to see if the thread can move to EXITED state. If there are any pollers, io_channels or pending device unregistrations in progress, thread_exit() will keep the thread in EXITING mode for this iteration. But a thread may post messages to itself during this cleanup process, so thread_exit() should also check if there are any messages on its queue. Found during testing of spdk_thread lifetime patch set. rbd bdev module will send messages to itself like this during cleanup. Without this change, rbd module testing with bdevperf would cause an spdk_thread to move to EXITED state prematurely. Signed-off-by: Jim Harris Change-Id: Ie611026a67b7fa48640ae83be03e29a9c64883a2 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15533 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Aleksey Marchuk --- lib/thread/thread.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 58b410fce..510d1079c 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -523,6 +523,11 @@ thread_exit(struct spdk_thread *thread, uint64_t now) goto exited; } + if (spdk_ring_count(thread->messages) > 0) { + SPDK_INFOLOG(thread, "thread %s still has messages\n", thread->name); + return; + } + TAILQ_FOREACH(poller, &thread->active_pollers, tailq) { if (poller->state != SPDK_POLLER_STATE_UNREGISTERED) { SPDK_INFOLOG(thread,