Commit de04fa74 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: If7d84c00fe1b666988fe06537836ba7b9cb161aa

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9580


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 1cfdbd42
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -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;
	}