Commit 320fdaa3 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

ut/event: add current reactor tsc accounting



This patch does not change the UT in functional way.

Added accounting of last_tsc and spdk_get_ticks() similar
to the real application.
First the reactor_run() [not _reactor_run()] starts
reactor->tsc_last to current time. UT now set it at the start
and never touch it again directly.

Second the spdk_get_ticks() is updated to the elapsed time
to simulate flow of time, and make sure that its further
usage is up to date to the current time.

Fixed typo in test case description for test_reactor_stats.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Iaa2eb00fa3bffc2f21f1692da0259f1d023086b8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7904


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Community-CI: Mellanox Build Bot
parent af935f76
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ test_reactor_stats(void)
	 * - thread1 for 300 with idle
	 * - thread2 for 400 with busy.
	 * Then,
	 * - both elapsed TSC of thread1 and thread2 should be 1000 (= 100 + 900).
	 * - both elapsed TSC of thread1 and thread2 should be 1100 (= 100 + 1000).
	 * - busy TSC of reactor should be 500 (= 100 + 400).
	 * - idle TSC of reactor should be 500 (= 200 + 300).
	 */
@@ -384,7 +384,12 @@ test_reactor_stats(void)

	spdk_cpuset_set_cpu(&cpuset, 0, true);

	reactor = spdk_reactor_get(0);
	SPDK_CU_ASSERT_FATAL(reactor != NULL);

	/* First reactor_run() sets the tsc_last. */
	MOCK_SET(spdk_get_ticks, 100);
	reactor->tsc_last = spdk_get_ticks();

	thread1 = spdk_thread_create(NULL, &cpuset);
	SPDK_CU_ASSERT_FATAL(thread1 != NULL);
@@ -392,11 +397,6 @@ test_reactor_stats(void)
	thread2 = spdk_thread_create(NULL, &cpuset);
	SPDK_CU_ASSERT_FATAL(thread2 != NULL);

	reactor = spdk_reactor_get(0);
	SPDK_CU_ASSERT_FATAL(reactor != NULL);

	reactor->tsc_last = 100;

	spdk_set_thread(thread1);
	busy1 = spdk_poller_register(poller_run_busy, (void *)100, 0);
	CU_ASSERT(busy1 != NULL);
@@ -421,6 +421,9 @@ test_reactor_stats(void)
	CU_ASSERT(reactor->busy_tsc == 100);
	CU_ASSERT(reactor->idle_tsc == 300);

	/* 100 + 100 + 300 = 500 ticks elapsed */
	CU_ASSERT(reactor->tsc_last == 500);

	spdk_set_thread(thread1);
	spdk_poller_unregister(&busy1);
	idle1 = spdk_poller_register(poller_run_idle, (void *)200, 0);
@@ -447,6 +450,9 @@ test_reactor_stats(void)
	CU_ASSERT(reactor->busy_tsc == 500);
	CU_ASSERT(reactor->idle_tsc == 500);

	/* 500 + 200 + 400 = 1100 ticks elapsed */
	CU_ASSERT(reactor->tsc_last == 1100);

	spdk_set_thread(thread1);
	spdk_poller_unregister(&idle1);
	spdk_thread_exit(thread1);
@@ -459,6 +465,9 @@ test_reactor_stats(void)

	CU_ASSERT(TAILQ_EMPTY(&reactor->threads));

	/* No further than 1100 ticks elapsed */
	CU_ASSERT(reactor->tsc_last == 1100);

	spdk_reactors_fini();

	free_cores();