Commit 68161ffc authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I61bf50de6a170ac73c8fe17e85077b90171dd9c0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1185


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
parent e0294b00
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ struct spdk_reactor {

	/* The last known rusage values */
	struct rusage					rusage;
	uint64_t					last_rusage;
} __attribute__((aligned(SPDK_CACHE_LINE_SIZE)));

int spdk_reactors_init(void);
+4 −6
Original line number Diff line number Diff line
@@ -306,16 +306,15 @@ _set_thread_name(const char *thread_name)
}

static int _reactor_schedule_thread(struct spdk_thread *thread);
static uint64_t g_rusage_period;

static int
_spdk_reactor_run(void *arg)
{
	struct spdk_reactor	*reactor = arg;
	struct spdk_thread	*thread;
	uint64_t		last_rusage = 0;
	struct spdk_lw_thread	*lw_thread, *tmp;
	char			thread_name[32];
	uint64_t		rusage_period = 0;
	int			rc __attribute__((unused));

	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);
	_set_thread_name(thread_name);

	rusage_period = (CONTEXT_SWITCH_MONITOR_PERIOD * spdk_get_ticks_hz()) / SPDK_SEC_TO_USEC;

	while (1) {
		uint64_t now;

@@ -361,9 +358,9 @@ _spdk_reactor_run(void *arg)
		}

		if (g_framework_context_switch_monitor_enabled) {
			if ((last_rusage + rusage_period) < now) {
			if ((reactor->last_rusage + g_rusage_period) < now) {
				get_rusage(reactor);
				last_rusage = now;
				reactor->last_rusage = now;
			}
		}
	}
@@ -414,6 +411,7 @@ spdk_reactors_start(void)
	int rc;
	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;

	current_core = spdk_env_get_current_core();