scheduler_dynamic: exit early from _get_thread_load()
_get_thread_load() is function used to determine the load of a thread based on relation of busy/idle tsc from previous scheduling period. In order to avoid division by 0 calculating the percentage, we can simply exit early determining that thread was not doing any work. Having this check here will make sure that no matter the changes in event framework, scheduler dynamic will work. Removed the place that updated last_stats if they weren't yet updated at least once (first scheduling period iteration). In this case after change to _get_thread_load() will be the same, as only the latest iteration will be used to calculate thread load. Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I75f0f12f024675f2473a26e30596d6eb28093d46 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7917 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: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
parent
d172854aa7
commit
a4bf3e1099
@ -74,6 +74,10 @@ _get_thread_load(struct spdk_lw_thread *lw_thread)
|
||||
lw_thread->last_stats.busy_tsc = lw_thread->snapshot_stats.busy_tsc;
|
||||
lw_thread->last_stats.idle_tsc = lw_thread->snapshot_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);
|
||||
}
|
||||
@ -157,17 +161,6 @@ balance(struct spdk_scheduler_core_info *cores_info, int cores_count,
|
||||
thread = spdk_thread_get_from_ctx(lw_thread);
|
||||
cpumask = spdk_thread_get_cpumask(thread);
|
||||
|
||||
if (lw_thread->last_stats.busy_tsc + lw_thread->last_stats.idle_tsc == 0) {
|
||||
lw_thread->last_stats.busy_tsc = lw_thread->snapshot_stats.busy_tsc;
|
||||
lw_thread->last_stats.idle_tsc = lw_thread->snapshot_stats.idle_tsc;
|
||||
|
||||
if (i != g_main_lcore) {
|
||||
busy_threads_present = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
thread_busy = lw_thread->snapshot_stats.busy_tsc - lw_thread->last_stats.busy_tsc;
|
||||
|
||||
load = _get_thread_load(lw_thread);
|
||||
|
Loading…
Reference in New Issue
Block a user