Commit cd83ea4a authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
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: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent d5b7f3c5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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_ */
+14 −6
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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: *;
};
+36 −0
Original line number Diff line number Diff line
@@ -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;