From 0094a1ee988d12117c1d70968df751b7a7200382 Mon Sep 17 00:00:00 2001 From: Alexis Murzeau Date: Thu, 22 Aug 2024 15:55:13 +0200 Subject: [PATCH] damc: cpufreq: ignore first measure after changing frequency The measure cause bouncing between frequencies. --- damc/damc_simple_lib/CPUFrequencyScaling.cpp | 8 ++++++++ damc/damc_simple_lib/CPUFrequencyScaling.h | 1 + 2 files changed, 9 insertions(+) diff --git a/damc/damc_simple_lib/CPUFrequencyScaling.cpp b/damc/damc_simple_lib/CPUFrequencyScaling.cpp index a838b11..2e54b70 100644 --- a/damc/damc_simple_lib/CPUFrequencyScaling.cpp +++ b/damc/damc_simple_lib/CPUFrequencyScaling.cpp @@ -41,6 +41,7 @@ CPUFrequencyScaling::CPUFrequencyScaling(OscRoot* oscRoot) oscRoot(oscRoot), oscCurrentFrequency(this, "freq", SystemCoreClock), current_ahb_divider(1), + recent_ahb_divider_change(false), max_cpu_usage_ratio_per_million(0), cpu_usage_points(0), cpu_usage_points_target(0) { @@ -63,6 +64,12 @@ void CPUFrequencyScaling::resetFrequencyToMaxPerformance() { } void CPUFrequencyScaling::notifyCurrentCpuUsage(uint32_t cpu_usage_ratio_per_million) { + // Skip first measure after a frequency change + if(recent_ahb_divider_change) { + recent_ahb_divider_change = false; + return; + } + cpu_usage_points++; if(cpu_usage_ratio_per_million > max_cpu_usage_ratio_per_million) { max_cpu_usage_ratio_per_million = cpu_usage_ratio_per_million; @@ -120,6 +127,7 @@ uint32_t CPUFrequencyScaling::setAHBDivider(uint32_t divider) { HAL_InitTick(TICK_INT_PRIORITY); current_ahb_divider = ahb_divider; + recent_ahb_divider_change = true; // Reset cpu usage stats cpu_usage_points = 0; diff --git a/damc/damc_simple_lib/CPUFrequencyScaling.h b/damc/damc_simple_lib/CPUFrequencyScaling.h index 5783862..3fc8110 100644 --- a/damc/damc_simple_lib/CPUFrequencyScaling.h +++ b/damc/damc_simple_lib/CPUFrequencyScaling.h @@ -21,6 +21,7 @@ class CPUFrequencyScaling : public OscContainer { OscRoot* oscRoot; OscReadOnlyVariable oscCurrentFrequency; uint32_t current_ahb_divider; + bool recent_ahb_divider_change; uint32_t max_cpu_usage_ratio_per_million; uint32_t cpu_usage_points;