lib/event: Put period for getrusage() into struct spdk_reactor

This is a preparation to the next patch which factors out the main
polling loop of _spdk_reactor_run() into a helper function reactor_run().

One of the subsequent patches will support CPU power saving by
adding sleep into reactor_run(). We should not insert sleep between
the main polling loop and getrusage() because now is got before
entering the main polling loop.

To put getrusage() into reactor_run(), we need to maintain last_rusage
in struct spdk_reactor and maintain g_rusage_period as a global
variable. This patch does these changes.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I61bf50de6a170ac73c8fe17e85077b90171dd9c0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1185
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 23:45:21 -04:00 committed by Tomasz Zawadzki
parent e0294b002d
commit 68161ffc00
2 changed files with 5 additions and 6 deletions

View File

@ -81,6 +81,7 @@ struct spdk_reactor {
/* The last known rusage values */ /* The last known rusage values */
struct rusage rusage; struct rusage rusage;
uint64_t last_rusage;
} __attribute__((aligned(SPDK_CACHE_LINE_SIZE))); } __attribute__((aligned(SPDK_CACHE_LINE_SIZE)));
int spdk_reactors_init(void); int spdk_reactors_init(void);

View File

@ -306,16 +306,15 @@ _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 int static int
_spdk_reactor_run(void *arg) _spdk_reactor_run(void *arg)
{ {
struct spdk_reactor *reactor = arg; struct spdk_reactor *reactor = arg;
struct spdk_thread *thread; struct spdk_thread *thread;
uint64_t last_rusage = 0;
struct spdk_lw_thread *lw_thread, *tmp; struct spdk_lw_thread *lw_thread, *tmp;
char thread_name[32]; char thread_name[32];
uint64_t rusage_period = 0;
int rc __attribute__((unused)); int rc __attribute__((unused));
SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore); SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore);
@ -326,8 +325,6 @@ _spdk_reactor_run(void *arg)
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore); snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
_set_thread_name(thread_name); _set_thread_name(thread_name);
rusage_period = (CONTEXT_SWITCH_MONITOR_PERIOD * spdk_get_ticks_hz()) / SPDK_SEC_TO_USEC;
while (1) { while (1) {
uint64_t now; uint64_t now;
@ -361,9 +358,9 @@ _spdk_reactor_run(void *arg)
} }
if (g_framework_context_switch_monitor_enabled) { if (g_framework_context_switch_monitor_enabled) {
if ((last_rusage + rusage_period) < now) { if ((reactor->last_rusage + g_rusage_period) < now) {
get_rusage(reactor); get_rusage(reactor);
last_rusage = now; reactor->last_rusage = now;
} }
} }
} }
@ -414,6 +411,7 @@ spdk_reactors_start(void)
int rc; int rc;
char thread_name[32]; char thread_name[32];
g_rusage_period = (CONTEXT_SWITCH_MONITOR_PERIOD * spdk_get_ticks_hz()) / SPDK_SEC_TO_USEC;
g_reactor_state = SPDK_REACTOR_STATE_RUNNING; g_reactor_state = SPDK_REACTOR_STATE_RUNNING;
current_core = spdk_env_get_current_core(); current_core = spdk_env_get_current_core();