From cd83ea4a6d7bd7c46d676213c65d119e0449241e Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 30 Apr 2021 23:25:15 +0900 Subject: [PATCH] thread: Add SPDK internal APIs spdk_thread_get_first/next_active/timed/paused_poller() The following patches will introduce red black tree to manage timed pollers efficiently but it will be based on macros available only in lib/thread/thread.c. Hence then it will be difficult to expose the internal of timed pollers tree outside the file. On the other hand, we do not want to include JSON into the file. Hence add a few SPDK internal APIs to iterate pollers list transparently. For spdk_thread_get_next_active/timed/pause_poller(), we omit the parameter thread and get it internally from poller->thread even if the names include the term "thread". This will be slightly cleaner. Signed-off-by: Shuhei Matsumoto Change-Id: I000801a2e4dc42fa79801a2fd6f2b06e1b769c88 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7717 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins --- include/spdk_internal/thread.h | 7 +++++++ lib/event/app_rpc.c | 20 +++++++++++++------ lib/thread/Makefile | 2 +- lib/thread/spdk_thread.map | 6 ++++++ lib/thread/thread.c | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/include/spdk_internal/thread.h b/include/spdk_internal/thread.h index 6d9e830d4..a29d7bdad 100644 --- a/include/spdk_internal/thread.h +++ b/include/spdk_internal/thread.h @@ -142,4 +142,11 @@ const char *spdk_poller_state_str(enum spdk_poller_state state); const char *spdk_io_device_get_name(struct io_device *dev); +struct spdk_poller *spdk_thread_get_first_active_poller(struct spdk_thread *thread); +struct spdk_poller *spdk_thread_get_next_active_poller(struct spdk_poller *prev); +struct spdk_poller *spdk_thread_get_first_timed_poller(struct spdk_thread *thread); +struct spdk_poller *spdk_thread_get_next_timed_poller(struct spdk_poller *prev); +struct spdk_poller *spdk_thread_get_first_paused_poller(struct spdk_thread *thread); +struct spdk_poller *spdk_thread_get_next_paused_poller(struct spdk_poller *prev); + #endif /* SPDK_THREAD_INTERNAL_H_ */ diff --git a/lib/event/app_rpc.c b/lib/event/app_rpc.c index b07bda12f..c7dede5bc 100644 --- a/lib/event/app_rpc.c +++ b/lib/event/app_rpc.c @@ -202,13 +202,18 @@ _rpc_thread_get_stats(void *arg) uint64_t timed_pollers_count = 0; uint64_t paused_pollers_count = 0; - TAILQ_FOREACH(poller, &thread->active_pollers, tailq) { + for (poller = spdk_thread_get_first_active_poller(thread); poller != NULL; + poller = spdk_thread_get_next_active_poller(poller)) { active_pollers_count++; } - TAILQ_FOREACH(poller, &thread->timed_pollers, tailq) { + + for (poller = spdk_thread_get_first_timed_poller(thread); poller != NULL; + poller = spdk_thread_get_next_timed_poller(poller)) { timed_pollers_count++; } - TAILQ_FOREACH(poller, &thread->paused_pollers, tailq) { + + for (poller = spdk_thread_get_first_paused_poller(thread); poller != NULL; + poller = spdk_thread_get_next_paused_poller(poller)) { paused_pollers_count++; } @@ -268,19 +273,22 @@ _rpc_thread_get_pollers(void *arg) spdk_json_write_named_uint64(ctx->w, "id", spdk_thread_get_id(thread)); spdk_json_write_named_array_begin(ctx->w, "active_pollers"); - TAILQ_FOREACH(poller, &thread->active_pollers, tailq) { + for (poller = spdk_thread_get_first_active_poller(thread); poller != NULL; + poller = spdk_thread_get_next_active_poller(poller)) { rpc_get_poller(poller, ctx->w); } spdk_json_write_array_end(ctx->w); spdk_json_write_named_array_begin(ctx->w, "timed_pollers"); - TAILQ_FOREACH(poller, &thread->timed_pollers, tailq) { + for (poller = spdk_thread_get_first_timed_poller(thread); poller != NULL; + poller = spdk_thread_get_next_timed_poller(poller)) { rpc_get_poller(poller, ctx->w); } spdk_json_write_array_end(ctx->w); spdk_json_write_named_array_begin(ctx->w, "paused_pollers"); - TAILQ_FOREACH(poller, &thread->paused_pollers, tailq) { + for (poller = spdk_thread_get_first_paused_poller(thread); poller != NULL; + poller = spdk_thread_get_next_paused_poller(poller)) { rpc_get_poller(poller, ctx->w); } spdk_json_write_array_end(ctx->w); diff --git a/lib/thread/Makefile b/lib/thread/Makefile index de4a09d85..fdaebd081 100644 --- a/lib/thread/Makefile +++ b/lib/thread/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 5 -SO_MINOR := 0 +SO_MINOR := 1 C_SRCS = thread.c LIBNAME = thread diff --git a/lib/thread/spdk_thread.map b/lib/thread/spdk_thread.map index 4f16fa7b8..0b0e3a952 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -59,6 +59,12 @@ # internal functions in spdk_internal/thread.h spdk_poller_state_str; spdk_io_device_get_name; + spdk_thread_get_first_active_poller; + spdk_thread_get_next_active_poller; + spdk_thread_get_first_timed_poller; + spdk_thread_get_next_timed_poller; + spdk_thread_get_first_paused_poller; + spdk_thread_get_next_paused_poller; local: *; }; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index c42b77903..aa0c31983 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1436,6 +1436,42 @@ spdk_poller_state_str(enum spdk_poller_state state) } } +struct spdk_poller * +spdk_thread_get_first_active_poller(struct spdk_thread *thread) +{ + return TAILQ_FIRST(&thread->active_pollers); +} + +struct spdk_poller * +spdk_thread_get_next_active_poller(struct spdk_poller *prev) +{ + return TAILQ_NEXT(prev, tailq); +} + +struct spdk_poller * +spdk_thread_get_first_timed_poller(struct spdk_thread *thread) +{ + return TAILQ_FIRST(&thread->active_pollers); +} + +struct spdk_poller * +spdk_thread_get_next_timed_poller(struct spdk_poller *prev) +{ + return TAILQ_NEXT(prev, tailq); +} + +struct spdk_poller * +spdk_thread_get_first_paused_poller(struct spdk_thread *thread) +{ + return TAILQ_FIRST(&thread->active_pollers); +} + +struct spdk_poller * +spdk_thread_get_next_paused_poller(struct spdk_poller *prev) +{ + return TAILQ_NEXT(prev, tailq); +} + struct call_thread { struct spdk_thread *cur_thread; spdk_msg_fn fn;