Commit 005b22d2 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Ben Walker
Browse files

ut/event: fix test_scheduler UT



This UT was not working as intended, and was covered by
scheduler implementation and direct modification
of the lw_thread stats in UT.

A single _reactor_run() iterates over all active pollers.
If at least one returns busy, so does the thread.
Thread load at the begining of UT is not 'low', but 100% busy.

To emulate loads outside of the 100% busy/idle, multiple
spdk_thread_polls need to be exectued.

As such to keep this case simple, the busy poller is removed.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent dd743a32
Loading
Loading
Loading
Loading
+14 −25
Original line number Diff line number Diff line
@@ -522,7 +522,6 @@ test_scheduler(void)
{
	struct spdk_cpuset cpuset = {};
	struct spdk_thread *thread[3];
	struct spdk_lw_thread *lw_thread;
	struct spdk_reactor *reactor;
	struct spdk_poller *busy, *idle;
	uint64_t current_time;
@@ -563,35 +562,25 @@ test_scheduler(void)

	/* Init threads stats (low load) */
	/* Each reactor starts at 100 tsc,
	 * ends at 100 + 10 + 90 = 200 tsc. */
	 * ends at 100 + 100 = 200 tsc. */
	current_time = 100;
	for (i = 0; i < 3; i++) {
		spdk_set_thread(thread[i]);
		/* FIXME: A single _reactor_run() iterates over all active pollers.
		 * If at least one returns busy, so does the thread. Load here is not
		 * 'low', but 100% busy. */
		busy = spdk_poller_register(poller_run_busy, (void *)10, 0);
		idle = spdk_poller_register(poller_run_idle, (void *)90, 0);
		idle = spdk_poller_register(poller_run_idle, (void *)100, 0);
		reactor = spdk_reactor_get(i);
		CU_ASSERT(reactor != NULL);
		MOCK_SET(spdk_get_ticks, current_time);
		reactor->tsc_last = spdk_get_ticks();
		_reactor_run(reactor);
		CU_ASSERT(reactor->tsc_last == 200);
		spdk_poller_unregister(&busy);
		spdk_poller_unregister(&idle);

		CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == 200);
		CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
		CU_ASSERT(stats.busy_tsc == 100);
		CU_ASSERT(stats.idle_tsc == 0);
		CU_ASSERT(reactor->busy_tsc == 100);
		CU_ASSERT(reactor->idle_tsc == 0);

		/* Update last stats so that we don't have to call scheduler twice */
		lw_thread = spdk_thread_get_ctx(thread[i]);
		lw_thread->last_stats.busy_tsc = UINT32_MAX;
		lw_thread->last_stats.idle_tsc = UINT32_MAX;
		CU_ASSERT(stats.busy_tsc == 0);
		CU_ASSERT(stats.idle_tsc == 100);
		CU_ASSERT(reactor->busy_tsc == 0);
		CU_ASSERT(reactor->idle_tsc == 100);
	}
	CU_ASSERT(spdk_get_ticks() == 200);
	current_time = 200;
@@ -623,13 +612,13 @@ test_scheduler(void)
		MOCK_SET(spdk_get_ticks, current_time);
		_reactor_run(reactor);
		CU_ASSERT(reactor->tsc_last == current_time);
		CU_ASSERT(reactor->busy_tsc == 100);
		CU_ASSERT(reactor->idle_tsc == 0);
		CU_ASSERT(reactor->busy_tsc == 0);
		CU_ASSERT(reactor->idle_tsc == 100);
		spdk_set_thread(thread[i]);
		CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == current_time);
		CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
		CU_ASSERT(stats.busy_tsc == 100);
		CU_ASSERT(stats.idle_tsc == 0);
		CU_ASSERT(stats.busy_tsc == 0);
		CU_ASSERT(stats.idle_tsc == 100);
	}
	CU_ASSERT(spdk_get_ticks() == current_time);

@@ -666,11 +655,11 @@ test_scheduler(void)
		CU_ASSERT(reactor->tsc_last == (current_time + 100 * (i + 1)));
		CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == (current_time + 100 * (i + 1)));
		CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
		CU_ASSERT(stats.busy_tsc == 200);
		CU_ASSERT(stats.idle_tsc == 0);
		CU_ASSERT(stats.busy_tsc == 100);
		CU_ASSERT(stats.idle_tsc == 100);
	}
	CU_ASSERT(reactor->busy_tsc == 400);
	CU_ASSERT(reactor->idle_tsc == 0);
	CU_ASSERT(reactor->busy_tsc == 300);
	CU_ASSERT(reactor->idle_tsc == 100);
	CU_ASSERT(spdk_get_ticks() == 500);
	current_time = 500;