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

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I24d4a52ecf885b6e7db749616ee1f95b82574dc5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7801


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent bd2fae2f
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -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);