From f5313b55018bdb05da468efb49b6dee4ff60a699 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 3 May 2021 10:12:58 +0900 Subject: [PATCH] thread: Factor out removing timed poller from list into a helper function The following patches will update the cache to the closest timed poller when removing it from the list. To do it easier, factor out the operation to remove a timed poller from timed_pollers list into a helper function. Signed-off-by: Shuhei Matsumoto Change-Id: I25016d86117b240a2651d1f06e23bea0342211f1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7719 Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/thread/thread.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index b1cfe48353..75a9081987 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -578,6 +578,12 @@ poller_insert_timer(struct spdk_thread *thread, struct spdk_poller *poller, uint TAILQ_INSERT_HEAD(&thread->timed_pollers, poller, tailq); } +static inline void +poller_remove_timer(struct spdk_thread *thread, struct spdk_poller *poller) +{ + TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); +} + static void thread_insert_poller(struct spdk_thread *thread, struct spdk_poller *poller) { @@ -665,11 +671,11 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll switch (poller->state) { case SPDK_POLLER_STATE_UNREGISTERED: - TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); + poller_remove_timer(thread, poller); free(poller); return 0; case SPDK_POLLER_STATE_PAUSING: - TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); + poller_remove_timer(thread, poller); TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq); poller->state = SPDK_POLLER_STATE_PAUSED; return 0; @@ -696,14 +702,14 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll switch (poller->state) { case SPDK_POLLER_STATE_UNREGISTERED: - TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); + poller_remove_timer(thread, poller); free(poller); break; case SPDK_POLLER_STATE_PAUSED: break; case SPDK_POLLER_STATE_RUNNING: poller->state = SPDK_POLLER_STATE_WAITING; - TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); + poller_remove_timer(thread, poller); poller_insert_timer(thread, poller, now); break; default: @@ -1128,7 +1134,7 @@ period_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bool */ now_tick = now_tick - poller->period_ticks + ticks * old_tv.it_value.tv_sec + \ (ticks * old_tv.it_value.tv_nsec) / SPDK_SEC_TO_NSEC; - TAILQ_REMOVE(&poller->thread->timed_pollers, poller, tailq); + poller_remove_timer(poller->thread, poller); poller_insert_timer(poller->thread, poller, now_tick); } } @@ -1427,7 +1433,7 @@ spdk_poller_pause(struct spdk_poller *poller) break; case SPDK_POLLER_STATE_RUNNING: if (poller->period_ticks > 0) { - TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); + poller_remove_timer(thread, poller); } else { TAILQ_REMOVE(&thread->active_pollers, poller, tailq); }