Commit 80323e20 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

lib/event: Count thread run time correctly on multiple threads per core



This patch updates reactor to count thread run time correctly
on multiple SPDK threads per CPU core configuration by using
the refined spdk_thread_poll().

Add tsc_last to struct spdk_reactor to use the end time of the
last thread as the start time of the next thread.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I21042867885d289ff0c23bf2a9ba6a8076a59673
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1256


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 avatarChangpeng Liu <changpeng.liu@intel.com>
parent 2139be15
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ struct spdk_reactor {
		uint32_t				reserved : 31;
	} flags;

	uint64_t					tsc_last;

	struct spdk_ring				*events;

	/* The last known rusage values */
+6 −8
Original line number Diff line number Diff line
@@ -313,19 +313,15 @@ 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);
		spdk_thread_poll(thread, 0, reactor->tsc_last);
		reactor->tsc_last = spdk_thread_get_last_tsc(thread);

		if (spdk_unlikely(lw_thread->resched)) {
			lw_thread->resched = false;
@@ -347,9 +343,9 @@ reactor_run(struct spdk_reactor *reactor)
	}

	if (g_framework_context_switch_monitor_enabled) {
		if ((reactor->last_rusage + g_rusage_period) < now) {
		if ((reactor->last_rusage + g_rusage_period) < reactor->tsc_last) {
			get_rusage(reactor);
			reactor->last_rusage = now;
			reactor->last_rusage = reactor->tsc_last;
		}
	}
}
@@ -371,6 +367,8 @@ _spdk_reactor_run(void *arg)
	snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
	_set_thread_name(thread_name);

	reactor->tsc_last = spdk_get_ticks();

	while (1) {
		reactor_run(reactor);