diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 69addc8bc2..b890f6e24e 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -908,7 +908,9 @@ _reactor_run(struct spdk_reactor *reactor) * tsc_last gets outdated. Update it to track * thread execution time correctly. */ if (spdk_unlikely(TAILQ_EMPTY(&reactor->threads))) { - reactor->tsc_last = spdk_get_ticks(); + now = spdk_get_ticks(); + reactor->idle_tsc += now - reactor->tsc_last; + reactor->tsc_last = now; return; } diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index eaeb381666..aaa1387442 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -382,7 +382,7 @@ test_reactor_stats(void) * Then, * - elapsed TSC of thread1 should be 2100 (= 2000+ 100). * - busy TSC of reactor should be 600 (= 500 + 100). - * - idle TSC of reactor should be 500 (= 500 + 0). + * - idle TSC of reactor should be 500 (= 500 + 900). */ MOCK_SET(spdk_env_get_current_core, 0); @@ -494,7 +494,7 @@ test_reactor_stats(void) CU_ASSERT(stats.idle_tsc == 0); CU_ASSERT(reactor->busy_tsc == 600); - CU_ASSERT(reactor->idle_tsc == 500); + CU_ASSERT(reactor->idle_tsc == 1400); /* 2000 + 100 = 2100 ticks elapsed */ CU_ASSERT(reactor->tsc_last == 2100);