From 80a13be9f51edf2c1e3b5f444b16a164b92d9fc9 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Mon, 18 Jan 2021 22:18:34 +0100 Subject: [PATCH] event: Save thread stats to last_stats field in spdk_lw_thread structure This field will be used in upcoming patches by scheduler to keep a history of threads statistics. Base on those scheduler will be able to calculate how busy a thread is. Also we have to save the value of this field while rescheduling thread. Signed-off-by: Maciej Szwed Change-Id: Iffbd1f946e1d159ec7277a39bc30161e71722456 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5972 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Shuhei Matsumoto Reviewed-by: Paul Luse --- include/spdk_internal/event.h | 1 + lib/event/reactor.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 5e9f8bf8c..d11cdb3a9 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -68,6 +68,7 @@ struct spdk_lw_thread { bool resched; struct spdk_thread_stats current_stats; struct spdk_thread_stats snapshot_stats; + struct spdk_thread_stats last_stats; }; struct spdk_reactor { diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 4aa2cd7c4..43ebc9f07 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -910,6 +910,7 @@ _reactor_schedule_thread(struct spdk_thread *thread) { uint32_t core; struct spdk_lw_thread *lw_thread; + struct spdk_thread_stats last_stats; struct spdk_event *evt = NULL; struct spdk_cpuset *cpumask; uint32_t i; @@ -919,7 +920,9 @@ _reactor_schedule_thread(struct spdk_thread *thread) lw_thread = spdk_thread_get_ctx(thread); assert(lw_thread != NULL); core = lw_thread->lcore; + last_stats = lw_thread->last_stats; memset(lw_thread, 0, sizeof(*lw_thread)); + lw_thread->last_stats = last_stats; pthread_mutex_lock(&g_scheduler_mtx); if (core == SPDK_ENV_LCORE_ID_ANY) {