thread: Consolidate poller_remove_timer() calls into a single place

This enable us to optimize the cache update when RB tree is supported.

Call poller_remove_timer() after getting the next element because
as TAILQ_FOREACH_SAFE() and RB_FOREACH_SAFE() do, TAILQ_NEXT() may
not be valid after the current element is removed.

Previously, the patch had called poller_remove_timer() before getting
the next element. However, thanks to the nice testing, this bug was
found.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I18afb4412115dc1696cc568610cbe3dc618c2357
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7909
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-05-18 11:53:41 +09:00 committed by Tomasz Zawadzki
parent 3ca15e33e4
commit 83c197633f

View File

@ -784,11 +784,9 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
poller_remove_timer(thread, poller);
free(poller);
return 0;
case SPDK_POLLER_STATE_PAUSING:
poller_remove_timer(thread, poller);
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
poller->state = SPDK_POLLER_STATE_PAUSED;
return 0;
@ -815,11 +813,9 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
poller_remove_timer(thread, poller);
free(poller);
break;
case SPDK_POLLER_STATE_PAUSING:
poller_remove_timer(thread, poller);
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
poller->state = SPDK_POLLER_STATE_PAUSED;
break;
@ -829,7 +825,6 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll
poller->state = SPDK_POLLER_STATE_WAITING;
/* fallthrough */
case SPDK_POLLER_STATE_WAITING:
poller_remove_timer(thread, poller);
poller_insert_timer(thread, poller, now);
break;
default:
@ -881,6 +876,7 @@ thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now)
}
tmp = TAILQ_NEXT(poller, tailq);
poller_remove_timer(thread, poller);
timer_rc = thread_execute_timed_poller(thread, poller, now);
if (timer_rc > rc) {