From 6edc4abe4bc85ffca2ee160d356185656ab05a5f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 7 May 2021 10:13:10 +0900 Subject: [PATCH] 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 Change-Id: I24d4a52ecf885b6e7db749616ee1f95b82574dc5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7801 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- test/unit/lib/event/reactor.c/reactor_ut.c | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index 3d5acbb37..347b0af29 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -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);