From 80323e20664b6dcbc94f69daad53744a4c12291a Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 13 Mar 2020 12:03:38 +0900 Subject: [PATCH] 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: Shuhei Matsumoto Change-Id: I21042867885d289ff0c23bf2a9ba6a8076a59673 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1256 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- include/spdk_internal/event.h | 2 ++ lib/event/reactor.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 282147d2a..5b73dd72b 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -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 */ diff --git a/lib/event/reactor.c b/lib/event/reactor.c index e0814c8b9..0ac7c15ba 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -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);