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: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I21b4c607977ed5926e0bb2743c33636cfc49f328
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8021
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
Tomasz Zawadzki 2021-05-24 11:44:08 -04:00 committed by Ben Walker
parent dd743a3285
commit 005b22d299

View File

@ -522,7 +522,6 @@ test_scheduler(void)
{ {
struct spdk_cpuset cpuset = {}; struct spdk_cpuset cpuset = {};
struct spdk_thread *thread[3]; struct spdk_thread *thread[3];
struct spdk_lw_thread *lw_thread;
struct spdk_reactor *reactor; struct spdk_reactor *reactor;
struct spdk_poller *busy, *idle; struct spdk_poller *busy, *idle;
uint64_t current_time; uint64_t current_time;
@ -563,35 +562,25 @@ test_scheduler(void)
/* Init threads stats (low load) */ /* Init threads stats (low load) */
/* Each reactor starts at 100 tsc, /* Each reactor starts at 100 tsc,
* ends at 100 + 10 + 90 = 200 tsc. */ * ends at 100 + 100 = 200 tsc. */
current_time = 100; current_time = 100;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
spdk_set_thread(thread[i]); spdk_set_thread(thread[i]);
/* FIXME: A single _reactor_run() iterates over all active pollers. idle = spdk_poller_register(poller_run_idle, (void *)100, 0);
* 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);
reactor = spdk_reactor_get(i); reactor = spdk_reactor_get(i);
CU_ASSERT(reactor != NULL); CU_ASSERT(reactor != NULL);
MOCK_SET(spdk_get_ticks, current_time); MOCK_SET(spdk_get_ticks, current_time);
reactor->tsc_last = spdk_get_ticks(); reactor->tsc_last = spdk_get_ticks();
_reactor_run(reactor); _reactor_run(reactor);
CU_ASSERT(reactor->tsc_last == 200); CU_ASSERT(reactor->tsc_last == 200);
spdk_poller_unregister(&busy);
spdk_poller_unregister(&idle); spdk_poller_unregister(&idle);
CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == 200); CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == 200);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0); CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 100); CU_ASSERT(stats.busy_tsc == 0);
CU_ASSERT(stats.idle_tsc == 0); CU_ASSERT(stats.idle_tsc == 100);
CU_ASSERT(reactor->busy_tsc == 100); CU_ASSERT(reactor->busy_tsc == 0);
CU_ASSERT(reactor->idle_tsc == 0); CU_ASSERT(reactor->idle_tsc == 100);
/* 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(spdk_get_ticks() == 200); CU_ASSERT(spdk_get_ticks() == 200);
current_time = 200; current_time = 200;
@ -623,13 +612,13 @@ test_scheduler(void)
MOCK_SET(spdk_get_ticks, current_time); MOCK_SET(spdk_get_ticks, current_time);
_reactor_run(reactor); _reactor_run(reactor);
CU_ASSERT(reactor->tsc_last == current_time); CU_ASSERT(reactor->tsc_last == current_time);
CU_ASSERT(reactor->busy_tsc == 100); CU_ASSERT(reactor->busy_tsc == 0);
CU_ASSERT(reactor->idle_tsc == 0); CU_ASSERT(reactor->idle_tsc == 100);
spdk_set_thread(thread[i]); spdk_set_thread(thread[i]);
CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == current_time); CU_ASSERT(spdk_thread_get_last_tsc(thread[i]) == current_time);
CU_ASSERT(spdk_thread_get_stats(&stats) == 0); CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 100); CU_ASSERT(stats.busy_tsc == 0);
CU_ASSERT(stats.idle_tsc == 0); CU_ASSERT(stats.idle_tsc == 100);
} }
CU_ASSERT(spdk_get_ticks() == current_time); 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(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_last_tsc(thread[i]) == (current_time + 100 * (i + 1)));
CU_ASSERT(spdk_thread_get_stats(&stats) == 0); CU_ASSERT(spdk_thread_get_stats(&stats) == 0);
CU_ASSERT(stats.busy_tsc == 200); CU_ASSERT(stats.busy_tsc == 100);
CU_ASSERT(stats.idle_tsc == 0); CU_ASSERT(stats.idle_tsc == 100);
} }
CU_ASSERT(reactor->busy_tsc == 400); CU_ASSERT(reactor->busy_tsc == 300);
CU_ASSERT(reactor->idle_tsc == 0); CU_ASSERT(reactor->idle_tsc == 100);
CU_ASSERT(spdk_get_ticks() == 500); CU_ASSERT(spdk_get_ticks() == 500);
current_time = 500; current_time = 500;