From 25baf7148de3a6dcb781d3bd7ff6324ad7dd7417 Mon Sep 17 00:00:00 2001 From: suhua Date: Thu, 21 Nov 2019 11:41:13 +0800 Subject: [PATCH] reactor: Change the context_switch period to microseconds Signed-off-by: suhua Change-Id: I95a4cc3cb5bef37e31a630171a47e28f14331494 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475333 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/event/reactor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 6bd0e11bb..3695c93e6 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -282,6 +282,7 @@ _spdk_event_queue_run_batch(struct spdk_reactor *reactor) return count; } +/* 1s */ #define CONTEXT_SWITCH_MONITOR_PERIOD 1000000 static int @@ -340,6 +341,7 @@ _spdk_reactor_run(void *arg) uint64_t last_rusage = 0; struct spdk_lw_thread *lw_thread, *tmp; char thread_name[32]; + uint64_t rusage_period = 0; SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore); @@ -349,6 +351,8 @@ _spdk_reactor_run(void *arg) snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore); _set_thread_name(thread_name); + rusage_period = (CONTEXT_SWITCH_MONITOR_PERIOD * spdk_get_ticks_hz()) / SPDK_SEC_TO_USEC; + while (1) { uint64_t now; int rc; @@ -374,7 +378,7 @@ _spdk_reactor_run(void *arg) } if (g_framework_monitor_context_switch_enabled) { - if ((last_rusage + CONTEXT_SWITCH_MONITOR_PERIOD) < now) { + if ((last_rusage + rusage_period) < now) { get_rusage(reactor); last_rusage = now; }