thread: Change remaining direct accesses outside lib/thread to spdk_thread to helper functions

Use spdk_thread_get_last_tsc() and spdk_thread_get_stats() in
unit tests for reactor. As a result, we can change one inclusion
from spdk_internal/thread.h to spdk/thread.h.

This is the same effort as spdk_poller.

The following patches will move the definition of struct spdk_thread and
enum spdk_thread_state from include/spdk_internal/thread.h to
lib/thread/thread.c.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I24d4a52ecf885b6e7db749616ee1f95b82574dc5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7801
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
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 10:13:10 +09:00 committed by Tomasz Zawadzki
parent bd2fae2f0e
commit 6edc4abe4b

View File

@ -36,7 +36,7 @@
#include "spdk_cunit.h"
#include "common/lib/test_env.c"
#include "event/reactor.c"
#include "spdk_internal/thread.h"
#include "spdk/thread.h"
#include "event/scheduler_static.c"
#include "event/scheduler_dynamic.c"
@ -359,6 +359,7 @@ test_reactor_stats(void)
struct spdk_thread *thread1, *thread2;
struct spdk_reactor *reactor;
struct spdk_poller *busy1, *idle1, *busy2, *idle2;
struct spdk_thread_stats stats;
int rc __attribute__((unused));
/* Test case is the following:
@ -406,12 +407,16 @@ test_reactor_stats(void)
_reactor_run(reactor);
CU_ASSERT(thread1->tsc_last == 200);
CU_ASSERT(thread1->stats.busy_tsc == 100);
CU_ASSERT(thread1->stats.idle_tsc == 0);
CU_ASSERT(thread2->tsc_last == 500);
CU_ASSERT(thread2->stats.busy_tsc == 0);
CU_ASSERT(thread2->stats.idle_tsc == 300);
spdk_set_thread(thread1);
CU_ASSERT(spdk_thread_get_last_tsc(thread1) == 200);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 100);
CU_ASSERT(stats.idle_tsc == 0);
spdk_set_thread(thread2);
CU_ASSERT(spdk_thread_get_last_tsc(thread2) == 500);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 0);
CU_ASSERT(stats.idle_tsc == 300);
CU_ASSERT(reactor->busy_tsc == 100);
CU_ASSERT(reactor->idle_tsc == 300);
@ -428,12 +433,16 @@ test_reactor_stats(void)
_reactor_run(reactor);
CU_ASSERT(thread1->tsc_last == 700);
CU_ASSERT(thread1->stats.busy_tsc == 100);
CU_ASSERT(thread1->stats.idle_tsc == 200);
CU_ASSERT(thread2->tsc_last == 1100);
CU_ASSERT(thread2->stats.busy_tsc == 400);
CU_ASSERT(thread2->stats.idle_tsc == 300);
spdk_set_thread(thread1);
CU_ASSERT(spdk_thread_get_last_tsc(thread1) == 700);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 100);
CU_ASSERT(stats.idle_tsc == 200);
spdk_set_thread(thread2);
CU_ASSERT(spdk_thread_get_last_tsc(thread2) == 1100);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 400);
CU_ASSERT(stats.idle_tsc == 300);
CU_ASSERT(reactor->busy_tsc == 500);
CU_ASSERT(reactor->idle_tsc == 500);