thread: Change direct accesses to poller outside lib/thread to helper functions

Most accesses to the struct spdk_poller outside lib/thread have been
done via functions but a few direct accesses remain.

Change these to indirect accesses by addinng a few helper functions
as SPDK internal APIs.

Add spdk_poller_get_name() to get the name of the poller.

Remove spdk_poller_state_str() and add spdk_poller_get_state_str().
Exposing enum spdk_poller_state outside lib/thread is not really
necessary.

This removal requires us to update major SO version.

Add spdk_poller_get_period_ticks() to get the period ticks of the
poller.

Add struct spdk_poller_stats and spdk_poller_get_stats() to get
the stats of the poller.

The next patch will move the definition of struct spdk_poller and
enum spdk_poller_state from include/spdk_internal/thread.h to
lib/thread/thread.c.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Id597dae074a15fcd8af09fd9d416a22ce2f403c3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7798
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-05-07 08:02:30 +09:00 committed by Tomasz Zawadzki
parent 9ff6238b88
commit 1aec9334d9
5 changed files with 48 additions and 12 deletions

View File

@ -81,6 +81,11 @@ struct spdk_poller {
char name[SPDK_MAX_POLLER_NAME_LEN + 1];
};
struct spdk_poller_stats {
uint64_t run_count;
uint64_t busy_count;
};
enum spdk_thread_state {
/* The thread is pocessing poller and message by spdk_thread_poll(). */
SPDK_THREAD_STATE_RUNNING,
@ -138,7 +143,10 @@ struct spdk_thread {
uint8_t ctx[0];
};
const char *spdk_poller_state_str(enum spdk_poller_state state);
const char *spdk_poller_get_name(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);
const char *spdk_io_device_get_name(struct io_device *dev);

View File

@ -250,13 +250,19 @@ SPDK_RPC_REGISTER("thread_get_stats", rpc_thread_get_stats, SPDK_RPC_RUNTIME)
static void
rpc_get_poller(struct spdk_poller *poller, struct spdk_json_write_ctx *w)
{
struct spdk_poller_stats stats;
uint64_t period_ticks;
period_ticks = spdk_poller_get_period_ticks(poller);
spdk_poller_get_stats(poller, &stats);
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "name", poller->name);
spdk_json_write_named_string(w, "state", spdk_poller_state_str(poller->state));
spdk_json_write_named_uint64(w, "run_count", poller->run_count);
spdk_json_write_named_uint64(w, "busy_count", poller->busy_count);
if (poller->period_ticks) {
spdk_json_write_named_uint64(w, "period_ticks", poller->period_ticks);
spdk_json_write_named_string(w, "name", spdk_poller_get_name(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);
if (period_ticks) {
spdk_json_write_named_uint64(w, "period_ticks", period_ticks);
}
spdk_json_write_object_end(w);
}

View File

@ -34,8 +34,8 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 5
SO_MINOR := 1
SO_VER := 6
SO_MINOR := 0
C_SRCS = thread.c
LIBNAME = thread

View File

@ -57,7 +57,10 @@
spdk_interrupt_mode_is_enabled;
# internal functions in spdk_internal/thread.h
spdk_poller_state_str;
spdk_poller_get_name;
spdk_poller_get_state_str;
spdk_poller_get_period_ticks;
spdk_poller_get_stats;
spdk_io_device_get_name;
spdk_thread_get_first_active_poller;
spdk_thread_get_next_active_poller;

View File

@ -1491,9 +1491,15 @@ spdk_poller_resume(struct spdk_poller *poller)
}
const char *
spdk_poller_state_str(enum spdk_poller_state state)
spdk_poller_get_name(struct spdk_poller *poller)
{
switch (state) {
return poller->name;
}
const char *
spdk_poller_get_state_str(struct spdk_poller *poller)
{
switch (poller->state) {
case SPDK_POLLER_STATE_WAITING:
return "waiting";
case SPDK_POLLER_STATE_RUNNING:
@ -1509,6 +1515,19 @@ spdk_poller_state_str(enum spdk_poller_state state)
}
}
uint64_t
spdk_poller_get_period_ticks(struct spdk_poller *poller)
{
return poller->period_ticks;
}
void
spdk_poller_get_stats(struct spdk_poller *poller, struct spdk_poller_stats *stats)
{
stats->run_count = poller->run_count;
stats->busy_count = poller->busy_count;
}
struct spdk_poller *
spdk_thread_get_first_active_poller(struct spdk_thread *thread)
{