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:
Shuhei Matsumoto 2020-03-08 20:52:09 -04:00 committed by Tomasz Zawadzki
parent 68161ffc00
commit fbb77a56c8

View File

@ -308,25 +308,12 @@ _set_thread_name(const char *thread_name)
static int _reactor_schedule_thread(struct spdk_thread *thread); static int _reactor_schedule_thread(struct spdk_thread *thread);
static uint64_t g_rusage_period; static uint64_t g_rusage_period;
static int static void
_spdk_reactor_run(void *arg) reactor_run(struct spdk_reactor *reactor)
{ {
struct spdk_reactor *reactor = arg; uint64_t now;
struct spdk_thread *thread; struct spdk_thread *thread;
struct spdk_lw_thread *lw_thread, *tmp; struct spdk_lw_thread *lw_thread, *tmp;
char thread_name[32];
int rc __attribute__((unused));
SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore);
/* Rename the POSIX thread because the reactor is tied to the POSIX
* thread in the SPDK event library.
*/
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
_set_thread_name(thread_name);
while (1) {
uint64_t now;
/* For each loop through the reactor, capture the time. This time /* For each loop through the reactor, capture the time. This time
* is used for all threads. */ * is used for all threads. */
@ -353,16 +340,37 @@ _spdk_reactor_run(void *arg)
} }
} }
if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING) {
break;
}
if (g_framework_context_switch_monitor_enabled) { if (g_framework_context_switch_monitor_enabled) {
if ((reactor->last_rusage + g_rusage_period) < now) { if ((reactor->last_rusage + g_rusage_period) < now) {
get_rusage(reactor); get_rusage(reactor);
reactor->last_rusage = now; reactor->last_rusage = now;
} }
} }
}
static int
_spdk_reactor_run(void *arg)
{
struct spdk_reactor *reactor = arg;
struct spdk_thread *thread;
struct spdk_lw_thread *lw_thread, *tmp;
char thread_name[32];
int rc __attribute__((unused));
SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore);
/* Rename the POSIX thread because the reactor is tied to the POSIX
* thread in the SPDK event library.
*/
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
_set_thread_name(thread_name);
while (1) {
reactor_run(reactor);
if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING) {
break;
}
} }
TAILQ_FOREACH_SAFE(lw_thread, &reactor->threads, link, tmp) { TAILQ_FOREACH_SAFE(lw_thread, &reactor->threads, link, tmp) {