From f6fb70730d9e897c74271b54940c91f840958cfe Mon Sep 17 00:00:00 2001 From: Michael Piszczek Date: Wed, 16 Dec 2020 20:25:53 -0500 Subject: [PATCH] thread: add spdk_poller_get_id Issue: spdk_top tracked pollers by the poller name string and the thread_id they are running on. This shows incorrect stats when multiple pollers exist on the same thread with the same name. Solution: Added a unique poller id for each poller on a thread and to allow spdk_top to track pollers by thread_id and poller_id. Signed-off-by: Michael Piszczek Change-Id: I1879e2afc9a929d1df9e8e35510f0092c5443bdc Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5868 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Tomasz Zawadzki --- doc/jsonrpc.md | 1 + include/spdk_internal/thread.h | 1 + lib/event/app_rpc.c | 1 + lib/thread/Makefile | 2 +- lib/thread/spdk_thread.map | 1 + lib/thread/thread.c | 18 ++++++++++++++++++ 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 7c30f17f4..2e272fec9 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -1310,6 +1310,7 @@ Example response: "timed_pollers": [ { "name": "spdk_rpc_subsystem_poll", + "id": 1, "state": "waiting", "run_count": 12345, "busy_count": 10000, diff --git a/include/spdk_internal/thread.h b/include/spdk_internal/thread.h index 752d45dd4..be2914790 100644 --- a/include/spdk_internal/thread.h +++ b/include/spdk_internal/thread.h @@ -48,6 +48,7 @@ struct io_device; struct spdk_thread; const char *spdk_poller_get_name(struct spdk_poller *poller); +uint64_t spdk_poller_get_id(struct spdk_poller *poller); const char *spdk_poller_get_state_str(struct spdk_poller *poller); uint64_t spdk_poller_get_period_ticks(struct spdk_poller *poller); void spdk_poller_get_stats(struct spdk_poller *poller, struct spdk_poller_stats *stats); diff --git a/lib/event/app_rpc.c b/lib/event/app_rpc.c index 883c86abb..3f7db6fd6 100644 --- a/lib/event/app_rpc.c +++ b/lib/event/app_rpc.c @@ -261,6 +261,7 @@ rpc_get_poller(struct spdk_poller *poller, struct spdk_json_write_ctx *w) spdk_json_write_object_begin(w); spdk_json_write_named_string(w, "name", spdk_poller_get_name(poller)); + spdk_json_write_named_uint64(w, "id", spdk_poller_get_id(poller)); spdk_json_write_named_string(w, "state", spdk_poller_get_state_str(poller)); spdk_json_write_named_uint64(w, "run_count", stats.run_count); spdk_json_write_named_uint64(w, "busy_count", stats.busy_count); diff --git a/lib/thread/Makefile b/lib/thread/Makefile index 846b32f52..484833409 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 := 6 -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 94b5c5e6b..672f2183e 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -58,6 +58,7 @@ # internal functions in spdk_internal/thread.h spdk_poller_get_name; + spdk_poller_get_id; spdk_poller_get_state_str; spdk_poller_get_period_ticks; spdk_poller_get_stats; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 17a760c71..53b3db1e6 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -91,6 +91,7 @@ struct spdk_poller { uint64_t next_run_tick; uint64_t run_count; uint64_t busy_count; + uint64_t id; spdk_poller_fn fn; void *arg; struct spdk_thread *thread; @@ -142,6 +143,7 @@ struct spdk_thread { size_t msg_cache_count; spdk_msg_fn critical_msg; uint64_t id; + uint64_t next_poller_id; enum spdk_thread_state state; int pending_unregister_count; @@ -438,6 +440,11 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask) thread->tsc_last = spdk_get_ticks(); + /* Monotonic increasing ID is set to each created poller beginning at 1. Once the + * ID exceeds UINT64_MAX a warning message is logged + */ + thread->next_poller_id = 1; + thread->messages = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY); if (!thread->messages) { SPDK_ERRLOG("Unable to allocate memory for message ring\n"); @@ -1518,6 +1525,11 @@ poller_register(spdk_poller_fn fn, poller->arg = arg; poller->thread = thread; poller->interruptfd = -1; + if (thread->next_poller_id == 0) { + SPDK_WARNLOG("Poller ID rolled over. Poller ID is duplicated.\n"); + thread->next_poller_id = 1; + } + poller->id = thread->next_poller_id++; poller->period_ticks = convert_us_to_ticks(period_microseconds); @@ -1712,6 +1724,12 @@ spdk_poller_get_name(struct spdk_poller *poller) return poller->name; } +uint64_t +spdk_poller_get_id(struct spdk_poller *poller) +{ + return poller->id; +} + const char * spdk_poller_get_state_str(struct spdk_poller *poller) {