From de04fa748f9fff60e51af6cb8d26e5d35aeeaa69 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 22 Sep 2021 09:45:35 -0700 Subject: [PATCH] scheduler/dynamic: add helper function to calculate busy pct This will be useful in some upcoming patches where we will be calculating these percentages in more places. Signed-off-by: Jim Harris Change-Id: If7d84c00fe1b666988fe06537836ba7b9cb161aa Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9580 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki Reviewed-by: Ben Walker --- module/scheduler/dynamic/scheduler_dynamic.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/module/scheduler/dynamic/scheduler_dynamic.c b/module/scheduler/dynamic/scheduler_dynamic.c index 35fc0059f..7023c4b53 100644 --- a/module/scheduler/dynamic/scheduler_dynamic.c +++ b/module/scheduler/dynamic/scheduler_dynamic.c @@ -54,6 +54,16 @@ static struct core_stats *g_cores; #define SCHEDULER_LOAD_LIMIT 20 #define SCHEDULER_CORE_LIMIT 95 +static uint8_t +_busy_pct(uint64_t busy, uint64_t idle) +{ + if ((busy + idle) == 0) { + return 0; + } + + return busy * 100 / (busy + idle); +} + static uint8_t _get_thread_load(struct spdk_scheduler_thread_info *thread_info) { @@ -62,12 +72,8 @@ _get_thread_load(struct spdk_scheduler_thread_info *thread_info) busy = thread_info->current_stats.busy_tsc; idle = thread_info->current_stats.idle_tsc; - if (busy == 0) { - /* No work was done, exit before possible division by 0. */ - return 0; - } /* return percentage of time thread was busy */ - return busy * 100 / (busy + idle); + return _busy_pct(busy, idle); } typedef void (*_foreach_fn)(struct spdk_scheduler_thread_info *thread_info); @@ -133,7 +139,7 @@ _is_core_over_limit(uint32_t core_id) } /* Work done was less than the limit */ - if (busy * 100 / (busy + idle) < SCHEDULER_CORE_LIMIT) { + if (_busy_pct(busy, idle) < SCHEDULER_CORE_LIMIT) { return false; }