ut/common: add poll_thread_times() to poll select number of iterations

Right now functions poll_thread() and poll_threads(), polled
always until there were no further messages to process.
This allows to put next operation to execute only after
previous one completed.

Function poll_thread_times() allows to poll certain thread
for exact number of executions. If 0 is passed to max_polls,
then this function executes single message and all pollers,
until no messages are left.

With this change it is possible to only run a thread
selected number of iterations. Allowing to add another operation
without first one finishing.

It will become useful in blobstore UT, where two operations
will be executed with slight delay between them.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I4a6537695389f30130ea2fd2fd43d7b2cb2dea39
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/772
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Tomasz Zawadzki 2020-02-12 07:26:57 -05:00
parent 94675ba17b
commit d7aff25df0

View File

@ -44,6 +44,7 @@ int allocate_threads(int num_threads);
void free_threads(void);
void poll_threads(void);
bool poll_thread(uintptr_t thread_id);
bool poll_thread_times(uintptr_t thread_id, uint32_t max_polls);
struct ut_msg {
spdk_msg_fn fn;
@ -121,6 +122,37 @@ free_threads(void)
spdk_thread_lib_fini();
}
bool
poll_thread_times(uintptr_t thread_id, uint32_t max_polls)
{
bool busy = false;
struct ut_thread *thread = &g_ut_threads[thread_id];
uintptr_t original_thread_id;
uint32_t polls_executed = 0;
if (max_polls == 0) {
/* If max_polls is set to 0,
* poll until no operation is pending. */
return poll_thread(thread_id);
}
assert(thread_id != (uintptr_t)INVALID_THREAD);
assert(thread_id < g_ut_num_threads);
original_thread_id = g_thread_id;
set_thread(INVALID_THREAD);
while (polls_executed < max_polls) {
if (spdk_thread_poll(thread->thread, 1, 0) > 0) {
busy = true;
}
polls_executed++;
}
set_thread(original_thread_id);
return busy;
}
bool
poll_thread(uintptr_t thread_id)
{