lib/event: calculate last_stats in event framework

Rather than to rely on schedulers to access and modify
last_stats values over multiple scheduling periods, move that
operation to event framework.

Providing this to the schedulers in generic manner is better
than enforcing that each scheduler has to keep track of this
data on their own.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Icaf3b4af80d86fafaddf328fd230db9743d21ab5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7971
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
Tomasz Zawadzki 2021-05-19 05:47:34 -04:00 committed by Ben Walker
parent 005b22d299
commit 47a6578ee5
2 changed files with 7 additions and 6 deletions

View File

@ -674,11 +674,18 @@ 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;
/* Save last stats before replacing them. */
last_stats = lw_thread->current_stats;
lw_thread->lcore = reactor->lcore;
spdk_set_thread(thread);
spdk_thread_get_stats(&lw_thread->current_stats);
spdk_set_thread(NULL);
lw_thread->last_stats = last_stats;
}
static void
@ -1170,7 +1177,6 @@ _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;
@ -1184,9 +1190,7 @@ _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;
if (current_lcore != SPDK_ENV_LCORE_ID_ANY) {
local_reactor = spdk_reactor_get(current_lcore);

View File

@ -71,9 +71,6 @@ _get_thread_load(struct spdk_lw_thread *lw_thread)
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;
lw_thread->last_stats.busy_tsc = lw_thread->current_stats.busy_tsc;
lw_thread->last_stats.idle_tsc = lw_thread->current_stats.idle_tsc;
if (busy == 0) {
/* No work was done, exit before possible division by 0. */
return 0;