From d9f5da13e44048240c6c06b3302e7c59d1829707 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 7 May 2021 11:30:00 -0400 Subject: [PATCH] lib/event: change last_stats to only describe last scheduling period So far the schedulers had to calculate the diff of current_stats - last_stats on their own to get tsc from last scheduling period. Renamed the current_stats to total_stats, but kept the meaning as stats describing tsc for lifetime of a thread. Instead change the meaning of the last_stats to describe the tsc of only last scheduling period and change its name to current_stats. Signed-off-by: Tomasz Zawadzki Change-Id: I1a165ff7c1afe659b432c3127a351a96878d1f3d Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7843 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Paul Luse Reviewed-by: Shuhei Matsumoto Reviewed-by: Konrad Sztyber Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins --- include/spdk_internal/event.h | 4 +++- lib/event/reactor.c | 15 ++++++++------- lib/event/scheduler_dynamic.c | 6 +++--- test/unit/lib/event/reactor.c/reactor_ut.c | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index e885a4c1a..ff9c7acf3 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -66,8 +66,10 @@ struct spdk_lw_thread { uint32_t lcore; uint32_t new_lcore; bool resched; + /* stats over a lifetime of a thread */ + struct spdk_thread_stats total_stats; + /* stats during the last scheduling period */ struct spdk_thread_stats current_stats; - struct spdk_thread_stats last_stats; }; /** diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 3242d92e2..ce575deaf 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -674,18 +674,19 @@ static void _init_thread_stats(struct spdk_reactor *reactor, struct spdk_lw_thread *lw_thread) { struct spdk_thread *thread = spdk_thread_get_from_ctx(lw_thread); - struct spdk_thread_stats last_stats; + struct spdk_thread_stats prev_total_stats; - /* Save last stats before replacing them. */ - last_stats = lw_thread->current_stats; + /* Read total_stats before updating it to calculate stats during the last scheduling period. */ + prev_total_stats = lw_thread->total_stats; lw_thread->lcore = reactor->lcore; spdk_set_thread(thread); - spdk_thread_get_stats(&lw_thread->current_stats); + spdk_thread_get_stats(&lw_thread->total_stats); spdk_set_thread(NULL); - lw_thread->last_stats = last_stats; + lw_thread->current_stats.busy_tsc = lw_thread->total_stats.busy_tsc - prev_total_stats.busy_tsc; + lw_thread->current_stats.idle_tsc = lw_thread->total_stats.idle_tsc - prev_total_stats.idle_tsc; } static void @@ -1147,11 +1148,11 @@ _schedule_thread(void *arg1, void *arg2) reactor = spdk_reactor_get(current_core); assert(reactor != NULL); - /* Update current_stats to reflect state of thread + /* Update total_stats to reflect state of thread * at the end of the move. */ thread = spdk_thread_get_from_ctx(lw_thread); spdk_set_thread(thread); - spdk_thread_get_stats(&lw_thread->current_stats); + spdk_thread_get_stats(&lw_thread->total_stats); spdk_set_thread(NULL); TAILQ_INSERT_TAIL(&reactor->threads, lw_thread, link); diff --git a/lib/event/scheduler_dynamic.c b/lib/event/scheduler_dynamic.c index 063da396c..b0f65abf5 100644 --- a/lib/event/scheduler_dynamic.c +++ b/lib/event/scheduler_dynamic.c @@ -68,8 +68,8 @@ _get_thread_load(struct spdk_lw_thread *lw_thread) { uint64_t busy, idle; - busy = lw_thread->current_stats.busy_tsc - lw_thread->last_stats.busy_tsc; - idle = lw_thread->current_stats.idle_tsc - lw_thread->last_stats.idle_tsc; + busy = lw_thread->current_stats.busy_tsc; + idle = lw_thread->current_stats.idle_tsc; if (busy == 0) { /* No work was done, exit before possible division by 0. */ @@ -158,7 +158,7 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count, thread = spdk_thread_get_from_ctx(lw_thread); cpumask = spdk_thread_get_cpumask(thread); - thread_busy = lw_thread->current_stats.busy_tsc - lw_thread->last_stats.busy_tsc; + thread_busy = lw_thread->current_stats.busy_tsc; load = _get_thread_load(lw_thread); diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index 37e9a7b6f..833a88f84 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -824,7 +824,7 @@ test_governor(void) /* Update last stats so that we don't have to call scheduler twice */ lw_thread = spdk_thread_get_ctx(thread[i]); - lw_thread->last_stats.idle_tsc = 1; + lw_thread->current_stats.idle_tsc = 1; } reactor = spdk_reactor_get(0);