lib/event: Factor out the main polling loop from _spdk_reactor_run()
It was too difficult for us to add unit test for _spdk_reactor_run() because the main polling loop in _spdk_reactor_run() was infinite if g_reactor_state is SPDK_REACTOR_STATE_RUNNING. Factor out the main polling loop and rusage update in _spdk_reactor_run() into a helper function reactor_run(). This improves the code readability as well. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: Ia26db14f44026fefd696443227c16d2be4166832 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1186 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
parent
68161ffc00
commit
fbb77a56c8
@ -308,6 +308,46 @@ _set_thread_name(const char *thread_name)
|
||||
static int _reactor_schedule_thread(struct spdk_thread *thread);
|
||||
static uint64_t g_rusage_period;
|
||||
|
||||
static void
|
||||
reactor_run(struct spdk_reactor *reactor)
|
||||
{
|
||||
uint64_t now;
|
||||
struct spdk_thread *thread;
|
||||
struct spdk_lw_thread *lw_thread, *tmp;
|
||||
|
||||
/* For each loop through the reactor, capture the time. This time
|
||||
* is used for all threads. */
|
||||
now = spdk_get_ticks();
|
||||
|
||||
_spdk_event_queue_run_batch(reactor);
|
||||
|
||||
TAILQ_FOREACH_SAFE(lw_thread, &reactor->threads, link, tmp) {
|
||||
thread = spdk_thread_get_from_ctx(lw_thread);
|
||||
spdk_thread_poll(thread, 0, now);
|
||||
|
||||
if (spdk_unlikely(lw_thread->resched)) {
|
||||
lw_thread->resched = false;
|
||||
TAILQ_REMOVE(&reactor->threads, lw_thread, link);
|
||||
_reactor_schedule_thread(thread);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spdk_unlikely(spdk_thread_is_exited(thread) &&
|
||||
spdk_thread_is_idle(thread))) {
|
||||
TAILQ_REMOVE(&reactor->threads, lw_thread, link);
|
||||
spdk_thread_destroy(thread);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_framework_context_switch_monitor_enabled) {
|
||||
if ((reactor->last_rusage + g_rusage_period) < now) {
|
||||
get_rusage(reactor);
|
||||
reactor->last_rusage = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_spdk_reactor_run(void *arg)
|
||||
{
|
||||
@ -326,43 +366,11 @@ _spdk_reactor_run(void *arg)
|
||||
_set_thread_name(thread_name);
|
||||
|
||||
while (1) {
|
||||
uint64_t now;
|
||||
|
||||
/* For each loop through the reactor, capture the time. This time
|
||||
* is used for all threads. */
|
||||
now = spdk_get_ticks();
|
||||
|
||||
_spdk_event_queue_run_batch(reactor);
|
||||
|
||||
TAILQ_FOREACH_SAFE(lw_thread, &reactor->threads, link, tmp) {
|
||||
thread = spdk_thread_get_from_ctx(lw_thread);
|
||||
spdk_thread_poll(thread, 0, now);
|
||||
|
||||
if (spdk_unlikely(lw_thread->resched)) {
|
||||
lw_thread->resched = false;
|
||||
TAILQ_REMOVE(&reactor->threads, lw_thread, link);
|
||||
_reactor_schedule_thread(thread);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spdk_unlikely(spdk_thread_is_exited(thread) &&
|
||||
spdk_thread_is_idle(thread))) {
|
||||
TAILQ_REMOVE(&reactor->threads, lw_thread, link);
|
||||
spdk_thread_destroy(thread);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
reactor_run(reactor);
|
||||
|
||||
if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_framework_context_switch_monitor_enabled) {
|
||||
if ((reactor->last_rusage + g_rusage_period) < now) {
|
||||
get_rusage(reactor);
|
||||
reactor->last_rusage = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TAILQ_FOREACH_SAFE(lw_thread, &reactor->threads, link, tmp) {
|
||||
|
Loading…
Reference in New Issue
Block a user